public IEnumerable <Action <IConsumeContext <TMessage> > > GetSaga <TMessage>(IConsumeContext <TMessage> context, Guid sagaId, InstanceHandlerSelector <TSaga, TMessage> selector, ISagaPolicy <TSaga, TMessage> policy) where TMessage : class
 {
     return(_inner.GetSaga(context, sagaId, (saga, message) =>
     {
         _context.InjectProperties(saga);
         return selector(saga, message);
     }, policy));
 }
Пример #2
0
        public static BlockHandler Create(BlockId blockId, IComponentContext componentContext)
        {
            if (_blockHandlerTypes.TryGetValue(blockId, out var type))
            {
                return(_blockHandlers.GetOrAdd(blockId, k =>
                {
                    var handler = (BlockHandler)componentContext.InjectProperties(Activator.CreateInstance(type, k));
                    handler.Initialize();
                    return handler;
                }));
            }

            return(_defaultBlockHandler ?? (_defaultBlockHandler = componentContext.InjectProperties(new DefaultBlockHandler())));
        }
Пример #3
0
        protected SchedulerTaskScriptDependencies ResolveScriptDependency(ISchedulerTaskScript script, IComponentContext context)
        {
            if (script.DependencyClassType == null || script.DependencyClassType == typeof(void))
            {
                //TODO: return some default dependency
                return(null);
            }

            var result = context.ResolveOptional(script.DependencyClassType) as SchedulerTaskScriptDependencies;

            //creating instance manually
            if (result == null)
            {
                result = Activator.CreateInstance(script.DependencyClassType)
                         as SchedulerTaskScriptDependencies;
                if (result == null)
                {
                    throw new Exception("Script Dependency can not be resolved. Check the dependency type");
                }
                context.InjectProperties(result);
            }

            if (result == null)
            {
                throw new Exception("Script Dependency can not be resolved");
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// Resolves all instance of the specified type from the container.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="type">The type to resolve.</param>
        /// <returns>The resolved instances.</returns>
        /// <exception>Thrown when the <paramref name="instance" /> argument is null.</exception>
        /// <exception>Thrown when the <paramref name="type" /> argument is null.</exception>
        public static IEnumerable <object> ResolveAll(this IComponentContext instance, Type type)
        {
            Argument.NotNull(instance, nameof(instance));
            Argument.NotNull(type, nameof(type));

            var target = ((IEnumerable <object>)instance.Resolve(typeof(IEnumerable <>).MakeGenericType(type))).ToList();

            foreach (var item in target)
            {
                instance.InjectProperties(item);
            }

            return(target);
        }
Пример #5
0
        private static IEnumerable <KeyValuePair <string, CoinTemplate> > LoadTemplates(string filename, JsonSerializer serializer, IComponentContext ctx)
        {
            using (var jreader = new JsonTextReader(File.OpenText(filename)))
            {
                var jo = serializer.Deserialize <JObject>(jreader);

                foreach (var o in jo)
                {
                    if (o.Value.Type != JTokenType.Object)
                    {
                        logger.ThrowLogPoolStartupException("Invalid coin-template file: dictionary of coin-templates expected");
                    }

                    var value = o.Value[nameof(CoinTemplate.Family).ToLower()];
                    if (value == null)
                    {
                        logger.ThrowLogPoolStartupException("Invalid coin-template: missing 'family' property");
                    }

                    var family = value.ToObject <CoinFamily>();
                    var result = (CoinTemplate)o.Value.ToObject(CoinTemplate.Families[family]);

                    ctx.InjectProperties(result);

                    // Patch explorer links
                    if ((result.ExplorerBlockLinks == null || result.ExplorerBlockLinks.Count == 0) &&
                        !string.IsNullOrEmpty(result.ExplorerBlockLink))
                    {
                        result.ExplorerBlockLinks = new Dictionary <string, string>
                        {
                            { "block", result.ExplorerBlockLink }
                        };
                    }

                    // Record the source of the template
                    result.Source = filename;

                    yield return(KeyValuePair.Create(o.Key, result));
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Override to return a closure that injects properties into a target.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>The injector.</returns>
        protected override Func<object, object> GetInjector(IComponentContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            return target =>
                       {
                           var targetType = target.GetType();
                           if (targetType.GetCustomAttributes(typeof(InjectPropertiesAttribute), true).Length > 0)
                           {
                               return context.InjectProperties(target);
                           }
                           else if (targetType.GetCustomAttributes(typeof(InjectUnsetPropertiesAttribute), true).Length > 0)
                           {
                               return context.InjectUnsetProperties(target);
                           }
                           else
                           {
                               return target;
                           }
                       };
        }
Пример #7
0
        /// <summary>
        /// Override to return a closure that injects properties into a target.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>The injector.</returns>
        protected override Func <object, object> GetInjector(IComponentContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            return(target =>
            {
                var targetType = target.GetType();
                if (targetType.GetCustomAttributes(typeof(InjectPropertiesAttribute), true).Length > 0)
                {
                    return context.InjectProperties(target);
                }
                else if (targetType.GetCustomAttributes(typeof(InjectUnsetPropertiesAttribute), true).Length > 0)
                {
                    return context.InjectUnsetProperties(target);
                }
                else
                {
                    return target;
                }
            });
        }
Пример #8
0
        protected SchedulerTaskScriptDependencies ResolveScriptDependency(ISchedulerTaskScript script, IComponentContext context)
        {
            if (script.DependencyClassType == null || script.DependencyClassType == typeof(void))
            {
                //TODO: return some default dependency
                return null;
            }

            var result = context.ResolveOptional(script.DependencyClassType) as SchedulerTaskScriptDependencies;

            //creating instance manually
            if (result == null)
            {
                result = Activator.CreateInstance(script.DependencyClassType)
                         as SchedulerTaskScriptDependencies;
                if (result == null) throw new Exception("Script Dependency can not be resolved. Check the dependency type");
                context.InjectProperties(result);
            }

            if(result==null) throw new Exception("Script Dependency can not be resolved");
            return result;
        }