ExecutionResult IValueGatheringService.Execute(XmlElement serviceData, bool allowSuspend)
 {
     package = (GuidancePackage)Site.Container;
     using (package.SetupTemporaryService(typeof(IDictionaryService), this.templateDictionary))
     {
         CopyDictionaryServiceToReplamentDictionary();
         if (executeActions)
         {
             ProcessT4Templates();
             result = ExecutionResult.Finish;
             return(result);
         }
         if (serviceData == UnfoldTemplate.NopWizardConfig)
         {
             result = ExecutionResult.Finish;
         }
         else
         {
             result = gatheringService.Execute(serviceData, allowSuspend);
         }
         if (result == ExecutionResult.Finish)
         {
             //Always return ExecutionResult.Suspend to avoid executing the actions
             return(ExecutionResult.Suspend);
         }
         else
         {
             result = ExecutionResult.Cancel;
         }
         return(result);
     }
 }
Beispiel #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);
            }
        }