public void GetFolderInformation(out string PrintJobsRootFolder, out string LabelDefinitionsRootFolder, out string PaperDefinitionsRootFolder)
        {
            GlobalDataStore.Logger.Debug("RemClientControlObject.GetFolderInformation");

            string AppPath = GlobalDataStore.AppPath;
            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));
                }
            }
            //not need all but fasted to use this for now...
            string             SettingsRootFolder;
            string             MachineName;
            int                PollFrequency;
            PrintGroupItemList PrintGroups = new PrintGroupItemList();

            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);
        }
Example #2
0
        private void LoadData()
        {
            //Laden van alle printgroepen...
            RemClientControlObjectProxy remoteObj;

            remoteObj = null;
            try
            {
                remoteObj = new RemClientControlObjectProxy();
                remoteObj.ConParameter = conParm;
                StartRemote();
                printGroups = remoteObj.GetRemoteLabelPrintGroupsEx();
                remoteObj.Dispose();
            }
            catch (RemClientControlObjectProxyException ex)
            {
                RenderError(ex.Message);
            }
            finally
            {
                StopRemote();
                if (remoteObj != null)
                {
                    remoteObj.Dispose();
                }
            }
        }
Example #3
0
 public PrintCommanderMainForm()
 {
     InitializeComponent();
     printGroups = new PrintGroupItemList();
     conParm     = new ConnectionParameter();
     manageToolStripMenuItem1.Enabled            = false;
     disablePrinterPoolToolStripMenuItem.Enabled = false;
     removePrinterPoolToolStripMenuItem1.Enabled = false;
     manageToolStripMenuItem.Enabled             = false;
     removePrinterPoolToolStripMenuItem.Enabled  = false;
     setAsDefaToolStripMenuItem.Enabled          = false;
 }
        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 StringCollection GetPaperTypes()
        {
            GlobalDataStore.Logger.Debug("RemClientControlObject.GetPaperTypes");

            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);

            StringCollection  theList;
            List <LabelXItem> itemList;

            itemList = new List <LabelXItem>();
            theList  = new StringCollection();
            Toolbox.Toolbox.GetItemsFromFolder(PaperDefinitionsRootFolder, ref itemList, string.Empty, LabelX.Toolbox.Toolbox.FileFilterXML);

            foreach (LabelXItem it in itemList)
            {
                theList.Add(it.Name);
            }
            return(theList);
        }
