예제 #1
0
        public void Uninstall()
        {
            // Check for admin rights
            if (false == this.IsAuthorized())
            {
                this.logSource.TraceEvent(TraceEventType.Error, (int)ApplicationExitCode.SecurityError, Resources.InsufficientAccessPermission);
                this.ExitCode = ApplicationExitCode.SecurityError;
                return;
            }

            if (false == IsServiceInstalled())
            {
                this.logSource.TraceEvent(TraceEventType.Error, (int)ApplicationExitCode.InputError, Resources.NotInstalledService);
                this.ExitCode = ApplicationExitCode.InputError;
                return;
            }

            try
            {
                ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location });
            }
            catch (Exception e)
            {
                this.logSource.TraceEvent(TraceEventType.Error, (int)ApplicationExitCode.RuntimeError, e.Message);
                this.ExitCode = ApplicationExitCode.RuntimeError;
            }
        }
예제 #2
0
        public void Uninstall()
        {
            // Check for admin rights
            if (false == this.IsAuthorized())
            {
                this.logSource.TraceEvent(TraceEventType.Error, (int)ApplicationExitCode.SecurityError, Resources.InsufficientAccessPermission);
                this.ExitCode = ApplicationExitCode.SecurityError;
                return;
            }

            if (false == IsServiceInstalled())
            {
                this.logSource.TraceEvent(TraceEventType.Error, (int)ApplicationExitCode.InputError, Resources.NotInstalledService);
                this.ExitCode = ApplicationExitCode.InputError;
                return;
            }

            try
            {
                ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
            }
            catch (Exception e)
            {
                this.logSource.TraceEvent(TraceEventType.Error, (int)ApplicationExitCode.RuntimeError, e.Message);
                this.ExitCode = ApplicationExitCode.RuntimeError;
            }
        }
예제 #3
0
        private void DisplayExceptionOnConsole(Exception e)
        {
            var rtle = e as ReflectionTypeLoadException;

            if (rtle != null)
            {
                DisplayLoaderExceptionsOnConsole(rtle);
            }

            Console.WriteLine(e.ToString());
            Console.WriteLine();
            Console.WriteLine(Resources.StopServiceMessage);
            Console.ReadLine();
            this.ExitCode = ApplicationExitCode.RuntimeError;
        }
예제 #4
0
        public void Start()
        {
            if (false == IsServiceInstalled())
            {
                this.Install();
                if (this.ExitCode != ApplicationExitCode.Success)
                {
                    return;
                }
            }

            ServiceController controller = GetController();

            switch (controller.Status)
            {
            case ServiceControllerStatus.Running:
                this.logSource.TraceInformation(Resources.ServiceAlreadyStarted);
                return;

            case ServiceControllerStatus.Stopped:
                try
                {
                    controller.Start();
                    controller.WaitForStatus(ServiceControllerStatus.Running, this.startServiceTiemout);
                    this.logSource.TraceInformation(Resources.ServiceStarted);
                    return;
                }
                catch (System.ServiceProcess.TimeoutException)
                {
                    logSource.TraceEvent(TraceEventType.Warning, (int)ApplicationExitCode.RuntimeError, Resources.ServiceNotStartedTimeout);
                    break;
                }
                catch (Exception e)
                {
                    this.logSource.TraceEvent(TraceEventType.Error, (int)ApplicationExitCode.RuntimeError, e.Message);
                    break;
                }

            default:
                this.logSource.TraceEvent(TraceEventType.Error, 0, Resources.ServiceNotStarted, controller.Status);
                break;
            }

            this.ExitCode = ApplicationExitCode.RuntimeError;
        }
