/// <summary> /// Initializes timers /// </summary> private void InitTimer() { try { // init retry timer _timerRetry = new Timer(); _timerRetry.Enabled = false; _timerRetry.AutoReset = false; _timerRetry.Interval = ConfigData.Interval_TimerRestart; _timerRetry.Elapsed += timerRetry_Elapsed; } catch (Exception ex) { WPFNotifier.Error(ex); } try { // init get printers timer _timerGetPrinters = new Timer(); _timerGetPrinters.Enabled = false; _timerGetPrinters.AutoReset = false; _timerGetPrinters.Interval = ConfigData.Interval_TimerGetPrinters; _timerGetPrinters.Elapsed += timerGetPrinters_Elapsed; } catch (Exception ex) { WPFNotifier.Error(ex); } }
/// AppOnStartup #region AppOnStartup /// <summary>The event occurs on startup.</summary> /// <param name="sender">The sender.</param> /// <param name="e">The event args</param> private void AppOnStartup(object sender, StartupEventArgs e) { mutex = new Mutex(true, UniqueMutexName, out isOwned); GC.KeepAlive(mutex); // check if mutex is owned if (isOwned) { // if mutex is owned then no other instances are active // create all the necessary data and run the app LogHelper.Init(ConfigData.FilePath_AppUsageLog); LogHelper.Log("Started " + System.Windows.Forms.Application.ProductVersion); ConfigData.Init(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; System.Windows.Forms.Application.ThreadException += Application_ThreadException; ProcessArgs(e.Args); MainController.Singleton.Run(); return; } // Application already run WPFNotifier.Warning("Application already run!"); // Terminate this instance. Shutdown(); }
/// <summary> /// Gets value from the postscript file line /// </summary> /// <param name="line">postscript file line</param> /// <returns>value from the postscript file line</returns> private static string GetLineValue(string line) { try { // find semicolon int index = line.IndexOf(':'); if (index > 0) { // find star int index2 = line.LastIndexOf('*'); if (index2 > index) { // find first space after star int index3 = line.IndexOf(' ', index2); if (index3 > index2) { // extract starred value return(line.Substring(index3).Trim()); } } else { // extract simple value return(line.Substring(index + 1).Trim()); } } } catch (Exception ex) { WPFNotifier.DebugError(ex); } return(null); }
/// <summary> /// Gets proper library /// </summary> /// <returns>path to the library</returns> private static string GetLib() { try { string path = getLib(true); if (File.Exists(path)) { return(path); } path = getLib(false); if (File.Exists(path)) { return(path); } path = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), getLib(false)); if (File.Exists(path)) { return(path); } throw new ArgumentNullException("File not found! " + Environment.NewLine + Application.ExecutablePath); } catch (Exception ex) { WPFNotifier.DebugError(ex); return(null); } }
/// <summary> /// Gets value from the postscript file line /// </summary> /// <param name="line">postscript file line</param> /// <returns>value from the postscript file line</returns> private static string GetLineValue2(string line) { try { int index = line.IndexOf('='); if (index > 0) { int index2 = line.IndexOf('"', index + 1) + 1; if (index2 > index) { int index3 = line.IndexOf('"', index2); if (index3 > index2) { // extract value return(line.Substring(index2, index3 - index2).Trim()); } } else { // extract simple value return(line.Substring(index + 1).Trim()); } } } catch (Exception ex) { WPFNotifier.DebugError(ex); } return(null); }
/// <summary> /// Initializes data /// </summary> private void Init() { try { LogHelper.LogDebug(); // get current dispatcher for work with UI _dispatcher = Dispatcher.CurrentDispatcher; // load config files API.LoadConfig(ConfigData.FilePath_InnerConfig); // local config or 1st config API.LoadConfig(ConfigData.FilePath_RemoteConfig); // remote config or 2nd config // removes old print jobs of the available printers RemoveJobs(); // establish call-backs PrintHelper.SkipMethod = SkipDocument; PrintHelper.AddWatcher = AddWatcher; // subscribe to the file monitor event fileMonitor.FileFound += fileMonitor_FileFound; // create list of (virtual) printers to be excluded from the track process List <string> allp = new List <string> { ConfigData.PrinterName, ConfigData.PrinterName2 }; // set up local watcher localPrintEventWatcher = new PrintEventWatcher(Environment.MachineName, Environment.MachineName, false, allp, "0.001"); localPrintEventWatcher.PrintJobPaused += LocalPrintEventWatcherPrintJobPaused; localPrintEventWatcher.PrintJobStarted += LocalPrintEventWatcherPrintJobStarted; localPrintEventWatcher.PrintJobCompleted += LocalPrintEventWatcherPrintJobCompleted; localPrintEventWatcher.PrintJobCancelled += LocalPrintEventWatcherPrintJobCancelled; // set up allowed printers to skip localPrintEventWatcher.AllowedPrintersToSkip = new List <string>(); localPrintEventWatcher.AllowedPrintersToSkip.Add(ConfigData.PrinterName); localPrintEventWatcher.AllowedPrintersToSkip.Add(ConfigData.PrinterName2); // initialize watcher localPrintEventWatcher.Init(); // update available printers UpdateAvailablePrinters(); // init print job watchers _watchers = new PrintJobWatchers(); _watchers.IssueFound += _watchers_IssueFound; _watchers.JobCompleted += _watchers_JobCompleted; } catch (Exception ex) { WPFNotifier.Error(ex); _timerRetry.Start(); } // set default printer SetDefaultPrinter(); }
/// Post #region Post /// <summary> /// Initiates post request /// </summary> /// <param name="url"></param> /// <returns></returns> public static IRestResponse Post(string url, Dictionary <string, string> queryParameters = null) { try { string req = url; if (queryParameters != null && queryParameters.Count > 0) { req += "?" + queryParameters.GetAsQueryString(); } LastCall = req; LogHelper.LogDebug(new Uri(req).AbsoluteUri); RestClient client = new RestClient(new Uri(req)); RestRequest request = new RestRequest(Method.POST); request.Timeout = 5000; request.AddParameter("undefined", "{}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); return(response); } catch (Exception ex) { WPFNotifier.DebugError(ex); return(null); } }
/// Print #region Print /// <summary> /// Prints data. /// </summary> public void Print() { // check if it's Demo mode if (IsTestMode) { return; } IsControlsEnabled = false; SetStatus(); Task t = new Task(() => { try { if (IsBlockedMode) { ResumeJobFirstTry(PrintJobData); } else { PrintFirstTry(PDFFileName, Title.Document, ChosenPrinter.Settings); } } catch (Exception ex) { WPFNotifier.Error(ex); } }); t.Start(); }
/// 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); } }
/// <summary> /// Shows advanced printer settings /// </summary> /// <param name="handle">window handle</param> /// <param name="printerName">printer name</param> /// <param name="settings">settings</param> public void ShowAdvancedPrinterSettings(IntPtr handle, string printerName, ref System.Drawing.Printing.PrinterSettings settings) { // check the printer settings if (settings == null || !settings.IsValid) { LogHelper.LogDebug("Invalid printer settings for " + printerName); return; } LogHelper.LogDebug(); try { // create new printer settings System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings(); // set new settings as an old one ps = settings; // show printer settings window as dialog for the current window if (PrintDialogHelper.EditPrinterSettings(ps, handle) == System.Windows.Forms.DialogResult.OK) { LogHelper.LogDebug("Printer settings changed"); // save changed printer settings settings = ps; } } catch (Exception ex) { WPFNotifier.Error(ex); } }
/// <summary> /// Shows advanced settings window. /// </summary> /// <param name="owner">owner</param> public void ShowAdvancedSettings(Window owner) { try { // get chosen printer by color setting Printer pr = GetChosenPrinterWithSettings(PrintWithColor); if (pr == null) { return; } UISettingsExtractor extractor = new UISettingsExtractor(ChosenPrinter.Name, DesktopHelper.GetDesktopWindow()); extractor.Start(); MainController.Singleton.ShowAdvancedPrinterSettings(new WindowInteropHelper(owner).Handle, ChosenPrinter.Name, ref PrinterSettings); extractor.Stop(); PrintBooklet = extractor.Booklet; LogHelper.LogDebug(PrintBooklet); pr.Settings = PrinterSettings; SetByPrinterSettings(); } catch (Exception ex) { WPFNotifier.DebugError(ex); } }
/// Dispose #region Dispose /// <summary> /// Disposes data /// </summary> public void Dispose() { // get rid of event watcher if (_eventWatcher != null) { try { _eventWatcher.EventArrived -= mewPrintJobs_JobArrived; _eventWatcher.Stop(); _eventWatcher.Dispose(); _eventWatcher = null; } catch (Exception ex) { WPFNotifier.DebugError(ex); } } // get rid of management scope if (managementScope != null) { try { managementScope = null; } catch (Exception ex) { WPFNotifier.DebugError(ex); } } }
/// timerAllowedToPrint #region timerAllowedToPrint /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void timerAllowedToPrint_Tick(object sender, EventArgs e) { timerAllowedToPrint.Stop(); if (!ConfigData.Config_DontCheckUserBalance) { AllowedToPrintResponse res = APIWrapper.CheckIfCanPrint(Environment.MachineName, Environment.UserName, PrintWithColor, NumberOfPrints, ChosenPrinter.Name); if (res == null) { WPFNotifier.Warning(string.Format("No response from server but still printing.")); Print(PDFFileName, PostScriptMetaData.Title, ChosenPrinter.Settings, PostScriptMetaData); } else { if (res.AllowedToPrint) { Print(PDFFileName, PostScriptMetaData.Title, ChosenPrinter.Settings, PostScriptMetaData); } else { timerAllowedToPrint.Start(); } } } timerAllowedToPrint.Start(); }
/// <summary> /// Shows blocked mode changes warning. /// </summary> private void ShowBlockedModeChangesWarning() { if (WPFNotifier.Question(string.Format("To make changes you have to get back to your document, make changes and then click 'Print' button once again.{0}{0}Do you want to abort and quit?", Environment.NewLine)) == MessageBoxResult.Yes) { Close(); } }
/// Print #region Print /// <summary> /// Prints PDF /// </summary> /// <param name="printer">printer settings</param> /// <param name="fileName">file name</param> /// <param name="printerName">printer name</param> /// <param name="documentName">document name</param> /// <returns></returns> public static bool Print_Default(PrinterSettings printer, string fileName, string documentName, string owner, string host) { try { if (!File.Exists(fileName)) { LogHelper.Log("No file found : " + fileName); return(false); } // Now print the PDF document using (var document = PdfDocument.Load(fileName)) { using (var printDocument = document.CreatePrintDocument()) { printDocument.DocumentName = documentName; printDocument.PrinterSettings = printer; printDocument.DefaultPageSettings = printer.DefaultPageSettings; printDocument.PrintController = new StandardPrintController(); printDocument.Print(); } } return(true); } catch (Exception ex) { WPFNotifier.Error(ex); return(false); } }
/// Methods #region Methods /// <summary> /// Saves printers data. /// </summary> public void Save(string fileName) { if (string.IsNullOrWhiteSpace(fileName)) { return; } try { /* * JArray array = new JArray(); * foreach (var item in this) * array.Add(JToken.Parse(JsonConvert.SerializeObject(item))); * * string json = array.ToString();*/ string json = JsonConvert.SerializeObject(this.ToArray()); if (!string.IsNullOrWhiteSpace(json)) { File.WriteAllText(fileName, json); } } catch (Exception ex) { WPFNotifier.Error(ex); } }
/// HasColor #region HasColor /// <summary> /// Indicates whether specified file has color or not. Has to be supported file (ps or pdf) /// </summary> /// <param name="fileName">file name</param> /// <returns>true if has color; otherwise false</returns> public static bool?HasColor(string fileName) { if (String.IsNullOrWhiteSpace(fileName)) { return(null); } try { if (!File.Exists(fileName)) { return(null); } SupportedPrintFormat format = GetFileFormat(fileName); if (format == SupportedPrintFormat.PDF) { return(GhostScriptHelper.HasColor(fileName)); } else if (format == SupportedPrintFormat.PS) { return(PostScriptHelper.HasColor(fileName)); } } catch (Exception ex) { WPFNotifier.Error(ex); } return(null); }
/// <summary> /// Updates available printers /// </summary> /// <returns>available printers</returns> public Printers UpdateAvailablePrinters() { LogHelper.LogDebug(); try { _availablePrinters = null; // just retrieve new data var xxx = AvailablePrinters; LogHelper.LogDebug("HasAvailablePrinters : " + HasAvailablePrinters); // change (real) printers of local print event watcher if (localPrintEventWatcher != null) { localPrintEventWatcher.PrintersToPauseAndShow = new List <string>(); // check if there are available printers if (HasAvailablePrinters) { LogHelper.LogDebug("AvailablePrinters : " + AvailablePrinters.NamesInSystem.Count); // add (real) printers localPrintEventWatcher.PrintersToPauseAndShow.AddRange(AvailablePrinters.NamesInSystem); } } return(_availablePrinters); } catch (Exception ex) { WPFNotifier.DebugError(ex); return(null); } }
/// <summary> /// /// </summary> /// <param name="host"></param> /// <param name="data"></param> /// <returns></returns> public static bool UpdateJobData(string host, ref PrintJobData data) { if (data == null) { return(false); } if (data.PrintJobTitle == null) { return(false); } if (String.IsNullOrWhiteSpace(data.PrintJobTitle.PrinterName)) { return(false); } bool updated = false; try { string printerName = data.PrintJobTitle.PrinterName; if (!String.IsNullOrWhiteSpace(host)) { printerName = data.PrintJobTitle.PrinterName.Replace(host, "").Trim(); if (printerName[0] == '\\') { printerName = printerName.Substring(1); } LogHelper.LogDebug("MAIN " + host + " printerName " + printerName); } else { LogHelper.LogDebug("MAIN local printerName " + printerName); } updated = UpdateJobData(ref data, printerName, host); /* * if (!updated) * { * int pos = data.PrintJobTitle.PrinterName.LastIndexOf("\""); * string nnn = null; * if (pos > 0) * nnn = data.PrintJobTitle.PrinterName.Substring(pos + 1); * LogHelper.LogDebug("nnn " + nnn); * updated = UpdateJobData(ref data, nnn, host); * }*/ } catch (Exception ex) { WPFNotifier.Error(ex); } return(updated); }
/// Print #region Print /// <summary> /// Prints file with specified printer and settings /// </summary> /// <param name="fileName">file name</param> /// <param name="printer">printer settings</param> public static void Print(string fileName, string documentName, PrinterSettings printer, PostScriptMetaData data) { if (String.IsNullOrWhiteSpace(fileName)) { return; } if (printer == null) { return; } if (data == null) { return; } try { // check the existence of the file if (!File.Exists(fileName)) { return; } // get file format SupportedPrintFormat format = GetFileFormat(fileName); string newFileName = fileName; // if Postscript file if (format == SupportedPrintFormat.PS) { newFileName = fileName + ".pdf"; // convert to .pdf GhostScriptHelper.ConvertPStoPDF(fileName, newFileName); } // create corresponding print job title PrintJobTitle title = new PrintJobTitle(printer.PrinterName, documentName, Environment.UserName, Environment.MachineName, -1); // skip this title SkipMethod(title); // print document if (PDFHelper.Print(printer, newFileName, documentName, Environment.UserName, Environment.MachineName)) { // add title watcher AddWatcher(title); // log printed data LogPrint(ConfigData.FilePath_PrintLog, documentName, printer, data.NumberOfPages); } } catch (Exception ex) { WPFNotifier.DebugError(ex); } }
/// <summary> /// Changes list of printers /// </summary> public void ChangePrinters() { LogHelper.LogDebug(); try { bool nocolored = false; CanPrintWithColor = true; List <string> printers = null; if (PrintWithColor) { printers = MainController.Singleton.AvailablePrinters.ColoredNames; if (printers == null || printers.Count < 1) { nocolored = true; } } else { printers = MainController.Singleton.AvailablePrinters.AllNames; } if (nocolored) { LogHelper.LogDebug("No available color printers found. You are not allowed to print colored this time."); WPFNotifier.Warning("No available color printers found. You are not allowed to print colored this time."); CanPrintWithColor = false; return; } if (printers == null || printers.Count < 1) { LogHelper.LogDebug("No available printers found. You are not allowed to print this time."); WPFNotifier.Warning("No available printers found. You are not allowed to print this time."); return; } LogHelper.LogDebug("Add printers to combo : " + printers.Count); MainController.Singleton.Dispatcher.Invoke(new Action(() => { Printers.Clear(); foreach (string name in printers.ToArray()) { Printers.Add(name); } }), DispatcherPriority.Background); Thread.Sleep(100); SetDefaultPrinter(); } catch (Exception ex) { WPFNotifier.Error("This printer is not available now. Try to use one of the other printers.", null, ex); Close(); } }
/// UpdateJobData #region UpdateJobData /// <summary> /// /// </summary> /// <param name="data"></param> /// <param name="printerName"></param> /// <param name="host"></param> /// <returns></returns> private static bool UpdateJobData(ref PrintJobData data, string printerName, string host) { bool updated = false; try { LogHelper.LogDebug("INNER START " + printerName); PrintQueue queue = GetPrintQueue(printerName, host); if (queue == null) { return(false); } queue.Refresh(); if (queue.NumberOfJobs > 0) { bool quit = false; while (!quit) { try { LogHelper.LogDebug("jobs " + queue.GetPrintJobInfoCollection().Count() + " | " + queue.NumberOfJobs); foreach (PrintSystemJobInfo info in queue.GetPrintJobInfoCollection()) { info.Refresh(); string docName = info.Name; int NumberOfPages = info.NumberOfPages; int xxx = info.NumberOfPagesPrinted; LogHelper.LogDebug("Printing " + info.IsPrinting + " | Paused " + info.IsPaused + " | Spooling " + info.IsSpooling + " | IsDeleting " + info.IsDeleting); LogHelper.LogDebug("pages " + NumberOfPages + " printed " + xxx); if (data.PrintJobTitle.Document == docName && data.PrintJobTitle.TotalPages < xxx) { data.PrintJobTitle.TotalPages = xxx; updated = true; } } quit = true; } catch (Exception ex) { queue.Refresh(); LogHelper.LogDebug("refresh"); WPFNotifier.Error(ex); } } } } catch (Exception ex) { WPFNotifier.Error(ex); } LogHelper.LogDebug("INNER END " + printerName); return(updated); }
/// <summary> /// Gets chosen printer and its' settings /// </summary> /// <returns></returns> public Printer GetChosenPrinterWithSettings(bool colored) { // check the selected index if (SelectedPrinterIndex < 0) { return(null); } try { LogHelper.LogDebug(); // get chosen printer Printer PrinterX = MainController.Singleton.AvailablePrinters.ByColor(colored)[SelectedPrinterIndex]; // set chosen printer ChosenPrinter = PrinterX; // check settings if (PrinterX.Settings == null) { // first time settings set // fullfill some important settings values PrinterSettings = new PrinterSettings() { PrinterName = ChosenPrinter.Name, Duplex = PrintDuplex, DefaultPageSettings = { Color = colored } }; // validate settings if (!PrinterSettings.IsValid) { throw new NotSupportedException("Wrong printer settings"); } // set settings PrinterX.Settings = PrinterSettings; } else { // set settings by saved settings set PrinterSettings = PrinterX.Settings; PrinterSettings.Duplex = PrintDuplex; PrinterSettings.DefaultPageSettings.Color = colored; PrinterSettings.Copies = NumberOfCopies; } return(PrinterX); } catch (Exception ex) { WPFNotifier.Error(ex); } return(null); }
/// <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); } }
/// <summary> /// /// </summary> /// <param appName="sender"></param> /// <param appName="e"></param> public static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { try { WPFNotifier.Error(e.Exception); } catch { } }
// Unhandled Exceptions #region Unhandled Exceptions /// <summary> /// /// </summary> /// <param appName="sender"></param> /// <param appName="e"></param> static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { try { WPFNotifier.Error(e.ExceptionObject as Exception); } catch { } }
/// <summary> /// /// </summary> /// <returns></returns> private MethodInfo[] GetMethods() { try { return((typeof(API)).GetMethods(BindingFlags.Public | BindingFlags.Static)); } catch (Exception ex) { WPFNotifier.DebugError(ex); return(null); } }
/// HasColor #region HasColor /// <summary> /// Indicates whether the image has color or not /// </summary> /// <param name="image">image to be inspected</param> /// <returns>true if has color; otherwise false</returns> public static bool HasColor(Image image) { try { return(!IsGrayScale(new Bitmap(image))); } catch (Exception ex) { WPFNotifier.DebugError(ex); return(false); } }
/// <summary> /// Tries to print first time /// </summary> /// <param name="fileName"></param> /// <param name="printerName"></param> /// <param name="printerSettings"></param> void PrintFirstTry(string fileName, string documentName, PrinterSettings printerSettings) { // check if it's Demo mode if (IsTestMode) { return; } if (ConfigData.Config_DontCheckUserBalance) { Print(fileName, documentName, printerSettings, PostScriptMetaData); } else { SetStatus("Checking user balance"); var res = APIWrapper.CheckIfCanPrint(Environment.MachineName, Environment.UserName, printerSettings.DefaultPageSettings.Color, NumberOfPrints, ChosenPrinter.Name); if (res == null) { WPFNotifier.Warning(string.Format("No response from server but still printing.")); Print(fileName, documentName, printerSettings, PostScriptMetaData); } else { if (res.Result) { if (res.AllowedToPrint) { Print(fileName, documentName, printerSettings, PostScriptMetaData); } else { //WPFNotifier.Warning(string.Format("You are not allowed to print in the current time.{0}Reason: {1}", Environment.NewLine, res.Reason)); SetStatus("Not allowed to print"); if (WPFNotifier.Question(string.Format("You are not allowed to print at the current time.{0}Reason: {1}{0}{2}", Environment.NewLine, res.Reason, "Do you want to leave the printing (Yes) or continue waiting (No)?")) == MessageBoxResult.Yes) { Close(); } else { StartTimerAllowedToPrint(); } } } else { WPFNotifier.Warning(string.Format("Not successful request CheckIfCanPrint.")); } } } }
/// GetPrinters #region GetPrinters /// <summary> /// Gets printer list from the specified config file /// </summary> /// <param name="fullPath">config file</param> /// <returns>printers</returns> public static Printers GetPrintersFromConfig(string fullPath) { LogHelper.LogDebug(fullPath); if (String.IsNullOrWhiteSpace(fullPath)) { return(null); } try { if (!File.Exists(fullPath)) { return(null); } string data = File.ReadAllText(fullPath); if (String.IsNullOrWhiteSpace(data)) { return(null); } LogHelper.LogDebug("From file: " + data); JArray jArray = JArray.Parse(data); foreach (JObject jObject in jArray.Children <JObject>()) { var workstation = jObject["workstation"]; if (workstation != null) { if (workstation.ToString() == Environment.MachineName) { LogHelper.LogDebug("Printer data found"); return(JsonConvert.DeserializeObject <Printers>(jObject["printers"].ToString())); } } else { return(JsonConvert.DeserializeObject <Printers>(jArray.ToString())); } } } catch (Exception ex) { WPFNotifier.DebugError(ex); } LogHelper.LogDebug("Printer data not found"); return(null); }