static void MakeDefConfig() { string directory = InfluxCollectConfig.GetDefaultPath(); string filename = InfluxCollectConfig.GetDefaultConfigFileName(); string configfile = String.Format("{0}\\{1}", directory, filename); //if there is no config, just make one from scratch try { InfluxCollectConfig.TryMakeDefaultConfig(directory, filename); } catch (Exception e) { System.Console.WriteLine("Got error " + e.Message); } }
protected override void OnStart(string[] args) { if (!EventLog.SourceExists(sSource)) { EventLog.CreateEventSource(sSource, sLog); } WriteEntryInLog(String.Format("Starting by reading config")); string directory = InfluxCollectConfig.GetDefaultPath(); string filename = InfluxCollectConfig.GetDefaultConfigFileName(); string configfile = String.Format("{0}\\{1}", directory, filename); //if there is no config, just make one from scratch try { InfluxCollectConfig.TryMakeDefaultConfig(directory, filename); } catch (Exception e) { WriteEntryInLog(e.Message); } this.influxconfig = new InfluxCollectConfig(); if (File.Exists(configfile)) { try { this.influxconfig = InfluxCollectConfig.ReadFromFile(configfile); } catch (Exception e) { WriteEntryInLog(String.Format("Could not read config file {0} error {1}", configfile, e.Message)); } } try { psinstance = PowerShell.Create(); psinstance.AddScript("if ( (Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapin VeeamPSSnapIn;}"); psinstance.Invoke(); if (psinstance.Streams.Error.Count > 0) { throw new Exception("Error loading ps : " + psinstance.Streams.Error[0].ToString()); } else { psinstance.Streams.ClearStreams(); } thread = new Thread(WorkThread); thread.Name = "Main Thread"; thread.IsBackground = true; thread.Start(); } catch (Exception e) { runningLock.EnterWriteLock(); this.state = ServiceState.ForceStop; runningLock.ExitWriteLock(); WriteEntryInLog(String.Format("Error on preloading, make sure you are running on a backup server {0}", e.Message)); this.Stop(); } }