Пример #1
0
        /// <summary>
        /// Executed when a job arrives on the queue
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event data</param>
        protected virtual void OnReceivedJob(object sender, ReceivedMessageEventArgs e)
        {
            var message = e.Message;
            var jobId   = e.Message.Id;

            var jobRequest        = CreateJobRequest(e.Message);
            var processingRequest = CreateProcessingRequest(jobRequest, e.Message);

            JobReceived?.Invoke(this, new JobReceivedEventArgs(processingRequest));
        }
Пример #2
0
        private void ReceiveJob(Socket socket)
        {
            PjlJobReader pjlProcessor      = new PjlJobReader();
            DateTime     lastConsoleUpdate = DateTime.Now;

            LogInfo("Processing job...");
            int      byteCount         = 0;
            DateTime firstByteReceived = DateTime.Now;
            DateTime lastByteReceived  = DateTime.MinValue;

            int size = 0;

            byte[] receiveBuffer = new byte[PacketSize];
            while ((size = socket.Receive(receiveBuffer)) > 0)
            {
                byteCount += size;

                pjlProcessor.ReadPrintJobBytes(receiveBuffer, size);
                lastByteReceived = DateTime.Now;

                // In an effort to not log something to the screen every 10,000 bytes
                // (which can be quite a bit on a fast machine), let's log screen updates 10 times a second.
                if (DateTime.Now > lastConsoleUpdate.AddMilliseconds(100))
                {
                    Console.Write($"BYTES READ: {byteCount}\r");
                    lastConsoleUpdate = DateTime.Now;
                }

                // This models a slight delay between blocks of data to slow down the overall
                // transfer of raw data.  By changing this value up or down, this component
                // can loosely model a slower or faster device.
                Thread.Sleep(PacketDelay);
            }

            LogInfo($"Job Received: {byteCount} bytes");

            PjlHeader             header  = pjlProcessor.Header;
            VirtualPrinterJobInfo jobInfo = new VirtualPrinterJobInfo(header)
            {
                FirstByteReceived = firstByteReceived,
                LastByteReceived  = lastByteReceived,
                BytesReceived     = byteCount
            };

            JobReceived?.Invoke(this, new VirtualPrinterJobInfoEventArgs(jobInfo));
        }