Пример #1
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");
            }
        }
Пример #2
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);
        }