Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
azabluda committed Aug 30, 2017
2 parents 7eaf48c + d63084e commit 37106e4
Show file tree
Hide file tree
Showing 92 changed files with 1,329 additions and 2,372 deletions.
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
next-version: 1.0.0-dev
next-version: 2.0.0-dev

branches:
develop:
Expand Down
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ It is important to note that InfoCarrier.Core dictates neither the communication
### Credits:
InfoCarrier.Core is bringing together the following open source projects
* [Entity Framework Core](https://github.com/aspnet/EntityFramework) by Microsoft.
* [Remote.Linq](https://github.com/6bee/Remote.Linq) and [aqua-core](https://github.com/6bee/aqua-core) by Christof Senn. You will notice that we are directly using classes `Remote.Linq.Expressions.Expression` and `Aqua.Dynamic.DynamicObject` from these two libraries.
* [Remote.Linq](https://github.com/6bee/Remote.Linq) and [aqua-core](https://github.com/6bee/aqua-core) by Christof Senn.

## Sample

Expand Down Expand Up @@ -60,23 +60,25 @@ public class BloggingContext : DbContext

Implement `IInfoCarrierBackend` interface, e.g. using Windows Communication Foundation
```C#
using IC = InfoCarrier.Core.Common;

public class WcfBackendImpl : IInfoCarrierBackend
{
private readonly ChannelFactory<IMyRemoteService> channelFactory
= new ChannelFactory<IMyRemoteService>(...);

public IEnumerable<Aqua.Dynamic.DynamicObject> QueryData(Remote.Linq.Expressions.Expression rlinq)
public IC.QueryDataResult QueryData(IC.QueryDataRequest request)
{
IMyRemoteService channel = this.channelFactory.CreateChannel()
using ((IDisposable)channel)
{
return channel.ProcessQueryDataRequest(rlinq);
return channel.ProcessQueryDataRequest(request);
}
}

public InfoCarrier.Core.Common.SaveChangesResult SaveChanges(IReadOnlyList<IUpdateEntry> entries)
public IC.SaveChangesResult SaveChanges(IReadOnlyList<IUpdateEntry> entries)
{
var request = new InfoCarrier.Core.Common.SaveChangesRequest(entries);
var request = new IC.SaveChangesRequest(entries);

IMyRemoteService channel = this.channelFactory.CreateChannel()
using ((IDisposable)channel)
Expand Down Expand Up @@ -104,7 +106,7 @@ using (var context = new BloggingContext(optionsBuilder.Options))
where owner.login == "hi-its-me"
where post.Title == "my-blog-post"
select post).Single();

myBlogPost.Date = DateTime.Now;

context.SaveChanges();
Expand All @@ -119,9 +121,9 @@ Use `QueryDataHelper` and `SaveChangesHelper` classes to implement the backend s
[ServiceContract]
public interface IMyRemoteService
{
IEnumerable<DynamicObject> ProcessQueryDataRequest(Remote.Linq.Expressions.Expression rlinq);
SaveChangesResult ProcessSaveChangesRequest(SaveChangesResult request);
QueryDataResult ProcessQueryDataRequest(QueryDataRequest request);

SaveChangesResult ProcessSaveChangesRequest(SaveChangesRequest request);
}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
Expand All @@ -134,15 +136,15 @@ public class MyRemoteService : IMyRemoteService
return new BloggingContext(optionsBuilder.Options);
}

public IEnumerable<DynamicObject> ProcessQueryDataRequest(Remote.Linq.Expressions.Expression rlinq)
public QueryDataResult ProcessQueryDataRequest(QueryDataRequest request)
{
using (var helper = new QueryDataHelper(this.CreateDbContext, rlinq))
using (var helper = new QueryDataHelper(this.CreateDbContext, request))
{
return helper.QueryData();
}
}
public SaveChangesResult ProcessSaveChangesRequest(SaveChangesResult request)

public SaveChangesResult ProcessSaveChangesRequest(SaveChangesRequest request)
{
using (var helper = new SaveChangesHelper(this.CreateDbContext, request))
{
Expand Down
2 changes: 2 additions & 0 deletions Style.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
<Rule Id="IDE1005" Action="Warning" />
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA0001" Action="None" />
<Rule Id="SA1117" Action="Warning" />
<Rule Id="SA1118" Action="Info" />
<Rule Id="SA1202" Action="Info" />
<Rule Id="SA1204" Action="Info" />
<Rule Id="SA1214" Action="Info" />
<Rule Id="SA1215" Action="Info" />
<Rule Id="SA1600" Action="None" />
<Rule Id="SA1601" Action="None" />
<Rule Id="SA1602" Action="None" />
<Rule Id="SA1604" Action="None" />
Expand Down
7 changes: 6 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
image: Visual Studio 2017

environment:
Test__SqlServer__DefaultConnection: Server=(local)\SQL2016;Database=master;User ID=sa;Password=Password12!

services: mssql2016

before_build:
- dotnet --info
- dotnet restore
Expand All @@ -10,7 +15,7 @@ build_script:
- dotnet pack src\InfoCarrier.Core\InfoCarrier.Core.csproj --output "..\..\artifacts" --configuration Debug --include-symbols

test_script:
echo DISABLE!!! dotnet test test\InfoCarrier.Core.FunctionalTests\InfoCarrier.Core.FunctionalTests.csproj
- dotnet test test\InfoCarrier.Core.FunctionalTests\InfoCarrier.Core.FunctionalTests.csproj

artifacts:
path: artifacts
2 changes: 1 addition & 1 deletion pack.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ for /f "delims=" %%i in ('tools\GitVersion.CommandLine\tools\GitVersion.exe /sho

clean ^
&& dotnet restore ^
&& echo DISABLE!!! dotnet test test\InfoCarrier.Core.FunctionalTests\InfoCarrier.Core.FunctionalTests.csproj ^
&& dotnet test test\InfoCarrier.Core.FunctionalTests\InfoCarrier.Core.FunctionalTests.csproj ^
&& dotnet pack src\InfoCarrier.Core\InfoCarrier.Core.csproj --output "..\..\artifacts" --configuration Debug --include-symbols
51 changes: 51 additions & 0 deletions src/InfoCarrier.Core/AsyncEnumerableAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace InfoCarrier.Core
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

internal class AsyncEnumerableAdapter<T> : IAsyncEnumerable<T>
{
private readonly Func<IAsyncEnumerator<T>> enumeratorFactory;

public AsyncEnumerableAdapter(Task<IEnumerable<T>> asyncResult)
{
this.enumeratorFactory =
() => new AsyncEnumerator(asyncResult);
}

public IAsyncEnumerator<T> GetEnumerator() => this.enumeratorFactory();

private class AsyncEnumerator : IAsyncEnumerator<T>
{
private readonly Task<IEnumerable<T>> asyncResult;
private IEnumerator<T> enumerator;

public AsyncEnumerator(Task<IEnumerable<T>> asyncResult)
{
this.asyncResult = asyncResult;
}

public T Current =>
this.enumerator == null
? default(T)
: this.enumerator.Current;

public void Dispose()
{
this.enumerator?.Dispose();
}

public async Task<bool> MoveNext(CancellationToken cancellationToken)
{
if (this.enumerator == null)
{
this.enumerator = (await this.asyncResult).GetEnumerator();
}

return this.enumerator.MoveNext();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace InfoCarrier.Core.Client
{
using Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.ExpressionVisitors;
using Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.ValueGeneration;
using Microsoft.Extensions.DependencyInjection;
using Query.ExpressionVisitors.Internal;
using Query.Internal;
using Storage.Internal;

public static class InfoCarrierServiceCollectionExtensions
{
public static IServiceCollection AddEntityFrameworkInfoCarrierBackend(this IServiceCollection serviceCollection)
{
var builder = new EntityFrameworkServicesBuilder(serviceCollection)
.TryAdd<IQueryCompiler, InfoCarrierQueryCompiler>()
.TryAdd<IDatabaseProvider, DatabaseProvider<InfoCarrierOptionsExtension>>()
.TryAdd<IValueGeneratorSelector, RelationalValueGeneratorSelector>()
.TryAdd<IDatabase>(p => p.GetService<IInfoCarrierDatabase>())
.TryAdd<IDbContextTransactionManager, InfoCarrierTransactionManager>()
.TryAdd<IDatabaseCreator, InfoCarrierDatabaseCreator>()
.TryAdd<IQueryContextFactory, InfoCarrierQueryContextFactory>()
.TryAdd<IEntityQueryModelVisitorFactory, InfoCarrierQueryModelVisitorFactory>()
.TryAdd<IEntityQueryableExpressionVisitorFactory, InfoCarrierEntityQueryableExpressionVisitorFactory>()
.TryAddProviderSpecificServices(b => b
.TryAddScoped<IInfoCarrierDatabase, InfoCarrierDatabase>()
.TryAddScoped<IMaterializerFactory, MaterializerFactory>());

builder.TryAddCoreServices();

return serviceCollection;
}
}
}
8 changes: 4 additions & 4 deletions src/InfoCarrier.Core/Client/IInfoCarrierBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
{
using System.Collections.Generic;
using System.Threading.Tasks;
using Aqua.Dynamic;
using Common;
using Microsoft.EntityFrameworkCore.Update;
using Remote.Linq.Expressions;

public interface IInfoCarrierBackend
{
IEnumerable<DynamicObject> QueryData(Expression rlinq);
string LogFragment { get; }

Task<IEnumerable<DynamicObject>> QueryDataAsync(Expression rlinq);
QueryDataResult QueryData(QueryDataRequest request);

Task<QueryDataResult> QueryDataAsync(QueryDataRequest request);

SaveChangesResult SaveChanges(IReadOnlyList<IUpdateEntry> entries);

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@ public InfoCarrierOptionsExtension(InfoCarrierOptionsExtension copyFrom)

public IInfoCarrierBackend InfoCarrierBackend { get; set; }

public virtual void ApplyServices(IServiceCollection services)
public string LogFragment => this.InfoCarrierBackend.LogFragment;

public virtual bool ApplyServices(IServiceCollection services)
{
services.AddEntityFrameworkInfoCarrierBackend();
return true;
}

public virtual long GetServiceProviderHashCode() => 0;

public virtual void Validate(IDbContextOptions options)
{
}
}
}
Loading

0 comments on commit 37106e4

Please sign in to comment.