/// <summary>
        ///     The clone object.
        /// </summary>
        /// <param name="clonedObject">
        ///     The cloned object.
        /// </param>
        /// <returns>
        ///     The <see cref="object" />.
        /// </returns>
        public static object CloneObject(object clonedObject)
        {
            var objserialized = SerializationEngine.ObjectToByteArray(clonedObject);
            var newobject     = SerializationEngine.ByteArrayToObject(objserialized);

            return(newobject);
        }
        public static void IngestMessagge(object message)
        {
            string senderId;
            string senderDescription;

            byte[] eventDataByte   = null;
            var    skeletonMessage = (ISkeletonMessage)message;

            // ****************************IF MESSAGE TYPE = GRABCASTER*************************
            try
            {
                // Check message subscription, it must come from engine
                if (skeletonMessage.Properties[Configuration.GrabCasterMessageTypeName].ToString()
                    != Configuration.GrabCasterMessageTypeValue)
                {
                    LogEngine.ConsoleWriteLine(
                        "Not GrabCaster message type received -DISCARED-",
                        ConsoleColor.DarkYellow);
                    return;
                }
                else
                {
                    // Who sent the message
                    senderId          = skeletonMessage.Properties[Configuration.MessageDataProperty.SenderId.ToString()].ToString();
                    senderDescription =
                        skeletonMessage.Properties[Configuration.MessageDataProperty.SenderDescriprion.ToString()].ToString();

                    //If using Guid pattern as string some system put an escape character like \ before the end brachet }

                    // Who receive the message
                    LogEngine.ConsoleWriteLine(
                        $"Event received from Sender {senderId} Sender description {senderDescription}",
                        ConsoleColor.DarkCyan);

                    // ****************************IF SAME SENDER*************************
                    if (senderId == Configuration.PointId())
                    {
                        LogEngine.ConsoleWriteLine("Same sender ID event discared.", ConsoleColor.Green);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                // If error then not message typeof (no property present.)
                LogEngine.WriteLog(
                    Configuration.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name} - Not GrabCaster message type received (Missing GrabCaster_MessageType_Name properties.) -DISCARED-",
                    Constant.ErrorEventIdHighCritical,
                    Constant.TaskCategoriesError,
                    ex,
                    EventLogEntryType.Error);
                return;
            }

            try
            {
                // ****************************GET FROM STORAGE IF REQUIRED*************************
                if ((bool)skeletonMessage.Properties[Configuration.MessageDataProperty.Persisting.ToString()])
                {
                    ParametersPersistEventFromBlob[0] = skeletonMessage.Properties[Configuration.MessageDataProperty.MessageId.ToString()];
                    var ret = methodPersistEventFromBlob.Invoke(classInstanceDpp, ParametersPersistEventFromBlob);
                    eventDataByte = (byte[])ret;
                }
                else
                {
                    eventDataByte = skeletonMessage.Body;
                }

                //*******************************************************************
                //              3 IF TYPES EVENT - CONSOLE - REST
                // first area events, second console, third rest
                //*******************************************************************

                // ****************************IF EVENT TYPE*************************
                if (skeletonMessage.Properties[Configuration.MessageDataProperty.MessageType.ToString()].ToString()
                    == Configuration.MessageDataProperty.Event.ToString())
                {
                    // ****************************IF EMBEDED TYPE EXECUTE TRIGGER*************************
                    if (skeletonMessage.Properties[Configuration.MessageDataProperty.Embedded.ToString()].ToString()
                        == "true")
                    {
                        var recChannelId =
                            skeletonMessage.Properties[Configuration.MessageDataProperty.ReceiverChannelId.ToString()].ToString();
                        var recPointId =
                            skeletonMessage.Properties[Configuration.MessageDataProperty.ReceiverPointId.ToString()].ToString();

                        //If using Guid pattern as string some system put an escape character like \ before the end brachet }

                        var reqAvailable = (recChannelId.Contains(Configuration.ChannelId()) &&
                                            recPointId.Contains(Configuration.PointId())) ||
                                           (recChannelId.Contains(Configuration.ChannelAll) &&
                                            recPointId.Contains(Configuration.PointId())) ||
                                           (recChannelId.Contains(Configuration.ChannelId()) &&
                                            recPointId.Contains(Configuration.ChannelAll)) ||
                                           (recChannelId.Contains(Configuration.ChannelAll) &&
                                            recPointId.Contains(Configuration.ChannelAll));

                        if (!reqAvailable)
                        {
                            return;
                        }
                        string idConfiguration =
                            skeletonMessage.Properties[Configuration.MessageDataProperty.IdConfiguration.ToString()].ToString();
                        string idComponent =
                            skeletonMessage.Properties[Configuration.MessageDataProperty.IdComponent.ToString()].ToString();

                        try
                        {
                            var triggerSingleInstance =
                                (from trigger in EventsEngine.BubblingTriggerConfigurationsSingleInstance
                                 where trigger.IdComponent == idComponent && trigger.IdConfiguration == idConfiguration
                                 select trigger).First();
                            var bubblingTriggerConfiguration = triggerSingleInstance;
                            LogEngine.ConsoleWriteLine($"Execute trigger idConfiguration {idConfiguration} and idComponent {idComponent}", ConsoleColor.Green);
                            EventsEngine.ExecuteTriggerConfiguration(bubblingTriggerConfiguration, skeletonMessage.Body);
                        }
                        catch (Exception ex)
                        {
                            LogEngine.WriteLog(Configuration.EngineName,
                                               $"Error in {MethodBase.GetCurrentMethod().Name} - ExecuteTriggerConfiguration Error - Missing the idConfiguration {idConfiguration} and idComponent {idComponent}",
                                               Constant.ErrorEventIdHighCritical,
                                               Constant.TaskCategoriesError,
                                               ex,
                                               EventLogEntryType.Error);
                        }


                        // ****************************IF EMBEDED RETURN HERE*************************
                        return;
                    }

                    // ****************************CAST TO BUBBLING EVENT*************************
                    var eventBubbling = (BubblingEvent)SerializationEngine.ByteArrayToObject(eventDataByte);

                    // ****************************PERSIST MESSAGE IN FOLDER*************************
                    PersistentProvider.PersistMessage(eventBubbling, PersistentProvider.CommunicationDiretion.OffRamp);

                    if (Configuration.LoggingVerbose())
                    {
                        var serializedEvents = JsonConvert.SerializeObject(
                            eventBubbling.Events,
                            Formatting.Indented,
                            new JsonSerializerSettings {
                            ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                        });
                        LogEngine.ConsoleWriteLine(
                            $"Event received from point id: {skeletonMessage.Properties[Configuration.MessageDataProperty.SenderId.ToString()]} -point name : {skeletonMessage.Properties[Configuration.MessageDataProperty.SenderDescriprion.ToString()]} - {serializedEvents}",
                            ConsoleColor.Green);
                    }

                    // ****************************IF EXIST EVENT TO EXECUTE*************************
                    var eventsAvailable = from eventbubble in eventBubbling.Events
                                          from channel in eventbubble.Channels
                                          from point in channel.Points
                                          where
                                          (channel.ChannelId == Configuration.ChannelId() &&
                                           point.PointId == Configuration.PointId()) ||
                                          (channel.ChannelId == Configuration.ChannelAll &&
                                           point.PointId == Configuration.PointId()) ||
                                          (channel.ChannelId == Configuration.ChannelId() &&
                                           point.PointId == Configuration.PointAll) ||
                                          (channel.ChannelId == Configuration.ChannelAll &&
                                           point.PointId == Configuration.PointAll)
                                          select eventbubble;


                    if (!eventsAvailable.Any())
                    {
                        // ****************************NO EVENT RETURN*************************
                        return;
                    }

                    // ****************************EVENT EXIST EXECUTE*************************
                    EventsEngine.ExecuteBubblingActionEvent(
                        eventBubbling,
                        false,
                        skeletonMessage.Properties[Configuration.MessageDataProperty.SenderId.ToString()].ToString());
                    return;
                }



                var receiverChannelId =
                    skeletonMessage.Properties[Configuration.MessageDataProperty.ReceiverChannelId.ToString()].ToString();
                var receiverPointId =
                    skeletonMessage.Properties[Configuration.MessageDataProperty.ReceiverPointId.ToString()].ToString();

                var requestAvailable = (receiverChannelId == Configuration.ChannelId() &&
                                        receiverPointId == Configuration.PointId()) ||
                                       (receiverChannelId == Configuration.ChannelAll &&
                                        receiverPointId == Configuration.PointId()) ||
                                       (receiverChannelId == Configuration.ChannelId() &&
                                        receiverPointId == Configuration.PointAll) ||
                                       (receiverChannelId == Configuration.ChannelAll &&
                                        receiverPointId == Configuration.PointAll);

                if (!requestAvailable)
                {
                    // ****************************NOT FOR ME*************************
                    return;
                }


                // **************************** IF CONSOLE TYPE *************************
                //Save in a string to simplify the reading and code
                string OperationTypRequested =
                    skeletonMessage.Properties[Configuration.MessageDataProperty.MessageType.ToString()].ToString();

                //******************* OPERATION CONF BAG- ALL THE CONF FILES AND DLLS ****************************************************************
                if (OperationTypRequested
                    == Configuration.MessageDataProperty.ConsoleSendBubblingBag.ToString() ||
                    OperationTypRequested
                    == Configuration.MessageDataProperty.ConsoleSendBubblingBagFromPoint.ToString())
                {
                    //If send or received operaion
                    bool sendOperation = true && OperationTypRequested == Configuration.MessageDataProperty.ConsoleSendBubblingBag.ToString();
                    if (!Configuration.DisableDeviceProviderInterface())
                    {
                        if (sendOperation)
                        {
                            OffRampEngineSending.SendMessageOnRamp(
                                EventsEngine.bubblingBag,
                                Configuration.MessageDataProperty.ConsoleSendBubblingBagFromPoint,
                                skeletonMessage.Properties[Configuration.MessageDataProperty.ChannelId.ToString()].ToString(),
                                skeletonMessage.Properties[Configuration.MessageDataProperty.SenderId.ToString()].ToString(),
                                null,
                                null);
                        }
                        else
                        {
                            setConsoleActionEventEmbedded(
                                Configuration.MessageDataProperty.ReceiverPointId.ToString(),
                                skeletonMessage);
                        }
                    }
                    else
                    {
                        LogEngine.WriteLog(
                            Configuration.EngineName,
                            "Warning the Device Provider Interface is disable, the GrabCaster point will be able to work in local mode only.",
                            Constant.ErrorEventIdHighCritical,
                            Constant.TaskCategoriesError,
                            null,
                            EventLogEntryType.Warning);
                    }
                }
                //******************* OPERATION CONF BAG- ALL THE CONF FILES AND DLLS ****************************************************************



                // **************************** REST SERVICE CALLS AREA *************************

                //RICEVE I BUBBLINGS
                // ****************************WRITE THE TRIGGERS AND EVENTS CONFIGURATION FILES IN FOLDERS*************************
                if (skeletonMessage.Properties[Configuration.MessageDataProperty.MessageType.ToString()].ToString()
                    == Configuration.MessageDataProperty.SyncSendBubblingConfiguration.ToString())
                {
                    // eventDataByte = NULL
                    LogEngine.ConsoleWriteLine(
                        $"SyncSendBubblingConfiguration from - {senderId} - {senderDescription}",
                        ConsoleColor.Cyan);
                    var syncConfigurationFilelIst =
                        (List <SyncConfigurationFile>)SerializationEngine.ByteArrayToObject(eventDataByte);
                    SyncProvider.SyncBubblingConfigurationFileList(
                        syncConfigurationFilelIst,
                        skeletonMessage.Properties[Configuration.MessageDataProperty.MessageType.ToString()].ToString(),
                        skeletonMessage.Properties[Configuration.MessageDataProperty.SenderId.ToString()].ToString(),
                        skeletonMessage.Properties[Configuration.MessageDataProperty.SenderName.ToString()].ToString(),
                        skeletonMessage.Properties[Configuration.MessageDataProperty.SenderDescriprion.ToString()].ToString(),
                        skeletonMessage.Properties[Configuration.MessageDataProperty.ChannelId.ToString()].ToString(),
                        skeletonMessage.Properties[Configuration.MessageDataProperty.ChannelName.ToString()].ToString(),
                        skeletonMessage.Properties[Configuration.MessageDataProperty.ChannelDescription.ToString()].ToString());
                    return;
                }

                //RICEVE LA CONF DAL PUNTO
                // ****************************WRITE THE POINT CONFIGURATION FILE IN FOLDERs*************************
                if (skeletonMessage.Properties[Configuration.MessageDataProperty.MessageType.ToString()].ToString()
                    == Configuration.MessageDataProperty.SyncSendConfiguration.ToString())
                {
                    // EventDataByte = NULL
                    LogEngine.ConsoleWriteLine(
                        $"SyncSendConfiguration from - {senderId} - {senderDescription}",
                        ConsoleColor.Cyan);
                    SyncProvider.SyncWriteConfiguration(
                        skeletonMessage.Properties[Configuration.MessageDataProperty.ChannelId.ToString()].ToString(),
                        skeletonMessage.Properties[Configuration.MessageDataProperty.SenderId.ToString()].ToString(),
                        eventDataByte);
                    return;
                }

                //RICEVE E SCRIVE UN FILE DI CONFIGURAZIONE TRIGGER O EVENT NELLA BUBBLIG
                // ****************************WRITE THE SPECIFIC BUBBLING FILE IN FOLDERS*************************
                if (skeletonMessage.Properties[Configuration.MessageDataProperty.MessageType.ToString()].ToString()
                    == Configuration.MessageDataProperty.SyncSendFileBubblingConfiguration.ToString())
                {
                    // EventDataByte = NULL
                    LogEngine.ConsoleWriteLine(
                        $"SyncSendFileBubblingConfiguration from - {senderId} - {senderDescription}",
                        ConsoleColor.Cyan);
                    var syncConfigurationFilelIst =
                        (List <SyncConfigurationFile>)SerializationEngine.ByteArrayToObject(eventDataByte);
                    SyncProvider.SyncLocalBubblingConfigurationFile(syncConfigurationFilelIst);
                    return;
                }


                //SCRIVE UN COMP DLL IN EVENTO O TRIGGER FOLDER
                // ****************************UPDATE A DLL COMPONENT IN FILE IN FOLDERS*************************
                if (skeletonMessage.Properties[Configuration.MessageDataProperty.MessageType.ToString()].ToString()
                    == Configuration.MessageDataProperty.SyncSendComponent.ToString())
                {
                    // EventDataByte = NULL
                    LogEngine.ConsoleWriteLine(
                        $"SyncSendComponent from - {senderId} - {senderDescription}",
                        ConsoleColor.Cyan);
                    var eventBubbling = (BubblingEvent)SerializationEngine.ByteArrayToObject(eventDataByte);
                    SyncProvider.SyncUpdateComponent(
                        skeletonMessage.Properties[Configuration.MessageDataProperty.ChannelId.ToString()].ToString(),
                        skeletonMessage.Properties[Configuration.MessageDataProperty.SenderId.ToString()].ToString(),
                        eventBubbling);
                    return;
                }

                // Request to send the local configuration
                // Send the configuration
                if (skeletonMessage.Properties[Configuration.MessageDataProperty.MessageType.ToString()].ToString()
                    == Configuration.MessageDataProperty.SyncSendRequestBubblingConfiguration.ToString())
                {
                    // EventDataByte = NULL
                    LogEngine.ConsoleWriteLine(
                        $"SyncSendBubblingConfiguration from - {senderId} - {senderDescription}",
                        ConsoleColor.Cyan);
                    SyncProvider.SyncSendBubblingConfiguration(
                        skeletonMessage.Properties[Configuration.MessageDataProperty.ChannelId.ToString()].ToString(),
                        skeletonMessage.Properties[Configuration.MessageDataProperty.SenderId.ToString()].ToString());
                    return;
                }

                // Request to send the  configuration
                // Send the configuration
                if (skeletonMessage.Properties[Configuration.MessageDataProperty.MessageType.ToString()].ToString()
                    == Configuration.MessageDataProperty.SyncSendRequestConfiguration.ToString())
                {
                    // EventDataByte = NULL
                    LogEngine.ConsoleWriteLine(
                        $"SyncSendRequestConfiguration from - {senderId} - {senderDescription}",
                        ConsoleColor.Cyan);

                    SyncProvider.SyncSendConfiguration(skeletonMessage.Properties[Configuration.MessageDataProperty.ChannelId.ToString()].ToString(),
                                                       skeletonMessage.Properties[Configuration.MessageDataProperty.SenderId.ToString()].ToString());


                    return;
                }


                // Request to send back a component
                if (skeletonMessage.Properties[Configuration.MessageDataProperty.MessageType.ToString()].ToString()
                    == Configuration.MessageDataProperty.SyncSendRequestComponent.ToString())
                {
                    // EventDataByte = NULL
                    LogEngine.ConsoleWriteLine(
                        $"SyncSendRequestComponent from - {senderId} - {senderDescription}",
                        ConsoleColor.Cyan);
                    SyncProvider.SyncSendComponent(
                        skeletonMessage.Properties[Configuration.MessageDataProperty.ChannelId.ToString()].ToString(),
                        skeletonMessage.Properties[Configuration.MessageDataProperty.SenderId.ToString()].ToString(),
                        skeletonMessage.Properties[Configuration.MessageDataProperty.IdComponent.ToString()].ToString());
                    return;
                }
            }
            catch (Exception ex)
            {
                LogEngine.WriteLog(Configuration.EngineName,
                                   $"Error in {MethodBase.GetCurrentMethod().Name}",
                                   Constant.ErrorEventIdHighCritical,
                                   Constant.TaskCategoriesError,
                                   ex,
                                   EventLogEntryType.Error);
            }
        }
        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);
            }
        }
