Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public void Start()
        {
            StartCalled = true;

            string AppPath = ACA.LabelX.GlobalDataStore.AppPath; // System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            string RemotingConfigFilePath = AppPath + @"\ACALabelXClient.config.xml";

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

            string Protocol;
            string Address;
            string Port;
            string Uri;

            Toolbox.Toolbox toolbox = new Toolbox.Toolbox();
            toolbox.GetRemotingClientConfiguraton(RemotingConfigFilePath, out Protocol, out Address, out Port, out Uri);

            Hashtable myTable = new Hashtable();

            switch (Protocol.ToLower())
            {
            case "http":
                myTable["name"] = "servercon";
                HttpClientChannel theHttp = new HttpClientChannel(myTable, null);
                ChannelServices.RegisterChannel(theHttp, false);
                break;

            case "tcp":
                myTable["name"] = "servercon";
                TcpClientChannel theTcp = new TcpClientChannel(myTable, null);
                ChannelServices.RegisterChannel(theTcp, false);
                break;

            default:
                throw new LabelXClientEngineException(string.Format("Cannot obtain the correct protocol from the Remoting configuration file: {0}\r\nProtocol found: {1}\r\nShould be: http, or tcp", RemotingConfigFilePath, Protocol));
            }

            ServerURL = string.Format("{0}://{1}:{2}/{3}", Protocol, Address, Port, Uri);

            PrintGroups = new List <LabelX.Toolbox.PrintGroupItem>();
            toolbox.GetGeneralClientConfiguraton(AppPath + @"\ACALabelXClient.config.xml", out PrintJobsRootFolder, out LabelDefinitionsRootFolder, out PaperDefinitionsRootFolder, out SettingsRootFolder, out PicturesRootFolder, out UpdateRootFolder, out MachineName, out PollFrequency, ref PrintGroups);
        }
Ejemplo n.º 6
0
        //~RemoteObject()
        //{
        //}

        public void SelfInit()
        {
            GlobalDataStore.Logger.Debug(string.Format("Object is executing in AppDomain {0}", AppDomain.CurrentDomain.FriendlyName));

            string AppPath  = GlobalDataStore.AppPath;
            string confPath = AppPath + @"\ACALabelXServer.config.xml";

            Toolbox.Toolbox toolbox = new Toolbox.Toolbox();
            string          pj, ld, pd, sd, pf, uf;

            toolbox.GetGeneralServerConfiguraton(confPath, out pj, out ld, out pd, out sd, out pf, out uf);
            PrintJobsRootFolder        = pj;
            LabelDefinitionsRootFolder = ld;
            PaperDefinitionsRootFolder = pd;
            SettingsRootFolder         = sd;
            PicturesRootFolder         = pf;
            UpdateRootFolder           = uf;
        }
Ejemplo n.º 7
0
        public void GetLabelPrintGroups(ref byte[] printgroupXMLCompressed, ref int UncompressedDataLength)
        {
            GlobalDataStore.Logger.Debug("RemClientControlObject.GetLabelPrintGroups");

            List <ACA.LabelX.Toolbox.PrintGroupItem> PrintGroups;

            PrintGroups = new List <LabelX.Toolbox.PrintGroupItem>();

            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));
                }
            }
            //not need all but fasted to use this for now...
            string PrintJobsRootFolder;
            string LabelDefinitionsRootFolder;
            string PaperDefinitionsRootFolder;
            string SettingsRootFolder;
            string MachineName;
            int    PollFrequency;

            Toolbox.Toolbox toolbox = new Toolbox.Toolbox();
            toolbox.GetGeneralClientConfiguraton(AppPath + @"\ACALabelXClient.config.xml",
                                                 out PrintJobsRootFolder,
                                                 out LabelDefinitionsRootFolder,
                                                 out PaperDefinitionsRootFolder,
                                                 out SettingsRootFolder,
                                                 out MachineName,
                                                 out PollFrequency,
                                                 ref PrintGroups);


            byte[] UncompressedPrintgroupXml;
            UncompressedPrintgroupXml = ConvertPrintergroupsToXML(PrintGroups);
            UncompressedDataLength    = UncompressedPrintgroupXml.Length;
            printgroupXMLCompressed   = PSLib.Compression.Compress(UncompressedPrintgroupXml);
        }
