Exemple #1
0
 private void openServicesButton_Click(object sender, EventArgs e)
 {
     try
     {
         m_StaticObjects.EnableServices();
         statusListBox.Items.Add("Internal and External Services Started");
     }
     catch (System.Exception ex)
     {
         if (ex.Message != null)
         {
             statusListBox.Items.Add(ex.Message);
         }
     }
 }
Exemple #2
0
        protected override void OnStart(string[] args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            if (args.Length > 0)
            {
                // The first parameter exists so assume it is the time to wait.
                // This allows a debugger to be attached to the process early on in the debug cycle.
                int timeToWait = 0;
                try
                {
                    timeToWait = int.Parse(args[0], CultureInfo.InvariantCulture);
                }
                catch (System.FormatException)
                {
                    // Just ignore format exceptions and assume that no value was specified.
                }

                if (timeToWait != 0)
                {
                    Thread.Sleep(timeToWait);
                }
            }


            try
            {
                // Tell the diagnostics helper where to log system events to.
                DiagnosticsHelper.SetEventLog(EventLog);

                // Cater for unhandled exceptions. Do this after the event log has been set up.
                // Load in the settings from the application directory if there are any.
                string pathForSystem              = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
                string pathForServiceSettings     = pathForSystem + "\\StackHash";
                string pathForTestServiceSettings = pathForServiceSettings + "\\Test";

                if (!Directory.Exists(pathForServiceSettings))
                {
                    Directory.CreateDirectory(pathForServiceSettings);
                }

                string testModeFileName     = pathForServiceSettings + "\\testmode.xml";
                string testSettingsFileName = pathForTestServiceSettings + "\\testsettings.xml";
                string settingsFileName     = pathForServiceSettings + "\\settings.xml";

                // Now initialise the controller with those settings.
                if (File.Exists(testModeFileName) && (TestSettings.TestMode == "1"))
                {
                    if (!Directory.Exists(pathForTestServiceSettings))
                    {
                        Directory.CreateDirectory(pathForTestServiceSettings);
                    }

                    m_StaticObjects = new StaticObjects(testSettingsFileName, true, true);
                }
                else
                {
                    m_StaticObjects = new StaticObjects(settingsFileName, true, false);
                }

                m_StaticObjects.EnableServices();
            }
            catch (System.Exception ex)
            {
                DiagnosticsHelper.LogMessage(DiagSeverity.ApplicationFatal, "Failed to start Stack Hash service " + ex.ToString());
                throw;
            }
        }