public IEnumerable <Feature> GetEnabledFeatures() { var currentShellDescriptor = _shellDescriptorManager.GetShellDescriptor(); if (currentShellDescriptor == null) // 当存储中找不到 Shell 信息时(可能初始化系统)我们应该启用所有模块。 { var allFeatures = this.GetAvailableFeatures(); _shellDescriptorManager.UpdateShellDescriptor(Enumerable.Empty <String>(), Enumerable.Empty <ShellParameter>()); return(allFeatures); } return(_moduleManager.GetEnabledFeatures(currentShellDescriptor).Select(this.LoadFeature)); }
public void ScheduleWork(string executionId) { var shellDescriptor = _shellDescriptorManager.GetShellDescriptor(); // TODO: this task entry may need to become appdata folder backed if it isn't already _processingEngine.AddTask( _shellSettings, shellDescriptor, "IRecipeSchedulerEventHandler.ExecuteWork", new Dictionary <string, object> { { "executionId", executionId } }); }
public void UpdateTerms(ContentItem contentItem, IEnumerable <TermPart> terms, string field) { var termsPart = contentItem.As <TermsPart>(); // removing current terms for specific field var termList = termsPart.Terms.Select((t, i) => new { Term = t, Index = i }) .Where(x => x.Term.Field == field) .Select(x => x) .OrderByDescending(i => i.Index) .ToList(); foreach (var x in termList) { termsPart.Terms.RemoveAt(x.Index); } // adding new terms list foreach (var term in terms) { // Remove the newly added terms because they will get processed by the Published-Event termList.RemoveAll(t => t.Term.Id == term.Id); termsPart.Terms.Add( new TermContentItem { TermsPartRecord = termsPart.Record, TermRecord = term.Record, Field = field }); } var termPartRecordIds = termList.Select(t => t.Term.TermRecord.Id).ToArray(); _processingEngine.AddTask(_shellSettings, _shellDescriptorManager.GetShellDescriptor(), "ITermCountProcessor.Process", new Dictionary <string, object> { { "termPartRecordIds", termPartRecordIds } }); }
public void OnActionExecuted(ActionExecutedContext filterContext) { var user = _wca.GetContext().CurrentUser; // Not doing anything on the admin or for anonymous users, and also if (AdminFilter.IsApplied(filterContext.RequestContext) || user == null) { return; } var notificationsUserPart = user.As <NotificationsUserPart>(); // Not checking if CheckIntervalMinutes hasn't passed yet since the last update. if (notificationsUserPart.LastCheckedUtc >= _clock.UtcNow.AddMinutes(-1 * Constants.NewNotificationCheckIntervalMinutes)) { return; } notificationsUserPart.LastCheckedUtc = _clock.UtcNow; // Using the processing engine to do the update after the request has executed so the user experience is not impacted. var shellDescriptor = _shellDescriptorManager.GetShellDescriptor(); _processingEngine.AddTask( _shellSettings, shellDescriptor, "IUserNotificationsUpdaterEventHandler.UpdateNotificationsForUser", new Dictionary <string, object> { { "userId", user.ContentItem.Id } } ); }
// Fires off a processing engine task to run the count processing after the request so it's non-blocking. private void RecalculateCount(IProcessingEngine processingEngine, ShellSettings shellSettings, IShellDescriptorManager shellDescriptorManager, TermsPart part) { var termPartRecordIds = part.Terms.Select(t => t.TermRecord.Id).ToArray(); processingEngine.AddTask(shellSettings, shellDescriptorManager.GetShellDescriptor(), "ITermCountProcessor.Process", new Dictionary <string, object> { { "termPartRecordIds", termPartRecordIds } }); }
/// <summary> /// Retrieves an enumeration of the available features together with its state (enabled / disabled). /// </summary> /// <returns>An enumeration of the available features together with its state (enabled / disabled).</returns> public IEnumerable <ModuleFeature> GetAvailableFeatures() { var enabledFeatures = _shellDescriptorManager.GetShellDescriptor().Features; return(_extensionManager.AvailableExtensions() .SelectMany(m => _extensionManager.LoadFeatures(m.Features)) .Select(f => AssembleModuleFromDescriptor(f, enabledFeatures .FirstOrDefault(sf => string.Equals(sf.Name, f.Descriptor.Id, StringComparison.OrdinalIgnoreCase)) != null))); }
public void ProcessCasePostsCount(int cAsePartId) { if (!_processedCaseParts.Contains(cAsePartId)) { _processedCaseParts.Add(cAsePartId); _processingEngine.AddTask(_shellSettings, _shellDescriptorManager.GetShellDescriptor(), "ICasePostsCountProcessor.Process", new Dictionary <string, object> { { "cAsePartId", cAsePartId } }); } }
public void QueuePackageUninstall(string packageId) { _processingEngine.AddTask( _shellSettings, _shellDescriptorManager.GetShellDescriptor(), "IPackageUninstallHandler.UninstallPackage", new Dictionary <string, object> { { "packageId", packageId } }); }
public void ProcessBidsCount(int bidsPartId) { if (!_processedBidsParts.Contains(bidsPartId)) { _processedBidsParts.Add(bidsPartId); _processingEngine.AddTask(_shellSettings, _shellDescriptorManager.GetShellDescriptor(), "IBidsCountProcessor.Process", new Dictionary <string, object> { { "BidsPartId", bidsPartId } }); } }
private void Queue(string industry, Func <WorkContext, IAtomicWorker> executorResolver) { _processingEngine.AddTask( _shellSettings, _shellDescriptorManager.GetShellDescriptor(), "IAtomicJobExecutor.Execute", new Dictionary <string, object> { { "industry", industry }, { "executorResolver", executorResolver } } ); }
public void Schedule(string indexName) { var shellDescriptor = _shellDescriptorManager.GetShellDescriptor(); _processingEngine.AddTask( _shellSettings, shellDescriptor, "IIndexNotifierHandler.UpdateIndex", new Dictionary <string, object> { { "indexName", indexName } } ); }
public void ExecuteAsyncTask(Action <ContentItem> task, ContentItem data) { ProcessAsync(new ShellTask { ProcessId = Guid.NewGuid().ToString("n"), TaskId = Guid.NewGuid().ToString("n"), ShellAction = task, ShellContextFactory = _shellContextFactory, ShellData = data, ShellDescriptor = _shellDescriptorManager.GetShellDescriptor(), ShellSettings = _shellSettings }); }
public void Schedule(bool force) { var shellDescriptor = _shellDescriptorManager.GetShellDescriptor(); _processingEngine.AddTask( _shellSettings, shellDescriptor, "IWarmupEventHandler.Generate", new Dictionary <string, object> { { "force", force } } ); }
public void Queue <TAtomicWorker>(string industry) where TAtomicWorker : IAtomicWorker { var shellDescriptor = _shellDescriptorManager.GetShellDescriptor(); Func <WorkContext, IAtomicWorker> executorResolver = (workContext) => workContext.Resolve <TAtomicWorker>(); _processingEngine.AddTask( _shellSettings, shellDescriptor, "IAtomicJobExecutor.Execute", new Dictionary <string, object> { { "industry", industry }, { "executorResolver", executorResolver } } ); }
public void AddTask(HiddenStringFieldUpdateProcessVariant variant, HiddenStringFieldSettings settings, ContentPartFieldDefinitionBuilder builder) { if (variant != HiddenStringFieldUpdateProcessVariant.None) { _processingEngine .AddTask(_shellSettings, _shellDescriptorManager.GetShellDescriptor(), "IHiddenStringFieldUpdateProcessor.Process", new Dictionary <string, object> { { "contentItemIds", GetIdsToProcess(variant, builder) }, { "partName", builder.PartName }, { "fieldName", builder.Name }, { "settings", settings } }); } }
// Fires off a processing engine task to run the count processing after the request so it's non-blocking. private void RecalculateCount(IProcessingEngine processingEngine, ShellSettings shellSettings, IShellDescriptorManager shellDescriptorManager, TermsPart part) { var termPartRecordIds = part.Terms.Select(t => t.TermRecord.Id).ToArray(); if (termPartRecordIds.Any()) { if (!_processedTermParts.Any()) { processingEngine.AddTask(shellSettings, shellDescriptorManager.GetShellDescriptor(), "ITermCountProcessor.Process", new Dictionary <string, object> { { "termPartRecordIds", _processedTermParts } }); } foreach (var termPartRecordId in termPartRecordIds) { _processedTermParts.Add(termPartRecordId); } } }
public ShellState GetShellState() { var stateRecord = GetExistingOrNewShellStateRecord(); var descriptor = _shellDescriptorManager.GetShellDescriptor(); var extraFeatures = descriptor == null?Enumerable.Empty <string>() : descriptor.Features .Select(r => r.Name) .Except(stateRecord.Features.Select(r => r.Name)); return(new ShellState { Features = stateRecord.Features .Select(featureStateRecord => new ShellFeatureState { Name = featureStateRecord.Name, EnableState = featureStateRecord.EnableState, InstallState = featureStateRecord.InstallState }) .Concat(extraFeatures.Select(name => new ShellFeatureState { Name = name })) .ToArray(), }); }
/// <summary> /// 创建 Shell 运行时上下文。 /// </summary> /// <returns>创建的 <see cref="ShellContext"/> 实例。</returns> public ShellContext CreateShellContext() { _logger.WriteTrace($"正在为应用程序 {_options.AppName}({_options.AppSystemName}) 创建 Shell 。"); var knownDescriptor = _shellDescriptorCache.Fetch(_options.AppName); if (knownDescriptor == null) { //本地没有存储蓝图信息,则先构建应用程序运行所需的最小蓝图。 _logger.WriteTrace("找不到缓存的 SehllDescriptor 对象。将使用最小蓝图启动应用程序。"); knownDescriptor = MinimumShellDescriptor(); } //组装应用程序组件构建蓝图。 var blueprint = _compositionStrategy.Compose(_options.AppName, knownDescriptor); ShellDescriptor currentDescriptor = _shellDescriptorManager.GetShellDescriptor(); //首次运行 currentDescriptor 可能为空,将用最小蓝图启动程序。 if (currentDescriptor != null && knownDescriptor.ApplicationName != currentDescriptor.ApplicationName) { _logger.WriteTrace("获得了新的 Shell 信息。 正在重新创建 Shell 蓝图。"); _shellDescriptorCache.Store(_options.AppName, currentDescriptor); blueprint = _compositionStrategy.Compose(_options.AppName, currentDescriptor); } //注意,ConfigureBlueprint 为迭代器方法,对属性赋值时切勿直接赋值,应该先保证调用。 //迭代器方法在实际使用时才会调用,更多请参考 C# 语言知识,这里先 ToArray 防止访问 ShellContext.Services 属性时造成多次调用。 var descriptor = this.BuildDependencies(blueprint); return(new ShellContext { Descriptor = currentDescriptor ?? knownDescriptor, Blueprint = blueprint, Services = descriptor.Item1, EventSubscriptors = descriptor.Item2 }); }
private void ImportPostsInBatches(ImportSettings importSettings, IContent parentContentItem, ICollection <Post> posts) { _contentManager.Clear(); const int batchSize = 100; int batchNo = 1; for (var i = 0; i < posts.Count; i += batchSize) { var postBatch = posts.Skip(i).Take(batchSize).ToList(); _processingEngine.AddTask( _shellSettings, _shellDescriptorManager.GetShellDescriptor(), "IScheduledBlogPostCollectionImport.Import", new Dictionary <string, object> { { "importSettings", importSettings }, { "parentContentItem", parentContentItem }, { "posts", postBatch }, { "batchNumber", batchNo } }); batchNo++; } }
// Fires off a processing engine task to run the count processing after the request so it's non-blocking. private void RecalculateCount(IProcessingEngine processingEngine, ShellSettings shellSettings, IShellDescriptorManager shellDescriptorManager, TermsPart part) { var termPartRecordIds = part.Terms.Select(t => t.TermRecord.Id).ToArray(); processingEngine.AddTask(shellSettings, shellDescriptorManager.GetShellDescriptor(), "ITermCountProcessor.Process", new Dictionary<string, object> { { "termPartRecordIds", termPartRecordIds } }); }
private void UpdateShell() { var descriptor = _shellDescriptorManager.GetShellDescriptor(); _shellDescriptorManager.UpdateShellDescriptor(descriptor.SerialNumber, descriptor.Features, descriptor.Parameters); }
/// <summary> /// Retrieves the enabled features. /// </summary> /// <returns>An enumeration of feature descriptors for the enabled features.</returns> public IEnumerable <FeatureDescriptor> GetEnabledFeatures() { var currentShellDescriptor = _shellDescriptorManager.GetShellDescriptor(); return(_extensionManager.EnabledFeatures(currentShellDescriptor)); }
// Fires off a processing engine task to run the count processing after the request so it's non-blocking. private void RecalculateCount(IProcessingEngine processingEngine, ShellSettings shellSettings, IShellDescriptorManager shellDescriptorManager, TermsPart part) { var termPartRecordIds = part.Terms.Select(t => t.TermRecord.Id).ToArray(); if (termPartRecordIds.Any()) { if (!_processedTermParts.Any()) { processingEngine.AddTask(shellSettings, shellDescriptorManager.GetShellDescriptor(), "ITermCountProcessor.Process", new Dictionary<string, object> { { "termPartRecordIds", _processedTermParts } }); } foreach (var termPartRecordId in termPartRecordIds) { _processedTermParts.Add(termPartRecordId); } } }