Ejemplo n.º 1
0
        // Protected Methods (1) 

        /// <inheriteddoc />
        protected override void OnLog(ILogMessage msg)
        {
            // use instance of 'msg'
            // as first argument for the workflow
            object[] basicArgs = new object[] { msg };

            // additional arguments from 'ProviderOfArguments' property
            IEnumerable <object> additionalArgs = CollectionHelper.AsSequence <object>(this._PROVIDER_OF_ARGUMENTS(this));

            // concat both
            IEnumerable <object> allArgs = basicArgs;

            if (additionalArgs != null)
            {
                allArgs = CollectionHelper.Concat(allArgs,
                                                  additionalArgs);
            }

            CollectionHelper.ForEach(this._WORKFLOW,
                                     delegate(IForEachItemExecutionContext <WorkflowFunc, object[]> ctx)
            {
                IWorkflowExecutionContext res = ctx.Item(ctx.State);

                if (res.HasBeenCanceled)
                {
                    ctx.Cancel = true;
                }
            }, CollectionHelper.ToArray(allArgs));
        }
Ejemplo n.º 2
0
        // Protected Methods (2) 

        /// <inheriteddoc />
        protected override IEnumerable <object> OnGetAllInstances(Type serviceType, object key)
        {
            IEnumerable <object> result = null;

            InstanceProvider provider;

            if (this._MULTI_PROVIDERS.TryGetValue(serviceType, out provider))
            {
                IEnumerable seq = provider.Invoke <IEnumerable>(this.BaseLocator,
                                                                key);

                if (seq != null)
                {
                    result = CollectionHelper.AsSequence <object>(seq);
                }

                if (result == null)
                {
                    throw new ServiceActivationException(serviceType, key);
                }
            }

            bool tryFallback = true;

            if (result == null)
            {
                if (this._BASE_LOCATOR != null)
                {
                    // use base service locator instead

                    tryFallback = false;
                    result      = this._BASE_LOCATOR
                                  .GetAllInstances(serviceType, key);
                }
            }

            if (tryFallback)
            {
                // try by fallback, if defined

                MultiInstanceFallbackProvider fb = this.MultiInstanceFallback;
                if (fb != null)
                {
                    result = fb(this, key, serviceType);
                }
            }

            return(result);
        }
        // Public Methods (1) 

        /// <summary>
        ///
        /// </summary>
        /// <see cref="CollectionHelper.AsSequence{T}(IEnumerable)" />
        public static IEnumerable <T> AsSequence <T>(this IEnumerable seq)
        {
            return(CollectionHelper.AsSequence <T>(seq));
        }