Ejemplo n.º 8
0
        public void Start(string CfgFilePath)
        {
            GlobalDataStore.Logger.Debug("AcaLabelXClientRemoteEngine.Start");

            ConfigFilePath = CfgFilePath;
            RemotingConfiguration.Configure(ConfigFilePath, false);
            string Protocol;
            string Address;
            string Port;
            string Uri;

            Toolbox.Toolbox toolbox = new Toolbox.Toolbox();
            toolbox.GetRemotingClientRemoteConfiguration(ConfigFilePath, out Protocol, out Address, out Port, out Uri);

            switch (Protocol.ToLower())
            {
            case "http":
                ChannelServices.RegisterChannel(new HttpClientChannel(), false);
                break;

            case "tcp":
                ChannelServices.RegisterChannel(new TcpClientChannel(), false);
                break;

            default:
                throw new ApplicationException(string.Format("Could not obtain the correct protocol from: {0}\r\nFound protocol: {1}\r\nShould be: http, or tcp", ConfigFilePath, Protocol));
            }
            //Address = "localhost";
            Address = "127.0.0.1";
            string ClientURL = string.Format("{0}://{1}:{2}/{3}", Protocol, Address, Port, Uri);

            ACA.LabelX.Client.RemClientControlObject objLabelXRemObject = (ACA.LabelX.Client.RemClientControlObject)Activator.GetObject(
                typeof(ACA.LabelX.Client.RemClientControlObject), ClientURL);

            if (objLabelXRemObject != null)
            {
                objLabelXRemObject.InitServer();
            }
        }
Ejemplo n.º 9
0
        public void Start()
        {
            StartCalled = true;

            string AppPath = ".\\"; // System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            string RemotingConfigFilePath = AppPath + @"\ACALabelXClientRemote.config.xml";

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

            string Protocol;
            string Address;
            string Port;
            string Uri;

            Toolbox.Toolbox toolbox = new Toolbox.Toolbox();
            toolbox.GetRemotingClientConfiguraton(RemotingConfigFilePath, out Protocol, out Address, out Port, out Uri);

            switch (Protocol.ToLower())
            {
            case "http":
                ChannelServices.RegisterChannel(new HttpClientChannel(), false);
                break;

            case "tcp":
                ChannelServices.RegisterChannel(new TcpClientChannel(), false);
                break;

            default:
                throw new LabelXClientCtrlEngineException(string.Format("Cannot obtain the correct protocol from the Remoting configuration file: {0}\r\nProtocol found: {1}\r\nShould be: http, or tcp", RemotingConfigFilePath, Protocol));
            }

            ServerURL = string.Format("{0}://{1}:{2}/{3}", Protocol, Address, Port, Uri);
        }
Ejemplo n.º 10
0
        public ACA.LabelX.Toolbox.PrintGroupItemList GetLabelPrintGroupsEx(out string Machine)
        {
            GlobalDataStore.Logger.Debug("RemClientControlObject.GetLabelPrintGroupsEx");
            ACA.LabelX.Toolbox.PrintGroupItemList PrintGroups;
            PrintGroups = new ACA.LabelX.Toolbox.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));
                }
            }
            //not need all but faster to use this for now...
            string PrintJobsRootFolder;
            string LabelDefinitionsRootFolder;
            string PaperDefinitionsRootFolder;
            string SettingsRootFolder;
            string MachineName;
            int    PollFrequency;

            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);
            Machine = MachineName;
            return(PrintGroups);
        }
