public void UpdateShellDescriptor(int priorSerialNumber, IEnumerable <ShellFeature> enabledFeatures, IEnumerable <ShellParameter> parameters)
        {
            var priorDescriptor = ShellDescriptor;
            var serialNumber    = priorDescriptor == null ? 0 : priorDescriptor.SerialNumber;

            if (priorSerialNumber != serialNumber)
            {
                throw new InvalidOperationException("Invalid serial number for shell descriptor");
            }

            if (enabledFeatures == null)
            {
                enabledFeatures = Enumerable.Empty <ShellFeature>();
            }
            if (parameters == null)
            {
                parameters = Enumerable.Empty <ShellParameter>();
            }

            var shellDescriptor = new ShellDescriptor
            {
                SerialNumber = ++serialNumber,
                Features     = enabledFeatures,
                Parameters   = parameters
            };

            ShellDescriptor = shellDescriptor;

            _events.Changed(shellDescriptor, _shellSettings.Name);
        }
Esempio n. 2
0
        public void UpdateShellDescriptor(int priorSerialNumber, IEnumerable <ShellFeature> enabledFeatures, IEnumerable <ShellParameter> parameters)
        {
            ShellDescriptorRecord shellDescriptorRecord = GetDescriptorRecord();
            var serialNumber = shellDescriptorRecord == null ? 0 : shellDescriptorRecord.SerialNumber;

            if (priorSerialNumber != serialNumber)
            {
                throw new InvalidOperationException("Invalid serial number for shell descriptor");
            }

            Logger.Information("Updating shell descriptor for shell '{0}'...", _shellSettings.Name);

            if (shellDescriptorRecord == null)
            {
                shellDescriptorRecord = new ShellDescriptorRecord {
                    SerialNumber = 1
                };
                _shellDescriptorRepository.Create(shellDescriptorRecord);
            }
            else
            {
                shellDescriptorRecord.SerialNumber++;
            }

            shellDescriptorRecord.Features.Clear();
            foreach (var feature in enabledFeatures)
            {
                shellDescriptorRecord.Features.Add(new ShellFeatureRecord {
                    Name = feature.Name, ShellDescriptorRecord = shellDescriptorRecord
                });
            }
            Logger.Debug("Enabled features for shell '{0}' set: {1}.", _shellSettings.Name, String.Join(", ", enabledFeatures.Select(feature => feature.Name)));

            shellDescriptorRecord.Parameters.Clear();
            foreach (var parameter in parameters)
            {
                shellDescriptorRecord.Parameters.Add(new ShellParameterRecord
                {
                    Component             = parameter.Component,
                    Name                  = parameter.Name,
                    Value                 = parameter.Value,
                    ShellDescriptorRecord = shellDescriptorRecord
                });
            }

            Logger.Debug("Parameters for shell '{0}' set: {1}.", _shellSettings.Name, String.Join(", ", parameters.Select(parameter => parameter.Name + "-" + parameter.Value)));

            Logger.Information("Shell descriptor updated for shell '{0}'.", _shellSettings.Name);

            _events.Changed(GetShellDescriptorFromRecord(shellDescriptorRecord), _shellSettings.Name);
        }
        public void ExecuteWork(string executionId)
        {
            // todo: this callback should be guarded against concurrency by the IProcessingEngine
            var scheduleMore = _recipeStepExecutor.Value.ExecuteNextStep(executionId);

            if (scheduleMore)
            {
                ScheduleWork(executionId);
            }
            else
            {
                // https://orchard.codeplex.com/workitem/19844
                // Because recipes execute in their own workcontext, we need to restart the shell, as signaling a cache won't work across workcontexts.
                _events.Changed(_shellDescriptorManager.GetShellDescriptor(), _shellSettings.Name);
            }
        }
        public void UpdateShellDescriptor(int priorSerialNumber, IEnumerable <ShellFeature> enabledFeatures, IEnumerable <ShellParameter> parameters)
        {
            ShellDescriptorRecord shellDescriptorRecord = GetDescriptorRecord();
            var serialNumber = shellDescriptorRecord == null ? 0 : shellDescriptorRecord.SerialNumber;

            if (priorSerialNumber != serialNumber)
            {
                throw new InvalidOperationException(T("Invalid serial number for shell descriptor").ToString());
            }

            if (shellDescriptorRecord == null)
            {
                shellDescriptorRecord = new ShellDescriptorRecord {
                    SerialNumber = 1
                };
                _shellDescriptorRepository.Create(shellDescriptorRecord);
            }
            else
            {
                shellDescriptorRecord.SerialNumber++;
            }

            _shellDescriptorRecord = shellDescriptorRecord;

            shellDescriptorRecord.Features.Clear();
            foreach (var feature in enabledFeatures)
            {
                shellDescriptorRecord.Features.Add(new ShellFeatureRecord {
                    Name = feature.Name, ShellDescriptorRecord = shellDescriptorRecord
                });
            }


            shellDescriptorRecord.Parameters.Clear();
            foreach (var parameter in parameters)
            {
                shellDescriptorRecord.Parameters.Add(new ShellParameterRecord {
                    Component             = parameter.Component,
                    Name                  = parameter.Name,
                    Value                 = parameter.Value,
                    ShellDescriptorRecord = shellDescriptorRecord
                });
            }

            _events.Changed(GetShellDescriptorFromRecord(shellDescriptorRecord), _shellSettings.Name);
        }