예제 #5
0
 public void ConsoleMode()
 {
     try
     {
         using (TraceEventServiceHost service = new TraceEventServiceHost())
         {
             service.Start();
             Console.WriteLine();
             Console.WriteLine(Resources.StopServiceMessage);
             Console.ReadLine();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         Console.WriteLine();
         Console.WriteLine(Resources.StopServiceMessage);
         Console.ReadLine();
         this.ExitCode = ApplicationExitCode.RuntimeError;
     }
 }
예제 #6
0
        public void Install(IEnumerable <Tuple <string, string> > arguments)
        {
            // Check for admin rights
            if (false == this.IsAuthorized())
            {
                this.logSource.TraceEvent(TraceEventType.Error, (int)ApplicationExitCode.SecurityError, Resources.InsufficientAccessPermission);
                this.ExitCode = ApplicationExitCode.SecurityError;
                return;
            }

            if (IsServiceInstalled())
            {
                this.logSource.TraceInformation(Resources.AlreadyInstalledService);
                return;
            }

            try
            {
                var installerArgs = new List <string>();

                var accountArgument = arguments.FirstOrDefault(a => a.Item1 == AccountParameterKey);
                if (accountArgument != null)
                {
                    installerArgs.Add("/account=" + accountArgument.Item2);
                }

                installerArgs.Add(Assembly.GetExecutingAssembly().Location);

                ManagedInstallerClass.InstallHelper(installerArgs.ToArray());
            }
            catch (Exception e)
            {
                this.logSource.TraceEvent(TraceEventType.Error, (int)ApplicationExitCode.RuntimeError, e.Message);
                this.ExitCode = ApplicationExitCode.RuntimeError;
            }
        }
예제 #7
0
        public void Install(IEnumerable<Tuple<string, string>> arguments)
        {
            // Check for admin rights
            if (false == this.IsAuthorized())
            {
                this.logSource.TraceEvent(TraceEventType.Error, (int)ApplicationExitCode.SecurityError, Resources.InsufficientAccessPermission);
                this.ExitCode = ApplicationExitCode.SecurityError;
                return;
            }

            if (IsServiceInstalled())
            {
                this.logSource.TraceInformation(Resources.AlreadyInstalledService);
                return;
            }

            try
            {
                var installerArgs = new List<string>();

                var accountArgument = arguments.FirstOrDefault(a => a.Item1 == AccountParameterKey);
                if (accountArgument != null)
                {
                    installerArgs.Add("/account=" + accountArgument.Item2);
                }

                installerArgs.Add(Assembly.GetExecutingAssembly().Location);

                ManagedInstallerClass.InstallHelper(installerArgs.ToArray());
            }
            catch (Exception e)
            {
                this.logSource.TraceEvent(TraceEventType.Error, (int)ApplicationExitCode.RuntimeError, e.Message);
                this.ExitCode = ApplicationExitCode.RuntimeError;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplicationException"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="exitCode">The exit code.</param>
 /// <param name="innerException">The inner exception.</param>
 public ApplicationException(string message, ApplicationExitCode exitCode, Exception innerException)
     : base(message, innerException)
 {
     this.exitCode = exitCode;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplicationException"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="exitCode">The exit code.</param>
 public ApplicationException(string message, ApplicationExitCode exitCode)
     : base(message)
 {
     this.exitCode = exitCode;
 }
예제 #10
0
        public void Start(IEnumerable<Tuple<string, string>> arguments)
        {
            if (false == IsServiceInstalled())
            {
                this.Install(arguments);
                if (this.ExitCode != ApplicationExitCode.Success)
                {
                    return;
                }
            }

            ServiceController controller = GetController();

            switch (controller.Status)
            {
                case ServiceControllerStatus.Running:
                    this.logSource.TraceInformation(Resources.ServiceAlreadyStarted);
                    return;
                case ServiceControllerStatus.Stopped:
                    try
                    {
                        controller.Start();
                        controller.WaitForStatus(ServiceControllerStatus.Running, this.startServiceTiemout);
                        this.logSource.TraceInformation(Resources.ServiceStarted);
                        return;
                    }
                    catch (System.ServiceProcess.TimeoutException)
                    {
                        logSource.TraceEvent(TraceEventType.Warning, (int)ApplicationExitCode.RuntimeError, Resources.ServiceNotStartedTimeout);
                        break;
                    }
                    catch (Exception e)
                    {
                        this.logSource.TraceEvent(TraceEventType.Error, (int)ApplicationExitCode.RuntimeError, e.Message);
                        break;
                    }

                default:
                    this.logSource.TraceEvent(TraceEventType.Error, 0, Resources.ServiceNotStarted, controller.Status);
                    break;
            }

            this.ExitCode = ApplicationExitCode.RuntimeError;
        }
예제 #11
0
        private void DisplayExceptionOnConsole(Exception e)
        {
            var rtle = e as ReflectionTypeLoadException;
            if (rtle != null)
            {
                DisplayLoaderExceptionsOnConsole(rtle);
            }

            Console.WriteLine(e.ToString());
            Console.WriteLine();
            Console.WriteLine(Resources.StopServiceMessage);
            Console.ReadLine();
            this.ExitCode = ApplicationExitCode.RuntimeError;
        }
예제 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplicationException"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="exitCode">The exit code.</param>
 /// <param name="innerException">The inner exception.</param>
 public ApplicationException(string message, ApplicationExitCode exitCode, Exception innerException)
     : base(message, innerException)
 {
     this.exitCode = exitCode;
 }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplicationException"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="exitCode">The exit code.</param>
 public ApplicationException(string message, ApplicationExitCode exitCode)
     : base(message)
 {
     this.exitCode = exitCode;
 }
예제 #14
0
 public void ConsoleMode()
 {
     try
     {
         using (var service = new TraceEventServiceHost())
         {
             service.Start();
             Console.WriteLine();
             Console.WriteLine(Resources.StopServiceMessage);
             Console.ReadLine();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         Console.WriteLine();
         Console.WriteLine(Resources.StopServiceMessage);
         Console.ReadLine();
         this.ExitCode = ApplicationExitCode.RuntimeError;
     }
 }