コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: OffRampEngine.cs プロジェクト: debiaggi/GrabCaster
        /// <summary>
        /// TODO The send message on ramp.
        /// </summary>
        /// <param name="bubblingTriggerConfiguration">
        /// TODO The bubbling trigger configuration.
        /// </param>
        /// <param name="ehMessageType">
        /// TODO The eh message type.
        /// </param>
        /// <param name="channelId">
        /// TODO The channel id.
        /// </param>
        /// <param name="pointId">
        /// TODO The point id.
        /// </param>
        /// <param name="properties">
        /// TODO The properties.
        /// </param>
        public static void SendMessageOnRamp(
            object bubblingTriggerConfiguration,
            Configuration.MessageDataProperty ehMessageType,
            string channelId,
            string pointId,
            Dictionary <string, object> properties,
            string pointIdOverrided)
        {
            try
            {
                if (Configuration.RunLocalOnly())
                {
                    LogEngine.WriteLog(Configuration.EngineName,
                                       $"Impossible to send the message using a remote message storage provider, this GrabCaster point is configured for local only execution.",
                                       Constant.DefconOne,
                                       Constant.TaskCategoriesError,
                                       null,
                                       EventLogEntryType.Warning);
                    return;
                }

                // Meter and measuring purpose
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                byte[] serializedMessage = null;
                // Create EH data message
                if (ehMessageType != Configuration.MessageDataProperty.ByteArray)
                {
                    serializedMessage = SerializationEngine.ObjectToByteArray(bubblingTriggerConfiguration);
                }
                else
                {
                    serializedMessage = (byte[])bubblingTriggerConfiguration;
                }

                var             messageId = Guid.NewGuid().ToString();
                SkeletonMessage data      = new SkeletonMessage(null);

                // IF > 256kb then persist
                if (serializedMessage.Length > secondaryPersistProviderByteSize && !secondaryPersistProviderEnabled)
                {
                    LogEngine.WriteLog(Configuration.EngineName,
                                       $"Error in {MethodBase.GetCurrentMethod().Name} - Impossible to send the message, the message body size if bigger than the secondaryPersistProviderByteSize paramenter but the secondaryPersistProviderEnabled is false.\rConsider to enable the secondaryPersistProviderEnabled paramanter in the config file and configure the storage component.",
                                       Constant.DefconOne,
                                       Constant.TaskCategoriesError,
                                       null,
                                       EventLogEntryType.Error);

                    return;
                }

                if (serializedMessage.Length > secondaryPersistProviderByteSize && secondaryPersistProviderEnabled)
                {
                    data.Body = Encoding.UTF8.GetBytes(messageId);
                    ParametersCreateEventUpStream[0] = serializedMessage;
                    ParametersCreateEventUpStream[1] = messageId;
                    methodPersistEventToBlob.Invoke(classInstanceDpp, ParametersCreateEventUpStream);
                    data.Properties.Add(Configuration.MessageDataProperty.Persisting.ToString(), true);
                }
                else
                {
                    data.Body = serializedMessage;
                    data.Properties.Add(Configuration.MessageDataProperty.Persisting.ToString(), false);
                }
                // Load custome Properties
                if (properties != null)
                {
                    foreach (var prop in properties)
                    {
                        data.Properties.Add(prop.Key, prop.Value);
                    }
                }

                data.Properties.Add(Configuration.MessageDataProperty.MessageId.ToString(), messageId);

                // Set main security subscription
                data.Properties.Add(Configuration.GrabCasterMessageTypeName, Configuration.GrabCasterMessageTypeValue);

                // Message context
                data.Properties.Add(
                    Configuration.MessageDataProperty.Message.ToString(),
                    Configuration.MessageDataProperty.Message.ToString());
                data.Properties.Add(Configuration.MessageDataProperty.MessageType.ToString(), ehMessageType.ToString());

                string senderid = pointIdOverrided != null? pointIdOverrided : Configuration.PointId();
                data.Properties.Add(Configuration.MessageDataProperty.SenderId.ToString(), senderid);

                data.Properties.Add(Configuration.MessageDataProperty.SenderName.ToString(), Configuration.PointName());
                data.Properties.Add(
                    Configuration.MessageDataProperty.SenderDescriprion.ToString(),
                    Configuration.PointDescription());
                data.Properties.Add(Configuration.MessageDataProperty.ChannelId.ToString(), Configuration.ChannelId());
                data.Properties.Add(
                    Configuration.MessageDataProperty.ChannelName.ToString(),
                    Configuration.ChannelName());
                data.Properties.Add(
                    Configuration.MessageDataProperty.ChannelDescription.ToString(),
                    Configuration.ChannelDescription());

                data.Properties.Add(Configuration.MessageDataProperty.ReceiverChannelId.ToString(), channelId);
                data.Properties.Add(Configuration.MessageDataProperty.ReceiverPointId.ToString(), pointId);

                stopWatch.Stop();
                var ts = stopWatch.Elapsed;
                data.Properties.Add(Configuration.MessageDataProperty.OperationTime.ToString(), ts.Milliseconds);

                lock (offRampEngine)
                {
                    if (ehMessageType == Configuration.MessageDataProperty.Event ||
                        ehMessageType == Configuration.MessageDataProperty.Trigger)
                    {
                        var bubblingEvent = (BubblingEvent)bubblingTriggerConfiguration;
                        if (Configuration.LoggingVerbose())
                        {
                            var serializedEvents = JsonConvert.SerializeObject(
                                bubblingEvent.Events,
                                Formatting.Indented,
                                new JsonSerializerSettings {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            });
                            LogEngine.ConsoleWriteLine(
                                $"Sent Message Type {ehMessageType}sent - Endpoints: {serializedEvents}",
                                ConsoleColor.Green);
                        }
                        else
                        {
                            LogEngine.ConsoleWriteLine($"Sent Message Type {ehMessageType}", ConsoleColor.Green);
                        }
                    }
                    else
                    {
                        LogEngine.ConsoleWriteLine($"Sent Message Type {ehMessageType}", ConsoleColor.Green);
                    }
                }
                offRampEngine.Enqueue(data);
            }
            catch (Exception ex)
            {
                LogEngine.WriteLog(
                    Configuration.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name}",
                    Constant.DefconOne,
                    Constant.TaskCategoriesEventHubs,
                    ex,
                    EventLogEntryType.Error);
            }
        }
コード例 #3
0
        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
        /// <summary>
        ///     TODO The send message on ramp.
        /// </summary>
        /// <param name="bubblingTriggerConfiguration">
        ///     TODO The bubbling trigger configuration.
        /// </param>
        /// <param name="ehMessageType">
        ///     TODO The eh message type.
        /// </param>
        /// <param name="channelId">
        ///     TODO The channel id.
        /// </param>
        /// <param name="pointId">
        ///     TODO The point id.
        /// </param>
        /// <param name="properties">
        ///     TODO The properties.
        /// </param>
        public static void SendMessageOffRamp(
            BubblingObject bubblingObject,
            string messageType,
            string channelId,
            string pointId,
            string pointIdOverrided)
        {
            try
            {
                //Create message Id
                bubblingObject.MessageId = Guid.NewGuid().ToString();

                //Create bubbling object message to send
                byte[] serializedMessage = SerializationEngine.ObjectToByteArray(bubblingObject);

                //If enabled and > secondaryPersistProviderByteSize then store the body
                //put the messageid in the body message to recover
                bubblingObject.Persisting = serializedMessage.Length > secondaryPersistProviderByteSize &&
                                            secondaryPersistProviderEnabled;

                if (bubblingObject.Persisting)
                {
                    bubblingObject.Data = EncodingDecoding.EncodingString2Bytes(bubblingObject.MessageId);
                    DevicePersistentProvider.PersistEventToStorage(serializedMessage, bubblingObject.MessageId);
                    bubblingObject.Persisting = true;
                }
                // Message context
                bubblingObject.MessageType = messageType;

                if (pointIdOverrided != null)
                {
                    bubblingObject.SenderPointId = pointIdOverrided;
                }
                else
                {
                    bubblingObject.SenderPointId = ConfigurationBag.Configuration.PointId;
                }

                bubblingObject.SenderName               = ConfigurationBag.Configuration.PointName;
                bubblingObject.SenderDescriprion        = ConfigurationBag.Configuration.PointDescription;
                bubblingObject.SenderChannelId          = ConfigurationBag.Configuration.ChannelId;
                bubblingObject.SenderChannelName        = ConfigurationBag.Configuration.ChannelName;
                bubblingObject.SenderChannelDescription = ConfigurationBag.Configuration.ChannelDescription;
                bubblingObject.SenderPointId            = ConfigurationBag.Configuration.PointId;
                bubblingObject.SenderName               = ConfigurationBag.Configuration.PointName;
                bubblingObject.SenderDescriprion        = ConfigurationBag.Configuration.PointDescription;
                bubblingObject.DestinationChannelId     = channelId;
                bubblingObject.DestinationPointId       = pointId;
                bubblingObject.HAGroup = ConfigurationBag.Configuration.HAGroup;

                LogEngine.WriteLog(ConfigurationBag.EngineName,
                                   $"SendMessageOffRamp 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);

                OffRampEngineQueue.Enqueue(bubblingObject);
            }
            catch (Exception ex)
            {
                LogEngine.WriteLog(
                    ConfigurationBag.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name}",
                    Constant.LogLevelError,
                    Constant.TaskCategoriesEventHubs,
                    ex,
                    Constant.LogLevelError);
            }
        }
コード例 #5
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);
            }
        }
コード例 #6
0
 /// <summary>
 ///     The serialize message.
 /// </summary>
 /// <returns>
 ///     The <see cref="byte[]" />.
 /// </returns>
 public static byte[] SerializeMessage(BubblingObject bubblingObject)
 {
     return(SerializationEngine.ObjectToByteArray(bubblingObject));
 }