private ModulePushNotification ScheduleJob(ModuleBackgroundJobOptions options) { var notification = new ModulePushNotification(_userNameResolver.GetCurrentUserName()); switch (options.Action) { case ModuleAction.Install: notification.Title = "Install Module"; notification.ProgressLog.Add(new ProgressMessage { Level = ProgressMessageLevel.Info, Message = "Starting installation..." }); break; case ModuleAction.Uninstall: notification.Title = "Uninstall Module"; notification.ProgressLog.Add(new ProgressMessage { Level = ProgressMessageLevel.Info, Message = "Starting uninstall..." }); break; } _pushNotifier.Send(notification); BackgroundJob.Enqueue(() => ModuleBackgroundJob(options, notification)); return(notification); }
public void ModuleBackgroundJob(ModuleBackgroundJobOptions options, ModulePushNotification notification) { try { notification.Started = DateTime.UtcNow; var moduleInfos = _externalModuleCatalog.Modules.OfType <ManifestModuleInfo>() .Where(x => options.Modules.Any(y => y.Identity.Equals(x.Identity))) .ToArray(); var reportProgress = new Progress <ProgressMessage>(m => { lock (_lockObject) { notification.Description = m.Message; notification.ProgressLog.Add(m); _pushNotifier.Send(notification); } }); switch (options.Action) { case ModuleAction.Install: _moduleInstaller.Install(moduleInfos, reportProgress); break; case ModuleAction.Uninstall: _moduleInstaller.Uninstall(moduleInfos, reportProgress); break; } } catch (Exception ex) { notification.ProgressLog.Add(new ProgressMessage { Level = ProgressMessageLevel.Error, Message = ex.ToString(), }); } finally { _settingsManager.SetValue(PlatformConstants.Settings.Setup.ModulesAutoInstallState.Name, AutoInstallState.Completed); notification.Finished = DateTime.UtcNow; notification.Description = "Installation finished."; notification.ProgressLog.Add(new ProgressMessage { Level = ProgressMessageLevel.Info, Message = notification.Description, }); _pushNotifier.Send(notification); } }
public void ModuleBackgroundJob(ModuleBackgroundJobOptions options, ModulePushNotification notification) { try { notification.Started = DateTime.UtcNow; var moduleInfos = _moduleCatalog.Modules.OfType <ManifestModuleInfo>() .Where(x => options.Modules.Any(y => y.Identity.Equals(x.Identity))) .ToArray(); var reportProgress = new Progress <ProgressMessage>(m => { lock (_lockObject) { notification.ProgressLog.Add(m); _pushNotifier.Send(notification); } }); switch (options.Action) { case ModuleAction.Install: _moduleInstaller.Install(moduleInfos, reportProgress); break; case ModuleAction.Uninstall: _moduleInstaller.Uninstall(moduleInfos, reportProgress); break; } } catch (Exception ex) { notification.ProgressLog.Add(new ProgressMessage { Level = ProgressMessageLevel.Error, Message = ex.ToString() }); } finally { notification.Finished = DateTime.UtcNow; notification.ProgressLog.Add(new ProgressMessage { Level = ProgressMessageLevel.Info, Message = "Installation finished.", }); _pushNotifier.Send(notification); } }