public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
 {
     var destValue = context.GetDestinationPropertyValue(destinationProperty.Name);
     if (destinationProperty.PropertyType.IsDefaultOrEmpty(destValue) == false)
         return Result.Unresolved;
     return inner.TryResolve(context, destinationProperty);
 }
 public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
 {
     var nested =  context.Nested(SourceProperty, destinationProperty);
     var executable = executor.CreateExecutableMapping(nested.SourceType);
     executable.Execute(nested);
     return new Result(true, nested.Destination);
 }
 public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
 {
     if(GetValue==null)
         throw new InvalidOperationException("GetValue was not assigned to this resolver.");
     if (context.Source == null)
         return Result.Unresolved;
     return new Result(true,GetValue(context.Source));
 }
 public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
 {
     if(inner==null)
     {
         inner = getResolver();
     }
     return inner.TryResolve(context, destinationProperty);
 }
 public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
 {
     //we need to keep the SOURCE the same, but change the destination
     var nested = context.Nested(destinationProperty);
     var executable = executor.CreateExecutableMapping(nested.SourceType);
     executable.Execute(nested);
     return new Result(true, nested.Destination);
 }
示例#6
0
 public IResolutionContext CreateNestedParallelContext(IDescribeMappableProperty sourceProperty, IDescribeMappableProperty destinationProperty, IResolutionContext parentContext)
 {
     var src = GetSourceValue(parentContext.Source, sourceProperty);
     var dest = GetDestValue(src,parentContext.Destination, destinationProperty);
     if (src == null && destinationProperty.IsCustomType)
         return new NullSourceContext(sourceProperty, valueAssignments, invoke, activate);
     return CreateContext(src, dest);
 }
示例#7
0
 public void Execute(IResolutionContext context)
 {
     foreach (var prop in destinationProperties.Where(p => resolverContainer.WillResolve(p)))
     {
         var assignment = context.BuildValueAssignment(prop);
         var resolver = resolverContainer.GetResolver(prop);
         var result = resolver.TryResolve(context, prop);
         assignment.SetValue(result);
     }
 }
 static ITransport GetTransport(IResolutionContext c)
 {
     try
     {
         return c.Get<ITransport>();
     }
     catch (Exception exception)
     {
         throw new RebusApplicationException(exception, @"Could not get transport - did you call 'EnableSagaAuditing' on a one-way client? (which is not capable of receiving messages, and therefore can never get to change the stage of any saga instances...)");
     }
 }
 public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
 {
     if (executor == null)
     {
         throw new DittoConfigurationException("UnflatteningResolver never bound an executable mapping on component type '{0}' for destination '{1}'. " +
             Environment.NewLine+
             "Be sure the type '{0}' is configured as a destination with source '{2}'",destinationType,context.Destination,context.SourceType);
     }
     //we need to keep the SOURCE the same, but change the destination
     var nested = context.Nested(destinationProperty);
     var executable = executor.CreateExecutableMapping(nested.SourceType);
     executable.Execute(nested);
     return new Result(true, nested.Destination);
 }
示例#10
0
        public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
        {
            var collectionContext = context.Nested(sourceProperty, destinationProperty);
            var src = (IList) context.GetSourcePropertyValue(sourceProperty.Name);
            var dest = (IList)activate.CreateCollectionInstance(destinationProperty.PropertyType, src.Count);
            for (int i = 0; i < src.Count; i++)
            {
                var sourceElement = sourceProperty.ElementAt(i);
                var elementContext = collectionContext.Nested(sourceElement, destinationProperty.ElementAt(i));
                var nestedExecutor = this.executor.CreateExecutableMapping(sourceElement.PropertyType);
                nestedExecutor.Execute(elementContext);
                dest.AddElement(elementContext.Destination,i);
            }

            return new Result(true, dest);
        }
示例#11
0
        public IFilter GetFailingFilter(IResolutionContext context)
        {
            if (Filters.Count != 2)
            {
                throw new AlgorythmException("XOR group can only contain two filters");
            }

            var result1 = Filters[0].GetFailingFilter(context) == null;
            var result2 = Filters[1].GetFailingFilter(context) == null;
            if (result1 ^ result2)
            {
                return null;
            }

            return this;
        }
