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("VLIX 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(async() => { 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 { } await Task.Delay(30000); } })).Start(); //************************************************* // ENABLE NAMED PIPE FOR CONFIGURATION FRONT END //************************************************* string LocalPipeName = Global.GetLocalPipeName(); WCFHost_Pipe = new WCFHost <VlixOPCContract, iVlixOPCContract>(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"); } }
/// <summary> /// THe main Class for the OPC Back End /// </summary> /// <param name="LocalPipeName">Use for OPC Admin Communication</param> public OPCBackEnd(string LocalPipeName = null) { 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("VLIX 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(async() => { 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 { } await Task.Delay(120000); } })).Start(); //************************************************* // ENABLE NAMED PIPE AND NET TCP FOR CONFIGURATION FRONT END //************************************************* if (LocalPipeName.IsNullOrWhiteSpace()) { LocalPipeName = "VlixOPC"; } //string LocalPipeName = GlobalWCF.GetLocalPipeName(); WCFHost_Pipe = new WCFHost <OPCServiceContract, iOPCServiceContract>(LocalPipeName, ""); WCFHost_Pipe.Start(); WCFHost_Tcp = new WCFHost <OPCServiceContract, iOPCServiceContract>(OPCBackEnd.Config.Tcp_Port, HostProtocolType.NetTCPSecure, OPCBackEnd.Config.Enable_Tcp_Authentication) { OnValidatingUsernamePassword = (string UN, string PW, out UserBase user) => { user = null; return(string.Equals(UN, OPCBackEnd.Config.Tcp_Username, StringComparison.OrdinalIgnoreCase) && PW == OPCBackEnd.Config.Tcp_Password); } }; WCFHost_Tcp.Start(); //**************************************** // ENABLE HTTP //**************************************** if (OPCBackEnd.Config.Enable_WebAPI_Http) { OPCBackEnd.EnableHttp(); } else { Logger.Log("Http API not Enabled"); } //**************************************** // ENABLE HTTPS //**************************************** if (OPCBackEnd.Config.Enable_WebAPI_Https) { OPCBackEnd.EnableHttps(); } else { Logger.Log("Https Secure API not Enabled"); } }