public bool UpdatePrinterStatus(PrintGroupItem it, string PrinterName, bool Status) { GlobalDataStore.Logger.Debug("RemClientControlObject.UpdatePrinterStatus-2"); bool bRet = true; string AppPath = GlobalDataStore.AppPath;; // System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); string sXMLFile; sXMLFile = AppPath + @"\ACALabelXClient.config.xml"; PrintGroupItem theItem; theItem = GetLabelPrintGroupByName(it.Name); //Retrieve again... could be changed on the server foreach (PrinterItem pi in it.GroupPrinters) { if (pi.LongName.Equals(PrinterName, StringComparison.OrdinalIgnoreCase)) { PrinterItem pi2; pi2 = pi; pi2.Enabled = Status; bRet = Toolbox.Toolbox.StorePrinter(sXMLFile, theItem, pi2); break; } } return(bRet); }
public bool RemovePrinterFromPrinterGroup(PrintGroupItem it, string PrinterName) { GlobalDataStore.Logger.Debug("RemClientControlObject.RemovePrinterFromPrinterGroup-2"); bool bRet; string AppPath = GlobalDataStore.AppPath;; // System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); bRet = Toolbox.Toolbox.RemovePrinterFromPrinterGroup(AppPath + @"\ACALabelXClient.config.xml", it, PrinterName); return(bRet); }
public PrintJobInfos GetPrintjobsForPrintgroup(PrintGroupItem it) { GlobalDataStore.Logger.Debug(string.Format("RemClientControlObject.GetPrintjobsForPrintgroup {0}", it.Name)); string AppPath = GlobalDataStore.AppPath;// System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); string RemotingConfigFilePath = AppPath + @"\ACALabelXClient.config.xml"; Toolbox.Toolbox toolbox = new Toolbox.Toolbox(); PrintJobInfos infos; infos = toolbox.GetPrintjobsForPrintgroup(RemotingConfigFilePath, it); return(infos); }
public bool AddPrinterToPrintGroupItem(PrintGroupItem it, string PrinterName) { GlobalDataStore.Logger.Debug("RemClientControlObject.AddPrinterToPrintGroupItem"); bool bRet = false; string PrintJobsRootFolder; string LabelDefinitionsRootFolder; string PaperDefinitionsRootFolder; string SettingsRootFolder; string MachineName; int PollFrequency; PrintGroupItemList PrintGroups; PrintGroups = new PrintGroupItemList(); string AppPath = GlobalDataStore.AppPath; // System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); string RemotingConfigFilePath = AppPath + @"\ACALabelXClient.config.xml"; lock (GlobalDataStore.LockClass) { if (!File.Exists(RemotingConfigFilePath)) { throw new LabelXRemClientControlOjectException(string.Format("Remoting configuration file doesn't exist: {0}", RemotingConfigFilePath)); } } Toolbox.Toolbox toolbox = new Toolbox.Toolbox(); toolbox.GetGeneralClientConfiguratonEx(AppPath + @"\ACALabelXClient.config.xml", out PrintJobsRootFolder, out LabelDefinitionsRootFolder, out PaperDefinitionsRootFolder, out SettingsRootFolder, out MachineName, out PollFrequency, ref PrintGroups); //First check if the printgroupitem still exists foreach (PrintGroupItem item in PrintGroups) { if (item.Name.Equals(it.Name, StringComparison.OrdinalIgnoreCase)) { PrinterItem pi; pi = new PrinterItem(); pi.LongName = PrinterName; pi.Enabled = true; pi.Trays = new PrinterTrayItems(); bRet = Toolbox.Toolbox.StorePrinter(AppPath + @"\ACALabelXClient.config.xml", item, pi); break; } } return(bRet); }
public bool UpdatePrintgroupStatus(PrintGroupItem it) { bool bRet = false; try { bRet = RemoteObject.UpdatePrintgroupStatus(it); } catch (Exception ex) { throw new RemClientControlObjectProxyException("Call to printer service failed.", ex); } return(bRet); }
public bool AddPrinterToPrintGroupItem(PrintGroupItem it, string PrinterName) { bool bRet = false; try { bRet = RemoteObject.AddPrinterToPrintGroupItem(it, PrinterName); } catch (Exception ex) { throw new RemClientControlObjectProxyException("Call to printer service failed.", ex); } return(bRet); }
public bool RemovePrinterFromPrinterGroup(PrintGroupItem it, PrinterItem pi) { bool bRet = false; try { bRet = RemoteObject.RemovePrinterFromPrinterGroup(it, pi); } catch (Exception ex) { throw new RemClientControlObjectProxyException("Call to printer service failed.", ex); } return(bRet); }
public bool UpdatePrinterForPrintgroup(PrintGroupItem it, PrinterItem pi) { GlobalDataStore.Logger.Debug("RemClientControlObject.UpdatePrinterForPrintgroup"); bool bRet = true; string AppPath = GlobalDataStore.AppPath;; // System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); string sXMLFile; sXMLFile = AppPath + @"\ACALabelXClient.config.xml"; PrintGroupItem theItem; theItem = GetLabelPrintGroupByName(it.Name); //Retrieve again... could be changed on the server bRet = Toolbox.Toolbox.StorePrinter(sXMLFile, theItem, pi); return(bRet); }
public PrintJobInfos GetPrintjobsForPrintgroup(PrintGroupItem it) { PrintJobInfos info; info = new PrintJobInfos(); try { info = RemoteObject.GetPrintjobsForPrintgroup(it); } catch (Exception ex) { throw new RemClientControlObjectProxyException("Call to printer service failed.", ex); } return(info); }
public bool UpdatePrintgroupStatus(PrintGroupItem it) { GlobalDataStore.Logger.Debug("RemClientControlObject.UpdatePrintgroupStatus"); bool bRet = true; string AppPath = GlobalDataStore.AppPath; string sXMLFile; sXMLFile = AppPath + @"\ACALabelXClient.config.xml"; PrintGroupItem theItem; theItem = GetLabelPrintGroupByName(it.Name); //Retrieve again... could be changed on the server theItem.Enabled = it.Enabled; bRet = Toolbox.Toolbox.StorePrinterGroupStatus(sXMLFile, theItem); return(bRet); }
public bool RemovePrinterFromPrinterGroup(PrintGroupItem it, PrinterItem pi) { GlobalDataStore.Logger.Debug("RemClientControlObject.RemovePrinterFromPrinterGroup"); return(RemovePrinterFromPrinterGroup(it, pi.LongName)); }
public bool UpdatePrinterStatus(PrintGroupItem it, PrinterItem pi) { GlobalDataStore.Logger.Debug("RemClientControlObject.UpdatePrinterStatus"); return(UpdatePrinterStatus(it, pi.LongName, pi.Enabled)); }
public ACA.LabelX.Toolbox.PrintGroupItem GetLabelPrintGroupByName(string sName) { GlobalDataStore.Logger.Debug("RemClientControlObject.GetLabelPrintGroupByName"); string AppPath = GlobalDataStore.AppPath; string RemotingConfigFilePath = AppPath + @"\ACALabelXClient.config.xml"; FileInfo fi; fi = new FileInfo(RemotingConfigFilePath); if (!fi.Exists) { throw new LabelXRemClientControlOjectException(string.Format("Remoting configuration file doesn't exist: {0}", RemotingConfigFilePath)); } // if (!File.Exists(RemotingConfigFilePath)) // throw new LabelXRemClientControlOjectException(string.Format("Remoting configuration file doesn't exist: {0}", RemotingConfigFilePath)); PrintGroupItem pgItem = null; lock (GlobalDataStore.LockClass) { XPathDocument theDoc; XPathNavigator nav; string sHelp; try { theDoc = new XPathDocument(RemotingConfigFilePath); } catch (System.Xml.XmlException e1) { ApplicationException e2; e2 = new ApplicationException(string.Format("XML syntax error in {0}: {1}", RemotingConfigFilePath, e1.Message), e1); throw e2; } nav = theDoc.CreateNavigator(); XPathNodeIterator nit; nit = nav.Select("/configuration/general-settings/print-groups/print-group[@name='" + sName + "']"); if (nit != null) { nit.MoveNext(); pgItem = new PrintGroupItem(); pgItem.GroupPrinters = new PrinterItems(); pgItem.Name = nit.Current.GetAttribute("name", string.Empty); pgItem.Enabled = nit.Current.GetAttribute("enabled", string.Empty).Equals("true", StringComparison.OrdinalIgnoreCase); nit = nav.Select("/configuration/general-settings/print-groups/print-group[@name='" + sName + "']/printer"); while (nit.MoveNext()) { PrinterItem pit; pit = new PrinterItem(); sHelp = nit.Current.GetAttribute("name", string.Empty); pit.LongName = sHelp; sHelp = nit.Current.GetAttribute("enabled", string.Empty); pit.Enabled = sHelp.Equals("true", StringComparison.OrdinalIgnoreCase); //Retrieve some other data for this printer... System.Printing.LocalPrintServer localServer; localServer = new System.Printing.LocalPrintServer(); System.Printing.PrintQueueCollection col; System.Printing.EnumeratedPrintQueueTypes[] myEnum = { EnumeratedPrintQueueTypes.Connections , EnumeratedPrintQueueTypes.Local }; col = localServer.GetPrintQueues(myEnum); System.Printing.PrintQueue theQueue = null; foreach (System.Printing.PrintQueue q in col) { if (q.FullName.Equals(pit.LongName, StringComparison.OrdinalIgnoreCase)) { theQueue = q; break; } } if (theQueue != null) { pit.QueueLength = theQueue.NumberOfJobs; pit.ShortName = theQueue.Name; pit.Online = !theQueue.IsOffline; pit.NeedsUserIntervention = theQueue.NeedUserIntervention; // //theQueue.NeedUserIntervention; } else { pit.QueueLength = 0; pit.NeedsUserIntervention = false; pit.ShortName = pit.LongName; pit.Online = true; } if (col != null) { col.Dispose(); col = null; } if (theQueue != null) { theQueue.Dispose(); theQueue = null; } if (nit.Current.HasChildren) { //nit.Current.MoveToFirstChild(); nit.Current.MoveToFirstChild(); //MoveToNext("tray", nav.LookupNamespace(nav.Prefix))) do { PrinterTrayItem ptit; ptit = new PrinterTrayItem(); ptit.TrayName = nit.Current.GetAttribute("name", string.Empty); ptit.CurrentPapertypeName = nit.Current.GetAttribute("papertype", string.Empty); pit.Trays.Add(ptit); } while (nit.Current.MoveToNext("tray", nav.LookupNamespace(nav.Prefix))); nit.Current.MoveToParent(); } //pit.CurrentPapertypeName = nit.Current.GetAttribute("papertype",string.Empty); //pit.Tray = nit.Current.GetAttribute("tray", string.Empty); pgItem.GroupPrinters.Add(pit); localServer.Dispose(); } } } return(pgItem); }
public bool RemovePrinterpool(PrintGroupItem it) { return(RemovePrinterpool(it.Name)); }
private bool HandlePrintJob(PrintGroupItem it, PrintJobInfo jobinfo, string PrintJobsRootFolder, string PaperDefinitionsRootFolder, string LabelDefinitionsRootFolder, int language) { bool ret = true; string sXMLFile; sXMLFile = jobinfo.FullFilename; //Retrieve some information for the selected printjob // The requested queueu, the printgroup (should be the current), and the LabelType string sPrintQueue; string sPrintGroup; string sLabelType; sPrintGroup = string.Empty; sPrintQueue = string.Empty; sLabelType = string.Empty; try { XPathDocument doc; doc = new XPathDocument(sXMLFile); XPathNavigator nav; nav = doc.CreateNavigator(); XPathNodeIterator theNode; theNode = nav.Select("/printjob/destination/printqueue"); if (theNode != null) { theNode.MoveNext(); sPrintQueue = theNode.Current.Value; } theNode = nav.Select("/printjob/destination/printgroup"); if (theNode != null) { theNode.MoveNext(); sPrintGroup = theNode.Current.Value; } theNode = nav.Select("/printjob/destination/labeltype"); if (theNode != null) { theNode.MoveNext(); sLabelType = theNode.Current.Value; } } catch (Exception e) { GlobalDataStore.Logger.Warning(string.Format("The following error occured while handeling file {0}:", jobinfo.FullFilename) + Environment.NewLine + e.Message); return(false); } //We now have the labeltype requested... we gather information on which paper this can be printed... List <string> papertypes; papertypes = new List <string>(); try { papertypes = GetPaperTypesOfLabelType(sLabelType); } catch (System.IO.FileNotFoundException) { //dit zou alleen mogen gebeuren als het labeltype niet bestaat als xmlbestand... GlobalDataStore.Logger.Warning(string.Format("Label {0} not defined. Job on hold.", sLabelType)); if (papertypes.Count > 0) { papertypes.Clear(); } return(false); } try { if (papertypes.Count == 0) { //can not print on no paper... GlobalDataStore.Logger.Warning(string.Format("Label {0} has no defined paper types. Job on hold.", sLabelType)); return(false); } else { if (papertypes.Count > 1) { //only one default allowed for now. GlobalDataStore.Logger.Warning(string.Format("Label {0} has more than one default paper type. Job on hold.", sLabelType)); return(false); } //check if papertype exists as an xml file string paperFileName = PaperDefinitionsRootFolder + papertypes[0] + ".xml"; if (!File.Exists(paperFileName)) { GlobalDataStore.Logger.Warning(string.Format("Papertype {0} has no xml file. Job on hold.", papertypes[0])); return(false); } } PrinterItemLocals pils; pils = new PrinterItemLocals(); foreach (PrinterItem pit in it.GroupPrinters) { PrinterItemLocal pil = new PrinterItemLocal(); pil.item = pit; pils.Add(pil); // //Gather windowsinformation for each printer in the windows printer queue // We gather the numberofjobs and if the printer is online. // } PrinterItemLocal bestFit; bestFit = null; foreach (PrinterItemLocal pil in pils) { //we do not print to printers that are physically offline if (!pil.item.Online) { continue; } //we do not print to printers that are marked disabled. if (!pil.item.Enabled) { continue; } if (pil.item.Trays != null) { foreach (PrinterTrayItem tit in pil.item.Trays) { if (tit.CurrentPapertypeName.Equals(papertypes[0], StringComparison.OrdinalIgnoreCase) || pil.item.LongName.Contains("Microsoft XPS Document Writer")) { //papiersoort klopt.. if (bestFit == null) { pil.Tray = tit; bestFit = pil; } else { if (pil.item.QueueLength < bestFit.item.QueueLength) { pil.Tray = tit; bestFit = pil; } } } } } } //We have selected a printer to print to if (bestFit != null) { ACA.LabelX.PrintJob.PrintJob p = new ACA.LabelX.PrintJob.PrintJob(PaperDefinitionsRootFolder, LabelDefinitionsRootFolder); p.Parse(jobinfo.FullFilename); // if (p.labels.Count == 0) { //Oeps.. a printjob with a default label, but no actual label is detected //Mark this job as handled now, without error ret = MarkPrintJobReady(jobinfo, "No Label in job."); return(ret); } //Check if all pictures are available ACA.LabelX.Label.LabelSet labelset = new ACA.LabelX.Label.LabelSet(); labelset.CurrentLabel = p.labels[0]; labelset.DefaultLabel = p.Defaultlabel; labelset.BaseLabel = p.LabelDef.DefaultLabel; labelset.StaticVarsLabel = p.StaticVarslabel; if (!p.LabelDef.CheckAllPicturesAvailable(labelset, language, true)) { GlobalDataStore.Logger.Warning(string.Format("Missing picture to print. Job on hold.", sLabelType)); return(false); } // //check if th language requested is pressent in the printjob // bool bFound = false; if (p.languages != null) { if (p.languages.Count > 0) { foreach (PrintJob.PrintJob.PrintLanguage x in p.languages) { if (x.Id == language) { bFound = true; } } } } //We have selected a language this job can be printed in... if (bFound) { ACA.LabelX.PrintEngine.PrintEngine pi = new ACA.LabelX.PrintEngine.PrintEngine(Environment.MachineName); pi.DesignMode = false; pi.AddPrintJob(p); GlobalDataStore.Logger.Info("Printing " + p.ID.ToString()); pi.Print(p.ID.ToString(), bestFit.item.LongName, bestFit.Tray.TrayName, papertypes[0], 0, uint.MaxValue, language); bestFit.item.QueueLength++; //There is now one job more in the queue.. ret = MarkPrintJobReady(jobinfo, bestFit.item.LongName); //Voeg printernaam en datum toe aan printjob xml file //mve, 2016-03-06 /* * lock (GlobalDataStore.LockClass) * { * string path = jobinfo.FullFilename; * XmlDocument theDoc = new XmlDocument(); * if (!File.Exists(path)) * { * return false; * } * theDoc.Load(path); * * XmlNode printedto = theDoc.SelectSingleNode("/printjob/destination/printedto"); * if (printedto == null) * { * XmlNode destinationnode = theDoc.SelectSingleNode("/printjob/destination"); * XmlElement NewPrintedTo = theDoc.CreateElement("printedto"); * NewPrintedTo.InnerText = bestFit.item.LongName; * destinationnode.AppendChild(NewPrintedTo); * } * else * { * printedto.InnerText = bestFit.item.LongName; * } * * XmlNode lastprinted = theDoc.SelectSingleNode("/printjob/destination/lastprinted"); * if (lastprinted == null) * { * XmlNode lastprintednode = theDoc.SelectSingleNode("/printjob/destination"); * XmlElement NewLastPrinted = theDoc.CreateElement("lastprinted"); * NewLastPrinted.InnerText = System.DateTime.Now.ToString("s"); * lastprintednode.AppendChild(NewLastPrinted); * } * else * { * lastprinted.InnerText = System.DateTime.Now.ToString("s"); * } * * XmlNode autorelease = theDoc.SelectSingleNode("/printjob/autorelease"); * autorelease.InnerText = "false"; * * * int counter = 0; * bool saveSuccessful = false; * while ((counter < 5) && (saveSuccessful == false)) * { * try * { * theDoc.Save(path); * Thread.Sleep(2000); * saveSuccessful = true; * } * catch (Exception ex) * { * Thread.Sleep(2000); * counter += 1; * GlobalDataStore.Logger.Warning(string.Format("The file {0} could not be saved: {1}", theDoc.Name, ex.Message)); * } * } * if (!saveSuccessful) * ret = false; * * } */ } else { GlobalDataStore.Logger.Warning(String.Format("Language of printjob {0} not suitable for this location.", p.ID.ToString())); ret = false; } } else { GlobalDataStore.Logger.Warning(String.Format("No suitable printer found for file {0}.", jobinfo.FullFilename)); ret = false; } } catch (Exception egen) { GlobalDataStore.Logger.Error(string.Format("Unexpected Error in HandlePrintJob: {0}.", egen.Message)); GlobalDataStore.Logger.Error(string.Format("Extra info: {0}.", egen.StackTrace)); if (egen.InnerException != null) { GlobalDataStore.Logger.Error(string.Format("Extra info: {0}.", egen.InnerException.Message)); } return(false); } return(ret); }