示例#12
0
        public IFilter GetFailingFilter(IResolutionContext context)
        {
            IEnumerable<IResolutionContext> argument = dependency.GetValue(context);

            if (!argument.Any())
            {
                return this;
            }

            if (argument.Any(x => x.MeetsConditions))
            {
                return null;
            }

            return argument.Select(x => x.FailingFilter)
                           .OrderByDescending(x => context.Node.Tree.FilterIndex.SafeGet(x))
                           .First();
        }
        static ISagaSnapshotStorage GetSagaSnapshotStorage(IResolutionContext c)
        {
            try
            {
                return c.Get<ISagaSnapshotStorage>();
            }
            catch (Exception exception)
            {
                throw new RebusApplicationException(exception, @"Could not get saga snapshot storage - did you call 'EnableSagaAuditing' without choosing a way to store the snapshots?

When you enable the saving of saga data snapshots, you must specify how to save them - it can be done by making further calls after 'EnableSagaAuditing', e.g. like so:

Configure.With(..)
    .(...)
    .Options(o => o.EnableSagaAuditing().StoreInSqlServer(....))
    .(...)");
            }
        }
        static IDataBusStorage GetDataBusStorage(IResolutionContext c)
        {
            try
            {
                return c.Get<IDataBusStorage>();
            }
            catch (Exception exception)
            {
                throw new RebusApplicationException(exception, @"Could not get data bus storage - did you call 'EnableDataBus' without choosing a way to store the data?

When you enable the data bus, you must specify how to save data - it can be done by making further calls after 'EnableDataBus', e.g. like so:

Configure.With(..)
    .(...)
    .Options(o => o.EnableDataBus().StoreInSqlServer(....))
    .(...)");

            }
        }
示例#15
0
 public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
 {
     return Result.Unresolved;
 }
示例#16
0
 public IEnumerable<IResolutionContext> Resolve(IResolutionContext parentContext, INode node)
 {
     return new[] { new ResolutionContext<IFilterGroup>(group, node, parentContext, store) };
 }
示例#17
0
 public IResolutionContext CreateNestedContext(IDescribeMappableProperty destinationProperty, IResolutionContext parentContext)
 {
     return inner.CreateNestedContext(destinationProperty, parentContext);
 }
 public virtual Task <object> Execute(IResolutionContext context, FieldResolutionDelegate next)
 {
     return(next(context));
 }
示例#19
0
 public IEnumerable <IResolutionContext> Resolve(IResolutionContext parentContext, INode node)
 {
     return(new[] { new ResolutionContext <IFilterGroup>(group, node, parentContext, store) });
 }
示例#20
0
 public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
 {
     return(Result.Unresolved);
 }
 public object Resolve(IResolutionContext context, Type serviceType)
 {
     return(_container.GetRequiredService(serviceType));
 }
 public object Resolve(IResolutionContext context, Type serviceType)
 {
     return _service;
 }
    static IProducerImplementation RegisterProducerImplementation(IEnumerable <string> bootstrapServers, IResolutionContext c, KafkaProducerConfigurationBuilder builder)
    {
        var loggerFactory = c.Get <ILoggerFactory>();

        return(new KafkaProducerImplementation(
                   loggerFactory: loggerFactory,
                   address: string.Join(";", bootstrapServers),
                   configurationCustomizer: builder.Apply
                   ));
    }
示例#24
0
 public IFilter GetFailingFilter(IResolutionContext context)
 {
     return(Filters.Any(filter => filter.GetFailingFilter(context) == null) ? null : this);
 }
 public IEnumerable <TItem> GetValue(IResolutionContext context)
 {
     return(context.GetFromTree(Token)
            .Cast <IResolutionContext <TItem> >()
            .Select(x => x.Value));
 }
示例#26
0
        public TItem GetValue(IResolutionContext context)
        {
            var definedcontext = context.ResolveSingle(Token) as IResolutionContext <TItem>;

            return(definedcontext.Value);
        }
        private static IEnumerable <NamedResolutionAttempt <ReadonlyProviderSetup> > TryResolveGroupReaders(IResolutionContext ctx, string[] mappedReaderKeys)
        {
            // First get the readers. Not all specified reader keys might exist if a provider is just read-write,
            // so for any that we don't find, we'll try to resolve a writer that matches the key

            var readerResolutionAttempts = mappedReaderKeys.Select(s =>
            {
                var resolveResult = ctx.TryResolve <ReadonlyProviderSetup>(s);
                return(resolveResult);
            })
                                           //.Where(y => y.Success).Select(y => y.Value).ToList();
                                           .OrderBy(x => x.Success ? x.Value.PriorityOrdinal : 999).ToList();

            // These readers were not found
            var notFoundReaderKeys = readerResolutionAttempts.Where(y => !y.Success).Select(y => y.Key).ToArray();

            // So try to resolve writers with matching keys
            var tryFindWriters = TryResolveGroupReadWriters(ctx, notFoundReaderKeys);

            // We need to return a sequence of ResolutionAttempt<ReadonlyProviderSetup>
            // Where we have found neither a reader nor a writer, need to include the error from both
            var expressWritersAsReaders = tryFindWriters
                                          .Select(y =>
            {
                if (!y.Success)
                {
                    return(new NamedResolutionAttempt <ReadonlyProviderSetup>(y.Key, y.Error));
                }

                var providerSetup    = y.Value;
                var newProviderSetup = (providerSetup is UninstalledProviderSetup)
                                                   ? new UninstalledReadonlyProviderSetup(
                    providerSetup.ProviderMetadata,
                    providerSetup.FrameworkContext,
                    providerSetup.Bootstrapper,
                    providerSetup.PriorityOrdinal)
                                                   : new ReadonlyProviderSetup(
                    new ReadonlyProviderUnitFactory
                        (providerSetup.UnitFactory.EntityRepositoryFactory),
                    providerSetup.ProviderMetadata,
                    providerSetup.FrameworkContext,
                    providerSetup.Bootstrapper,
                    providerSetup.PriorityOrdinal);

                return(new NamedResolutionAttempt <ReadonlyProviderSetup>(y.Key, true, newProviderSetup));
            });

            // Where the reader and writer resolution attempts contain the same key,
            // we need to merge the error messages for the caller if it wasn't a success
            // or overwrite the values if it was

            // First get a sequence of the readers we know we can return
            var totalItemsToReturn =
                new List <NamedResolutionAttempt <ReadonlyProviderSetup> >(
                    readerResolutionAttempts.Where(x => !notFoundReaderKeys.Contains(x.Key)));

            // Now check the items where we tried to resolve a reader, and then had to try to resolve a writer
            var keysInBoth = readerResolutionAttempts.Select(x => x.Key).Intersect(expressWritersAsReaders.Select(x => x.Key));

            foreach (var key in keysInBoth)
            {
                var originalReaderAttempt = readerResolutionAttempts.FirstOrDefault(x => x.Key == key);
                var writerAttempt         = expressWritersAsReaders.FirstOrDefault(x => x.Key == key);
                if (originalReaderAttempt != null && writerAttempt != null)
                {
                    if (!writerAttempt.Success)
                    {
                        totalItemsToReturn.Add(new NamedResolutionAttempt <ReadonlyProviderSetup>(writerAttempt.Key,
                                                                                                  new InvalidOperationException("Could not resolve a writer or a reader for key {0}. \nReader error: {1}. \nWriter error: {2}"
                                                                                                                                .InvariantFormat(key, originalReaderAttempt.Error.ToString(),
                                                                                                                                                 writerAttempt.Error.ToString()))));
                    }
                    else
                    {
                        totalItemsToReturn.Add(writerAttempt);
                    }
                }
            }

            // Now return the total set
            return(totalItemsToReturn.OrderBy(x => x.Success ? x.Value.PriorityOrdinal : 999));
        }
        private static IEnumerable <NamedResolutionAttempt <ProviderSetup> > TryResolveGroupReadWriters(IResolutionContext x, string[] mappedReadWriterKeys)
        {
            var readWriters = mappedReadWriterKeys.Select(s =>
            {
                var resolveResult = x.TryResolve <ProviderSetup>(s);
                return(resolveResult);
            })
                              //.Where(y => y.Success).Select(y => y.Value)
                              .OrderBy(y => y.Success ? y.Value.PriorityOrdinal : 999).ToList();

            return(readWriters);
        }
 private static Lazy <AbstractTask, TaskMetadata> GetCacheWatcherTaskFactory(IResolutionContext x, string trigger)
 {
     return(new Lazy <AbstractTask, TaskMetadata>(
                () => new CacheWatcherTask(x.Resolve <IFrameworkContext>()),
                new TaskMetadata(trigger, true)));
 }
示例#30
0
 public IFilter GetFailingFilter(IResolutionContext context)
 {
     return(Filters
            .Select(t => t.GetFailingFilter(context))
            .FirstOrDefault(filter => filter != null));
 }
示例#31
0
 public CustomEntityDisplayModelMapper(
     IResolutionContext resolutionContext
     )
 {
     _resolutionContext = resolutionContext;
 }
示例#32
0
 public QueryHandlerFactory(
     IResolutionContext resolutionContext
     )
 {
     _resolutionContext = resolutionContext;
 }
 private IEnumerable <IMention> ExtractMentions(IResolutionContext context)
 {
     return(_extractors.SelectMany(extractor => extractor.ExtractMentions(context)));
 }
示例#34
0
 public IFilter GetFailingFilter(IResolutionContext context)
 {
     return(Filters.All(x => x.GetFailingFilter(context) == null) ? this : null);
 }
示例#35
0
 public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
 {
     throw new InvalidOperationException("Should not resolve");
 }
 internal IList <ICircuitBreaker> Build(IResolutionContext context) => _circuitBreakerFactories.Select(factory => factory(context)).ToList();
示例#37
0
 public IResolutionContext CreateNestedContext(IDescribeMappableProperty destinationProperty, IResolutionContext parentContext)
 {
     var dest = invoke.GetValue(destinationProperty.Name, parentContext.Destination) ?? activate.CreateInstance(destinationProperty.PropertyType);
     return CreateContext(parentContext.Source, dest);
 }
示例#38
0
 public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
 {
     return(new Result(true, destinationProperty.PropertyType.DefaultValue()));
 }
示例#39
0
 public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
 {
     throw new DittoExecutionException("{0} requires a component configuration which was not provided.",destinationProperty);
 }
示例#40
0
 public IResolutionContext CreateNestedParallelContext(IDescribeMappableProperty sourceProperty, IDescribeMappableProperty destinationProperty, IResolutionContext parentContext)
 {
     return inner.CreateNestedParallelContext(sourceProperty, destinationProperty, parentContext);
 }
示例#41
0
        private static ProviderMappingGroup GenerateMappingGroup(string mappingName, IResolutionContext resolutionContext, string[] mappedReadWriterKeys, string[] mappedReaderKeys)
        {
            var tryReadersInGroup = TryResolveGroupReaders(resolutionContext, mappedReaderKeys).ToArray();
            var tryReadWritersInGroup = TryResolveGroupReadWriters(resolutionContext, mappedReadWriterKeys).ToArray();

            var readersInGroup = tryReadersInGroup.Where(x => x.Success);
            var readWritersInGroup = tryReadWritersInGroup.Where(x => x.Success);

            if (!readersInGroup.Any() && !readWritersInGroup.Any())
            {
                var errorBuilder = new StringBuilder();
                errorBuilder.AppendLine("Writers:");
                foreach (var namedResolutionAttempt in tryReadWritersInGroup)
                {
                    errorBuilder.AppendLine("Key: {0}, Error: {1}".InvariantFormat(namedResolutionAttempt.Key, namedResolutionAttempt.Error.ToString()));
                }
                errorBuilder.AppendLine();
                errorBuilder.AppendLine("Readers:");
                foreach (var namedResolutionAttempt in tryReadersInGroup)
                {
                    errorBuilder.AppendLine("Key: {0}, Error: {1}".InvariantFormat(namedResolutionAttempt.Key, namedResolutionAttempt.Error.ToString()));
                }
                throw new InvalidOperationException(
                    "Could not create mapping group '{0}'. Errors:\n{1}".InvariantFormat(mappingName,
                                                                                         errorBuilder.ToString()));
            }

            var uriMatches = resolutionContext.Resolve<IEnumerable<WildcardUriMatch>>(mappingName);
            var frameworkContext = resolutionContext.Resolve<IFrameworkContext>();

            var readonlyProviderSetups = readersInGroup.Select(x => x.Value).ToArray();
            var providerSetups = readWritersInGroup.Select(x => x.Value).ToArray();

            return new ProviderMappingGroup(mappingName, uriMatches, readonlyProviderSetups, providerSetups, frameworkContext);
        }
示例#42
0
 public IFilter GetFailingFilter(IResolutionContext context)
 {
     return Filters.Any(filter => filter.GetFailingFilter(context) == null) ? null : this;
 }
示例#43
0
        private static IEnumerable<NamedResolutionAttempt<ReadonlyProviderSetup>> TryResolveGroupReaders(IResolutionContext ctx, string[] mappedReaderKeys)
        {
            // First get the readers. Not all specified reader keys might exist if a provider is just read-write,
            // so for any that we don't find, we'll try to resolve a writer that matches the key

            var readerResolutionAttempts = mappedReaderKeys.Select(s =>
                                                           {
                                                               var resolveResult = ctx.TryResolve<ReadonlyProviderSetup>(s);
                                                               return resolveResult;
                                                           })
                //.Where(y => y.Success).Select(y => y.Value).ToList();
                .OrderBy(x => x.Success ? x.Value.PriorityOrdinal : 999).ToList();

            // These readers were not found
            var notFoundReaderKeys = readerResolutionAttempts.Where(y => !y.Success).Select(y => y.Key).ToArray();

            // So try to resolve writers with matching keys
            var tryFindWriters = TryResolveGroupReadWriters(ctx, notFoundReaderKeys);

            // We need to return a sequence of ResolutionAttempt<ReadonlyProviderSetup>
            // Where we have found neither a reader nor a writer, need to include the error from both
            var expressWritersAsReaders = tryFindWriters
                .Select(y => 
                    {
                        if (!y.Success)
                        {
                            return new NamedResolutionAttempt<ReadonlyProviderSetup>(y.Key, y.Error);
                        }

                        var providerSetup = y.Value;
                        var newProviderSetup = (providerSetup is UninstalledProviderSetup)
                                                   ? new UninstalledReadonlyProviderSetup(
                                                         providerSetup.ProviderMetadata,
                                                         providerSetup.FrameworkContext,
                                                         providerSetup.Bootstrapper,
                                                         providerSetup.PriorityOrdinal)
                                                   : new ReadonlyProviderSetup(
                                                         new ReadonlyProviderUnitFactory
                                                             (providerSetup.UnitFactory.EntityRepositoryFactory),
                                                         providerSetup.ProviderMetadata,
                                                         providerSetup.FrameworkContext,
                                                         providerSetup.Bootstrapper,
                                                         providerSetup.PriorityOrdinal);

                        return new NamedResolutionAttempt<ReadonlyProviderSetup>(y.Key, true, newProviderSetup);
                    });

            // Where the reader and writer resolution attempts contain the same key, 
            // we need to merge the error messages for the caller if it wasn't a success
            // or overwrite the values if it was

            // First get a sequence of the readers we know we can return
            var totalItemsToReturn =
                new List<NamedResolutionAttempt<ReadonlyProviderSetup>>(
                    readerResolutionAttempts.Where(x => !notFoundReaderKeys.Contains(x.Key)));

            // Now check the items where we tried to resolve a reader, and then had to try to resolve a writer
            var keysInBoth = readerResolutionAttempts.Select(x => x.Key).Intersect(expressWritersAsReaders.Select(x => x.Key));
            foreach (var key in keysInBoth)
            {
                var originalReaderAttempt = readerResolutionAttempts.FirstOrDefault(x => x.Key == key);
                var writerAttempt = expressWritersAsReaders.FirstOrDefault(x => x.Key == key);
                if (originalReaderAttempt != null && writerAttempt != null)
                    if (!writerAttempt.Success)
                    {
                        totalItemsToReturn.Add(new NamedResolutionAttempt<ReadonlyProviderSetup>(writerAttempt.Key,
                            new InvalidOperationException("Could not resolve a writer or a reader for key {0}. \nReader error: {1}. \nWriter error: {2}"
                                                              .InvariantFormat(key, originalReaderAttempt.Error.ToString(),
                                                                               writerAttempt.Error.ToString()))));
                    }
                    else
                    {
                        totalItemsToReturn.Add(writerAttempt);
                    }
            }

            // Now return the total set
            return totalItemsToReturn.OrderBy(x => x.Success ? x.Value.PriorityOrdinal : 999);
        }
示例#44
0
 public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
 {
     throw new DittoExecutionException("'{0}' requires a collection configuration which was not provided. "+Environment.NewLine+
         "Be sure you have either provided configuration for the element type ('{1}'), or the collection.",
         destinationProperty,destinationProperty.ElementType.PropertyType);
 }
 public UpdateCommandHandlerFactory(
     IResolutionContext resolutionContext
     )
 {
     _resolutionContext = resolutionContext;
 }
示例#46
0
 private static Lazy<AbstractTask, TaskMetadata> GetCacheWatcherTaskFactory(IResolutionContext x, string trigger)
 {
     return new Lazy<AbstractTask, TaskMetadata>(
         () => new CacheWatcherTask(x.Resolve<IFrameworkContext>()),
         new TaskMetadata(trigger, true));
 }
示例#47
0
 public IFilter GetFailingFilter(IResolutionContext context)
 {
     return Filters.All(x => x.GetFailingFilter(context) == null) ? this : null;
 }
示例#48
0
        private static IEnumerable<NamedResolutionAttempt<ProviderSetup>> TryResolveGroupReadWriters(IResolutionContext x, string[] mappedReadWriterKeys)
        {
            var readWriters = mappedReadWriterKeys.Select(s =>
                                                              {
                                                                  var resolveResult = x.TryResolve<ProviderSetup>(s);
                                                                  return resolveResult;
                                                              })
                //.Where(y => y.Success).Select(y => y.Value)
                .OrderBy(y => y.Success ? y.Value.PriorityOrdinal : 999).ToList();

            return readWriters;
        }
示例#49
0
 public IFilter GetFailingFilter(IResolutionContext context)
 {
     return(filter.GetFailingFilter(context) == null ? this : null);
 }
示例#50
0
 private object GetValue(GraphFieldInfo fieldInfo, IResolutionContext context)
 {
     var source = GetSource(fieldInfo, context);
     var propertyInfo = fieldInfo.AttributeProvider as PropertyInfo;
     return propertyInfo?.GetValue(source);
 }
示例#51
0
 public IResolutionContext CreateNestedParallelContext(IDescribeMappableProperty sourceProperty, IDescribeMappableProperty destinationProperty, IResolutionContext parentContext)
 {
     return(inner.CreateNestedParallelContext(sourceProperty, destinationProperty, parentContext));
 }
示例#52
0
 public IResolutionContext CreateNestedContext(IDescribeMappableProperty destinationProperty, IResolutionContext parentContext)
 {
     return(inner.CreateNestedContext(destinationProperty, parentContext));
 }
示例#53
0
 public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
 {
     throw new InvalidOperationException("Should not resolve");
 }
示例#54
0
 public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
 {
     return new Result(true, destinationProperty.PropertyType.DefaultValue());
 }
示例#55
0
 public RoleInitializerFactory(
     IResolutionContext resolutionContext
     )
 {
     _resolutionContext = resolutionContext;
 }