示例#1
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();
                    }

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

                    // show UI
                    window.ShowDialog();
                }), DispatcherPriority.Background);
            }
            catch (Exception ex)
            {
                WPFNotifier.Error(ex);
            }
        }
示例#2
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);
            }
        }