示例#1
0
        public Task CreateTaskAsync(ContentItem contentItem, IndexingTaskTypes type)
        {
            if (contentItem == null)
            {
                throw new ArgumentNullException("contentItem");
            }

            if (contentItem.Id == 0)
            {
                // Ignore that case, when Update is called on a content item which has not be "created" yet

                return(Task.CompletedTask);
            }

            var indexingTask = new IndexingTask
            {
                CreatedUtc    = _clock.UtcNow,
                ContentItemId = contentItem.ContentItemId,
                Type          = type
            };

            lock (_tasksQueue)
            {
                if (_tasksQueue.Count == 0)
                {
                    ShellScope.AddDeferredTask(scope => FlushAsync(scope, _tasksQueue));
                }

                _tasksQueue.Add(indexingTask);
            }

            return(Task.CompletedTask);
        }
        public Task CreateTaskAsync(ContentItem contentItem, IndexingTaskTypes type)
        {
            if (contentItem == null)
            {
                throw new ArgumentNullException("contentItem");
            }

            if (contentItem.Id == 0)
            {
                // Ignore that case, when Update is called on a content item which has not be "created" yet

                return(Task.CompletedTask);
            }

            var indexingTask = new IndexingTask
            {
                CreatedUtc    = _clock.UtcNow,
                ContentItemId = contentItem.ContentItemId,
                Type          = type
            };

            if (_tasksQueue.Count == 0)
            {
                var tasksQueue = _tasksQueue;

                // Using a local var prevents the lambda from holding a ref on this scoped service.
                ShellScope.AddDeferredTask(scope => FlushAsync(scope, tasksQueue));
            }

            _tasksQueue.Add(indexingTask);

            return(Task.CompletedTask);
        }
示例#3
0
        public Task ActivatedAsync()
        {
            if (_shellSettings.State == TenantState.Running)
            {
                ShellScope.AddDeferredTask(async scope =>
                {
                    var luceneIndexSettingsService = scope.ServiceProvider.GetRequiredService <LuceneIndexSettingsService>();
                    var luceneIndexingService      = scope.ServiceProvider.GetRequiredService <LuceneIndexingService>();
                    var indexManager = scope.ServiceProvider.GetRequiredService <LuceneIndexManager>();

                    var luceneIndexSettings = await luceneIndexSettingsService.GetSettingsAsync();

                    foreach (var settings in luceneIndexSettings)
                    {
                        if (!indexManager.Exists(settings.IndexName))
                        {
                            await luceneIndexingService.CreateIndexAsync(settings);
                            await luceneIndexingService.ProcessContentItemsAsync(settings.IndexName);
                        }
                    }
                });
            }

            return(Task.CompletedTask);
        }
        private Task AddContextAsync(ContentContextBase context)
        {
            // Do not index a preview content item.
            if (_httpContextAccessor.HttpContext?.Features.Get <ContentPreviewFeature>()?.Previewing == true)
            {
                return(Task.CompletedTask);
            }

            if (context.ContentItem.Id == 0)
            {
                // Ignore that case, when Update is called on a content item which has not be "created" yet.
                return(Task.CompletedTask);
            }

            if (_contexts.Count == 0)
            {
                var contexts = _contexts;

                // Using a local var prevents the lambda from holding a ref on this scoped service.
                ShellScope.AddDeferredTask(scope => IndexingAsync(scope, contexts));
            }

            _contexts.Add(context);

            return(Task.CompletedTask);
        }
示例#5
0
        public Task ExecuteAsync(RecipeExecutionContext context)
        {
            if (!String.Equals(context.Name, "Content", StringComparison.OrdinalIgnoreCase))
            {
                return(Task.CompletedTask);
            }

            var model        = context.Step.ToObject <ContentStepModel>();
            var contentItems = model.Data.ToObject <ContentItem[]>();

            // If the shell is activated there is no migration in progress.
            if (ShellScope.Context.IsActivated)
            {
                var contentManager = ShellScope.Services.GetRequiredService <IContentManager>();
                return(contentManager.ImportAsync(contentItems));
            }

            // Otherwise, the import of content items is deferred after all migrations are completed,
            // this prevents e.g. a content handler to trigger a workflow before worflows migrations.
            ShellScope.AddDeferredTask(scope =>
            {
                var contentManager = scope.ServiceProvider.GetRequiredService <IContentManager>();
                return(contentManager.ImportAsync(contentItems));
            });

            return(Task.CompletedTask);
        }
        public string CreateTask()
        {
            ShellScope.AddDeferredTask(scope =>
            {
                var logger = scope.ServiceProvider.GetService <ILogger <HomeController> >();
                logger.LogError("Task deferred successfully");
                return(Task.CompletedTask);
            });

            return("Check for logs");
        }
