示例#1
0
        public void Activate()
        {
            var appBuilder = new AppBuilder();

            appBuilder.Properties["host.AppName"] = _shellSettings.Name;

            var orderedMiddlewares = _owinMiddlewareProviders
                                     .SelectMany(p => p.GetOwinMiddlewares())
                                     .OrderBy(obj => obj.Priority, new FlatPositionComparer());

            foreach (var middleware in orderedMiddlewares)
            {
                middleware.Configure(appBuilder);
            }

            // Register the Orchard middleware after all others.
            appBuilder.UseOrchard();

            var pipeline  = appBuilder.Build();
            var allRoutes = new List <RouteDescriptor>();

            allRoutes.AddRange(_routeProviders.SelectMany(provider => provider.GetRoutes()));
            allRoutes.AddRange(_httpRouteProviders.SelectMany(provider => provider.GetRoutes()));

            _routePublisher.Publish(allRoutes, pipeline);
            _modelBinderPublisher.Publish(_modelBinderProviders.SelectMany(provider => provider.GetModelBinders()));

            using (var scope = _workContextAccessor.CreateWorkContextScope()) {
                using (var events = scope.Resolve <Owned <IOrchardShellEvents> >()) {
                    events.Value.Activated();
                }
            }

            _sweepGenerator.Activate();
        }
        public void Activate()
        {
            IAppBuilder appBuilder = new AppBuilder();

            appBuilder.Properties["host.AppName"] = _shellSettings.Name;

            var orderedMiddlewares = _owinMiddlewareProviders
                                     .SelectMany(p => p.GetOwinMiddlewares())
                                     .OrderBy(obj => obj.Priority, new FlatPositionComparer());

            foreach (var middleware in orderedMiddlewares)
            {
                middleware.Configure(appBuilder);
            }

            // register the Orchard middleware after all others
            appBuilder.UseOrchard();

            Func <IDictionary <string, object>, Task> pipeline = appBuilder.Build();

            var allRoutes = new List <RouteDescriptor>();

            allRoutes.AddRange(_routeProviders.SelectMany(provider => provider.GetRoutes()));
            allRoutes.AddRange(_httpRouteProviders.SelectMany(provider => provider.GetRoutes()));

            _routePublisher.Publish(allRoutes, pipeline);
            _modelBinderPublisher.Publish(_modelBinderProviders.SelectMany(provider => provider.GetModelBinders()));

            using (var events = _eventsFactory()) {
                events.Value.Activated();
            }

            _sweepGenerator.Activate();
        }
示例#3
0
 public void Process(ScheduledTaskContext context)
 {
     if (context.Task.TaskType.StartsWith(UPDATEVALUES_TASK + "_"))
     {
         _sweepGenerator.Terminate();
         try {
             // Task name is something like HiddenStringFieldValueUpdate_ContentType_PartName_FieldName
             var partFieldName = context.Task.TaskType.Split('_');
             if (partFieldName.Length == 5)
             {
                 var typeName  = partFieldName[1];
                 var partName  = partFieldName[2];
                 var fieldName = partFieldName[3];
                 HiddenStringFieldUpdateProcessVariant updateType;
                 var validUpdate = Enum.TryParse(partFieldName[4], out updateType);
                 if (validUpdate)
                 {
                     ProcessInternal(updateType, typeName, partName, fieldName);
                 }
             }
         } catch (Exception ex) {
             Logger.Error(ex, "Update Hidden String Values Error: " + context.Task.TaskType + " - " + ex.Message);
         } finally {
             _sweepGenerator.Activate();
         }
     }
 }
        public void Activate()
        {
            _routePublisher.Publish(_routeProviders.SelectMany(provider => provider.GetRoutes()));
            _modelBinderPublisher.Publish(_modelBinderProviders.SelectMany(provider => provider.GetModelBinders()));

            _sweepGenerator.Activate();

            using (var events = _eventsFactory()) {
                events.Value.Activated();
            }
        }
示例#5
0
        /// <summary>
        /// 激活外壳。
        /// </summary>
        public void Activate()
        {
            using (var events = _eventsFactory())
            {
                foreach (var eventse in events.Value)
                {
                    eventse.Activated();
                }
            }

            _sweepGenerator.Activate();
        }
示例#6
0
        /// <summary>
        /// 激活外壳。
        /// </summary>
        public void Activate()
        {
            using (var scope = _lifetimeScope.CreateWorkContextScope())
            {
                foreach (var shellEventse in scope.Resolve <IEnumerable <IShellEvents> >())
                {
                    shellEventse.Activated();
                }
            }

            _sweepGenerator.Activate();
        }
        public void Activate()
        {
            var allRoutes = new List <RouteDescriptor>();

            allRoutes.AddRange(_routeProviders.SelectMany(provider => provider.GetRoutes()));
            allRoutes.AddRange(_httpRouteProviders.SelectMany(provider => provider.GetRoutes()));

            _routePublisher.Publish(allRoutes);
            _modelBinderPublisher.Publish(_modelBinderProviders.SelectMany(provider => provider.GetModelBinders()));

            using (var events = _eventsFactory()) {
                events.Value.Activated();
            }

            _sweepGenerator.Activate();
        }
        public override void Execute(ImportActionContext context)
        {
            var recipeDocument = context.RecipeDocument ?? RecipeDocument;

            if (recipeDocument == null)
            {
                return;
            }

            // Give each execution step a chance to augment the recipe step before it will be scheduled.
            PrepareRecipe(recipeDocument);

            // Sets the request timeout to a configurable amount of seconds to give enough time to execute custom recipes.
            if (_orchardServices.WorkContext.HttpContext != null)
            {
                _orchardServices.WorkContext.HttpContext.Server.ScriptTimeout = RecipeExecutionTimeout;
            }

            // Suspend background task execution.
            _sweepGenerator.Terminate();

            // Import or setup using the specified recipe.
            var executionId = ResetSite ? Setup(recipeDocument) : ExecuteRecipe(recipeDocument);

            if (executionId == null)
            {
                _orchardServices.Notifier.Warning(T("The recipe contained no steps. No work was scheduled."));
                _sweepGenerator.Activate();
                return;
            }

            // Resume background tasks once import/setup completes.
            var recipe = _recipeParser.ParseRecipe(recipeDocument);
            var activateSweepGeneratorStep = new RecipeStep(Guid.NewGuid().ToString("N"), recipe.Name, "ActivateSweepGenerator", new XElement("ActivateSweepGenerator"));

            _recipeStepQueue.Enqueue(executionId, activateSweepGeneratorStep);
            _recipeStepResultRepository.Create(new RecipeStepResultRecord {
                ExecutionId = executionId,
                RecipeName  = recipe.Name,
                StepId      = activateSweepGeneratorStep.Id,
                StepName    = activateSweepGeneratorStep.Name
            });

            context.ExecutionId    = executionId;
            context.RecipeDocument = recipeDocument;
        }
