Example #1
0
        private static DeleporterService CreateInstance()
        {
            if (!_hasRegisteredChannel)
            {
                ChannelServices.RegisterChannel(new TcpChannel(
                                                    new Hashtable {
                    { "port", 0 }, { "typeFilterLevel", TypeFilterLevel.Full }, { "name", Guid.NewGuid().ToString() }
                },
                                                    new BinaryClientFormatterSinkProvider(),
                                                    new BinaryServerFormatterSinkProvider {
                    TypeFilterLevel = TypeFilterLevel.Full
                }
                                                    ), false);
                RemotingConfiguration.RegisterWellKnownClientType(typeof(DeleporterService), DeleporterConfiguration.HostAddress);
                _hasRegisteredChannel = true;
            }
            var instance = new DeleporterService();

            try {
                instance.RegisterAssemblyProvider(new AssemblyProvider());
            }
            catch (SocketException socketException)
            {
                LoggerClient.Log("Failed to create a channel on port {0}", DeleporterConfiguration.RemotingPort);

                throw new Exception(string.Format("Deleporter client was unable to connect to the remoting port {0} to the server.  Likely causes: 1) RemotingPort or WebHostPort settings are not the same in both projects; 2) WebServer may not have been able to listen on the remoting port because something else is using the port. Try using another port.", DeleporterConfiguration.RemotingPort), socketException);
            }

            LoggerClient.Log("Created remoting channel on port {0}", DeleporterConfiguration.RemotingPort);

            return(instance);
        }
Example #2
0
        public void Stop()
        {
            if (_casinniServer == null)
            {
                LoggerClient.Log("Cassini was not started by this process ... ");
                return;
            }

            LoggerClient.Log("Cassini stopping ... ");

            _casinniServer.Stop();
            _casinniServer.InitializeLifetimeService();
            try {
                DeleporterUtilities.WaitForLocalPortToBecomeAvailable(DeleporterConfiguration.WebHostPort);
                LoggerClient.Log("Cassini Stopped");
            }
            catch (Exception exception)
            {
                LoggerClient.Log("FAILURE: Cassini did not appear to release port {0} within 10 seconds.  Please make sure that Selenium Server is shut down first."
                                 , DeleporterConfiguration.WebHostPort);
                throw new Exception(string.Format("Cassini did not appear to release port {0} within 10 seconds.  Please make sure that Selenium Server is shut down first."
                                                  , DeleporterConfiguration.WebHostPort), exception);
            } finally {
                LoggerClient.Dispose();
            }
        }
Example #3
0
 public AzureStorageClient()
 {
     storageAccount     = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
     LoggerClient       = new LoggerClient(storageAccount);
     BlobClient         = new BlobClient(storageAccount);
     MessageQueueClient = new MessageQueueClient(storageAccount);
 }
Example #4
0
        private void AgentWindowLoad(object sender, EventArgs e)
        {
            LoggerClient.Initialize();
            this.logger.Send("ScadaDataClient", "Data (upload) Program starts at " + DateTime.Now);

            this.InitSysNotifyIcon();
            this.MakeWindowShownFront();
            this.ShowInTaskbar = false;
            this.SetExceptionToolStripMenuItem.Checked = false;
            this.statusStrip.Items.Add(this.GetConnetionString());
            this.statusStrip.Items.Add(new ToolStripSeparator());
            this.statusStrip.Items.Add("MS: " + Settings.Instance.Mn);
            this.statusStrip.Items.Add(new ToolStripSeparator());
            // this.statusStrip.Items.Add("数据中心IP:");

            this.cmdReceiver = new CommandReceiver(Ports.DataClient);
            cmdReceiver.Start(this.OnLocalCommand);

            SystemEvents.SessionEnding += SystemEvents_SessionEnding;

            this.InitDetailsListView();
            if (this.StartState)
            {
                this.Start();
            }
        }
Example #5
0
        public static void Run(Action codeToExecute)
        {
            LoggerClient.Log("Deleporting Action");
            var result = Current.ExecuteAction(new SerializableDelegate <Action>(codeToExecute));

            CopyFields(result.Delegate.Target, codeToExecute.Target);
        }
