Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VirtualPrinterJobLog" /> class.
        /// </summary>
        /// <param name="jobInfo">The <see cref="VirtualPrinterJobInfo" />.</param>
        /// <exception cref="ArgumentNullException"><paramref name="jobInfo" /> is null.</exception>
        public VirtualPrinterJobLog(VirtualPrinterJobInfo jobInfo)
        {
            if (jobInfo == null)
            {
                throw new ArgumentNullException(nameof(jobInfo));
            }

            VirtualPrinterJobId       = SequentialGuid.NewGuid();
            PrintJobClientId          = UniqueFile.ExtractId(jobInfo.PjlHeader.JobName);
            PjlJobName                = jobInfo.PjlHeader.JobName;
            PjlLanguage               = jobInfo.PjlHeader.Language;
            FirstByteReceivedDateTime = jobInfo.FirstByteReceived;
            LastByteReceivedDateTime  = jobInfo.LastByteReceived;
            BytesReceived             = jobInfo.BytesReceived;
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VirtualPrinterJobInfoEventArgs" /> class.
 /// </summary>
 /// <param name="job">The job.</param>
 public VirtualPrinterJobInfoEventArgs(VirtualPrinterJobInfo job)
 {
     Job = job;
 }