Esempio n. 1
0
        static void Main(string[] args)
        {
            // Interop.CoInitializeSecurity(IntPtr.Zero, -1, null, IntPtr.Zero, Interop.RPC_C_AUTHN_LEVEL_NONE, Interop.RPC_C_IMP_LEVEL_IDENTIFY, IntPtr.Zero, Interop.EOAC_NONE, IntPtr.Zero);
            long hres;
            try
            {
                hres = Interop.CoInitializeSecurity(IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero, (uint)RpcAuthnLevel.None, (uint)RpcImpLevel.Identify, IntPtr.Zero, (uint)EoAuthnCap.None, IntPtr.Zero);
            }
            catch (COMException e)
            {
                Logger.LogMessage("CoInitializeSecurity Execption: " + e.Message, Logger.FATAL);
            }
            bool restartLogAppend = false;
            string opt = null;

            int dwResetPeriod = 60 * 60;
            //            Debugger.Break();

            try
            {
                ProjectInstaller.sServiceName = ConfigurationManager.AppSettings["ServiceName"];
                ProjectInstaller.dwResetPeriod = Convert.ToInt32(ConfigurationManager.AppSettings["ResetPeriod"]);
                ProjectInstaller.sServiceUser = ConfigurationManager.AppSettings["ServiceUser"];
                ProjectInstaller.sServicePassword = ConfigurationManager.AppSettings["ServicePassword"];
                restartLogAppend = Convert.ToBoolean(ConfigurationManager.AppSettings["RestartLogAppend"]);
            }
            catch (Exception)
            {
                dwResetPeriod = 60 * 60;
            }

            Logger.RestartLog(restartLogAppend);

            string version = Misc.VersionNumber();
            Logger.LogMessage("MTConnect 4 OPC Agent OPC Version 2.0 - Release " + version, Logger.FATAL);

            if (args.Length > 0)
            {

                // check for arguments
                opt = args[0];

                ProjectInstaller.dwResetPeriod = dwResetPeriod;
                try
                {
                    if (opt != null && opt.ToLower() == "/install")
                    {

                        TransactedInstaller ti = new TransactedInstaller();
                        ProjectInstaller pi = new ProjectInstaller();
                        ti.Installers.Add(pi);
                        String path = String.Format("/assemblypath={0}",
                                                    Assembly.GetExecutingAssembly().Location);
                        String[] cmdline = { path };
                        InstallContext ctx = new InstallContext("", cmdline);
                        ti.Context = ctx;
                        ti.Install(new Hashtable());
                    }
                    else if (opt != null && opt.ToLower() == "/uninstall")
                    {
                        TransactedInstaller ti = new TransactedInstaller();
                        ProjectInstaller mi = new ProjectInstaller();
                        ti.Installers.Add(mi);
                        String path = String.Format("/assemblypath={0}",
                                                    Assembly.GetExecutingAssembly().Location);

                        String[] cmdline = { path };
                        InstallContext ctx = new InstallContext("", cmdline);
                        ti.Context = ctx;
                        ti.Uninstall(null);
                    }
                }
                catch (Exception e)
                {
                    Logger.LogMessage(e.Message, Logger.FATAL);
                }
            }
            if (opt == null) // e.g. ,nothing on the command line
            {
            #if ( ! DEBUG )
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] {new Service1()};
                ServiceBase.Run(ServicesToRun);
            #else
                // debug code: allows the process to run as a non-service
                // will kick off the service start point, but never kill it
                // shut down the debugger to exit
                Service1 service = new Service1();
                service.OnStart(null);
                Thread.Sleep(Timeout.Infinite);
            #endif
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            // Interop.CoInitializeSecurity(IntPtr.Zero, -1, null, IntPtr.Zero, Interop.RPC_C_AUTHN_LEVEL_NONE, Interop.RPC_C_IMP_LEVEL_IDENTIFY, IntPtr.Zero, Interop.EOAC_NONE, IntPtr.Zero);
            long hres;

            try
            {
                hres = Interop.CoInitializeSecurity(IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero, (uint)RpcAuthnLevel.None, (uint)RpcImpLevel.Identify, IntPtr.Zero, (uint)EoAuthnCap.None, IntPtr.Zero);
            }
            catch (COMException e)
            {
                Logger.LogMessage("CoInitializeSecurity Execption: " + e.Message, Logger.FATAL);
            }
            bool   restartLogAppend = false;
            string opt = null;


            int dwResetPeriod = 60 * 60;

//            Debugger.Break();

            try
            {
                ProjectInstaller.sServiceName     = ConfigurationManager.AppSettings["ServiceName"];
                ProjectInstaller.dwResetPeriod    = Convert.ToInt32(ConfigurationManager.AppSettings["ResetPeriod"]);
                ProjectInstaller.sServiceUser     = ConfigurationManager.AppSettings["ServiceUser"];
                ProjectInstaller.sServicePassword = ConfigurationManager.AppSettings["ServicePassword"];
                restartLogAppend = Convert.ToBoolean(ConfigurationManager.AppSettings["RestartLogAppend"]);
            }
            catch (Exception)
            {
                dwResetPeriod = 60 * 60;
            }

            Logger.RestartLog(restartLogAppend);

            string version = Misc.VersionNumber();

            Logger.LogMessage("MTConnect 4 OPC Agent OPC Version 2.0 - Release " + version, Logger.FATAL);

            if (args.Length > 0)
            {
                // check for arguments
                opt = args[0];

                ProjectInstaller.dwResetPeriod = dwResetPeriod;
                try
                {
                    if (opt != null && opt.ToLower() == "/install")
                    {
                        TransactedInstaller ti = new TransactedInstaller();
                        ProjectInstaller    pi = new ProjectInstaller();
                        ti.Installers.Add(pi);
                        String path = String.Format("/assemblypath={0}",
                                                    Assembly.GetExecutingAssembly().Location);
                        String[]       cmdline = { path };
                        InstallContext ctx     = new InstallContext("", cmdline);
                        ti.Context = ctx;
                        ti.Install(new Hashtable());
                    }
                    else if (opt != null && opt.ToLower() == "/uninstall")
                    {
                        TransactedInstaller ti = new TransactedInstaller();
                        ProjectInstaller    mi = new ProjectInstaller();
                        ti.Installers.Add(mi);
                        String path = String.Format("/assemblypath={0}",
                                                    Assembly.GetExecutingAssembly().Location);

                        String[]       cmdline = { path };
                        InstallContext ctx     = new InstallContext("", cmdline);
                        ti.Context = ctx;
                        ti.Uninstall(null);
                    }
                }
                catch (Exception e)
                {
                    Logger.LogMessage(e.Message, Logger.FATAL);
                }
            }
            if (opt == null) // e.g. ,nothing on the command line
            {
#if (!DEBUG)
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] { new Service1() };
                ServiceBase.Run(ServicesToRun);
#else
                // debug code: allows the process to run as a non-service
                // will kick off the service start point, but never kill it
                // shut down the debugger to exit
                Service1 service = new Service1();
                service.OnStart(null);
                Thread.Sleep(Timeout.Infinite);
#endif
            }
        }