示例#7
0
 public async Task ImportAsync(ImportingJobDescriptor descriptor)
 {
     ShellScope.AddDeferredTask(async defferedTaskContext => {
         using (var tx = _transactionManager.BeginTransaction()) {
             var importTask = await this.CreateTaskAsync(descriptor);
             var context    = new ImportingTaskContext(defferedTaskContext.ServiceProvider, _environment.ContentRootFileProvider);
             await this.DoImportAsync(importTask, context);
             await tx.CommitAsync();
         }
     });
     await Task.CompletedTask;
 }
示例#8
0
        private Task AddContextAsync(ContentContextBase context)
        {
            if (_contexts.Count == 0)
            {
                var contexts = _contexts;

                // Using a local var prevents the lambda from holding a ref on this scoped service.
                ShellScope.AddDeferredTask(scope => IndexingAsync(scope, contexts));
            }

            _contexts.Add(context);

            return(Task.CompletedTask);
        }
示例#9
0
        // UserId column is added. This initializes the UserId property to the UserName for existing users.
        // The UserName property rather than the NormalizedUserName is used as the ContentItem.Owner property matches the UserName.
        // New users will be created with a generated Id.
        // This code can be removed in a later version.
        public int UpdateFrom5()
        {
            // Defer this until after the subsequent migrations have succeded as the schema has changed.
            ShellScope.AddDeferredTask(async scope =>
            {
                var session = scope.ServiceProvider.GetRequiredService <ISession>();
                var users   = await session.Query <User>().ListAsync();
                foreach (var user in users)
                {
                    user.UserId = user.UserName;
                    session.Save(user);
                }
            });

            return(6);
        }
示例#10
0
        // Migrate any user names replacing '@' with '+' as user names can no longer be an email address.
        // This code can be removed in a later version.
        public int UpdateFrom7()
        {
            // Defer this until after the subsequent migrations have succeded as the schema has changed.
            ShellScope.AddDeferredTask(async scope =>
            {
                var session = scope.ServiceProvider.GetRequiredService <ISession>();
                var users   = await session.Query <User, UserIndex>(u => u.NormalizedUserName.Contains("@")).ListAsync();
                foreach (var user in users)
                {
                    user.UserName           = user.UserName.Replace('@', '+');
                    user.NormalizedUserName = user.NormalizedUserName.Replace('@', '+');
                    session.Save(user);
                }
            });

            return(8);
        }
示例#11
0
        // Migrate null LocalizedContentItemIndex Latest column.
        public int UpdateFrom3()
        {
            // Defer this until after the subsequent migrations have succeded as the schema has changed.
            ShellScope.AddDeferredTask(async scope =>
            {
                var session = scope.ServiceProvider.GetRequiredService <ISession>();
                var localizedContentItems = await session.Query <ContentItem, LocalizedContentItemIndex>().ListAsync();

                foreach (var localizedContentItem in localizedContentItems)
                {
                    localizedContentItem.Latest = localizedContentItem.ContentItem.Latest;
                    session.Save(localizedContentItem);
                }
            });

            return(4);
        }
示例#12
0
        private void FireApplyChangesIfNeeded()
        {
            ShellScope.AddDeferredTask(async scope =>
            {
                var stateManager      = scope.ServiceProvider.GetRequiredService <IShellStateManager>();
                var shellStateUpdater = scope.ServiceProvider.GetRequiredService <IShellStateUpdater>();
                var shellState        = await stateManager.GetShellStateAsync();

                while (shellState.Features.Any(FeatureIsChanging))
                {
                    if (_logger.IsEnabled(LogLevel.Information))
                    {
                        _logger.LogInformation("Adding pending task 'ApplyChanges' for tenant '{TenantName}'", scope.ShellContext.Settings.Name);
                    }

                    await shellStateUpdater.ApplyChanges();
                }
            });
        }
        private Task AddContextAsync(ContentContextBase context)
        {
            // A previewed content item is transient, and is marked as such with a negative id.
            if (context.ContentItem.Id == -1)
            {
                return(Task.CompletedTask);
            }

            if (_contexts.Count == 0)
            {
                var contexts = _contexts;

                // Using a local var prevents the lambda from holding a ref on this scoped service.
                ShellScope.AddDeferredTask(scope => IndexingAsync(scope, contexts));
            }

            _contexts.Add(context);

            return(Task.CompletedTask);
        }
示例#14
0
        private void CreateHackathonUsersIndex()
        {
            SchemaBuilder.CreateMapIndexTable(typeof(HackathonUsersIndex), table => table
                                              .Column <string>("UserId", c => c.WithLength(26))
                                              .Column <string>("UserName", c => c.WithLength(26))
                                              .Column <string>("Email", c => c.Nullable().WithLength(255))
                                              .Column <string>("ContactEmail", c => c.Nullable().WithLength(255))
                                              .Column <string>("FirstName", c => c.WithLength(26))
                                              .Column <string>("LastName", c => c.WithLength(26))
                                              .Column <string>("Language", c => c.WithLength(4))
                                              .Column <string>("TeamContentItemId", c => c.WithLength(26)),
                                              null
                                              );

            ShellScope.AddDeferredTask(async scope => {
                var session = scope.ServiceProvider.GetRequiredService <ISession>();
                var users   = await session.Query <User>().ListAsync();
                foreach (var user in users)
                {
                    session.Save(user);
                }
            });
        }
