コード例 #1
0
        /// <summary>
        /// Set things in motion so your service can do its work.
        /// </summary>
        protected override void OnStart(string[] args)
        {
            try
            {
                m_RegValues = new RegValues();
                m_TimeStep  = Convert.ToDouble(m_RegValues.ChInterval) * 60000;                //Minutes
                //m_TimeStep = (Convert.ToDouble(m_RegValues.ChInterval) * 60) * 60000; //Hours

                m_Timer           = new System.Timers.Timer();
                m_Timer.Elapsed  += new ElapsedEventHandler(myTimer_Elapsed);
                m_Timer.AutoReset = true;
                m_Timer.Interval  = m_TimeStep;
                m_Timer.Enabled   = false;
                //			nextInc = this.getIncNearTime(m_Start);//new DateTime(1971,1,1);
                //			nextFull = this.getFullNearTime(m_Start);//new DateTime(1971,1,1);
                this.m_Timer.Start();

                this.EventLog.WriteEntry("OneAssistance Service started OK", EventLogEntryType.Information);
            }
            catch (System.Exception e)
            {
                System.Exception ie = e;
                while (ie.InnerException != null)
                {
                    ie = ie.InnerException;
                }
                throw(ie);
            }
        }
コード例 #2
0
        public ParamsWin()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            m_RegValues = new RegValues();

            efSystemDSN.Text  = m_RegValues.DBInstance;
            efDBUser.Text     = m_RegValues.DBUser;
            efDBPassword.Text = m_RegValues.DBPassword;
            efRetypePwd.Text  = m_RegValues.DBPassword;

            ddInterval.Value = Convert.ToDecimal(m_RegValues.ChInterval);

            efSMTPserver.Text   = m_RegValues.SMTPServer;
            efSMTPport.Text     = m_RegValues.SMTPPort.ToString();
            efSMTPuser.Text     = m_RegValues.SMTPUser;
            efSMTPpwd.Text      = m_RegValues.SMTPPassword;
            efSMTPretype.Text   = m_RegValues.SMTPPassword;
            cbEnableSSL.Checked = m_RegValues.EnableSSL;

            efNotifyTo.Text = m_RegValues.NotifyTo;

            //getRegValues();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
コード例 #3
0
        // The main entry point for the process
        static void Main(string[] args)
        {
            string opt = null;

            // check for arguments
            if (args.Length > 0)
            {
                opt = args[0];
                if (opt != null && opt.ToLower() == "/install")
                {
                    ParamsWin mForm = new ParamsWin();
                    if (mForm.ShowDialog() == DialogResult.Cancel)
                    {
                        return;
                    }

                    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;
                    try
                    {
                        ServiceController mService = new ServiceController("OneAssistance");
                        if (mService.DisplayName != string.Empty)
                        {
                            if (mService.CanStop)
                            {
                                mService.Stop();
                                mService.WaitForStatus(ServiceControllerStatus.Stopped);
                            }
                            ti.Uninstall(null);
                        }
                    }
                    catch (System.Exception)
                    {
                    }

                    ti.Install(new Hashtable());
                }
                else if (opt != null && opt.ToLower() == "/update")
                {
                    try
                    {
                        ServiceController mService = new ServiceController("OneAssistance");
                        string            n        = mService.DisplayName;
                    }
                    catch (System.Exception e)
                    {
                        MessageBox.Show(e.Message, "OneAssistanceSrvc /update", MessageBoxButtons.OK);
                        return;
                    }

                    ParamsWin mForm = new ParamsWin();
                    if (mForm.ShowDialog() == DialogResult.OK)
                    {
                        MessageBox.Show("Service params successfully updated!", "OneAssistance Service", MessageBoxButtons.OK);
                    }
                }
                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;
                    try
                    {
                        ti.Uninstall(null);
                    }
                    catch (System.Exception)
                    {
                    }
                    RegValues lRegValues = new RegValues();
                    lRegValues.clearRegValues();
                }
                else if (opt != null && opt.ToLower() == "/version")
                {
                    MessageBox.Show("Version: 1.0.0", "OneAssistance Service", MessageBoxButtons.OK);
                }
            }

            if (opt == null)             // e.g. ,nothing on the command line
            {
#if (!DEBUG)
                System.ServiceProcess.ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] { new DoCheckUp() };
                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
                DoIntegration service = new DoIntegration();
                service.OnStart(null);
                Thread.Sleep(Timeout.Infinite);
#endif
            }
        }