StartHostedService() private method

private StartHostedService ( ) : void
return void
Beispiel #1
0
        /// <summary>
        /// Runs the console host.
        /// </summary>
        public void Run()
        {
            if ((object)m_serviceHost == null)
            {
                throw new NullReferenceException("Service host reference is null");
            }

            string userInput = "";

            try
            {
                Thread.CurrentPrincipal      = new GenericPrincipal(new GenericIdentity(UserInfo.CurrentUserID), new[] { "Administrator" });
                m_serviceHost.UpdatedStatus += m_serviceHost_UpdatedStatus;
                m_serviceHost.StartHostedService();
                m_serviceHost.SendRequest(m_clientID, "Filter -Remove 0");

                while (!string.Equals(userInput, "Exit", StringComparison.OrdinalIgnoreCase))
                {
                    // Wait for a command from the user.
                    userInput = System.Console.ReadLine();

                    // Write a blank line to the console.
                    WriteLine();

                    if (!string.IsNullOrWhiteSpace(userInput))
                    {
                        // The user typed in a command and didn't just hit <ENTER>.
                        switch (userInput.ToUpper())
                        {
                        case "CLS":
                            // User wants to clear the console window.
                            System.Console.Clear();
                            break;

                        case "EXIT":
                            // User wants to exit hosted session.
                            break;

                        default:
                            // User wants to send a request to the service.
                            m_serviceHost.SendRequest(m_clientID, userInput);

                            if (string.Compare(userInput, "Help", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                DisplayHelp();
                            }

                            break;
                        }
                    }
                }
            }
            finally
            {
                m_serviceHost.StopHostedService();
                m_serviceHost.UpdatedStatus -= m_serviceHost_UpdatedStatus;
            }
        }
Beispiel #2
0
        private void DebugHost_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                // Call user overridable debug host loading method
                DebugHostLoading();

                // Initialize text.
                m_productName              = AssemblyInfo.EntryAssembly.Title;
                this.Text                  = string.Format(this.Text, m_productName);
                notifyIcon.Text            = string.Format(notifyIcon.Text, m_productName);
                LabelNotice.Text           = string.Format(LabelNotice.Text, m_productName);
                exitToolStripMenuItem.Text = string.Format(exitToolStripMenuItem.Text, m_productName);

                // Minimize the window.
                this.WindowState = FormWindowState.Minimized;

                // Start the windows service.
                ServiceHost.StartHostedService();
            }
        }