Beispiel #1
0
 void host_Closed(object sender, EventArgs e)
 {
     WriteLog.WriteToLog(EventLogEntryType.Warning, String.Format("WCF service {0} was closed. This is unexpected if service is not stopped", host.Description.ServiceType));
 }
Beispiel #2
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static int Main(string[] args)
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                new Service1()
            };
            if (System.Environment.UserInteractive)
            {
                if (args.Length != 1 || args[0] == "?" || (args[0].Replace("-", "/") + "   ").Substring(0, 2) == "/h")
                {
                    Console.WriteLine("OneDrive Sync Status Service");
                    Console.WriteLine("============================");
                    Console.WriteLine("Syntax: OdSyncService.exe [/i] [/u]");
                    Console.WriteLine("Where:");
                    Console.WriteLine("\t/i install the service");
                    Console.WriteLine("\t/u uninstall the service");
                    return(0); // ok
                }

                // we only care about the first two characters
                string arg = args[0].Replace("-", "/").ToLowerInvariant().Substring(0, 2);

                string PathToSelf = Assembly.GetExecutingAssembly().Location;


                switch (arg)
                {
                case "/i":      // install
                    try
                    {
                        ManagedInstallerClass.InstallHelper(
                            new string[] { PathToSelf });
                        WriteLog.WriteInformationEvent("Service installed successfully");

                        return(0);
                    }
                    catch (Exception ex)
                    {
                        WriteLog.WriteErrorEvent(String.Format("Installation failed: {0} {1}", ex.GetType().ToString(), ex.Message));
                        return(-1);
                    }
                    break;

                case "/u":      // uninstall
                    try
                    {
                        ManagedInstallerClass.InstallHelper(
                            new string[] { "/u", PathToSelf });
                        WriteLog.WriteInformationEvent("Service uninstalled successfully");
                        return(0);
                    }
                    catch (Exception ex)
                    {
                        WriteLog.WriteErrorEvent(String.Format("Uninstallation failed: {0} {1}", ex.GetType().ToString(), ex.Message));
                        return(-1);
                    }
                    break;

                default:      // unknown option
                    Console.WriteLine("Invalid option: {0}", args[0]);
                    Console.WriteLine(string.Empty);

                    return(-1);
                }
            }

            ServiceBase.Run(ServicesToRun);
            return(0);
        }
Beispiel #3
0
 void host_Faulted(object sender, EventArgs e)
 {
     WriteLog.WriteToLog(EventLogEntryType.Error, String.Format("WCF service {0} failed. This is unexpected. Please restart service.", host.Description.ServiceType));
 }