public InMemoryCrudDataEndpoint( [NotNull] TypeConfiguration <T, TId> typeConfig, IEqualityComparer <T> comparer, [NotNull] IDictionary <TId, T> items) : this(typeConfig, comparer) { if (items == null) { throw new ArgumentNullException(nameof(items)); } _items = items; }
private ItemMatcher( [NotNull] TypeConfiguration <T1, TId> t1Config, [NotNull] TypeConfiguration <T2, TId> t2Config) { if (t1Config == null) { throw new ArgumentNullException(nameof(t1Config)); } if (t2Config == null) { throw new ArgumentNullException(nameof(t2Config)); } _t1Config = t1Config; _t2Config = t2Config; }
/// <summary> /// The create type instance. /// </summary> /// <param name="typeConfiguration"> The type configuration. </param> /// <typeparam name="T"> The type to return. </typeparam> /// <returns> The new instance of <see cref="T"/>. </returns> private static T CreateTypeInstance <T>(TypeConfiguration typeConfiguration) where T : class { if (typeConfiguration == null || string.IsNullOrEmpty(typeConfiguration.TypeName)) { return(null); } var loggerType = Type.GetType(typeConfiguration.TypeName); if (loggerType == null) { return(null); } return((T)Activator.CreateInstance(loggerType)); }
public void SetUpTest() { var type1Config = new TypeConfiguration <LocalTestResource, int>( ltr => ltr.CorrelationId.HasValue ? ltr.CorrelationId.Value : -1, -1); LocalEndpoint = new InMemoryCrudDataEndpoint <LocalTestResource, int>(type1Config, TestData.LocalResults); var endpoint1Config = new EndpointConfiguration <LocalTestResource, int>( type1Config, LocalEndpoint); var type2Config = new TypeConfiguration <RemoteTestResource, int>(rtr => rtr.Id, 0); RemoteEndpoint = new InMemoryCrudDataEndpoint <RemoteTestResource, int>(type2Config, TestData.RemoteResults); var endpoint2Config = new EndpointConfiguration <RemoteTestResource, int>( type2Config, RemoteEndpoint); // This clearly requires a configuration API. ChannelConfig = new ChannelConfiguration <LocalTestResource, RemoteTestResource, int, ItemMatch <LocalTestResource, RemoteTestResource> >(endpoint1Config, endpoint2Config, new TestResourceTranslator()); var itemsPreprocessor = new ItemMatcher <LocalTestResource, RemoteTestResource, int, ItemMatch <LocalTestResource, RemoteTestResource> >(ChannelConfig); ChannelConfig.ItemsPreprocessor = itemsPreprocessor.Match; var resolvers = new List <ISynchronizationResolver <ItemMatch <LocalTestResource, RemoteTestResource> > > { new SynchronizationResolver <ItemMatch <LocalTestResource, RemoteTestResource>, ChannelConfiguration <LocalTestResource, RemoteTestResource, int, ItemMatch <LocalTestResource, RemoteTestResource> > >( ChannelConfig, (item, cfg) => item.Result1 == null, (item, cfg) => { var synchItem = item.Result1; cfg.TypeTranslator.TranslateBackward(item.Result2, ref synchItem); // Now the translate decides wether a new item has to be created, but the decision is there anyway because of the Create. cfg.Type1EndpointConfiguration.Endpoint.Create(synchItem); return(new SynchronizationResult(true)); }) }; Plumber = new ItemMatchPipelinePlumber <LocalTestResource, RemoteTestResource, int>(ChannelConfig, resolvers, itemsPreprocessor.Match); ConstructTestSubject(); }
/// <summary> /// Adds an <see cref="object"/> and its dependencies to the <see cref="CurrentGraph"/>. /// </summary> /// <param name="value">The <see cref="object"/> to add.</param> /// <returns>The created <see cref="SerializeNode"/> representing <paramref name="value"/>.</returns> private SerializeNode GetNode(object value) { if (value != null && !TypeConfiguration.MatchAny().Match(value?.GetType())) { throw new TypeMatchException(TypeConfiguration.MatchAny(), value?.GetType()); } var existing = CurrentGraph.Nodes.FirstOrDefault(n => object.ReferenceEquals(n.Value, value)); if (existing != null) { //// Existing nodes should be reused. return(existing); } else { var node = new SerializeNode(currentId.ToString(), value); currentId++; //// Adds the newly-created node to the graph. CurrentGraph.AddNode(node); //// Check if dependencies need to be resolved or if the value is native/null. if (value != null && !TypeConfiguration.MatchNative().Match(value.GetType())) { //// Get all of the dependencies as connections (unique for each individual node, so can construct them here). var dependencies = Providers.GetDependencies(value) .Select(p => new SerializeDependency(p.Key, node, GetNode(p.Value))); foreach (var dep in dependencies) { //// Add new dependencies to the graph. CurrentGraph.AddConnection(dep); } } else { node.IsNative = true; } return(node); } }
public void SetUpTest() { var type1Config = new TypeConfiguration <LocalTestResource, int>(ltr => ltr.CorrelationId.HasValue ? ltr.CorrelationId.Value : -1); _localEndpoint = new InMemoryCrudDataEndpoint <LocalTestResource, int>(type1Config, TestData.LocalResults); var endpoint1Config = new EndpointConfiguration <LocalTestResource, int>( type1Config, _localEndpoint); var type2Config = new TypeConfiguration <RemoteTestResource, int>(rtr => rtr.Id); _remoteEndpoint = new InMemoryCrudDataEndpoint <RemoteTestResource, int>(type2Config, TestData.RemoteResults); var endpoint2Config = new EndpointConfiguration <RemoteTestResource, int>( type2Config, _remoteEndpoint); // This clearly requires a configuration API. var channelConfig = new ChannelConfiguration <LocalTestResource, RemoteTestResource, int, ItemMatch <LocalTestResource, RemoteTestResource> >(endpoint1Config, endpoint2Config, new TestResourceTranslator()); var itemsPreprocessor = new ItemMatcher <LocalTestResource, RemoteTestResource, int, ItemMatch <LocalTestResource, RemoteTestResource> >(channelConfig); channelConfig.ItemsPreprocessor = itemsPreprocessor.Match; channelConfig.AddSynchAction(new SynchronizationResolver <ItemMatch <LocalTestResource, RemoteTestResource>, ChannelConfiguration <LocalTestResource, RemoteTestResource, int, ItemMatch <LocalTestResource, RemoteTestResource> > >( channelConfig, (item, cfg) => { return(item.Result1 == null); }, (item, cfg) => { var synchItem = item.Result1; cfg.TypeTranslator.TranslateBackward(item.Result2, ref synchItem); // Now the translate decides wether a new item has to be created, but the decision is there anyway because of the Create. cfg.Type1EndpointConfiguration.Endpoint.Create(synchItem); return(new SynchronizationResult(true)); } )); //var t2epConfig = new EndpointConfiguration() _channelUnderTest = new OneWayPullChannel <LocalTestResource, RemoteTestResource, int, ItemMatch <LocalTestResource, RemoteTestResource> >( channelConfig, () => Task.FromResult(_localEndpoint.ReadAll().AsEnumerable()), () => Task.FromResult(_remoteEndpoint.ReadAll().AsEnumerable())); }
public void SetUpTest() { var type1Config = new TypeConfiguration<LocalTestResource, int>( ltr => ltr.CorrelationId.HasValue ? ltr.CorrelationId.Value : -1, -1); LocalEndpoint = new InMemoryCrudDataEndpoint<LocalTestResource, int>(type1Config, TestData.LocalResults); var endpoint1Config = new EndpointConfiguration<LocalTestResource, int>( type1Config, LocalEndpoint); var type2Config = new TypeConfiguration<RemoteTestResource, int>(rtr => rtr.Id, 0); RemoteEndpoint = new InMemoryCrudDataEndpoint<RemoteTestResource, int>(type2Config, TestData.RemoteResults); var endpoint2Config = new EndpointConfiguration<RemoteTestResource, int>( type2Config, RemoteEndpoint); // This clearly requires a configuration API. ChannelConfig = new ChannelConfiguration<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>(endpoint1Config, endpoint2Config, new TestResourceTranslator()); var itemsPreprocessor = new ItemMatcher<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>(ChannelConfig); ChannelConfig.ItemsPreprocessor = itemsPreprocessor.Match; var resolvers = new List<ISynchronizationResolver<ItemMatch<LocalTestResource, RemoteTestResource>>> { new SynchronizationResolver<ItemMatch<LocalTestResource,RemoteTestResource>, ChannelConfiguration<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>>( ChannelConfig, (item, cfg) => item.Result1 == null, (item, cfg) => { var synchItem = item.Result1; cfg.TypeTranslator.TranslateBackward(item.Result2, ref synchItem); // Now the translate decides wether a new item has to be created, but the decision is there anyway because of the Create. cfg.Type1EndpointConfiguration.Endpoint.Create(synchItem); return new SynchronizationResult(true); }) }; Plumber = new ItemMatchPipelinePlumber<LocalTestResource, RemoteTestResource, int>(ChannelConfig, resolvers, itemsPreprocessor.Match); ConstructTestSubject(); }
public static IObjectFieldDescriptor UsePaging( IObjectFieldDescriptor descriptor, Type?type, Type?entityType = null, GetPagingProvider?resolvePagingProvider = null, PagingOptions options = default) { if (descriptor is null) { throw new ArgumentNullException(nameof(descriptor)); } FieldMiddleware placeholder = next => context => default; descriptor .Use(placeholder) .Extend() .OnBeforeCreate((c, d) => { MemberInfo?member = d.ResolverMember ?? d.Member; IExtendedType schemaType = GetSchemaType(c.TypeInspector, member, type); var configuration = new TypeConfiguration <ObjectFieldDefinition> { Definition = d, On = ApplyConfigurationOn.Completion, Configure = (c, d) => ApplyConfiguration( c, d, entityType, resolvePagingProvider, options, placeholder) }; configuration.Dependencies.Add( new TypeDependency( TypeReference.Create(schemaType, TypeContext.Output), TypeDependencyKind.Named)); d.Configurations.Add(configuration); }); return(descriptor); }
public void SetUpTest() { var type1Config = new TypeConfiguration<LocalTestResource, int>(ltr => ltr.CorrelationId.HasValue ? ltr.CorrelationId.Value : -1); _localEndpoint = new InMemoryCrudDataEndpoint<LocalTestResource, int>(type1Config, TestData.LocalResults); var endpoint1Config = new EndpointConfiguration<LocalTestResource, int>( type1Config, _localEndpoint); var type2Config = new TypeConfiguration<RemoteTestResource, int>(rtr => rtr.Id); _remoteEndpoint = new InMemoryCrudDataEndpoint<RemoteTestResource, int>(type2Config, TestData.RemoteResults); var endpoint2Config = new EndpointConfiguration<RemoteTestResource, int>( type2Config, _remoteEndpoint); // This clearly requires a configuration API. var channelConfig = new ChannelConfiguration<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>(endpoint1Config, endpoint2Config, new TestResourceTranslator()); var itemsPreprocessor = new ItemMatcher<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>(channelConfig); channelConfig.ItemsPreprocessor = itemsPreprocessor.Match; channelConfig.AddSynchAction(new SynchronizationResolver<ItemMatch<LocalTestResource,RemoteTestResource>, ChannelConfiguration<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>>( channelConfig, (item, cfg) => { return item.Result1 == null; }, (item, cfg) => { var synchItem = item.Result1; cfg.TypeTranslator.TranslateBackward(item.Result2, ref synchItem); // Now the translate decides wether a new item has to be created, but the decision is there anyway because of the Create. cfg.Type1EndpointConfiguration.Endpoint.Create(synchItem); return new SynchronizationResult(true); } )); //var t2epConfig = new EndpointConfiguration() _channelUnderTest = new OneWayPullChannel<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>( channelConfig, () => Task.FromResult(_localEndpoint.ReadAll().AsEnumerable()), () => Task.FromResult(_remoteEndpoint.ReadAll().AsEnumerable())); }
public void Setup() { _config = new TypeConfiguration(typeof(Bar)); _fluent = new FluentTypeConfiguration(_config); }
public InMemoryCrudDataEndpoint([NotNull] TypeConfiguration <T, TId> typeConfig) : this(typeConfig, (IEqualityComparer <T>)null) { }
public InMemoryCrudDataEndpoint(TypeConfiguration <T, TId> typeConfig, IEnumerable <T> items) : this(typeConfig, items.ToDictionary(item => typeConfig.IdExtractor(item))) { }
public InMemoryCrudDataEndpoint( [NotNull] TypeConfiguration <T, TId> typeConfig, [NotNull] IDictionary <TId, T> items) : this(typeConfig, null, items) { }
public FluentTypeConfiguration(TypeConfiguration configuration) { _configuration = configuration; }
public static void AddConfiguration <TEntity>(this ModelBuilder modelBuilder, TypeConfiguration <TEntity> configuration, List <PropertyInfo> dbsets, string schema) where TEntity : class { var modelType = typeof(TEntity); var isInDbSet = dbsets.Any(x => x.PropertyType.GenericTypeArguments.First() == modelType); var baseType = modelType.GetTypeInfo().BaseType; if (!isInDbSet) { var isTablePerHierarchy = dbsets.Any(x => x.PropertyType.GenericTypeArguments.First() == baseType); var entityTypeConfiguration = new EntityTypeConfiguration(); entityTypeConfiguration.Map(modelBuilder.Entity <TEntity>(), true, schema, isTablePerHierarchy); } configuration.Map(modelBuilder.Entity <TEntity>()); }
public PropertyCommand(TypeConfiguration <T> .PropertyConfiguration configuration) : base(configuration.Property.GetMethod, configuration) { this.ParameterConfigurations = new IParameterConfiguration[0].AsReadOnly(); }
/// <summary> /// Constructs new instances of the object tree starting at the given <see cref="SerializeNode"/>, passing constructor parameters greedily where possible. /// </summary> /// <param name="startNode">The <see cref="SerializeNode"/> to start construction at.</param> private void Construct(SerializeNode startNode) { if (!constructed.Contains(startNode)) { try { if (startNode.IsNative) { //// Test only against native trusted types. if (startNode.DesiredType != null && !TypeConfiguration.MatchNative().Match(startNode.DesiredType)) { throw new TypeMatchException(TypeConfiguration.MatchNative(), startNode.DesiredType?.GetType()); } if (startNode.Value is JToken token) { if (token.Type == JTokenType.Null) { startNode.Value = null; } else { startNode.Value = token.ToObject(startNode.DesiredType); } constructed.Add(startNode); } else { throw new SerializationException("Native object not encapsulated in expected JToken value."); } } else { //// Test only against non-native trusted types. if (!TypeConfiguration.MatchTrusted().Match(startNode.DesiredType)) { throw new TypeMatchException(TypeConfiguration.MatchTrusted(), startNode.DesiredType?.GetType()); } //// Get all dependencies. var dependencies = CurrentGraph.GetConnections(startNode); dependencyMap.Add(startNode, new List <SerializeDependency>(dependencies)); //// Construct an object with non-circular dependencies. object newValue = Constructors.Construct( startNode.DesiredType, dependencies .Where(d => !IsCircular(d)) .ToDictionary( d => d.DependencyId, d => { Construct(d.EndNode); Populate(d.EndNode); return(d.EndNode.Value); }), out var usedKeys); dependencyMap[startNode].RemoveRange( dependencyMap[startNode].ToArray() .Where(d => usedKeys.Contains(d.DependencyId))); startNode.Value = newValue; constructed.Add(startNode); foreach (var dep in dependencyMap[startNode]) { Construct(dep.EndNode); } } } catch (Exception ex) { throw new SerializationException($"Constructing {GetPath(startNode)} failed.", ex); } } }
public MethodCommand(TypeConfiguration <T> .MethodConfiguration configuration) : base(configuration.Method, configuration) { this._configuration = configuration; }
public InputBuilder() { _typeConfiguration = new TypeConfiguration(this); _sizeConfiguration = new InputSizeConfiguration(this); _groupConfiguration = new GroupConfiguration(); }
public NativeMapsMasterViewModel(IServiceDispatcher serviceDispatcher) : base(serviceDispatcher) { Items.Add(new ViewModelMenuItem("Single Map", TypeConfiguration.Create <MapViewModel>(new { Title = "Single Map", ZoomLevel = 15.0, Center = new Location(48.21, 16.37) }))); Items.Add(new ViewModelMenuItem("Multiple Maps", TypeConfiguration.Create <MultipleMapViewModel>(new { Title = "Multiple Maps", ZoomLevel1 = 12.0, Center1 = new Location(48.21, 16.37), Markers1 = new ObservableCollection <Marker>(new List <Marker>() { new Marker() { Center = new Location(48.20, 16.37), Icon = "bus" }, new Marker() { Center = new Location(48.22, 16.37), Icon = "underground" }, new Marker() { Center = new Location(48.21, 16.36), Draggable = true }, new Marker() { Center = new Location(48.21, 16.38), Title = "Title", Content = "Content" } }), ZoomLevel2 = 9.0, Center2 = new Location(40.7536868, -73.9982661) }))); Items.Add(new ViewModelMenuItem("Tile Overlay Map", TypeConfiguration.Create <TileOverlayMapViewModel>(new { Title = "Tile Overlay Map", ZoomLevel = 12.0, Center = new Location(48.21, 16.37) }))); Items.Add(new ViewModelMenuItem("Satellite Map", TypeConfiguration.Create <MapViewModel>(new { Title = "Satellite Map", ZoomLevel = 15.0, Center = new Location(48.21, 16.37), MapType = MapType.Satellite }))); Items.Add(new ViewModelMenuItem("Two Way Map", TypeConfiguration.Create <TwoWayMapViewModel>(new { Title = "Two Way Map", ZoomLevel = 12.0, Center = new Location(48.21, 16.37), Markers = new ObservableCollection <Marker>(new List <Marker>() { new Marker() { Center = new Location(48.23, 16.37), Draggable = true }, new Marker() { Center = new Location(48.19, 16.37), Draggable = true } }) }))); }
public static IEndpointConfiguration <T, TId> CreateTestEndpointConfig <T, TId>(TypeConfiguration <T, TId> configuration) where TId : IEquatable <TId> { var endpoint = new InMemoryCrudDataEndpoint <T, TId>(configuration); return(new EndpointConfiguration <T, TId>(configuration, endpoint)); }