Ejemplo n.º 1
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.º 2
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.º 3
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);
                }
            }
        }