Example #6
0
        public void Stop()
        {
            if (_iisExpressProcess == null)
            {
                LoggerClient.Log("IIS Express was not started by this process ... ");
                return;
            }

            LoggerClient.Log("IIS Express Stopping ... ");
            _iisExpressProcess.Kill();

            try
            {
                DeleporterUtilities.WaitForLocalPortToBecomeAvailable(DeleporterConfiguration.WebHostPort);
                LoggerClient.Log("IIS Express Stopped");
            }
            catch (Exception exception)
            {
                var message = string.Format("IIS Express did not appear to release port {0} within 10 seconds.  " +
                                            "Please make sure that Selenium Server is shut down first.", DeleporterConfiguration.WebHostPort);
                LoggerClient.Log(message);
                throw new Exception(message, exception);
            }
            finally
            {
                LoggerClient.Dispose();
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            var consoleLogger    = new LoggerClient(new ConsoleMessageDispatcherFactory());
            var fileSystemLogger = new LoggerClient(new FileSystemMessageDispatcherFactory());

            consoleLogger.Log("a message for console dispatcher.");
            fileSystemLogger.Log("a message for file system dispatcher.");
        }
Example #8
0
        public void TestTizenLogger()
        {
            var dummyChannel = "TizenLog";
            var logger       = new TizenLogger(dummyChannel, LogLevel.Verbose);
            var loggerClient = new LoggerClient(logger);

            loggerClient.Func();
        }
Example #9
0
        public static void LogInfo()
        {
            LoggerClient client = new LoggerClient();



            client.Log("", LogType.Info, 1, "zhangqingguang", "证书测试", "证书测试", null, null);
        }
Example #10
0
        static void Main(string[] args)
        {
            var client = new LoggerClient("console");

            client.Log("a message");

            client = new LoggerClient("filesystem");
            client.Log("another message");
        }
Example #11
0
        public static void Main()
        {
            var client = new LoggerClient(new DevelopmentMessageFactory());

            client.Log("a test message.");

            client = new LoggerClient(new ProductionMessageFactory());
            client.Log("another test message.");
        }
Example #12
0
 public void Stop()
 {
     if (this._seleniumServer != null)
     {
         LoggerClient.Log("Selenium Instance stopping ... ");
         this._seleniumServer.Kill();
         DeleporterUtilities.WaitForLocalPortToBecomeAvailable(DeleporterConfiguration.SeleniumServerPort);
         LoggerClient.Log("Selenium Stopped");
     }
 }
Example #13
0
        public static void Initialize()
        {
            RecordManager.mysql = new MySQLRecord();

            RecordManager.analysis = new AnalysisRecord();

            LoggerClient.Initialize();
            RecordManager.logger = new LoggerClient();
            // RecordManager.frameworkRecord = new FileRecord("");
        }
 private static void LogPortChanges(int newWebHostPort, int newRemotingPort, DeleporterConfigurationSection configSection)
 {
     if (configSection.WebHostPort != newWebHostPort)
     {
         LoggerClient.Log("Changing WebHostPort in web.config from {0} to {1}", configSection.WebHostPort, newWebHostPort);
     }
     if (configSection.RemotingPort != newRemotingPort)
     {
         LoggerClient.Log("Changing RemotingPort in web.config from {0} to {1}", configSection.WebHostPort, newWebHostPort);
     }
 }
Example #15
0
        public static T Run <T>(Func <T> codeToExecute)
        {
            LoggerClient.Log("Deleporting Func");

            var genericType          = typeof(SerializableDelegate <>).MakeGenericType(typeof(Func <T>));
            var serializableDelegate = Activator.CreateInstance(genericType, codeToExecute);
            var result = Current.ExecuteFunction((SerializableDelegate <Func <T> >)serializableDelegate);

            CopyFields(result.DelegateCalled.Delegate.Target, codeToExecute.Target);

            return(result.DelegateCallResult);
        }
Example #16
0
        public bool Start()
        {
            if (_started)
            {
                return(false);
            }
            _started = true;

            DeleporterUtilities.SetWebAndRemotingPortsBasedOnAvailability();

            if (!DeleporterUtilities.LocalPortIsAvailable(DeleporterConfiguration.WebHostPort))
            {
                LoggerClient.Log("ERROR: IIS Express port {0} is being used. Attempt to start IIS Express has been aborted",
                                 DeleporterConfiguration.WebHostPort);
                return(false);
            }

            var fileName = FileUtilities.TryToFindProgramFile("iisexpress.exe", "IIS Express");

            if (fileName == null)
            {
                throw new FileNotFoundException("IIS Express was not found on this machine.");
            }

            _iisExpressProcess = new Process
            {
                StartInfo =
                {
                    FileName  = fileName,
                    Arguments =
                        "/path:\"" + DeleporterConfiguration.FullyQualifiedPathToWebApp + "\" /port:"
                        + DeleporterConfiguration.WebHostPort + " /trace:error",
                    WindowStyle     = ProcessWindowStyle.Hidden,
                    UseShellExecute = false,
                    CreateNoWindow  = true,
                }
            };

            LoggerClient.Log("IIS Express starting on port {0} using path {1}... ", DeleporterConfiguration.WebHostPort, DeleporterConfiguration.FullyQualifiedPathToWebApp);
            try {
                _iisExpressProcess.Start();
            } catch (SocketException ex) {
                LoggerClient.Log("Couldn't start IIS Express ...  {0}", ex.Message);
                return(false);
            }

            DeleporterUtilities.WaitForLocalPortToBecomeUnavailable(DeleporterConfiguration.WebHostPort);
            DeleporterUtilities.PrimeServerHomepage();
            LoggerClient.Log("IIS Express Started");
            return(true);
        }
Example #17
0
        public bool Start()
        {
            if (this._started)
            {
                return(false);
            }
            this._started = true;

            if (!DeleporterUtilities.LocalPortIsAvailable(DeleporterConfiguration.SeleniumServerPort))
            {
                LoggerClient.Log("Selenium port {0} is being used. Attempt to start Selenium has been aborted. "
                                 + "A previous instance may be running in which case we will just use that.",
                                 DeleporterConfiguration.SeleniumServerPort);
                return(false);
            }

            var javaExecutable = FileUtilities.TryToFindProgramFile("java.exe", "java");

            this.ThrowIfFilesDontExist(DeleporterConfiguration.SeleniumServerJar, javaExecutable);

            this._seleniumServer = new Process
            {
                StartInfo =
                {
                    FileName  = javaExecutable,
                    Arguments =
                        string.Format("-jar {0} -port {1}",
                                      DeleporterConfiguration.SeleniumServerJar,
                                      DeleporterConfiguration.SeleniumServerPort),
                    UseShellExecute = false,
                    CreateNoWindow  = true
                }
            };

            LoggerClient.Log("Selenium Instance starting on port {0} using jar {1}... ",
                             DeleporterConfiguration.SeleniumServerPort, DeleporterConfiguration.SeleniumServerJar);
            try {
                this._seleniumServer.Start();
            } catch (Exception ex) {
                LoggerClient.Log("Couldn't start Selenium ... {0}", ex.Message);
                return(false);
            }

            // 20 seconds max ... checking every 0.1 seconds
            DeleporterUtilities.WaitForLocalPortToBecomeUnavailable(DeleporterConfiguration.SeleniumServerPort,
                                                                    100,
                                                                    200);
            LoggerClient.Log("Selenium Started");
            return(true);
        }
Example #18
0
        public void TestLogServerFromClient()
        {
            // Arrange
            var endpoint           = "tcp://127.0.0.1:55011";
            var nsEndpoint         = "tcp://127.0.0.1:55021";
            var msgPushSocket      = "This is a message from a PUSH zsocket.";
            var msgLogger          = "This is a test message from the LoggerClient.";
            var clientName         = "Test Client";
            var systemRegistration = new SystemRegistration(clientName, endpoint)
            {
                Id = 1
            };
            var logList      = new List <string>();
            var mockLog      = new Mock <ILogger>();
            var loggerServer = new LoggerServer("Test Logger Server", endpoint, nsEndpoint, mockLog.Object);

            mockLog.Setup(l => l.WriteLine(It.IsAny <string>())).Callback((string msg) => {
                logList.Add(msg);
                if (logList.Count > 1)
                {
                    loggerServer.Stop();
                }
            });

            var task = Task.Run(() => loggerServer.StartAsync(endpoint));

            Thread.Sleep(300);

            var pushContext = new ZContext();
            var pushSocket  = new ZSocket(pushContext, ZSocketType.PUSH);

            pushSocket.Connect(endpoint);

            var loggerClient = new LoggerClient(endpoint, clientName, nsEndpoint);
            var vts          = new VectorTimeStamp();

            vts.Update(systemRegistration.Id, DateTime.Now);

            // Act
            loggerClient.WriteLine(msgLogger, vts);
            Thread.Sleep(25);
            pushSocket.Send(new ZFrame(msgPushSocket));
            task.Wait();

            // Assert
            Assert.AreEqual(2, logList.Count);
            Assert.AreEqual($"{clientName}:{vts}: {msgLogger}", logList[0]);
            Assert.AreEqual(msgPushSocket, logList[1]);
        }
Example #19
0
        private void DoLog(string fileName, string msg)
        {
            string line = string.Format("[{0}] {1}", DateTime.Now.ToString("HH:mm:ss"), msg);

            if (LoggerClient.Contains(fileName))
            {
                this.logger.Send(fileName, line);
            }
            Logger logger = Log.GetLogFile(fileName);

            if (logger != null)
            {
                logger.Log(line);
            }
        }
Example #20
0
        public async Task <IActionResult?> Logger([FromRoute] string?loggerName)
        {
            Response.Headers.Add("Cache-Control", "no-cache");

            if (Request.Headers.ContainsKey("Accept") && Request.Headers["Accept"] == "text/event-stream")
            {
                var client = new LoggerClient(new Guid(), loggerName, Request, Response, ControllerContext.HttpContext.RequestAborted);
                logger.ConnectClient(client);
                await ControllerContext.HttpContext.RequestAborted.WhenCancelled();

                logger.DisconnectClient(client);
                return(null);
            }
            else
            {
                return(Ok(logger.GetFirstTimeResult(loggerName, Request)));
            }
        }
Example #21
0
        internal void DoLog(string deviceKey, string msg)
        {
            if (this.UIThreadMashaller == null)
            {
                return;
            }

            this.UIThreadMashaller.Mashall((_n) =>
            {
                if (ExistLoggerConsoleProc() && LoggerClient.Contains(deviceKey))
                {
                    this.logger.Send(deviceKey, msg);
                }
                Logger logger = Log.GetLogFile(deviceKey);
                if (logger != null)
                {
                    logger.Log(msg);
                }
            });
        }
Example #22
0
        private static void WriteDataToLog(Device device, string content, RecordType recordType, bool flush = false)
        {
            // To Log File
            DateTime      now        = DateTime.Now;
            StreamWriter  fileWriter = RecordManager.GetLogFileStream(device, now);
            string        time       = string.Format("[{0:HH:mm:ss}] ", now);
            StringBuilder sb         = new StringBuilder(time);

            sb.Append(string.Format(" <{0}> ", recordType.ToString()));
            sb.Append(content);
            string line = sb.ToString();

            fileWriter.WriteLine(line);

            // Flush Control.
#if DEBUG
            fileWriter.Flush();
#else
            if (flush)
            {
                fileWriter.Flush();
            }
#endif

            if (flushCtrlCount % 10 == 0)
            {
                fileWriter.Flush();
            }
            flushCtrlCount = (flushCtrlCount + 1) % 5;

            // To Log Console
            if (ExistLoggerConsoleProc())
            {
                string deviceKey = device.Id.ToLower();
                if (LoggerClient.Contains(deviceKey))
                {
                    logger.Send(deviceKey, line);
                }
            }
        }
Example #23
0
        private void AgentWindowLoad(object sender, EventArgs e)
        {
            this.Visible = false;
            LoggerClient.Initialize();
            this.logger.Send("ScadaDataClient", "Data (upload) Program starts at " + DateTime.Now);

            this.InitSysNotifyIcon();
            this.MakeWindowShownFront();
            this.ShowInTaskbar = false;
            this.SetExceptionToolStripMenuItem.Checked = false;

            this.cmdReceiver = new CommandReceiver(Ports.DataClient);
            cmdReceiver.Start(this.OnLocalCommand);

            SystemEvents.SessionEnding += SystemEvents_SessionEnding;

            this.InitDetailsListView();
            if (this.StartState)
            {
                this.Start();
            }
        }
Example #24
0
        public bool Start()
        {
            if (_started)
            {
                return(false);
            }
            _started = true;

            DeleporterUtilities.SetWebAndRemotingPortsBasedOnAvailability();

            if (!DeleporterUtilities.LocalPortIsAvailable(DeleporterConfiguration.WebHostPort))
            {
                LoggerClient.Log("ERROR: Cassini port {0} is being used. Attempt to start Cassini has been aborted",
                                 DeleporterConfiguration.WebHostPort);
                throw new InvalidOperationException(string.Format("Cassini port {0} is being used by something else. Attempt to start Cassini has been aborted",
                                                                  DeleporterConfiguration.WebHostPort));
            }

            LoggerClient.Log("Using web.config location {0} with port {1}",
                             DeleporterConfiguration.FullyQualifiedPathToWebApp, DeleporterConfiguration.WebHostPort);

            _casinniServer = new Microsoft.VisualStudio.WebHost.Server(DeleporterConfiguration.WebHostPort, "/",
                                                                       DeleporterConfiguration.FullyQualifiedPathToWebApp);

            LoggerClient.Log("Cassini starting on port {0} using path {1}... ", DeleporterConfiguration.WebHostPort, DeleporterConfiguration.FullyQualifiedPathToWebApp);
            try {
                _casinniServer.Start();
            } catch (Exception ex) {
                LoggerClient.Log("Couldn't start Cassini ... {0}", ex.Message);
                return(false);
            }

            DeleporterUtilities.WaitForLocalPortToBecomeUnavailable(DeleporterConfiguration.WebHostPort);
            LoggerClient.Log("Cassini Started");
            DeleporterUtilities.PrimeServerHomepage();
            return(true);
        }
Example #25
0
        internal static async Task StartAsync(string analyzerName, string analyzerEndpoint, string publisherName, string publisherEndpoint, string nsEndpoint, string logServerName)
        {
            Console.WriteLine("Disease Analyzer: " + analyzerName);
            var loggerClient1 = new LoggerClient(logServerName, analyzerName, nsEndpoint);
            var consoleLogger = new ConsoleLogger();
            await loggerClient1.GetLogServerEndpointAsync(logServerName);

            Logger1 = new MultiLogger(consoleLogger, loggerClient1);
            Logger2 = new MultiLogger(consoleLogger, new LoggerClient(logServerName, analyzerName, nsEndpoint)
            {
                LogServerEndpoint = loggerClient1.LogServerEndpoint
            });

            var analyzerServer  = new AnalyzerServer(analyzerName, analyzerEndpoint, nsEndpoint, Logger1);
            var publisherServer = new OutbreakPublisherServer(publisherName, publisherEndpoint, nsEndpoint, Logger2);

            var analyzerServerRegTask  = analyzerServer.RegisterAsync();
            var publisherServerRegTask = publisherServer.RegisterAsync();
            await Task.WhenAll(analyzerServerRegTask, publisherServerRegTask);

            var analyzerTask  = analyzerServer.StartAsync(analyzerEndpoint);
            var publisherTask = publisherServer.StartAsync(publisherEndpoint, ZSocketType.PUB, publisherServer.ReceiveAction);
            await Task.WhenAll(analyzerTask, publisherTask);
        }
Example #26
0
        public async static Task Main(string[] args)
        {
            Environment.SetEnvironmentVariable("mqttPowerpilotHostname", "mosquitto");
            Environment.SetEnvironmentVariable("mqttPowerpilotPort", "8883");
            Environment.SetEnvironmentVariable("mqttPowerpilotUser", "superAdmin");
            Environment.SetEnvironmentVariable("mqttPowerpilotPassword", "powerpilot");
            Environment.SetEnvironmentVariable("powerpilotSecure", "true");
            Environment.SetEnvironmentVariable("powerpilotTopic", "application/powerpilot/uplink/#");

            Environment.SetEnvironmentVariable("mqttSparkplugHostname", "mosquitto");
            Environment.SetEnvironmentVariable("mqttSparkplugPort", "8883");
            Environment.SetEnvironmentVariable("mqttSparkplugUser", "superAdmin");
            Environment.SetEnvironmentVariable("mqttSparkplugPassword", "powerpilot");
            Environment.SetEnvironmentVariable("sparkplugSecure", "true");
            Environment.SetEnvironmentVariable("sparkplugTopic", "spBv1.0/DTX/{0}/PowerPilotCS/{1}");

            Environment.SetEnvironmentVariable("binaryServiceAddress", "http://binaryprotocol-service:5000");
            Environment.SetEnvironmentVariable("loggerServiceAddress", "http://logger-service:9031");

            Environment.SetEnvironmentVariable("dataServiceUrl", "https://data.devpower.powerpilot.nz");
            Environment.SetEnvironmentVariable("dataServiceToken", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoid2ViX3VzZXIiLCJ1c2VyIjoidGltYyJ9.eKUu_Iw3bk-5oxj7HAmOE4QZjd0rNsyXUWQpDB7QYUA");

            foreach (System.Collections.DictionaryEntry env in Environment.GetEnvironmentVariables())
            {
                string name  = (string)env.Key;
                string value = (string)env.Value;
                if (name.StartsWith("mqtt") || name.StartsWith("subscribe") || name.StartsWith("sparkplug"))
                {
                    Console.WriteLine("{0}={1}", name, value);
                }
            }

            var mqttPowerpilotHostname = Environment.GetEnvironmentVariable("mqttPowerpilotHostname");
            var mqttPowerpilotPort     = Int32.Parse(Environment.GetEnvironmentVariable("mqttPowerpilotPort"));
            var mqttPowerpilotUser     = Environment.GetEnvironmentVariable("mqttPowerpilotUser");
            var mqttPowerpilotPassword = Environment.GetEnvironmentVariable("mqttPowerpilotPassword");
            var powerpilotSecure       = Environment.GetEnvironmentVariable("powerpilotSecure");
            var powerpilotTopic        = Environment.GetEnvironmentVariable("powerpilotTopic");

            var mqttSparkplugHostname = Environment.GetEnvironmentVariable("mqttSparkplugHostname");
            var mqttSparkplugPort     = Int32.Parse(Environment.GetEnvironmentVariable("mqttSparkplugPort"));
            var mqttSparkplugUser     = Environment.GetEnvironmentVariable("mqttSparkplugUser");
            var mqttSparkplugPassword = Environment.GetEnvironmentVariable("mqttSparkplugPassword");
            var sparkplugSecure       = Environment.GetEnvironmentVariable("sparkplugSecure");
            var sparkplugTopic        = Environment.GetEnvironmentVariable("sparkplugTopic");

            var dataServiceUrl   = Environment.GetEnvironmentVariable("dataServiceUrl");
            var dataServiceToken = Environment.GetEnvironmentVariable("dataServiceToken");

            // logger
            var loggerAddress = Environment.GetEnvironmentVariable("loggerServiceAddress");
            var loggerClient  = new LoggerClient(loggerAddress, "MqttToSparkPlug");

            // mqtt client for receiving powerpilot format messages
            var mqttPowerpilotWrapper = await MQTTClientWrapperFactory.GetNewMQTTClientWrapper(mqttPowerpilotUser, mqttPowerpilotPassword, mqttPowerpilotHostname, mqttPowerpilotPort, true, loggerClient);

            await mqttPowerpilotWrapper.Subscribe(powerpilotTopic);

            // mqtt client for sending sparkplug format messages
            var mqttSparkplugWrapper = await MQTTClientWrapperFactory.GetNewMQTTClientWrapper(mqttSparkplugUser, mqttSparkplugPassword, mqttSparkplugHostname, mqttSparkplugPort, true, loggerClient);

            // subscribe to commands - spBv1.0/DTX/DCMD/PowerPilotCS/+
            await mqttSparkplugWrapper.Subscribe(string.Format(sparkplugTopic, SparkPlugMessageTypes.DCMD, "+"));

            // data service client
            HttpClient httpClient        = new HttpClient();
            var        dataServiceClient = new DataServiceClient(httpClient, dataServiceUrl, dataServiceToken);

            // sparkplug generator
            var sparkPlugGenerator = new SparkPlugGenerator(loggerClient, dataServiceClient, sparkplugTopic);

            // pipe messages
            mqttSparkplugWrapper.MQTTConnected    += sparkPlugGenerator.OnMQTTClientConnected;
            mqttPowerpilotWrapper.MessageReceived += sparkPlugGenerator.ProcessMessage;
            sparkPlugGenerator.MessageProcessed   += mqttSparkplugWrapper.Publish;

            // commands
            mqttSparkplugWrapper.MessageReceived += sparkPlugGenerator.ProcessMessage;

            CreateHostBuilder(args).Build().Run();
        }
Example #27
0
 public Form1()
 {
     InitializeComponent();
     client = new LoggerClient("TcpBasicEndPoint");
 }
        protected void ProcessThread()
        {
            if (m_LoggerClient == null)
                return;

            bool isAlive = true;
            int signalValue;

            while (isAlive)
            {
                signalValue = WaitHandle.WaitAny(m_Events);

                if (m_LoggerClient.State != System.ServiceModel.CommunicationState.Opened)
                {
                    isAlive = false;
                    lock (m_ObjLock)
                    {
                        m_LoggerClient = null;
                    }
                }
                else if (signalValue == THREAD_CONTINUE)
                {
                    ProcessQueue();
                }
                else if (signalValue == THREAD_EXIT)
                {
                    isAlive = false;
                }
            }
        }
        protected bool Open()
        {
            if (m_LoggerClient == null)
            {
                m_Events = new AutoResetEvent[2];
                m_Events[THREAD_CONTINUE] = m_EventContinue;
                m_Events[THREAD_EXIT] = m_EventExit;

                // Allow exception to be thrown
                try
                {
                    lock (m_ObjLock)
                    {
                        m_LoggerClient = new LoggerClient();

                        m_LoggerClient.Open();

                        m_Thread = new Thread(new ThreadStart(ProcessThread));
                        m_Thread.Name = "PubSubLoggerClient";
                        m_Thread.Priority = ThreadPriority.BelowNormal;
                        m_Thread.Start();
                    }
                    return true;
                }
                finally
                {
                    System.Diagnostics.Debug.Assert(m_LoggerClient.State == System.ServiceModel.CommunicationState.Opened, "Could not connect to PubSubHost");
                }
            }
            return false;
        }
        protected bool Close()
        {
            if (m_LoggerClient != null)
            {
                lock (m_ObjLock)
                {
                    m_EventExit.Set();
                    ProcessQueue();

                    if (m_Thread != null)
                    {
                        m_Thread.Abort();
                        m_Thread = null;
                    }
                    if (m_LoggerClient.State == System.ServiceModel.CommunicationState.Opened)
                    {
                        m_LoggerClient.Close();
                    }
                    m_LoggerClient = null;
                }
            }

            return false;
        }
Example #31
0
 public Logger(LoggerClient loggerCLient)
 {
     this.logger = loggerCLient;
 }