Пример #1
0
        // -------------------------------------------------------------------
        /// <summary>
        /// Server connect
        /// </summary>
        public void srvConnect(string channel)
        {
            //Console.WriteLine("srvConnect, Program.isService= {0} ", Program.isService);

            if (Program.isService)
            {
                JobsServer.disconnect();
                log.Info("Connecting to jobs server via service...");
                srvConnectService(channel);
            }
            else
            {
                Pipe.clientStop();
                log.Info("Connecting to jobs server directly...");
                srvConnectLocal(channel);
            }
        }
Пример #2
0
        public void service(bool state)
        {
            bool isRunning = ServiceControl.isRunning(serviceName);

            Program.isService = state;
            if (state)
            {
                try
                {
                    if (!ServiceControl.isInstalled(serviceName))
                    {
                        Process p = Process.Start(new ProcessStartInfo()
                        {
                            FileName    = serviceExe,
                            Arguments   = "/i",
                            WindowStyle = ProcessWindowStyle.Hidden
                        });
                        p.WaitForExit(30000);
                        ServiceControl.startType(serviceName, ServiceControl.StartupTypes.Disabled);
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex, "Error while installing service");
                    MessageBox.Show("Can't install service. Error is: {0}", ex.Message);
                }

                try
                {
                    if (isRunning)
                    {
                        ServiceControl.stop(serviceName, 5000);
                    }
                    ServiceControl.start(serviceName, 5000);
                    JobsServer.disconnect();
                    if (Program.config.channel.Length > 0)
                    {
                        srvConnect(Program.config.channel);
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex, "Error while starting service");
                    MessageBox.Show("Can't run service. Error is: {0}", ex.Message);
                    //serviceEnabledCheckBox.Checked = false;
                }
            }
            else if (isRunning)
            {
                try
                {
                    ServiceControl.stop(serviceName, 5000);
                    if (Program.config.channel.Length > 0)
                    {
                        srvConnect(Program.config.channel);
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex, "Error while stopping service");
                    MessageBox.Show("Can't stop service. Error is: {0}", ex.Message);
                    //serviceEnabledCheckBox.Checked = true;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Login button handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="ev"></param>
        private void submit_Click(object sender, EventArgs ev)
        {
            log.Info("Submit click event");
            if (Credentials.SrvXT == null || Credentials.SrvXT.Length == 0)
            {
                MessageBox.Show("Jobs server API key is empty - can't connect to jobs server.");
                return;
            }

            if (isLoggedIn())
            {
                JobsServer.disconnect();
                Program.config.channel = "";
                Program.config.login   = "";
                Program.config.save();
                loginInput.Text    = "";
                passwordInput.Text = "";
                loginSetState();
                return;
            }

            loginTab.Focus();
            loginInput.Enabled    = false;
            passwordInput.Enabled = false;
            submit.Enabled        = false;
            LoginResponse resp = null;

            log.Info("Connecting to login server...");
            try
            {
                resp = LoginServer.login(loginInput.Text, passwordInput.Text);
            }
            catch (Exception err)
            {
                log.Error(err, "Login error.");
            }

            if (resp != null)
            {
                statusLogin.Text = "logged in";
                if (LoginServer.locations != null)
                {
                    Program.config.locations = updateLocations(LoginServer.locations, LoginServer.defaultLocation);
                }

                // Registers
                Registers.Add(LoginServer.registers);
                //foreach (Register r in LoginServer.registers)
                //{
                //    Registers.Add(r);
                //}

                foreach (RegisterDD rdd in registersDD)
                {
                    rdd.setItems(Program.config.registers);
                }

                Program.config.login              = loginInput.Text;
                Program.config.channel            = LoginServer.channel;
                Program.config.availableLocations = LoginServer.locations;
                Program.config.save();
                //configSave.Enabled = false;
                srvConnect(LoginServer.channel);
            }
            else
            {
                log.Error("Login error: empty response");
            }

            loginInput.Enabled    = true;
            passwordInput.Enabled = true;
            //submit.Enabled = true;
            loginSetState();
        }