Exemplo n.º 1
0
 static void onStateChanged_handler(object sender, ConnectionState state)
 {
     JobsServer.state = state;
     JobsServer.onStateChanged(state.ToString());
     if (state == ConnectionState.Connected | state == ConnectionState.Failed | state == ConnectionState.Unavailable)
     {
         isConnecting = false;
     }
 }
Exemplo n.º 2
0
        // -------------------------------------------------------------------
        /// <summary>
        /// Connect to jobs server
        /// </summary>
        public static void srvConnect(string channel)
        {
            log.Info("Connecting to jobs server...");
            List <Listener> msgWrokers = new List <Listener> {
                Jobs.init(channel, (ex, job) =>
                {
                    log.Info("New print job event. Job is: {0}", job);
                    //jobsTable.add(job);
                    jobs.Add(job);
                    job.onChange += job_onChange;
                    //pushData();
                    updateRequired = true;
                })
            };

            Action <PusherException> onError = (err) =>
            {
                log.Error("Pusher error: {0}", err);
            };

            Action <String> onStateChanged = (state) =>
            {
                //Invoke(new setStatusCb(this.setStatus), new object[] { state });
                log.Info("Pusher state changed to: {0}", state);

                data.state     = state;
                updateRequired = true;

                switch (state)
                {
                case "disconnected":
                    log.Warn("Pusher state is disconnected");
                    break;

                case "unavailable":
                    Thread.Sleep(pusherReconnectDelay);
                    srvConnect(channel);
                    log.Warn("Pusher state is unavailable. Reconnecting in {0} seconds.", pusherReconnectDelay / 1000);
                    break;

                default:
                    break;
                }
            };

            try
            {
                JobsServer.connect(msgWrokers, onError, onStateChanged);
            }
            catch (Exception ex)
            {
                log.Error(ex, "Error while connecting to pusher");
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        public void srvConnectLocal(string channel)
        {
            log.Info("Connecting to jobs server...");
            List <Listener> msgWrokers = new List <Listener> {
                Jobs.init(channel, (ex, job) =>
                {
                    log.Info("New print job event. Job is: {0}", job);
                    jobsTable.add(job);
                })
            };

            Action <PusherException> onError = (err) =>
            {
                log.Error("Pusher error: {0}", err);
            };

            Action <String> onStateChanged = (state) =>
            {
                Invoke(new setStatusCb(this.setStatus), new object[] { state });
                log.Info("Pusher state changed to: {0}", state);
                switch (state)
                {
                case "disconnected":
                    log.Warn("Pusher state is disconnected");
                    break;

                case "unavailable":
                    Thread.Sleep(pusherReconnectDelay);
                    srvConnect(channel);
                    log.Warn("Pusher state is unavailable. Reconnecting in {0} seconds.", pusherReconnectDelay / 1000);
                    break;

                default:
                    break;
                }
            };

            JobsServer.connect(msgWrokers, onError, onStateChanged);
        }
Exemplo n.º 5
0
 static void onError_handler(object sender, PusherException error)
 {
     JobsServer.onError(error);
 }
Exemplo n.º 6
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;
                }
            }
        }
Exemplo n.º 7
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();
        }