示例#15
0
 private void FireApplyChangesIfNeeded()
 {
     ShellScope.AddDeferredTask(new Func <ShellScope, Task>(this.u003cFireApplyChangesIfNeededu003eb__4_0));
     return;
 }
        public async Task <(IEnumerable <IFeatureInfo>, IEnumerable <IFeatureInfo>)> UpdateFeaturesAsync(ShellDescriptor shellDescriptor,
                                                                                                         IEnumerable <IFeatureInfo> featuresToDisable, IEnumerable <IFeatureInfo> featuresToEnable, bool force)
        {
            var featureEventHandlers = ShellScope.Services.GetServices <IFeatureEventHandler>();

            var enabledFeatureIds = _extensionManager.GetFeatures()
                                    .Where(f => shellDescriptor.Features.Any(sf => sf.Id == f.Id))
                                    .Select(f => f.Id)
                                    .ToHashSet();

            var installedFeatureIds = enabledFeatureIds
                                      .Concat(shellDescriptor.Installed.Select(sf => sf.Id))
                                      .ToHashSet();

            var alwaysEnabledIds = _alwaysEnabledFeatures.Select(sf => sf.Id).ToArray();

            var allFeaturesToDisable = featuresToDisable
                                       .Where(f => !alwaysEnabledIds.Contains(f.Id))
                                       .SelectMany(feature => GetFeaturesToDisable(feature, enabledFeatureIds, force))
                                       .Distinct()
                                       .Reverse()
                                       .ToList();

            foreach (var feature in allFeaturesToDisable)
            {
                enabledFeatureIds.Remove(feature.Id);

                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Disabling feature '{FeatureName}'", feature.Id);
                }

                await featureEventHandlers.InvokeAsync((handler, featureInfo) => handler.DisablingAsync(featureInfo), feature, _logger);
            }

            var allFeaturesToEnable = featuresToEnable
                                      .SelectMany(feature => GetFeaturesToEnable(feature, enabledFeatureIds, force))
                                      .Distinct()
                                      .ToList();

            foreach (var feature in allFeaturesToEnable)
            {
                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Enabling feature '{FeatureName}'", feature.Id);
                }

                await featureEventHandlers.InvokeAsync((handler, featureInfo) => handler.EnablingAsync(featureInfo), feature, _logger);
            }

            var allFeaturesToInstall = allFeaturesToEnable
                                       .Where(f => !installedFeatureIds.Contains(f.Id))
                                       .ToList();

            foreach (var feature in allFeaturesToInstall)
            {
                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Installing feature '{FeatureName}'", feature.Id);
                }

                await featureEventHandlers.InvokeAsync((handler, featureInfo) => handler.InstallingAsync(featureInfo), feature, _logger);
            }

            if (allFeaturesToEnable.Count > 0)
            {
                enabledFeatureIds.UnionWith(allFeaturesToEnable.Select(f => f.Id));
            }

            if (allFeaturesToDisable.Count > 0 || allFeaturesToEnable.Count > 0)
            {
                await _shellDescriptorManager.UpdateShellDescriptorAsync(
                    shellDescriptor.SerialNumber,
                    enabledFeatureIds.Select(id => new ShellFeature(id)).ToArray());

                ShellScope.AddDeferredTask(async scope =>
                {
                    var featureEventHandlers = scope.ServiceProvider.GetServices <IFeatureEventHandler>();
                    var logger = scope.ServiceProvider.GetRequiredService <ILogger <ShellFeaturesManager> >();

                    foreach (var feature in allFeaturesToInstall)
                    {
                        if (logger.IsEnabled(LogLevel.Information))
                        {
                            logger.LogInformation("Feature '{FeatureName}' was installed", feature.Id);
                        }

                        await featureEventHandlers.InvokeAsync((handler, featureInfo) => handler.InstalledAsync(featureInfo), feature, logger);
                    }

                    foreach (var feature in allFeaturesToEnable)
                    {
                        if (logger.IsEnabled(LogLevel.Information))
                        {
                            logger.LogInformation("Feature '{FeatureName}' was enabled", feature.Id);
                        }

                        await featureEventHandlers.InvokeAsync((handler, featureInfo) => handler.EnabledAsync(featureInfo), feature, logger);
                    }

                    foreach (var feature in allFeaturesToDisable)
                    {
                        if (logger.IsEnabled(LogLevel.Information))
                        {
                            logger.LogInformation("Feature '{FeatureName}' was disabled", feature.Id);
                        }

                        await featureEventHandlers.InvokeAsync((handler, featureInfo) => handler.DisabledAsync(featureInfo), feature, logger);
                    }
                });
            }

            return(allFeaturesToDisable, allFeaturesToEnable);
        }