Пример #4
0
        public static void IngestMessagge(object message)
        {
            string senderId;
            string senderDescription;

            byte[] eventDataByte   = null;
            var    skeletonMessage = (ISkeletonMessage)message;

            // ****************************IF MESSAGE TYPE = GRABCASTER*************************
            try
            {
                // Check message subscription, it must come from engine
                if (skeletonMessage.Properties[Configuration.GrabCasterMessageTypeName].ToString()
                    != Configuration.GrabCasterMessageTypeValue)
                {
                    LogEngine.ConsoleWriteLine(
                        "Not GrabCaster message type received -DISCARED-",
                        ConsoleColor.DarkYellow);
                    return;
                }
                else
                {
                    // Who sent the message
                    senderId          = skeletonMessage.Properties[Configuration.MessageDataProperty.SenderId.ToString()].ToString();
                    senderDescription =
                        skeletonMessage.Properties[Configuration.MessageDataProperty.SenderDescriprion.ToString()].ToString();

                    //If using Guid pattern as string some system put an escape character like \ before the end brachet }

                    // Who receive the message
                    LogEngine.ConsoleWriteLine(
                        $"Event received from Sender {senderId} Sender description {senderDescription}",
                        ConsoleColor.DarkCyan);

                    // ****************************IF SAME SENDER*************************
                    //TODO DELETE the  + "debug"
                    if (senderId == Configuration.PointId() + "debug")
                    {
                        LogEngine.ConsoleWriteLine("Same sender ID event discared.", ConsoleColor.Green);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                // If error then not message typeof (no property present.)
                LogEngine.WriteLog(
                    Configuration.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name} - Not GrabCaster message type received (Missing GrabCaster_MessageType_Name properties.) -DISCARED-",
                    Constant.DefconOne,
                    Constant.TaskCategoriesError,
                    ex,
                    EventLogEntryType.Error);
                return;
            }

            try
            {
                // ****************************GET FROM STORAGE IF REQUIRED*************************
                if ((bool)skeletonMessage.Properties[Configuration.MessageDataProperty.Persisting.ToString()])
                {
                    ParametersPersistEventFromBlob[0] = skeletonMessage.Properties[Configuration.MessageDataProperty.MessageId.ToString()];
                    var ret = methodPersistEventFromBlob.Invoke(classInstanceDpp, ParametersPersistEventFromBlob);
                    eventDataByte = (byte[])ret;
                }
                else
                {
                    eventDataByte = skeletonMessage.Body;
                }

                //*******************************************************************
                //              3 IF TYPES EVENT - CONSOLE - REST
                // first area events, second console, third rest
                //*******************************************************************

                // ****************************IF EVENT TYPE*************************
                if (skeletonMessage.Properties[Configuration.MessageDataProperty.MessageType.ToString()].ToString()
                    == Configuration.MessageDataProperty.Event.ToString())
                {
                    // ****************************IF EMBEDED TYPE EXECUTE TRIGGER*************************
                    if (skeletonMessage.Properties[Configuration.MessageDataProperty.Embedded.ToString()].ToString()
                        == "true")
                    {
                        var recChannelId =
                            skeletonMessage.Properties[Configuration.MessageDataProperty.ReceiverChannelId.ToString()].ToString();
                        var recPointId =
                            skeletonMessage.Properties[Configuration.MessageDataProperty.ReceiverPointId.ToString()].ToString();

                        //If using Guid pattern as string some system put an escape character like \ before the end brachet }

                        var reqAvailable = (recChannelId.Contains(Configuration.ChannelId()) &&
                                            recPointId.Contains(Configuration.PointId())) ||
                                           (recChannelId.Contains(Configuration.ChannelAll) &&
                                            recPointId.Contains(Configuration.PointId())) ||
                                           (recChannelId.Contains(Configuration.ChannelId()) &&
                                            recPointId.Contains(Configuration.ChannelAll)) ||
                                           (recChannelId.Contains(Configuration.ChannelAll) &&
                                            recPointId.Contains(Configuration.ChannelAll));

                        if (!reqAvailable)
                        {
                            return;
                        }
                        string idConfiguration =
                            skeletonMessage.Properties[Configuration.MessageDataProperty.IdConfiguration.ToString()].ToString();
                        string idComponent =
                            skeletonMessage.Properties[Configuration.MessageDataProperty.IdComponent.ToString()].ToString();

                        try
                        {
                            var triggerSingleInstance =
                                (from trigger in EventsEngine.BubblingTriggerConfigurationsSingleInstance
                                 where trigger.IdComponent == idComponent && trigger.IdConfiguration == idConfiguration
                                 select trigger).First();
                            var bubblingTriggerConfiguration = triggerSingleInstance;
                            LogEngine.ConsoleWriteLine($"Execute trigger idConfiguration {idConfiguration} and idComponent {idComponent}", ConsoleColor.Green);
                            EventsEngine.ExecuteTriggerConfiguration(bubblingTriggerConfiguration, skeletonMessage.Body);
                        }
                        catch (Exception ex)
                        {
                            LogEngine.WriteLog(Configuration.EngineName,
                                               $"Error in {MethodBase.GetCurrentMethod().Name} - ExecuteTriggerConfiguration Error - Missing the idConfiguration {idConfiguration} and idComponent {idComponent}",
                                               Constant.DefconOne,
                                               Constant.TaskCategoriesError,
                                               ex,
                                               EventLogEntryType.Error);
                        }


                        // ****************************IF EMBEDED RETURN HERE*************************
                        return;
                    }

                    // ****************************CAST TO BUBBLING EVENT*************************
                    var eventBubbling = (BubblingEvent)SerializationEngine.ByteArrayToObject(eventDataByte);

                    // ****************************PERSIST MESSAGE IN FOLDER*************************
                    PersistentProvider.PersistMessage(eventBubbling, PersistentProvider.CommunicationDiretion.OffRamp);

                    if (Configuration.LoggingVerbose())
                    {
                        var serializedEvents = JsonConvert.SerializeObject(
                            eventBubbling.Events,
                            Formatting.Indented,
                            new JsonSerializerSettings {
                            ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                        });
                        LogEngine.ConsoleWriteLine(
                            $"Event received from point id: {skeletonMessage.Properties[Configuration.MessageDataProperty.SenderId.ToString()]} -point name : {skeletonMessage.Properties[Configuration.MessageDataProperty.SenderDescriprion.ToString()]} - {serializedEvents}",
                            ConsoleColor.Green);
                    }

                    // ****************************IF EXIST EVENT TO EXECUTE*************************
                    var eventsAvailable = from eventbubble in eventBubbling.Events
                                          from channel in eventbubble.Channels
                                          from point in channel.Points
                                          where
                                          (channel.ChannelId == Configuration.ChannelId() &&
                                           point.PointId == Configuration.PointId()) ||
                                          (channel.ChannelId == Configuration.ChannelAll &&
                                           point.PointId == Configuration.PointId()) ||
                                          (channel.ChannelId == Configuration.ChannelId() &&
                                           point.PointId == Configuration.PointAll) ||
                                          (channel.ChannelId == Configuration.ChannelAll &&
                                           point.PointId == Configuration.PointAll)
                                          select eventbubble;


                    if (!eventsAvailable.Any())
                    {
                        // ****************************NO EVENT RETURN*************************
                        return;
                    }

                    // ****************************EVENT EXIST EXECUTE*************************
                    EventsEngine.ExecuteBubblingActionEvent(
                        eventBubbling,
                        false,
                        skeletonMessage.Properties[Configuration.MessageDataProperty.SenderId.ToString()].ToString());
                    return;
                }



                var receiverChannelId =
                    skeletonMessage.Properties[Configuration.MessageDataProperty.ReceiverChannelId.ToString()].ToString();
                var receiverPointId =
                    skeletonMessage.Properties[Configuration.MessageDataProperty.ReceiverPointId.ToString()].ToString();

                var requestAvailable = (receiverChannelId == Configuration.ChannelId() &&
                                        receiverPointId == Configuration.PointId()) ||
                                       (receiverChannelId == Configuration.ChannelAll &&
                                        receiverPointId == Configuration.PointId()) ||
                                       (receiverChannelId == Configuration.ChannelId() &&
                                        receiverPointId == Configuration.PointAll) ||
                                       (receiverChannelId == Configuration.ChannelAll &&
                                        receiverPointId == Configuration.PointAll);

                if (!requestAvailable)
                {
                    // ****************************NOT FOR ME*************************
                    return;
                }


                // **************************** SYNC AREA *************************
                //Save in a string to simplify the reading and code
                string OperationTypRequested =
                    skeletonMessage.Properties[Configuration.MessageDataProperty.MessageType.ToString()].ToString();

                //******************* OPERATION CONF BAG- ALL THE CONF FILES AND DLLS ****************************************************************
                //Receive the request to send the bubbling
                if (OperationTypRequested == Configuration.MessageDataProperty.ConsoleRequestSendBubblingBag.ToString())
                {
                    if (!Configuration.DisableExternalEventsStreamEngine())
                    {
                        //If I am console do nothing
                        if (Configuration.IamConsole())
                        {
                            OffRampEngineSending.SendMessageOnRamp(
                                EventsEngine.bubblingBag,
                                Configuration.MessageDataProperty.ConsoleBubblingBagToSyncronize,
                                skeletonMessage.Properties[Configuration.MessageDataProperty.ChannelId.ToString()].ToString(),
                                skeletonMessage.Properties[Configuration.MessageDataProperty.SenderId.ToString()].ToString(),
                                null,
                                null);
                        }
                    }
                    else
                    {
                        LogEngine.WriteLog(
                            Configuration.EngineName,
                            "Warning the Device Provider Interface is disable, the GrabCaster point will be able to work in local mode only.",
                            Constant.DefconThree,
                            Constant.TaskCategoriesError,
                            null,
                            EventLogEntryType.Warning);
                    }
                }
                //Receive the request to send the bubbling
                if (OperationTypRequested == Configuration.MessageDataProperty.ConsoleBubblingBagToSyncronize.ToString())
                {
                    if (!Configuration.DisableExternalEventsStreamEngine())
                    {
                        //se non sono console
                        //metto
                        if (!Configuration.IamConsole())
                        {
                            byte[] bubblingContent   = SerializationEngine.ObjectToByteArray(skeletonMessage.Body);
                            string currentSyncFolder = Configuration.SyncDirectorySyncIn();
                            GrabCaster.Framework.CompressionLibrary.Helpers.CreateFromBytearray(skeletonMessage.Body, currentSyncFolder);
                        }
                        else
                        {
                            setConsoleActionEventEmbedded(skeletonMessage.Properties[Configuration.MessageDataProperty.SenderId.ToString()].ToString(),
                                                          skeletonMessage);
                        }
                    }
                    else
                    {
                        LogEngine.WriteLog(
                            Configuration.EngineName,
                            "Warning the Device Provider Interface is disable, the GrabCaster point will be able to work in local mode only.",
                            Constant.DefconThree,
                            Constant.TaskCategoriesError,
                            null,
                            EventLogEntryType.Warning);
                    }
                }
            }
            catch (Exception ex)
            {
                LogEngine.WriteLog(Configuration.EngineName,
                                   $"Error in {MethodBase.GetCurrentMethod().Name}",
                                   Constant.DefconOne,
                                   Constant.TaskCategoriesError,
                                   ex,
                                   EventLogEntryType.Error);
            }
        }
Пример #5
0
 /// <summary>
 ///     The serialize message.
 /// </summary>
 /// <returns>
 ///     The <see cref="byte[]" />.
 /// </returns>
 public static BubblingObject DeserializeMessage(byte[] byteArray)
 {
     return((BubblingObject)SerializationEngine.ByteArrayToObject(byteArray));
 }