Esempio n. 1
0
        /// Window Event Handling
        #region Window Event Handling

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void WindowClosed(object sender, EventArgs e)
        {
            try
            {
                // get window as a sender of event
                PrintingControlWindow window = sender as PrintingControlWindow;

                // check the window
                if (window != null && window.ViewModel != null && window.ViewModel.PrintJobTitle != null)
                {
                    // remove window from the list
                    listOfWindows.Remove(window);

                    // remove print job title from the titles
                    localPrintEventWatcher.AllowedPrintersTitles.RemoveTitle(window.ViewModel.PrintJobTitle);

                    // unsubscribe from event
                    window.Closed -= WindowClosed;
                }
            }
            catch (Exception ex)
            {
                WPFNotifier.Error(ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Launches print control window for the specified file. (Virtual printer method)
        /// </summary>
        /// <param name="eFileName">file name</param>
        /// <param name="copyFile">copy file flag</param>
        public void LaunchPrintControl(string eFileName, bool copyFile = true)
        {
            // check the file name
            if (string.IsNullOrWhiteSpace(eFileName))
            {
                return;
            }

            LogHelper.LogDebug("Launch UI For File " + eFileName);

            try
            {
                string newFileName = eFileName;
                if (copyFile)
                {
                    // create new file name
                    newFileName = Path.Combine(ConfigData.Path_Processing, Path.GetFileName(eFileName));

                    // if the file with new file name exists
                    if (File.Exists(newFileName))
                    {
                        // delete the file
                        File.Delete(newFileName);
                    }

                    // copy old file to the new one
                    File.Copy(eFileName, newFileName);
                }

                _dispatcher.BeginInvoke(new Action(() =>
                {
                    PrintJobTitle title = null;

                    // check the allowed printers
                    if (localPrintEventWatcher.AllowedPrintersTitles != null && localPrintEventWatcher.AllowedPrintersTitles.Count > 0)
                    {
                        // get the last title from the allowed printers (this needs for retrieving the correct print job title, for example)
                        title = localPrintEventWatcher.AllowedPrintersTitles.Last();
                    }

                    // show preparing progress
                    //MainController.Singleton.ShowProgressWindow("Preparing", "Your document is being prepared for printing, please wait...");

                    // set up an launch UI for the incoming file
                    PrintingControlWindow window = new PrintingControlWindow(newFileName, title);
                    window.Closed += WindowClosed;

                    // show UI
                    window.Show();
                }), DispatcherPriority.Background);
            }
            catch (Exception ex)
            {
                WPFNotifier.Error(ex);
            }
        }
Esempio n. 3
0
        /// Init
        #region Init

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="owner">owner</param>
        /// <param name="model">model</param>
        public PrintingControlViewModel(PrintingControlWindow owner, PrintingControlModel model)
        {
            // set owner
            _owner = owner;

            // set model
            _model                  = model;
            _model.Closed          += _model_Closed;
            _model.StatusChanged   += _model_StatusChanged;
            _model.ColorDetermined += _model_ColorDetermined;
            _model.ReadyToPrint    += _model_ReadyToPrint;

            // init model
            model.Init();

            // set top most
            SetTopMost();
        }
        /// <summary>
        /// Disposes data.
        /// </summary>
        public void Dispose()
        {
            // dispose model
            if (_model != null)
            {
                _model.Closed          -= _model_Closed;
                _model.StatusChanged   -= _model_StatusChanged;
                _model.ColorDetermined -= _model_ColorDetermined;
                _model.ReadyToPrint    -= _model_ReadyToPrint;
                _model = null;
            }

            // dispose owner
            if (_owner != null)
            {
                _owner = null;
            }
        }
        /// Init
        #region Init

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="owner">owner</param>
        /// <param name="model">model</param>
        public PrintingControlViewModel(PrintingControlWindow owner, PrintingControlModel model)
        {
            // show preparing progress
            // MainController.Singleton.ShowProgressWindow("Preparing", "Your document is being prepared for printing, please wait...");

            // set owner
            _owner = owner;

            // set model
            _model                  = model;
            _model.Closed          += _model_Closed;
            _model.StatusChanged   += _model_StatusChanged;
            _model.ColorDetermined += _model_ColorDetermined;
            _model.ReadyToPrint    += _model_ReadyToPrint;

            // init model
            model.Init();

            // set top most
            SetTopMost();
        }
Esempio n. 6
0
        /// <summary>
        /// Launches print control window for the specified data. (Real printer method)
        /// </summary>
        /// <param name="printJob"></param>
        public void LaunchPrintControl(PrintJobData printJob)
        {
            // check the print job data
            if (printJob == null || printJob.PrintJobTitle == null)
            {
                return;
            }

            LogHelper.LogDebug("Launch For Real Printer " + printJob.PrintJobTitle);

            try
            {
                _dispatcher.BeginInvoke(new Action(() =>
                {
                    // Update print job logic:
                    // if the window already created but we received additional data (like number of pages) then find that window and update it's data

                    // iterate through the list of windows
                    foreach (var f in listOfWindows)
                    {
                        LogHelper.LogDebug("Seek Window");

                        // get the data context of the window - has to be a PrintingControlViewModel
                        var dc = f.DataContext as PrintingControlViewModel;

                        // check the data context
                        if (dc != null)
                        {
                            // compare print job titles
                            if (dc.PrintJobTitle.Equals(printJob.PrintJobTitle))
                            {
                                LogHelper.LogDebug("Window found");
                                // update data
                                f.UpdateData(printJob);
                                return;
                            }
                        }
                    }

                    // if the job ain't present for some reason at this moment then leave
                    if (!PrintHelper.HasPrintJob(printJob.ServerHost, printJob.PrintJobTitle))
                    {
                        return;
                    }

                    // set up an launch UI for the incoming data
                    PrintingControlWindow window = new PrintingControlWindow(printJob);
                    window.Closed += WindowClosed;

                    // add window to a list
                    listOfWindows.Add(window);

                    // show UI
                    window.ShowDialog();
                }), DispatcherPriority.Background);
            }
            catch (Exception ex)
            {
                WPFNotifier.Error(ex);
            }
        }