Beispiel #1
0
        public void OnMessageReceived(object sender, MessageEventArgs args)
        {
            Message response = null;

            if (args.message is ReadyMessage)
            {
                ReadyMessage readyMessage = args.message as ReadyMessage;

                RemoveFromBackup(readyMessage.idReceived);
                if (messageQueue.Count == 0)
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(WaitSend));
                }
                else
                {
                    response = messageQueue.DequeueValue();
                }
            }
            else if (args.message is RecordMessage)
            {
                RecordMessage recordMessage = args.message as RecordMessage;

                EnqueueWork(recordMessage.htmlRecord);
                TrackJob(recordMessage.htmlRecord);

                response = new ReadyMessage(recordMessage.id);
            }
            else if (args.message is StatusRequest)
            {
                StatusRequest statusRequest = args.message as StatusRequest;

                ObjectId  jobId  = statusRequest.requestedId;
                JobStatus status = GetJobStatus(jobId);

                if (status == JobStatus.ErrorLoading || status == JobStatus.ErrorRequesting || status == JobStatus.LoadingPages)
                {
                    StopTrackingJob(jobId);
                }
                KeyValuePair <ObjectId, JobStatus> statusPair = new KeyValuePair <ObjectId, JobStatus>
                                                                    (key: jobId, value: status);
                response = new StatusReport(statusPair);
            }
            else if (args.message is DestroyedBuffer)
            {
                response = new ResendMessage();
            }
            else if (args.message is ResendMessage)
            {
                response = RetrieveFromBackup();
            }

            if (response != null)
            {
                Send(response);
            }

            PrintJobs();
        }
Beispiel #2
0
        public void OnServerConnection(object sender, EventArgs args)
        {
            Message readyMessage = new ReadyMessage(ObjectId.Empty);

            Send(BSON.Serialize <Message>(readyMessage));
        }