public static void UpdateSettings(RootActionBase sender, Configuration config) { if (sender == null) { throw new ArgumentNullException(nameof(sender), "Unable to update application settings without a Sender object provided."); } if (config == null) { throw new ArgumentNullException(nameof(config), "Unable to locate application settings file location without the configuration object provided."); } _config = config; XDocument appConfig = (config.AreSettingsExternal) ? XDocument.Load(ExternalAppConfigPath) : XDocument.Load(AppConfigPath); IDictionary <string, string> settings = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> setting in _config.AppSettings) { settings.Add(setting.Key, sender.GetContextAction(setting.Value).NewValue); } foreach (KeyValuePair <string, string> setting in settings) { AddOrUpdateSetting(appConfig, setting); } SaveAppConfig(config.AreSettingsExternal ? ExternalAppConfigPath : AppConfigPath, appConfig); }
private void SetUpEventLogSource(RootActionBase sender) { string source = sender.GetContextAction("Event Log Source").NewValue; if (EventLog.SourceExists(source)) { return; } EventLog.CreateEventSource(source, _config.EventLogLog); EventLog.WriteEntry(source, $"Testing if logging is setup correctly for {source}. Source: {source}, Log: {_config.EventLogLog}"); Logger.LogInstallProgress($"Successfully setup Event Log Source \"{source}\" in Event Log \"{_config.EventLogLog}\""); }
private void ExecutePostInstallActions(RootActionBase sender) { // Update to match number of external statement in try below const int numberOfActions = 7; // Leave alone int currentAction = 1; Progress.Show(); try { UpdateProgress(GetProgressPercent(numberOfActions, ref currentAction), "Updating settings"); UpdateSettingsAction.UpdateSettings(sender, _config); UpdateProgress(GetProgressPercent(numberOfActions, ref currentAction), "Updating global settings path"); UpdateSettingsAction.UpdateGlobalSettingsPath(sender, _config); UpdateProgress(GetProgressPercent(numberOfActions, ref currentAction), "Updating service URL"); UpdateSettingsAction.UpdateServiceUrl(sender, _config); UpdateProgress(GetProgressPercent(numberOfActions, ref currentAction), "Creating database"); DatabaseAction.CreateAndUpdateDatabase(Logger, _config); UpdateProgress(GetProgressPercent(numberOfActions, ref currentAction), "Applying database security settings"); DatabaseAction.UpdateDatabaseSecurityPermissions(Logger, _config); UpdateProgress(GetProgressPercent(numberOfActions, ref currentAction), "Populating database"); DatabaseAction.PopulateDatabase(Logger, _config); UpdateProgress(GetProgressPercent(numberOfActions, ref currentAction), "Setting up event log source"); SetUpEventLogSource(sender); UpdateProgress(100, "Done"); } catch (Exception ex) { Logger.LogInstallProgress("ERROR"); Logger.LogInstallProgress(ex.ToString()); throw; } finally { if (Progress.Visible) { Progress.Close(); Progress.Dispose(); } } }
private void SetUpEventLogSource(RootActionBase sender) { Logger.LogInstallProgress("Setting up the Event Log Source."); string log = "BgmCollaboration"; string source = sender.GetContextAction("Log Source").NewValue; if (EventLog.SourceExists(source)) { return; } EventLog.CreateEventSource(source, log); EventLog.WriteEntry(source, $"Testing if logging is setup correctly for {source}. Source: {source}, Log: {log}"); Logger.LogInstallProgress($"Successfully setup Event Log Source \"{source}\" in Event Log \"{log}\""); }
public static void UpdateGlobalSettingsPath(RootActionBase sender, Configuration config) { if (config == null) { throw new ArgumentNullException(nameof(config), "Unable to locate application settings file location without the configuration object provided."); } _config = config; XDocument appConfig = XDocument.Load(AppConfigPath); XmlNamespaceManager namespaceManager = ConstructEnterpriseLibraryNamespaceManager(); // NOTE: Add/Remove records to match instances of Global Settings (i.e. DataConfiguration) UpdateGlobalSettingPathAttribute(appConfig, namespaceManager, "GlobalSettings", config.GlobalSettings2File); UpdateGlobalSettingKeyPathAttribute(appConfig, namespaceManager, "File Key Algorithm Storage Provider", config.SettingsKeyFile); SaveAppConfig(AppConfigPath, appConfig); }
private void ExecutePostInstallActions(RootActionBase sender) { // Update to match number of external statement in try below const int numberOfActions = 4; // Leave alone int currentAction = 1; Progress.Show(); try { UpdateProgress(GetProgressPercent(numberOfActions, ref currentAction), "Updating settings"); UpdateSettingsAction.UpdateSettings(sender, _config); UpdateProgress(GetProgressPercent(numberOfActions, ref currentAction), "Updating global settings path"); UpdateSettingsAction.UpdateGlobalSettingsPath(sender, _config); UpdateProgress(GetProgressPercent(numberOfActions, ref currentAction), "Setting up event log source"); SetUpEventLogSource(sender); UpdateProgress(GetProgressPercent(numberOfActions, ref currentAction), "Setting up scheduled task"); SetupScheduledTask(sender); UpdateProgress(100, "Done"); } catch (Exception ex) { Logger.LogInstallProgress("ERROR"); Logger.LogInstallProgress(ex.ToString()); throw; } finally { if (Progress.Visible) { Progress.Close(); Progress.Dispose(); } } }
public static void UpdateServiceUrl(RootActionBase sender, Configuration config) { if (config == null) { throw new ArgumentNullException(nameof(config), "Unable to locate application settings file location without the configuration object provided."); } _config = config; XDocument appConfig = XDocument.Load(AppConfigPath); string serviceUrl = sender.GetContextAction("Locations Service URL").NewValue; if (string.IsNullOrWhiteSpace(serviceUrl)) { throw new NullReferenceException("No settings was provided for the Locations Service Url."); } UpdateLocationsServiceUrl(appConfig, serviceUrl); SaveAppConfig(AppConfigPath, appConfig); }
private void ExecutePreInstallActions(RootActionBase sender) { Progress.Show(); try { // No actions to execute } catch (Exception ex) { Logger.LogInstallProgress("ERROR"); Logger.LogInstallProgress(ex.ToString()); throw; } finally { if (Progress.Visible) { Progress.Close(); Progress.Dispose(); } } }
private void SetupScheduledTask(RootActionBase sender) { string taskName = _config.ProductName; string username = sender.GetContextAction("Task Username").NewValue; string password = sender.GetContextAction("Task Password").NewValue; //short dailyInterval = short.Parse(sender.GetContextAction("Task Daily Interval").NewValue); double runInterval = double.Parse(sender.GetContextAction("Task Run Interval").NewValue); double dailyDuration = double.Parse(sender.GetContextAction("Task Daily Duration").NewValue); double runDuration = double.Parse(sender.GetContextAction("Task Run Duration").NewValue); ExecAction executable = new ExecAction(_config.ExecutableName, null, _config.BinTarget); TimeTrigger trigger = new TimeTrigger { StartBoundary = DateTime.Now.AddMinutes(5), // Just start in 5 minutes after install ExecutionTimeLimit = (runDuration > 0) ? TimeSpan.FromSeconds(runDuration) : TimeSpan.Zero //DailyInterval = (short)((dailyInterval > 0) ? dailyInterval : 1), // TimeSpan.Zero = never/always (depending on context). i.e. No interval, no duration, no time limit, etc. // TimeSpan.Zero is the default value on the property regardless }; trigger.Repetition.Interval = (runInterval > 0) ? TimeSpan.FromSeconds(runInterval) : TimeSpan.Zero; trigger.Repetition.Duration = (dailyDuration > 0) ? TimeSpan.FromHours(dailyDuration) : TimeSpan.Zero; using (TaskService svc = new TaskService()) { svc.AddTask(taskName, trigger, executable, username, password, TaskLogonType.Password); } Logger.LogInstallProgress("Successfully setup Scheduled Task with the following parameters."); Logger.LogInstallProgress($"Task Name: {taskName}"); Logger.LogInstallProgress($"Run As: {username}"); //Logger.LogInstallProgress($"Daily Interval: {dailyInterval}"); Logger.LogInstallProgress($"Run Interval: {runInterval}"); Logger.LogInstallProgress($"Daily Duration: {dailyDuration}"); Logger.LogInstallProgress($"Run Duration: {runDuration}"); }