Esempio n. 1
0
        private IValueGatheringService GetValueGatheringService(ITypeResolutionService resolution,
                                                                RecipeGatheringServiceData gatheringConfig)
        {
            IValueGatheringService gathering;

            // A custom value gathering type has been specified, we will use that one instead of using the built-in one
            if (!String.IsNullOrEmpty(gatheringConfig.ServiceType))
            {
                gathering = GetInstance <IValueGatheringService>(resolution, gatheringConfig.ServiceType);

                // Add the service to the current container (just for playing nice)
                this.AddService(typeof(IValueGatheringService), gathering);
            }
            else
            {
                gathering = GetService <IValueGatheringService>();
            }
            return(gathering);
        }
Esempio n. 2
0
        /// <summary>
        /// Executes the recipe, processing the configuration received at construction time.
        /// </summary>
        /// <param name="allowSuspend">Specifies whether the recipe can be suspended.</param>
        /// <remarks>
        /// Only when the recipe is executed completely (that is, it's not suspended or cancelled), the
        /// return value will be <see langword="true"/>.
        /// </remarks>
        /// <returns>Whether the recipe finished executing succesfully.</returns>
        public ExecutionResult Execute(bool allowSuspend)
        {
            ITypeResolutionService resolution   = GetService <ITypeResolutionService>(true);
            IDictionaryService     arguments    = GetService <IDictionaryService>(true);
            IDictionaryService     readonlyargs = new ReadOnlyDictionaryService(arguments);
            IDictionary            providers    = LoadProviders(resolution);

            // Setup custom action execution service if specified.
            if (Configuration.Actions != null)
            {
                if (!String.IsNullOrEmpty(Configuration.Actions.ExecutionServiceType))
                {
                    AddService(typeof(IActionExecutionService),
                               GetInstance <IActionExecutionService>(resolution, Configuration.Actions.ExecutionServiceType));
                }
                // Setup custom action coordinator service if specified.
                if (!String.IsNullOrEmpty(Configuration.Actions.CoordinatorServiceType))
                {
                    AddService(typeof(IActionCoordinationService),
                               GetInstance <IActionCoordinationService>(resolution, Configuration.Actions.CoordinatorServiceType));
                }
            }

            try
            {
                CallProviders(providers, readonlyargs, arguments, true);
                ThrowIfValueTypeArgumentIsOptionalNotNullable();
                IConfigurationService configservice = GetService <IConfigurationService>(true);
                object wizardconfig = configservice.CurrentGatheringServiceData;

                // Check if we have null values.
                ThrowIfValueTypeArgumentIsOptionalNotNullable();
                RecipeGatheringServiceData gatheringConfig = (RecipeGatheringServiceData)wizardconfig;

                // Collect if we have both a wizard and a gathering strategy.
                if (wizardconfig != null)
                {
                    IValueGatheringService gathering = GetValueGatheringService(resolution, gatheringConfig);
                    if (gathering == null)
                    {
                        throw new RecipeExecutionException(this.Configuration.Name,
                                                           Properties.Resources.Recipe_ArgumentGatheringRequired);
                    }

                    ExecutionResult result = gathering.Execute(gatheringConfig.Any, allowSuspend);
                    if (result == ExecutionResult.Suspend && !allowSuspend)
                    {
                        throw new InvalidOperationException(Properties.Resources.Recipe_CantSuspendRecipe);
                    }
                    if (result == ExecutionResult.Finish)
                    {
                        CallProviders(providers, readonlyargs, arguments, false);
                        ThrowIfRequiredArgumentsAreNull(arguments);
                        ExecuteActions(readonlyargs, arguments, resolution);
                    }
                    return(result);
                }
                else
                {
                    CallProviders(providers, readonlyargs, arguments, false);
                    ThrowIfRequiredArgumentsAreNull(arguments);
                    ExecuteActions(readonlyargs, arguments, resolution);
                    return(ExecutionResult.Finish);
                }
            }
            finally
            {
                UnloadProviders(providers);
            }
        }