예제 #1
0
        /// <summary>
        /// Rolls back to the state of the counter, and performs the normal rollback.
        /// </summary>
        /// <param name="savedState">The saved state for the installation.</param>
        public override void Rollback(IDictionary savedState)
        {
            ConsoleHarness.WriteToConsole(ConsoleColor.White, "Rolling back service {0}.", Configuration.Name);

            // load the assembly file name and the config
            ConfigureInstallers();
            base.Rollback(savedState);
        }
예제 #2
0
        /// <summary>
        /// Installer class, to use run InstallUtil against this .exe
        /// </summary>
        /// <param name="savedState">The saved state for the installation.</param>
        public override void Install(IDictionary savedState)
        {
            ConsoleHarness.WriteToConsole(ConsoleColor.White, "Installing service {0}.", Configuration.Name);

            // install the service
            ConfigureInstallers();
            base.Install(savedState);

            // wire up the event log source, if provided
            if (!string.IsNullOrWhiteSpace(Configuration.EventLogSource))
            {
                // create the source if it doesn't exist
                if (!EventLog.SourceExists(Configuration.EventLogSource))
                {
                    EventLog.CreateEventSource(Configuration.EventLogSource, "Application");
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Removes the counters, then calls the base uninstall.
        /// </summary>
        /// <param name="savedState">The saved state for the installation.</param>
        public override void Uninstall(IDictionary savedState)
        {
            ConsoleHarness.WriteToConsole(ConsoleColor.White, "Un-Installing service {0}.", Configuration.Name);

            // load the assembly file name and the config
            ConfigureInstallers();
            base.Uninstall(savedState);

            // wire up the event log source, if provided
            if (!string.IsNullOrWhiteSpace(Configuration.EventLogSource))
            {
                // create the source if it doesn't exist
                if (EventLog.SourceExists(Configuration.EventLogSource))
                {
                    EventLog.DeleteEventSource(Configuration.EventLogSource);
                }
            }
        }
예제 #4
0
        // The main entry point for the windows service application.
        static void Main(string[] args)
        {
            try
            {
                // If install was a command line flag, then run the installer at runtime.
                if (args.Contains("-install", StringComparer.InvariantCultureIgnoreCase))
                {
                    WindowsServiceInstaller.RuntimeInstall <ServiceImplementation>();
                }

                // If uninstall was a command line flag, run uninstaller at runtime.
                else if (args.Contains("-uninstall", StringComparer.InvariantCultureIgnoreCase))
                {
                    WindowsServiceInstaller.RuntimeUnInstall <ServiceImplementation>();
                }

                // Otherwise, fire up the service as either console or windows service based on UserInteractive property.
                else
                {
                    var implementation = new ServiceImplementation();

                    // If started from console, file explorer, etc, run as console app.
                    if (Environment.UserInteractive)
                    {
                        ConsoleHarness.Run(args, implementation);
                    }

                    // Otherwise run as a windows service
                    else
                    {
                        ServiceBase.Run(new WindowsServiceHarness(implementation));
                    }
                }
            }

            catch (Exception ex)
            {
                ConsoleHarness.WriteToConsole(ConsoleColor.Red, "\nAn exception occurred in Main(): {0}", ex);
                ConsoleHarness.WaitForKey(true);
            }
        }
예제 #5
0
        internal new void WriteEntry(string message, EventLogEntryType type)
        {
            if (useConsole)
            {
                ConsoleColor color = ConsoleColor.Green;
                switch (type)
                {
                case EventLogEntryType.Error:
                    color = ConsoleColor.Red; break;

                case EventLogEntryType.Information:
                    color = ConsoleColor.Blue; break;

                case EventLogEntryType.Warning:
                    color = ConsoleColor.White; break;
                }

                ConsoleHarness.WriteToConsole(color, "\n" + message);
            }
            else
            {
                base.WriteEntry(message, type);
            }
        }
예제 #6
0
 /// <summary>
 /// This method is called when a custom command is issued to the service.
 /// </summary>
 /// <param name="command">The command identifier to execute.</param >
 public void OnCustomCommand(int command)
 {
     ConsoleHarness.WriteToConsole(ConsoleColor.DarkGreen, "OnCustomCommand({0})", command);
 }
예제 #7
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 /// <filterpriority>2</filterpriority>
 public void Dispose()
 {
     ConsoleHarness.WriteToConsole(ConsoleColor.DarkMagenta, "Dispose()");
 }
예제 #8
0
 /// <summary>
 /// This method is called when the machine the service is running on
 /// is being shutdown.
 /// </summary>
 public void OnShutdown()
 {
     ConsoleHarness.WriteToConsole(ConsoleColor.DarkRed, "OnShutdown()");
 }
예제 #9
0
 /// <summary>
 /// This method is called when a service gets a request to resume
 /// after a pause is issued.
 /// </summary>
 public void OnContinue()
 {
     ConsoleHarness.WriteToConsole(ConsoleColor.Blue, "OnContinue()");
 }
예제 #10
0
 /// <summary>
 /// This method is called when a service gets a request to pause,
 /// but not stop completely.
 /// </summary>
 public void OnPause()
 {
     ConsoleHarness.WriteToConsole(ConsoleColor.Magenta, "OnPause()");
 }
예제 #11
0
 /// <summary>
 /// This method is called when the service gets a request to stop.
 /// </summary>
 public void OnStop()
 {
     ConsoleHarness.WriteToConsole(ConsoleColor.Red, "OnStop()");
 }
예제 #12
0
 /// <summary>
 /// This method is called when the service gets a request to start.
 /// </summary>
 /// <param name="args">Any command line arguments</param>
 public void OnStart(string[] args)
 {
     ConsoleHarness.WriteToConsole(ConsoleColor.Green, "OnStart({0})", args);
 }