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)); }
/// <summary> /// Initializes a new instance of the <see cref="VirtualPrinterJobInfo" /> class. /// </summary> /// <param name="pjlHeader">The PJL header.</param> /// <exception cref="ArgumentNullException"><paramref name="pjlHeader" /> is null.</exception> public VirtualPrinterJobInfo(PjlHeader pjlHeader) { PjlHeader = pjlHeader ?? throw new ArgumentNullException(nameof(pjlHeader)); }