Ejemplo n.º 1
0
        /// <summary>
        ///     The module's callback function that is called upon message receipt.
        /// </summary>
        /// <param name="received_message">The message being sent to the module.</param>
        /// <returns></returns>
        public void Receive(Message received_message)
        {
            DeviceEvent deviceEvent = received_message.ToDeviceEvent();

            if (deviceEvent == null)
            {
                Console.WriteLine($"{_moduleName}: Message recieved with wrong expected format. Message will be discarted");
                return;
            }

            LogingHelps.LogMessage(deviceEvent, _moduleName, LogingHelps.RecievedAction);

            //This should be async
            DeviceEvent deviceEventAfterLogicApplied = ApplyLogic(deviceEvent);

            if (deviceEventAfterLogicApplied == null)
            {
                Console.WriteLine($"{_moduleName}: Message for {deviceEvent.deviceId} has been filtered out");
                return;
            }

            Publish(deviceEventAfterLogicApplied);

            LogingHelps.LogMessage(deviceEventAfterLogicApplied, _moduleName, LogingHelps.PublishedAction);
        }
Ejemplo n.º 2
0
        private void DoWork()
        {
            var randomizer = new Random(DateTime.Now.Millisecond);

            while (_keepRunningWorkerThread)
            {
                var deviceEvent = new DeviceEvent()
                {
                    deviceId  = Guid.NewGuid().ToString(),
                    eventName = "randomName " + randomizer.Next(),
                    dateTime  = DateTime.UtcNow,
                    content   = "some random content " + randomizer.Next()
                };

                Publish(deviceEvent);

                LogingHelps.LogMessage(deviceEvent, _moduleName, LogingHelps.PublishedAction);

                Thread.Sleep(_configuration.threadInternalMiliseconds);
            }
        }