示例#9
0
        public void Activate()
        {
            var allRoutes = new List <RouteDescriptor>();

            foreach (var routeProvider in routeProviders)
            {
                routeProvider.GetRoutes(allRoutes);
            }

            routePublisher.Publish(allRoutes);

            using (var events = eventsFactory())
            {
                events.Value.Activated();
            }

            sweepGenerator.Activate();
        }
示例#10
0
 public override void Execute(RecipeExecutionContext context)
 {
     _sweepGenerator.Activate();
 }
        public void Process(ScheduledTaskContext context)
        {
            string taskTypeStr = context.Task.TaskType;

            if (taskTypeStr.IndexOf(Constants.TaskTypeBase) == 0)
            {
                try {
                    //For some reason, querying the db for the records related to the task returns null
                    //Hence, we placed the part id in the TaskType.
                    int pid = int.Parse(taskTypeStr.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries).Last());
                    ScheduledTaskPart part = (ScheduledTaskPart)_orchardServices.ContentManager.Get <ScheduledTaskPart>(pid);
                    if (part == null)
                    {
                        Logger.Error("Laser.TaskScheduler was unable to identify and process the task of type " + taskTypeStr);
                    }
                    else
                    {
                        //Trigger the event
                        //get the signal name for from the part to track edits that may have been done.
                        if (part.ExecutionType == ExecutionTypes.WorkFlow)
                        {
                            _workflowManager.TriggerEvent(
                                SignalActivity.SignalEventName,
                                context.Task.ContentItem,
                                () => new Dictionary <string, object> {
                                { "Content", context.Task.ContentItem },
                                { SignalActivity.SignalEventName, part.SignalName }
                            }
                                );
                        }
                        else
                        {
                            if (part.ExecutionType == ExecutionTypes.Razor)
                            {
                                if (part.LongTask)
                                {
                                    _sweepGenerator.Terminate();
                                    try {
                                        var result = _razorExecuteService.Execute(part.SignalName, context.Task.ContentItem, new Dictionary <string, object>()
                                        {
                                            { "Content", context.Task.ContentItem },
                                            { SignalActivity.SignalEventName, part.SignalName }
                                        }).Trim();
                                    }
                                    catch (Exception ex) {
                                        Logger.Error(ex, "ScheduledTaskTasksHandler -> Long Task Error on " + taskTypeStr + ex.Message);
                                    }
                                    finally {
                                        if (part.LongTask)
                                        {
                                            _sweepGenerator.Activate();
                                        }
                                    }
                                }
                                else
                                {
                                    var result = _razorExecuteService.Execute(part.SignalName, context.Task.ContentItem, new Dictionary <string, object>()
                                    {
                                        { "Content", context.Task.ContentItem },
                                        { SignalActivity.SignalEventName, part.SignalName }
                                    }).Trim();
                                }
                            }
                        }

                        if (part.Autodestroy)
                        {
                            var sc = new ScheduledTaskViewModel(part);
                            sc.Delete = true;
                            var list = new List <ScheduledTaskViewModel>();
                            list.Add(sc);
                            _scheduledTaskService.UpdateRecords(list);
                        }
                        else
                        {
                            //if the part has periodicity and it was not unscheduled, we may reschedule the task
                            if (part.PeriodicityTime > 0 && part.RunningTaskId > 0)
                            {
                                //define tasktype
                                string      newTaskTypeStr = Constants.TaskTypeBase + "_" + part.SignalName + "_" + part.Id;
                                ContentItem ci             = null;
                                if (part.ContentItemId > 0)
                                {
                                    ci = _orchardServices.ContentManager.Get(part.ContentItemId);
                                }
                                DateTime scheduleTime = _scheduledTaskService.ComputeNextScheduledTime(part);
                                _taskManager.CreateTask(newTaskTypeStr, scheduleTime, ci);
                                part.RunningTaskId = _repoTasks.Get(str => str.TaskType.Equals(newTaskTypeStr)).Id;
                            }
                            else
                            {
                                part.RunningTaskId = 0;
                            }
                        }
                    }
                }
                catch (Exception ex) {
                    Logger.Error(ex, "ScheduledTaskTasksHandler -> Error on " + taskTypeStr + " id= " + context.Task.ContentItem + ex.Message);
                }
            }
        }