Ejemplo n.º 11
0
        public void SynchronizePrintJobs()
        {
            EnsureStartIsCalled();

            Directory.CreateDirectory(PrintJobsRootFolder);

            //Get all printgroups
            Toolbox.Toolbox toolbox = new Toolbox.Toolbox();
            toolbox.GetClientPrintGroups(ACA.LabelX.GlobalDataStore.AppPath + @"\ACALabelXClient.config.xml", ref PrintGroups);

            foreach (Toolbox.PrintGroupItem printGroup in PrintGroups)
            {
                Directory.CreateDirectory(PrintJobsRootFolder + printGroup.Name);
            }

            List <Toolbox.LabelXItem> remoteItems = new List <Toolbox.LabelXItem>();

            GetRemotePrintJobs(remoteItems);

            List <Toolbox.LabelXItem> localItems = new List <Toolbox.LabelXItem>();

            GetLocalPrintJobs(ref localItems);

            List <Toolbox.LabelXItem> itemsToDownload = new List <Toolbox.LabelXItem>();

            Toolbox.Toolbox.GetAddedItems(localItems, remoteItems, ref itemsToDownload);
            Toolbox.Toolbox.GetChangedItems(localItems, remoteItems, ref itemsToDownload);
            //
            //Code below will remove local printjobs if server printjobs are removed.
            //This would be usable if we wantted to keep the files on the server until
            //they are realy printed. We decided not to do this. Jobs on the server
            //will be removed as soon as a file is transfered and the hass is successfully
            //matched...
            //List<Toolbox.LabelXItem> itemsToDelete = new List<Toolbox.LabelXItem>();
            //Toolbox.Toolbox.GetDeletedItems(localItems, remoteItems, ref itemsToDelete);
            //
            //foreach (Toolbox.LabelXItem itemToDelete in itemsToDelete)
            //{
            //    GlobalDataStore.Logger.Info("Deleting printjob: " + itemToDelete.Name);
            //    string path = PrintJobsRootFolder + itemToDelete.Name + ".xml";
            //    File.Delete(GetFilePathWithStatus(path, FILESTATUS.FS_NONE));
            //    File.Delete(GetFilePathWithStatus(path, FILESTATUS.FS_DOWNLOADING));
            //}

            foreach (Toolbox.LabelXItem itemToDownload in itemsToDownload)
            {
                GlobalDataStore.Logger.Info("Downloading printjob: " + itemToDownload.Name);
                DownloadPrintJob(MachineName, Path.GetDirectoryName(itemToDownload.Name), Path.GetFileName(itemToDownload.Name));
            }

            //New handler
            //We have transferd some  files now. We re-retrieve the localItems and compare this
            //with the local items
            List <Toolbox.LabelXItem> localItemsBis = new List <Toolbox.LabelXItem>();

            GetLocalPrintJobs(ref localItemsBis);
            foreach (Toolbox.LabelXItem itemOnLocalDir in localItemsBis)
            {
                foreach (Toolbox.LabelXItem itemRemote in itemsToDownload)
                {
                    if (itemOnLocalDir.Name.Equals(itemRemote.Name))
                    {
                        //this was the file we needed... check hash to be sure
                        if (itemOnLocalDir.Hash == itemRemote.Hash)
                        {
                            RemoveRemotePrintJobs(itemRemote);
                            break;
                        }
                    }
                }
            }

            //See if duplicate items exist on the server and delete them. (This shouldn't happen but you never know)
            foreach (Toolbox.LabelXItem localitem in localItems)
            {
                foreach (Toolbox.LabelXItem remoteItem in remoteItems)
                {
                    if (localitem.Name.Equals(remoteItem.Name))
                    {
                        //this was the file we needed... check hash to be sure
                        if (localitem.Hash == remoteItem.Hash)
                        {
                            RemoveRemotePrintJobs(remoteItem);
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
 public void ReceiveStatusUpdate(out string updateNodig)
 {
     Toolbox.Toolbox toolbox = new Toolbox.Toolbox();
     MachineName = toolbox.GetMachineName(GlobalDataStore.AppPath + @"\ACALabelXClient.config.xml");
     updateNodig = GetRemoteObject().startUpdate(GlobalDataStore.ProgramVersion, MachineName);
 }
Ejemplo n.º 13
0
        public bool Start()
        {
            bool bRet;
            bool FirstRun = true;

            moetstoppen = false;

Opnieuw:
            bRet = true;

            string AppPath = GlobalDataStore.AppPath; //System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            try
            {
                ACALabelXController controller = new ACALabelXController();
                controller.Start(AppPath + @"\ACALabelXServer.config.xml");
                GlobalDataStore.Logger.Info("=======================================");
                GlobalDataStore.Logger.Info("Configuration:");
                GlobalDataStore.Logger.Info("=======================================");
                Toolbox.Toolbox toolbox = new Toolbox.Toolbox();
                toolbox.GetGeneralServerConfiguraton(AppPath + @"\ACALabelXServer.config.xml", out PrintJobsRootFolder, out LabelDefinitionsRootFolder, out PaperDefinitionsRootFolder, out SettingsRootFolder, out PicturesRootFolder, out UpdateRootFolder);
                GlobalDataStore.Logger.Info("PrintJobsRootFolder: " + PrintJobsRootFolder);
                GlobalDataStore.Logger.Info("LabelDefinitionsRootFolder: " + LabelDefinitionsRootFolder);
                GlobalDataStore.Logger.Info("PaperDefinitionsRootFolder: " + PaperDefinitionsRootFolder);
                GlobalDataStore.Logger.Info("SettingsRootFolder: " + SettingsRootFolder);
                GlobalDataStore.Logger.Info("PicturesRootFolder: " + PicturesRootFolder);
                GlobalDataStore.Logger.Info("UpdateRootFolder: " + UpdateRootFolder);
                GlobalDataStore.Logger.Info("=======================================");

                FileSystemWatcher updateFolderWatcher = new FileSystemWatcher
                {
                    Filter             = "",
                    InternalBufferSize = 128,
                    Path = UpdateRootFolder,
                    IncludeSubdirectories = true,
                    NotifyFilter          = (NotifyFilters.Attributes | NotifyFilters.CreationTime |
                                             NotifyFilters.DirectoryName | NotifyFilters.FileName |
                                             NotifyFilters.LastWrite | NotifyFilters.Size)
                };

                updateFolderWatcher.Changed            += onUpdateChanged;
                updateFolderWatcher.Created            += onUpdateChanged;
                updateFolderWatcher.Deleted            += onUpdateChanged;
                updateFolderWatcher.Renamed            += onUpdateChanged;
                updateFolderWatcher.EnableRaisingEvents = true;

                FileSystemWatcher pictureFolderWatcher = new FileSystemWatcher
                {
                    Filter             = "",
                    InternalBufferSize = 128,
                    Path = PicturesRootFolder,
                    IncludeSubdirectories = true,
                    NotifyFilter          = (NotifyFilters.Attributes | NotifyFilters.CreationTime |
                                             NotifyFilters.DirectoryName | NotifyFilters.FileName |
                                             NotifyFilters.LastWrite | NotifyFilters.Size)
                };

                pictureFolderWatcher.Changed            += onPictureChanged;
                pictureFolderWatcher.Created            += onPictureChanged;
                pictureFolderWatcher.Deleted            += onPictureChanged;
                pictureFolderWatcher.Renamed            += onPictureChanged;
                pictureFolderWatcher.EnableRaisingEvents = true;

                timer.Elapsed += timer_Tick;
                timer.Interval = 1000;
                timer.Enabled  = true;
                FirstRun       = false;
                while (!moetstoppen)
                {
                    Thread.Sleep(100);
                }
            }
            catch (Exception e)
            {
                GlobalDataStore.Logger.Error(string.Format("Error:\r\n{0}\r\n\r\nTarget site:\r\n{1}\r\n\r\nStack trace:\r\n{2}", e.Message, e.TargetSite, e.StackTrace));
                if (e.InnerException != null)
                {
                    GlobalDataStore.Logger.Error(string.Format("Error:\r\n{0}\r\n\r\nTarget site:\r\n{1}\r\n\r\nStack trace:\r\n{2}", e.InnerException.Message, e.InnerException.TargetSite, e.InnerException.StackTrace));
                }
                bRet = false;
                if (FirstRun)
                {
                    FirstRun = false;
                    //echt stoppen
                }
                else
                {
                    //Log a speep event and try again in 10 minutes.
                    GlobalDataStore.Logger.Error("The above error prevents LabelPrint from printing. Retying in 10 minutes.");
                    Thread.Sleep(1000 * 60 * 10); // sleep 10 minutes.

                    goto Opnieuw;                 //Oeps... violation of all learned rules.
                }
            }
            return(bRet);
        }
Ejemplo n.º 14
0
        public void Start(string ConfigFilePath)
        {
            const bool methode1 = true;
            Hashtable  Props;
            //IChannel ServiceChannel;
            string           Protocol;
            string           Address;
            string           Port;
            string           Uri;
            TcpServerChannel theTcp;

            if (methode1)
            {
                this.ConfigFilePath = ConfigFilePath;

                RemotingConfiguration.Configure(ConfigFilePath, false);

                Toolbox.Toolbox toolbox = new Toolbox.Toolbox();
                toolbox.GetRemotingServerConfiguraton(ConfigFilePath, out Protocol, out Address, out Port, out Uri);

                string sipnr = GlobalDataStore.GetAppSetting("localhost");
                Address = sipnr;
                string ClientURL = string.Format("{0}://{1}:{2}/{3}", Protocol, Address, Port, Uri);
                ACA.LabelX.RemoteObject objLabelXRemoteObject = (ACA.LabelX.RemoteObject)Activator.GetObject(
                    typeof(ACA.LabelX.RemoteObject), ClientURL);
                if (objLabelXRemoteObject != null)
                {
                    toolbox.GetGeneralServerConfiguraton(ConfigFilePath, out PrintJobsRootFolder, out LabelDefinitionsRootFolder, out PaperDefinitionsRootFolder, out SettingsRootFolder, out PictureRootFolder, out UpdateRootFolder);
                    objLabelXRemoteObject.InitServer(PrintJobsRootFolder, LabelDefinitionsRootFolder, PaperDefinitionsRootFolder, SettingsRootFolder, UpdateRootFolder);
                }
            }
            else
            {
                this.ConfigFilePath = ConfigFilePath;

                //RemotingConfiguration.Configure(ConfigFilePath, false);
                Props = new Hashtable();

                Toolbox.Toolbox toolbox = new Toolbox.Toolbox();
                toolbox.GetRemotingServerConfiguraton(ConfigFilePath, out Protocol, out Address, out Port, out Uri);

                HttpChannel theHttp2;
                Hashtable   myTable = new Hashtable();
                SoapServerFormatterSinkProvider theProvider = new SoapServerFormatterSinkProvider();
                //BinaryServerFormatterSinkProvider theProvider = new BinaryServerFormatterSinkProvider();
                //theProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                ClientIPInjectorSinkProvider injectorProvider;
                injectorProvider = new ClientIPInjectorSinkProvider();

                //BinaryClientFormatterSinkProvider theClientProv = new BinaryClientFormatterSinkProvider();
                //Props["port"] = "8080";
                Props["port"] = "18080";
                Props["name"] = "ACALabelXRemoteObject";
                //Props["address"] = "localhost";
                Props["address"] = "127.0.0.1";

                theProvider.Next = injectorProvider;
                //theProvider.Next = new ClientIPInjectorSinkProvider();

                switch (Protocol.ToLower())
                {
                case "http":
                    myTable["name"] = "serversite";
                    theHttp2        = new HttpChannel(Props, null, theProvider);
                    ChannelServices.RegisterChannel(theHttp2, false);
                    break;

                case "tcp":
                    myTable["name"] = "serversite";
                    theTcp          = new TcpServerChannel(myTable, theProvider);
                    ChannelServices.RegisterChannel(theTcp, false);
                    break;

                default:
                    throw new ApplicationException(string.Format("Could not obtain the correct protocol from: {0}\r\nFound protocol: {1}\r\nShould be: http, or tcp", ConfigFilePath, Protocol));
                }
                RemoteObject theObject = new RemoteObject();
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(ACA.LabelX.RemoteObject), "ACALabelXRemoteObject", WellKnownObjectMode.Singleton);

                //Address = "localhost";
                Address = "127.0.0.1";
                string ClientURL = string.Format("{0}://{1}:{2}/{3}", Protocol, Address, Port, Uri);
                ACA.LabelX.RemoteObject objLabelXRemoteObject = (ACA.LabelX.RemoteObject)Activator.GetObject(
                    typeof(ACA.LabelX.RemoteObject), ClientURL);
                if (objLabelXRemoteObject != null)
                {
                    toolbox.GetGeneralServerConfiguraton(ConfigFilePath, out PrintJobsRootFolder, out LabelDefinitionsRootFolder, out PaperDefinitionsRootFolder, out SettingsRootFolder, out PictureRootFolder, out UpdateRootFolder);
                    objLabelXRemoteObject.InitServer(PrintJobsRootFolder, LabelDefinitionsRootFolder, PaperDefinitionsRootFolder, SettingsRootFolder, UpdateRootFolder);
                }
            }
        }
Ejemplo n.º 15
0
        /*
         * 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);
        }