Example #6
0
 public LabelQuitPaperChangeForm()
 {
     InitializeComponent();
     printGroups = new PrintGroupItemList();
 }
        private void WritePrintGroupsToLocalClientXML(PrintGroupItemList printgroups, string confPath, string MachineName)
        {
            //Only used in standalone version
            XmlDocument theDoc = new XmlDocument();
            XmlNode     rootNode;

            if (File.Exists(confPath))
            {
                try
                {
                    theDoc.Load(confPath);
                    rootNode = theDoc.SelectSingleNode("/clients");
                }
                catch
                {
                    //clients.xml damaged, recreate clients.xml
                    XmlDeclaration xmlDeclaration = theDoc.CreateXmlDeclaration("1.0", "utf-8", null);
                    // Create the root element
                    rootNode = theDoc.CreateElement("clients");
                    theDoc.InsertBefore(xmlDeclaration, theDoc.DocumentElement);
                    theDoc.AppendChild(rootNode);
                }
            }
            else
            {
                XmlDeclaration xmlDeclaration = theDoc.CreateXmlDeclaration("1.0", "utf-8", null);
                // Create the root element
                rootNode = theDoc.CreateElement("clients");
                theDoc.InsertBefore(xmlDeclaration, theDoc.DocumentElement);
                theDoc.AppendChild(rootNode);
            }

            string      xpath = "/clients/machine[@name='" + MachineName + "']";
            XmlNodeList lst   = theDoc.SelectNodes(xpath);
            XmlNode     node2;

            if (lst == null)
            {
                node2 = null;
            }
            else
            {
                node2 = lst.Count > 0 ? lst[0] : null;
            }
            //XmlNode node2 = theDoc.SelectSingleNode(xpath);
            if (node2 != null)
            {
                foreach (XmlNode chld in node2.ChildNodes)
                {
                    node2.RemoveChild(chld);
                }
                node2.Attributes["lastseen"].Value    = DateTime.Now.ToString("o");
                node2.Attributes["externalip"].Value  = "127.0.0.1";
                node2.Attributes["internalip"].Value  = "127.0.0.1";
                node2.Attributes["description"].Value = "";
            }
            else
            {
                XmlElement el = theDoc.CreateElement("machine");
                el.SetAttribute("name", MachineName);
                el.SetAttribute("firstseen", DateTime.Now.ToString("o"));
                el.SetAttribute("lastseen", DateTime.Now.ToString("o"));
                el.SetAttribute("externalip", "127.0.0.1");
                el.SetAttribute("internalip", "127.0.0.1");
                el.SetAttribute("description", "");
                node2 = rootNode.AppendChild(el);
            }
            XmlElement pgsnode = theDoc.CreateElement("printgroups");

            foreach (PrintGroupItem o in printgroups)
            {
                XmlElement gnode = theDoc.CreateElement("printgroup");
                gnode.SetAttribute("name", o.Name);
                pgsnode.AppendChild(gnode);
            }
            node2.AppendChild(pgsnode);
            theDoc.Save(confPath);
        }
        /*
         * What do we want to do?
         * We want to shedule printjobs which are available on the system to the printgroup.
         * So we collect the printgroups and the printjobs. Then we determine the desired
         * papertypes for each labeltype named in the printjob.
         * If a label has more than one suitable papertype, we only take the default for now.
         * It is the intention to let the user release the job to another papertype in a later stage.
         *
         * We then query all available printers which are part of the desired printgroup
         * and determine the windows printer queue length. We also determine if a printer
         * is online or offline.
         * We only consider online printers. If more than one printer with the same papertype
         * is available we take the one for which the windows queuelength is the smallest.
         */

        public bool Start()
        {
            int printLanguage;
            PrintGroupItemList PrintGroups;

            PrintGroups = new PrintGroupItemList();
            GlobalDataStore.Logger.Warning("Starting printing engine...");
            string AppPath = GlobalDataStore.AppPath; // System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            string RemotingConfigFilePath = AppPath + @"\ACALabelXClient.config.xml";

            if (!File.Exists(RemotingConfigFilePath))
            {
                throw new LabelXRemClientControlOjectException(string.Format("Remoting configuration file doesn't exist: {0}", RemotingConfigFilePath));
            }

            //not need all but fasted to use this for now...

            string MachineName = string.Empty;
            int    PollFrequency;

            Toolbox.Toolbox toolbox = new Toolbox.Toolbox();

            //When a user changes the printlanguage, we print the total of the
            //current printjob in one language. We only check the variable when
            //handling a new job.
            string slang = toolbox.GetClientConfigurationLanguage(AppPath + @"\ACALabelXClient.config.xml");

            try
            {
                currentLanguage = int.Parse(slang);
            }
            catch (Exception)
            {
                currentLanguage = 1043;
            }

            printLanguage = currentLanguage;

            while (true)
            {
                if (moetstoppen)
                {
                    break;
                }
                //
                //Reread the printgroup XML... mayby not needed everytime...
                //
                if (PrintGroups.Count > 0)
                {
                    PrintGroups.Clear();
                }

                //Remark MVE:
                //  Hier lezen we de XML. De manager uppdate deze bevoorbeeld met een printer 'offline'
                //  maar in het loopje hier beneden, lezen we dit niet telkens opnieuw. D.w.z. dat het
                //  disabelen niet helpt zolang we in de verwerking van printjobs zijn. pas als alle printjobs
                //  klaar zijn gaan we hier uit en is de disable/enable pas definitief
                //  Zie plaats gemarkeerd met ***2 waar we de 'enabled' status van een printer opnieuw zouden moeten inlezen.
                try
                {
                    toolbox.GetGeneralClientConfiguratonEx(AppPath + @"\ACALabelXClient.config.xml",
                                                           out PrintJobsRootFolder,
                                                           out LabelDefinitionsRootFolder,
                                                           out PaperDefinitionsRootFolder,
                                                           out SettingsRootFolder,
                                                           out MachineName,
                                                           out PollFrequency,
                                                           ref PrintGroups);
                }
                catch (Exception e)
                {
                    GlobalDataStore.Logger.Error("Could not retrieve client configuration: " + e.Message);
                }

                bool writePrintgroupsToXml = false;
                //JBOS, 20-08-2013, Removing lock: It may cause an issue where this thread (PT) stops. It'll cause the program to stop printing until it is restarted.
                //lock (GlobalDataStore.LockClass)
                //{
                if ((GlobalDataStore.IsStandAlone) && (GlobalDataStore.MustWriteStandAlonePrintGroups))
                {
                    //write clients.xml file in SettingsRootFolder
                    writePrintgroupsToXml = true;
                    GlobalDataStore.MustWriteStandAlonePrintGroups = false;
                }
                //}
                if (writePrintgroupsToXml)
                {
                    try
                    {
                        WritePrintGroupsToLocalClientXML(PrintGroups, SettingsRootFolder + "Clients.xml", MachineName);
                    }
                    catch
                    {
                        GlobalDataStore.Logger.Info("Error writing printgroups to Clients.xml");
                        GlobalDataStore.MustWriteStandAlonePrintGroups = true;
                    }
                }
                SortedList <DateTime, PrintJobInfo> datelist = new SortedList <DateTime, PrintJobInfo>();
                foreach (PrintGroupItem it in PrintGroups)
                {
                    ///mve
                    /// **2 hier zouden we de status van de printer opnieuw moeten lezen
                    ///
                    // We may not handle disabled printgroupitems
                    if (!it.Enabled)
                    {
                        continue;
                    }

                    PrintJobInfos printjobs;
                    printjobs = new PrintJobInfos();
                    RemClientControlObject theObj;
                    theObj    = new RemClientControlObject();
                    printjobs = theObj.GetPrintjobsForPrintgroup(it);

                    //
                    //Now we have the name of all the printjobs for the group
                    //
                    foreach (PrintJobInfo jobinfo in printjobs)
                    {
                        ///
                        ///hier zouden we de printerstatus moeten opnieuw lezen en vullen.
                        ///
                        //Add dates and jobid to an array
                        if (jobinfo.LastPrinted != null && jobinfo.LastPrinted > new DateTime(1970, 1, 1))
                        {
                            try
                            {
                                datelist.Add(jobinfo.LastPrinted, jobinfo);
                            }
                            catch (ArgumentException)
                            {   //Make sure theres no key exception
                                bool notadded = true;
                                int  counter  = 1;
                                while (notadded)
                                {
                                    if (!(datelist.ContainsKey(jobinfo.LastPrinted.AddMilliseconds(counter))))
                                    {
                                        datelist.Add(jobinfo.LastPrinted.AddMilliseconds(counter), jobinfo);
                                        notadded = false;
                                    }
                                    else
                                    {
                                        counter++;
                                    }
                                }
                            }
                        }

                        //Printjobs which are not released may not be printed.
                        if (!jobinfo.AutoRelease)
                        {
                            continue;
                        }

                        if (moetstoppen)
                        {
                            break;
                        }

                        printLanguage = currentLanguage;

                        GlobalDataStore.Logger.Info("Attempting to print " + jobinfo.ID);
                        bool succes = HandlePrintJob(it, jobinfo, PrintJobsRootFolder, PaperDefinitionsRootFolder, LabelDefinitionsRootFolder, printLanguage);
                        if (succes)
                        {
                            jobinfo.AutoRelease = false;
                            GlobalDataStore.Logger.Info("Succesfully printed " + jobinfo.ID);
                        }
                    }
                    if (moetstoppen)
                    {
                        break;
                    }
                }

                //remove oldest if more than 5 in list
                //remove if older than 3 days

                List <PrintJobInfo> tempprintjobinfolist = new List <PrintJobInfo>();
                try
                {
                    foreach (KeyValuePair <DateTime, PrintJobInfo> pair in datelist)
                    {
                        if (pair.Key < DateTime.Now.AddDays(-3))
                        {
                            if (RemovePrintJob(pair.Value))
                            {
                                GlobalDataStore.Logger.Info("Deleted " + pair.Value.FullFilename);
                            }
                        }
                        else
                        {
                            tempprintjobinfolist.Add(pair.Value);
                        }
                    }
                }
                catch (Exception e)
                {
                    GlobalDataStore.Logger.Error("Unable to remove oldest printjobs (older than 3 days): " + e.Message);
                }

                try
                {
                    while (tempprintjobinfolist.Count > 5)
                    {
                        if (RemovePrintJob(tempprintjobinfolist[0]))
                        {
                            GlobalDataStore.Logger.Info("Deleted " + tempprintjobinfolist[0].FullFilename);
                        }
                        tempprintjobinfolist.RemoveAt(0);
                    }
                }
                catch (Exception e)
                {
                    GlobalDataStore.Logger.Error("Unable to remove oldest printjobs (more than 5 found): " + e.Message);
                }


                if (moetstoppen)
                {
                    break;
                }
                //Then we sleep a while (say 3 second)
                Thread.Sleep(3000);
            }
            return(true);
        }
        /*
         * private void HandlePrintJob(PrintGroupItemList PrintGroups, LabelXItem it, string PrintJobsRootFolder, string PaperDefinitionsRootFolder, string LabelDefinitionsRootFolder)
         * {
         *  string sXmlFile;
         *  string sPrintQueue;
         *  string sPrintGroup;
         *  string sLabelType;
         *
         *  sPrintGroup = string.Empty;
         *  sPrintQueue = string.Empty;
         *  sLabelType = string.Empty;
         *
         *  sXmlFile = PrintJobsRootFolder + it.Name + ".XML";
         *
         *  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;
         *  }
         *
         *  //
         *  // Retrieve Papertype of labeltype
         *  //
         *  List<string> papertypes;
         *
         *  papertypes = new List<string>();
         *  papertypes = GetPaperTypesOfLabelType(sLabelType);
         *
         *
         *  doc = null;
         *
         *  GlobalDataStore.Logger.Info("Handling: " + it.Name);
         *
         *  bool bRendered = false;
         *  foreach (PrintGroupItem item in PrintGroups)
         *  {
         *      if (item.Name.Equals(sPrintGroup, StringComparison.OrdinalIgnoreCase))
         *      {
         *          bRendered = false;
         *          foreach (string s in papertypes)
         *          {
         *              foreach (PrinterItem pit in item.GroupPrinters)
         *              {
         *                  if (pit.Trays != null)
         *                  {
         *                      foreach (PrinterTrayItem ptit in pit.Trays)
         *                      {
         *                          if (ptit.CurrentPapertypeName.Equals(s, StringComparison.OrdinalIgnoreCase))
         *                          {
         *                              GlobalDataStore.Logger.Info("Would start rendering " + it.Name + " on " + pit.Name);
         *                              ACA.LabelX.PrintJob.PrintJob p = new ACA.LabelX.PrintJob.PrintJob(PaperDefinitionsRootFolder, LabelDefinitionsRootFolder);
         *                              sXmlFile = PrintJobsRootFolder + it.Name + ".XML";
         *                              p.Parse(sXmlFile);
         *
         *                              ACA.LabelX.PrintEngine.PrintEngine pi = new ACA.LabelX.PrintEngine.PrintEngine("pc-mve2");
         *                              pi.DesignMode = false;
         *                              pi.AddPrintJob(p);
         *                              pi.Print();
         *
         *                              int teller = 0;
         *                              bool bRet = false;
         *                              while ((teller < 5) && (bRet == false))
         *                              {
         *                                  //
         *                                  //It can be another tread is reading this file.
         *                                  //Wait sometime until they release the file.
         *                                  bRet = Win32ApiFunctions.DeleteFilesToRecycleBin(sXmlFile);
         *                                  Thread.Sleep(2000);
         *                              }
         *                              bRendered = true;
         *                              break;
         *                          }
         *                      }
         *                  }
         *              }
         *              if (bRendered)
         *              {
         *                  break;
         *              }
         *          }
         *      }
         *      if (!bRendered)
         *      {
         *          break;
         *      }
         *  }
         *  if (!bRendered)
         *  {
         *      GlobalDataStore.Logger.Info("Could not render " + it.Name);
         *  }
         * }*/

        private void GetLocalPrintJobs(ref List <ACA.LabelX.Toolbox.LabelXItem> items, PrintGroupItemList PrintGroups)
        {
            foreach (PrintGroupItem PrintGroup in PrintGroups)
            {
                ACA.LabelX.Toolbox.Toolbox.GetItemsFromFolder(PrintJobsRootFolder + PrintGroup.Name, ref items, PrintGroup.Name + @"\", LabelX.Toolbox.Toolbox.FileFilterXML);
            }
        }