예제 #1
0
        /// <summary>
        /// Get event from a printer, it could be ink issue or page issue
        /// If the event is critical, change printer
        /// </summary>
        /// <param name="sender">The object sender</param>
        /// <param name="e">The argument sent</param>
        public void Event(object sender, EventArgs e)
        {
            if (!(e is PrinterEventArgs))
            {
                return;
            }

            PrinterEventArgs args = (PrinterEventArgs)e;

            MessageBoxPrint(args);

            if (args.Critical)
            {
                if (args.ErrorMessage == "Ink quantity less than 1%")
                {
                    AddInk(CurrentPrinter);
                }

                else
                {
                    AddPages(CurrentPrinter);
                }

                if (CurrentPrinter == (PrinterUserControl)sender)
                {
                    queue.Enqueue(CurrentPrinter);
                    CurrentPrinter = queue.Dequeue();
                }
            }
        }
예제 #2
0
        public MainWindow()
        {
            InitializeComponent();

            queue = new Queue <PrinterUserControl>();
            foreach (Control item in printersGrid.Children)
            {
                if (item is PrinterUserControl)
                {
                    PrinterUserControl printer = item as PrinterUserControl;
                    printer.InkEmpty    += Event;
                    printer.PageMissing += Event;
                    queue.Enqueue(printer);
                }
            }
            CurrentPrinter = queue.Dequeue();
        }
예제 #3
0
 public void AddPages(PrinterUserControl p)
 {
     CurrentPrinter.PageCount +=
         rand.Next(PrinterUserControl.MIN_ADD_PAGES, PrinterUserControl.MAX_PAGES);
 }
예제 #4
0
 public void AddInk(PrinterUserControl p)
 {
     CurrentPrinter.InkCount +=
         rand.NextDouble() + rand.Next((int)PrinterUserControl.MIN_ADD_INK, (int)PrinterUserControl.MAX_INK);
 }