public IHttpActionResult TryToAutoInstallModules() { var notification = new webModel.ModuleAutoInstallPushNotification(User.Identity.Name) { Title = "Modules installation", //set completed by default Finished = DateTime.UtcNow }; if (!_settingsManager.GetValue("VirtoCommerce.ModulesAutoInstalled", false)) { lock (_lockObject) { if (!_settingsManager.GetValue("VirtoCommerce.ModulesAutoInstalled", false)) { var moduleBundles = ConfigurationHelper.SplitAppSettingsStringValue("VirtoCommerce:AutoInstallModuleBundles"); if (!moduleBundles.IsNullOrEmpty()) { _settingsManager.SetValue("VirtoCommerce.ModulesAutoInstalled", true); _settingsManager.SetValue(_autoInstallStateSetting, webModel.AutoInstallState.Processing); EnsureModulesCatalogInitialized(); var modules = new List <ManifestModuleInfo>(); var moduleVersionGroups = _moduleCatalog.Modules .OfType <ManifestModuleInfo>() .Where(x => x.Groups.Intersect(moduleBundles, StringComparer.OrdinalIgnoreCase).Any()) .GroupBy(x => x.Id); //Need install only latest versions foreach (var moduleVersionGroup in moduleVersionGroups) { var alreadyInstalledModule = _moduleCatalog.Modules.OfType <ManifestModuleInfo>().FirstOrDefault(x => x.IsInstalled && x.Id.EqualsInvariant(moduleVersionGroup.Key)); //skip already installed modules if (alreadyInstalledModule == null) { var latestVersion = moduleVersionGroup.OrderBy(x => x.Version).LastOrDefault(); if (latestVersion != null) { modules.Add(latestVersion); } } } var modulesWithDependencies = _moduleCatalog.CompleteListWithDependencies(modules) .OfType <ManifestModuleInfo>() .Where(x => !x.IsInstalled) .Select(x => x.ToWebModel()) .ToArray(); if (modulesWithDependencies.Any()) { var options = new webModel.ModuleBackgroundJobOptions { Action = webModel.ModuleAction.Install, Modules = modulesWithDependencies }; //reset finished date notification.Finished = null; BackgroundJob.Enqueue(() => ModuleBackgroundJob(options, notification)); } } } } } return(Ok(notification)); }
public IHttpActionResult TryToAutoInstallModules() { var notification = new webModel.ModuleAutoInstallPushNotification("System") { Title = "Modules installation", //set completed by default Finished = DateTime.UtcNow }; EnsureModulesCatalogInitialized(); if (!_settingsManager.GetValue("VirtoCommerce.ModulesAutoInstalled", false)) { lock (_lockObject) { if (!_settingsManager.GetValue("VirtoCommerce.ModulesAutoInstalled", false)) { var moduleBundles = ConfigurationManager.AppSettings.GetValues("VirtoCommerce:AutoInstallModuleBundles"); if (!moduleBundles.IsNullOrEmpty()) { _settingsManager.SetValue("VirtoCommerce.ModulesAutoInstalled", true); var modules = new List<ManifestModuleInfo>(); var moduleVersionGroups = _moduleCatalog.Modules .OfType<ManifestModuleInfo>() .Where(x => x.Groups.Intersect(moduleBundles, StringComparer.OrdinalIgnoreCase).Any()) .GroupBy(x => x.Id); //Need install only latest versions foreach (var moduleVersionGroup in moduleVersionGroups) { var alreadyInstalledModule = _moduleCatalog.Modules.OfType<ManifestModuleInfo>().FirstOrDefault(x => x.IsInstalled && x.Id.EqualsInvariant(moduleVersionGroup.Key)); //skip already installed modules if (alreadyInstalledModule == null) { var latestVersion = moduleVersionGroup.OrderBy(x => x.Version).LastOrDefault(); if (latestVersion != null) { modules.Add(latestVersion); } } } var modulesWithDependencies = _moduleCatalog.CompleteListWithDependencies(modules) .OfType<ManifestModuleInfo>() .Where(x => !x.IsInstalled) .Select(x => x.ToWebModel()) .ToArray(); if (modulesWithDependencies.Any()) { var options = new webModel.ModuleBackgroundJobOptions { Action = webModel.ModuleAction.Install, Modules = modulesWithDependencies }; //reset finished date notification.Finished = null; BackgroundJob.Enqueue(() => ModuleBackgroundJob(options, notification)); } } } } } return Ok(notification); }