Esempio n. 5
0
        public void UpdateShellDescriptor(int priorSerialNumber, IEnumerable <ShellFeature> enabledFeatures, bool throwEvent = true)
        {
            var shellDescriptorRecord = GetDescriptorRecord();
            var serialNumber          = shellDescriptorRecord == null ? 0 : shellDescriptorRecord.SerialNumber;

            //2013-12-18: Hack
            //bool isFirstRun = (serialNumber == 0 && priorSerialNumber == 1) || (serialNumber == 1 && priorSerialNumber == 0);

            //if (!isFirstRun)
            //{
            //    if (priorSerialNumber != serialNumber)
            //    {
            //        throw new InvalidOperationException(T("Invalid serial number for shell descriptor").ToString());
            //    }
            //}

            if (shellDescriptorRecord == null)
            {
                shellDescriptorRecord = new ShellDescriptorRecord
                {
                    Id           = Guid.NewGuid(),
                    SerialNumber = 1,
                    Features     = string.Join(";", enabledFeatures.Select(x => x.Name))
                };

                shellDescriptorRepository.Insert(shellDescriptorRecord);
            }
            else
            {
                shellDescriptorRecord.SerialNumber++;
                shellDescriptorRecord.Features = string.Join(";", enabledFeatures.Select(x => x.Name));
                shellDescriptorRepository.Update(shellDescriptorRecord);
            }

            if (throwEvent)
            {
                events.Changed(GetShellDescriptorFromRecord(shellDescriptorRecord), shellSettings.Name);
            }
        }
Esempio n. 6
0
        public void ExecuteWork(string executionId)
        {
            ThreadContext.Properties["ExecutionId"] = executionId;
            try {
                // todo: this callback should be guarded against concurrency by the IProcessingEngine
                var scheduleMore = _recipeStepExecutor.Value.ExecuteNextStep(executionId);
                if (scheduleMore)
                {
                    Logger.Information("Scheduling next step of recipe.");
                    ScheduleWork(executionId);
                }
                else
                {
                    Logger.Information("All recipe steps executed; restarting shell.");

                    // Because recipes execute in their own workcontext, we need to restart the shell, as signaling a cache won't work across workcontexts.
                    _events.Changed(_shellDescriptorManager.GetShellDescriptor(), _shellSettings.Name);
                }
            }
            finally {
                ThreadContext.Properties["ExecutionId"] = null;
            }
        }