public static void IngestMessagge(BubblingObject bubblingObject) { try { LogEngine.WriteLog(ConfigurationBag.EngineName, $"IngestMessagge bubblingObject.SenderChannelId {bubblingObject.SenderChannelId} " + $"bubblingObject.SenderPointId {bubblingObject.SenderPointId} " + $"bubblingObject.DestinationChannelId {bubblingObject.DestinationChannelId} " + $" bubblingObject.DestinationPointId {bubblingObject.DestinationPointId} " + $"bubblingObject.MessageType {bubblingObject.MessageType}" + $"bubblingObject.Persisting {bubblingObject.Persisting} " + $"bubblingObject.MessageId {bubblingObject.MessageId} " + $"bubblingObject.Name {bubblingObject.Name}", Constant.LogLevelError, Constant.TaskCategoriesConsole, null, Constant.LogLevelVerbose); //If local event then execute if (bubblingObject.LocalEvent) { //new Task(() => //{ // EventsEngine.ExecuteEventsInTrigger( // bubblingObject, // bubblingObject.Events[0], // false, // bubblingObject.SenderPointId); //}).Start(); EventsEngine.ExecuteEventsInTrigger( bubblingObject, bubblingObject.Events[0], false, bubblingObject.SenderPointId); return; } //Check if message is for this point var receiverChannelId = bubblingObject.DestinationChannelId; var receiverPointId = bubblingObject.DestinationPointId; var requestAvailable = (receiverChannelId == ConfigurationBag.Configuration.ChannelId && receiverPointId == ConfigurationBag.Configuration.PointId) || (receiverChannelId == ConfigurationBag.ChannelAll && receiverPointId == ConfigurationBag.Configuration.PointId) || (receiverChannelId == ConfigurationBag.Configuration.ChannelId && receiverPointId == ConfigurationBag.PointAll) || (receiverChannelId == ConfigurationBag.ChannelAll && receiverPointId == ConfigurationBag.PointAll); if (!requestAvailable) { // ****************************NOT FOR ME************************* return; } if (bubblingObject.SenderPointId == ConfigurationBag.Configuration.PointId) { // **************************** HA AREA ************************* if (bubblingObject.MessageType == "HA" && bubblingObject.HAGroup == ConfigurationBag.Configuration.HAGroup && EventsEngine.HAEnabled) { //If HA group member and HA EventsEngine.HAPoints[EventsEngine.HAPointTickId] = DateTime.Now; long haTickFrom = long.Parse(UTF8Encoding.UTF8.GetString(bubblingObject.Data)); //if same tick then return because same point if (haTickFrom == EventsEngine.HAPointTickId) { return; } DateTime dt; lock (EventsEngine.HAPoints) { //If not exist then add if (!EventsEngine.HAPoints.TryGetValue(haTickFrom, out dt)) { EventsEngine.HAPoints.Add(haTickFrom, DateTime.Now); } else { EventsEngine.HAPoints[haTickFrom] = DateTime.Now; } } byte[] content = UTF8Encoding.UTF8.GetBytes(EventsEngine.HAPointTickId.ToString()); BubblingObject bubblingObjectToSync = new BubblingObject(content); bubblingObject.MessageType = "HA"; OffRampEngineSending.SendMessageOffRamp(bubblingObjectToSync, "HA", bubblingObject.SenderChannelId, bubblingObject.SenderPointId, string.Empty); } else { return; } } // ****************************GET FROM STORAGE IF REQUIRED************************* if (bubblingObject.Persisting) { bubblingObject = (BubblingObject) SerializationEngine.ByteArrayToObject( DevicePersistentProvider.PersistEventFromStorage(bubblingObject.MessageId)); } #region EVENT // ****************************IF EVENT TYPE************************* if (bubblingObject.MessageType == "Event") { //If HA group member and HA if (EventsEngine.HAEnabled) { //Check if is the first in list, if not then discard EventsEngine.HAPoints.OrderBy(key => key.Key); if (EventsEngine.HAPoints.Count > 1 && EventsEngine.HAPoints.First().Key != EventsEngine.HAPointTickId) { return; } } //Check if is Syncronouse response if (bubblingObject.SyncronousFromEvent && bubblingObject.SenderPointId == ConfigurationBag.Configuration.PointId) { //Yes it's a syncronous response from my request from this pointid //Execute the delegate and exit var propDataContext = bubblingObject.DataContext; bubblingObject.SyncronousFromEvent = false; EventsEngine.SyncAsyncEventsExecuteDelegate(bubblingObject.SyncronousToken, propDataContext); bubblingObject.SenderPointId = ""; bubblingObject.SyncronousToken = ""; return; } // ****************************EVENT EXIST EXECUTE************************* EventsEngine.ExecuteEventsInTrigger( bubblingObject, bubblingObject.Events[0], false, bubblingObject.SenderPointId); return; } #endregion #region CONSOLE // **************************** SYNC AREA ************************* //******************* OPERATION CONF BAG- ALL THE CONF FILES AND DLLS **************************************************************** //Receive a package folder to syncronize him self if (bubblingObject.MessageType == "SyncPull") { byte[] content = Helpers.CreateFromDirectory( ConfigurationBag.Configuration.DirectoryOperativeRootExeName); BubblingObject bubblingObjectToSync = new BubblingObject(content); bubblingObject.MessageType = "SyncPush"; OffRampEngineSending.SendMessageOffRamp(bubblingObjectToSync, "SyncPush", bubblingObject.SenderChannelId, bubblingObject.SenderPointId, string.Empty); } //Receive the request to send the bubbling if (bubblingObject.MessageType == "SyncPush") { LogEngine.DirectEventViewerLog( $"Received a syncronization package from channel ID {bubblingObject.SenderChannelId} and point ID {bubblingObject.SenderChannelId}\rAutoSyncronizationEnabled parameter = {ConfigurationBag.Configuration.AutoSyncronizationEnabled}", 2); if (ConfigurationBag.Configuration.AutoSyncronizationEnabled) { byte[] bubblingContent = SerializationEngine.ObjectToByteArray(bubblingObject.Data); string currentSyncFolder = ConfigurationBag.SyncDirectorySyncIn(); Helpers.CreateFromBytearray(bubblingObject.Data, currentSyncFolder); } } #endregion } catch (Exception ex) { LogEngine.WriteLog(ConfigurationBag.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.LogLevelError, Constant.TaskCategoriesError, ex, Constant.LogLevelError); } }