예제 #1
0
        static void Main(string[] args)
        {
            Global.Product = new ProductDetails("OpenPlantOPC", typeof(OPCBackEndConfig), "Open-Plant\\OPOPC");
            bool SendResult = (new EmbeddedResourceFileSender()).SendFiles("OpenPlantOPC", "SendToProgramDataDirectory", Global.Product.ProgramDataDirectory, "*", false, Assembly.GetExecutingAssembly());

            if (!SendResult)
            {
                throw new CustomException("FATAL ERROR: Unable to access Directory '" + Global.Product.ProgramDataDirectory);
            }
            OPCBackEnd oPCBackEnd = new OPCBackEnd();
        }
예제 #2
0
        public OPCBackEnd()
        {
            Logger.ClearLogs();
            if (!Global.Product.TryLoadConfigFile())
            {
                throw new CustomException("FATAL ERROR: Unable to load Config File '" + Global.Product.ConfigFilePath + "'");
            }
            OPCBackEnd.Config = (OPCBackEndConfig)Global.Product.Config;
            Logger.EnableLogger();
            Thread.Sleep(100);
            Logger.Log("***************************************************");
            Thread.Sleep(100);
            Logger.Log("OPEN-PLANT OPC (BACK END) STARTED");
            Thread.Sleep(100);
            Logger.Log("***************************************************");
            Thread.Sleep(100);
            Logger.Log("Log Path = '" + Global.Product.LogFilePath + "'");
            OPCBackEnd.OPCClassicBrowserEngine = new OPCClassicBrowserEngine();
            OPCBackEnd.OPCUABrowserEngine      = new OPCUABrowserEngine();


            //*************************************************
            //   REPORT NUMBER OF CALLS PER MINUTE
            //*************************************************
            (new Thread(() =>
            {
                while (true)
                {
                    DateTime DTGate = DateTime.UtcNow.AddMinutes(-1);
                    int TotalCallsLastMinute = TotalAPICalls.Count(C => C > DTGate);
                    Logger.Log("Total API Calls Last Minute = " + TotalCallsLastMinute);
                    try { TotalAPICalls.RemoveWhere(C => C < DTGate); } catch { }
                    Thread.Sleep(30000);
                }
            })).Start();


            //*************************************************
            //   ENABLE NAMED PIPE FOR CONFIGURATION FRONT END
            //*************************************************
            string LocalPipeName = Global.GetLocalPipeName();

            WCFHost_Pipe = new WCFHost <OpenPlantOPCContract, iOpenPlantOPCContract>(LocalPipeName, "");
            WCFHost_Pipe.Start();



            //****************************************
            //   ENABLE HTTP
            //****************************************
            if (OPCBackEnd.Config.EnableAPI_Http)
            {
                OPCBackEnd.EnableHttp();
            }
            else
            {
                Logger.Log("Http API not Enabled");
            }


            //****************************************
            //   ENABLE HTTPS
            //****************************************
            if (OPCBackEnd.Config.EnableAPI_Https)
            {
                OPCBackEnd.EnableHttps();
            }
            else
            {
                Logger.Log("Https Secure API not Enabled");
            }
        }
예제 #3
0
        public bool TrySaveSettings(OPCBackEndConfig OPCBackEndConfig)
        {
            try
            {
                Logger.Log("Saving and applying Open-Plant OPC New Back End Configuration...");
                bool             ChangeOccured           = false;
                OPCBackEndConfig CurrentOPCBackEndConfig = (OPCBackEndConfig)Global.Product.Config;

                //HTTP Settings
                if (CurrentOPCBackEndConfig.EnableAPI_Http != OPCBackEndConfig.EnableAPI_Http ||
                    CurrentOPCBackEndConfig.Http_Port != OPCBackEndConfig.Http_Port)
                {
                    ChangeOccured = true;
                    if (OPCBackEndConfig.EnableAPI_Http)
                    {
                        OPCBackEnd.WCFHost_Http?.Stop(); OPCBackEnd.EnableHttp();
                    }
                    else
                    {
                        OPCBackEnd.WCFHost_Http?.Stop();
                    }
                }

                //HTTPS Settings
                if (CurrentOPCBackEndConfig.EnableAPI_Https != OPCBackEndConfig.EnableAPI_Https ||
                    CurrentOPCBackEndConfig.Https_Port != OPCBackEndConfig.Https_Port ||
                    CurrentOPCBackEndConfig.RequireAPIBasicAuthentication != OPCBackEndConfig.RequireAPIBasicAuthentication ||
                    CurrentOPCBackEndConfig.Username_ForAPIBasicAuthentication != OPCBackEndConfig.Username_ForAPIBasicAuthentication ||
                    CurrentOPCBackEndConfig.Password_ForAPIBasicAuthentication != OPCBackEndConfig.Password_ForAPIBasicAuthentication ||
                    CurrentOPCBackEndConfig.SubjectAlternativeNames_ForHTTPSCert != OPCBackEndConfig.SubjectAlternativeNames_ForHTTPSCert)
                {
                    ChangeOccured = true;
                    if (OPCBackEndConfig.EnableAPI_Https)
                    {
                        OPCBackEnd.WCFHost_Https?.Stop(); OPCBackEnd.EnableHttps();
                    }
                    else
                    {
                        OPCBackEnd.WCFHost_Https?.Stop();
                    }
                }

                //OPC Settings
                if (CurrentOPCBackEndConfig.OPCClassic_SubscriptionGroupSizeLimit != OPCBackEndConfig.OPCClassic_SubscriptionGroupSizeLimit)
                {
                    ChangeOccured = true;
                    OPCBackEnd.OPCClassicBrowserEngine.OPCGroupSizeLimit = OPCBackEndConfig.OPCClassic_SubscriptionGroupSizeLimit.ToInt(40);
                }
                if (CurrentOPCBackEndConfig.OPCCUA_SubscriptionGroupSizeLimit != OPCBackEndConfig.OPCCUA_SubscriptionGroupSizeLimit)
                {
                    ChangeOccured = true;
                    OPCBackEnd.OPCUABrowserEngine.OPCGroupSizeLimit = OPCBackEndConfig.OPCCUA_SubscriptionGroupSizeLimit.ToInt(40);
                }
                if (ChangeOccured)
                {
                    OPCBackEnd.Config     = OPCBackEndConfig;
                    Global.Product.Config = OPCBackEndConfig;
                    Global.Product.Config.TrySaveConfigFile();
                    Logger.Log("Successfully saved Open-Plant OPC Back End Configuration at '" + Global.Product.ConfigFilePath + "'");
                }
                else
                {
                    Logger.Log("Save did not execute as there were no changes made!");
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }