/// <summary>
 /// Initializes a new instance of the <see cref="SyncConfigurationFile"/> class.
 /// </summary>
 /// <param name="fileType">
 /// The file type.
 /// </param>
 /// <param name="name">
 /// The name.
 /// </param>
 /// <param name="fileContent">
 /// The file content.
 /// </param>
 /// <param name="channelId">
 /// The channel id.
 /// </param>
 public SyncConfigurationFile(
     Configuration.MessageDataProperty fileType,
     string name,
     byte[] fileContent,
     string channelId)
 {
     this.FileType    = fileType;
     this.Name        = name;
     this.FileContent = fileContent;
     this.ChannelId   = channelId;
 }
Esempio n. 2
0
        // http://localhost:8000/GrabCaster/SyncSendFileBubblingConfiguration?ChannelID={047B6D1E-A991-4CB1-ACAB-E83C3BDC0097}&PointID={B0A46E60-443C-4E8A-A6ED-7F2CB34CF9E5}&FileName=Demo Get SimpleFile Remote.trg&MessageType=Trigger
        public string SyncSendFileBubblingConfiguration(
            string channelId,
            string pointId,
            string fileName,
            Configuration.MessageDataProperty messageType)
        {
            try
            {
                if (Base.Configuration.DisableExternalEventsStreamEngine())
                {
                    LogEngine.WriteLog(
                        Base.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);

                    return
                        ("Warning the Device Provider Interface is disable, the GrabCaster point will be able to work in local mode only.");
                }

                SyncProvider.SyncSendFileBubblingConfiguration(channelId, pointId, fileName, messageType);
            }
            catch (Exception ex)
            {
                LogEngine.WriteLog(
                    Base.Configuration.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name}",
                    Constant.DefconOne,
                    Constant.TaskCategoriesError,
                    ex,
                    EventLogEntryType.Error);
                return(ex.Message);
            }

            return($"Syncronization Executed at {DateTime.Now}.");
        }
Esempio n. 3
0
        /// <summary>
        /// Send a message service as Sync received or sync available in json format
        ///     e un messaggio di servizio, tipo, sync disponibile eccetera, non e importantissimo
        /// </summary>
        /// <param name="ehMessageType">
        /// The EH Message Type.
        /// </param>
        /// <param name="channelId">
        /// The Channel ID.
        /// </param>
        /// <param name="pointId">
        /// The Point ID.
        /// </param>
        /// <param name="idComponent">
        /// The ID Component.
        /// </param>
        /// <param name="subscriberId">
        /// The subscriber ID.
        /// </param>
        public static void SendNullMessageOnRamp(
            Configuration.MessageDataProperty ehMessageType,
            string channelId,
            string pointId,
            string idComponent,
            string subscriberId,
            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();
                var data = new SkeletonMessage(Encoding.UTF8.GetBytes(string.Empty));
                data.Properties.Add(Configuration.MessageDataProperty.Persisting.ToString(), false);

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

                data.Properties.Add(Configuration.MessageDataProperty.MessageId.ToString(), Guid.NewGuid().ToString());
                data.Properties.Add(
                    Configuration.MessageDataProperty.Message.ToString(),
                    Configuration.MessageDataProperty.Message.ToString());
                data.Properties.Add(Configuration.MessageDataProperty.SubscriberId.ToString(), subscriberId);
                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);
                data.Properties.Add(Configuration.MessageDataProperty.IdComponent.ToString(), idComponent);

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

                // Queue the data
                lock (offRampEngine)
                {
                    offRampEngine.Enqueue(data);
                }

                LogEngine.ConsoleWriteLine(
                    $"Sent Message Type: {ehMessageType} - To ChannelID: {channelId} PointID: {pointId}",
                    ConsoleColor.DarkMagenta);
            }
            catch (Exception ex)
            {
                LogEngine.WriteLog(
                    Configuration.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name}",
                    Constant.DefconOne,
                    Constant.TaskCategoriesEventHubs,
                    ex,
                    EventLogEntryType.Error);
            }
        }
Esempio n. 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 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);
            }
        }