Beispiel #1
0
        /// <summary>
        /// Make an Id for a boundary event
        /// </summary>
        /// <param name="ev"></param>
        /// <param name="msId"></param>
        /// <returns></returns>
        public static string BoundaryMakeId(EventHolder ev, MicroserviceId msId)
        {
            var    e  = ev.Data as BoundaryEvent;
            string id = $"{e.Payload?.Message?.ProcessCorrelationKey ?? "NoCorrId"}_{e.Id}";

            return($"{string.Join("_", id.Split(Path.GetInvalidFileNameChars()))}.json");
        }
Beispiel #2
0
 /// <summary>
 /// This is the default constructor.
 /// </summary>
 /// <param name="serviceHandlers">The service handler container.</param>
 /// <param name="collector">The data collector.</param>
 /// <param name="sharedServices">The shared service context.</param>
 /// <param name="originatorId">This is the Microservice identifiers.</param>
 /// <param name="outgoingRequest">This is the outgoing request initiator.</param>
 public OnDataCollectionContext(
     IServiceHandlers serviceHandlers
     , IDataCollection collector
     , ISharedService sharedServices
     , MicroserviceId originatorId
     , IMicroserviceDispatch outgoingRequest) : base(serviceHandlers, collector, sharedServices, originatorId, outgoingRequest)
 {
 }
Beispiel #3
0
 /// <summary>
 /// This is the default constructor.
 /// </summary>
 /// <param name="serializer">The serialization container.</param>
 /// <param name="collector">The data collector.</param>
 /// <param name="sharedServices">The shared service context.</param>
 /// <param name="originatorId">This is the Microservice identifiers.</param>
 /// <param name="outgoingRequest">This is the outgoing request initiator.</param>
 public OnDataCollectionContext(
     IPayloadSerializationContainer serializer
     , IDataCollection collector
     , ISharedService sharedServices
     , MicroserviceId originatorId
     , IMicroserviceDispatch outgoingRequest) : base(serializer, collector, sharedServices, originatorId, outgoingRequest)
 {
 }
 /// <summary>
 /// This is the default constructor.
 /// </summary>
 /// <param name="rq">The incoming request.</param>
 /// <param name="rsCol">The outgoing response collection.</param>
 /// <param name="serializer">The serialization container.</param>
 /// <param name="collector">The data collector.</param>
 /// <param name="sharedServices">The shared service context.</param>
 /// <param name="originatorId">This is the Microservice identifiers.</param>
 /// <param name="outgoingRequest">This is the outgoing request initiator.</param>
 public CommandMethodRequestContext(TransmissionPayload rq, List <TransmissionPayload> rsCol
                                    , IPayloadSerializationContainer serializer
                                    , IDataCollection collector
                                    , ISharedService sharedServices
                                    , MicroserviceId originatorId
                                    , ICommandOutgoing outgoingRequest) : base(rq, rsCol, serializer, collector, sharedServices, originatorId, outgoingRequest)
 {
 }
Beispiel #5
0
        /// <summary>
        /// This method serializes incoming objects in to standard JSON format encoded as UTF8.
        /// </summary>
        /// <param name="e">The incoming EventBase.</param>
        /// <param name="id">The Microservice Id</param>
        /// <returns>Returns the byte array.</returns>
        public static AzureStorageBinary DefaultJsonBinarySerializer(EventHolder e, MicroserviceId id)
        {
            var jObj = JObject.FromObject(e.Data);
            var body = jObj.ToString();

            return(new AzureStorageBinary {
                Blob = Encoding.UTF8.GetBytes(body)
            });
        }
Beispiel #6
0
 /// <summary>
 /// This is the default constructor.
 /// </summary>
 /// <param name="schedule">The incoming schedule.</param>
 /// <param name="token">The cancellation token.</param>
 /// <param name="serializer">The serialization container.</param>
 /// <param name="collector">The data collector.</param>
 /// <param name="sharedServices">The shared service context.</param>
 /// <param name="originatorId">This is the Microservice identifiers.</param>
 public CommandScheduleInlineContext(Schedule schedule, CancellationToken token
                                     , IPayloadSerializationContainer serializer
                                     , IDataCollection collector
                                     , ISharedService sharedServices
                                     , MicroserviceId originatorId) : base(serializer, collector, sharedServices, originatorId)
 {
     Schedule = schedule;
     Token    = token;
 }
Beispiel #7
0
 /// <summary>
 /// This is the default constructor.
 /// </summary>
 /// <param name="rq">The incoming request.</param>
 /// <param name="rsCol">The outgoing response collection.</param>
 /// <param name="serializer">The serialization container.</param>
 /// <param name="collector">The data collector.</param>
 /// <param name="sharedServices">The shared service context.</param>
 /// <param name="originatorId">This is the Microservice identifiers.</param>
 public CommandMethodInlineContext(TransmissionPayload rq, List <TransmissionPayload> rsCol
                                   , IPayloadSerializationContainer serializer
                                   , IDataCollection collector
                                   , ISharedService sharedServices
                                   , MicroserviceId originatorId) : base(serializer, collector, sharedServices, originatorId)
 {
     Request   = rq;
     Responses = rsCol;
 }
 /// <summary>
 /// This is the default constructor.
 /// </summary>
 /// <param name="rq">The incoming request.</param>
 /// <param name="rsCol">The outgoing response collection.</param>
 /// <param name="serviceHandlers">The service handlers container.</param>
 /// <param name="collector">The data collector.</param>
 /// <param name="sharedServices">The shared service context.</param>
 /// <param name="originatorId">This is the Microservice identifiers.</param>
 /// <param name="outgoingRequest">This is the outgoing request initiator.</param>
 public CommandRequestContextBase(TransmissionPayload rq, List <TransmissionPayload> rsCol
                                  , IServiceHandlers serviceHandlers
                                  , IDataCollection collector
                                  , ISharedService sharedServices
                                  , MicroserviceId originatorId
                                  , O outgoingRequest) : base(serviceHandlers, collector, sharedServices, originatorId, outgoingRequest)
 {
     Request   = rq;
     Responses = rsCol;
 }
Beispiel #9
0
        /// <summary>
        /// This method writes the event holder to table storage.
        /// </summary>
        /// <param name="e">The event holder to write to table storage.</param>
        /// <param name="id">The service id.</param>
        /// <returns>This is an async process.</returns>
        public override async Task Write(EventHolder e, MicroserviceId id)
        {
            //Create the output.
            var output = Serializer(e, id);

            // Create the TableOperation object that inserts the customer entity.
            TableOperation insert = TableOperation.Insert(output);

            // Execute the insert operation.
            await Table.ExecuteAsync(insert);
        }
Beispiel #10
0
        public static ITableEntity ToTableTelemetryEvent(EventHolder e, MicroserviceId msId)
        {
            var ev = e.Data as TelemetryEvent;

            var dict = new Dictionary <string, EntityProperty>();

            dict.Add("Metric", new EntityProperty(ev.MetricName));
            dict.Add("Value", new EntityProperty(ev.Value));

            return(new DynamicTableEntity("Telemetry" + DatePartition(), ev.TraceId, "*", dict));
        }
Beispiel #11
0
 /// <summary>
 /// This is the default constructor.
 /// </summary>
 /// <param name="schedule">The incoming schedule.</param>
 /// <param name="token">The cancellation token.</param>
 /// <param name="serviceHandlers">The service handler container.</param>
 /// <param name="collector">The data collector.</param>
 /// <param name="sharedServices">The shared service context.</param>
 /// <param name="originatorId">This is the Microservice identifiers.</param>
 /// <param name="outgoingRequest">This is the outgoing request initiator.</param>
 public CommandScheduleInlineContext(Schedule schedule, CancellationToken token
     , IServiceHandlers serviceHandlers
     , IDataCollection collector
     , ISharedService sharedServices
     , MicroserviceId originatorId
     , ICommandOutgoing outgoingRequest)
     : base(serviceHandlers, collector, sharedServices, originatorId, outgoingRequest)
 {
     Schedule = schedule;
     Token = token;
 }
Beispiel #12
0
 /// <summary>
 /// This is the default constructor.
 /// </summary>
 /// <param name="serializer">The serialization container.</param>
 /// <param name="collector">The data collector.</param>
 /// <param name="sharedServices">The shared service context.</param>
 /// <param name="originatorId">This is the Microservice identifiers.</param>
 public CommandContextBase(
     IPayloadSerializationContainer serializer
     , IDataCollection collector
     , ISharedService sharedServices
     , MicroserviceId originatorId)
 {
     PayloadSerializer = serializer;
     Collector         = collector;
     SharedServices    = sharedServices;
     OriginatorId      = originatorId;
 }
Beispiel #13
0
        public static ITableEntity ToTableDispatcherEvent(EventHolder e, MicroserviceId msId)
        {
            var ev = e.Data as DispatcherEvent;

            var dict = new Dictionary <string, EntityProperty>();

            dict.Add("IsSuccess", new EntityProperty(ev.IsSuccess));
            dict.Add("Type", GetEnum <PayloadEventType>(ev.Type));
            dict.Add("Reason", GetEnum <DispatcherRequestUnresolvedReason>(ev.Reason));
            dict.Add("Delta", new EntityProperty(ev.Delta));
            dict.Add("Ex", new EntityProperty(ev.Ex?.Message));
            dict.AddPayloadCommon(ev.Payload);

            //ETag: Set this value to '*' to blindly overwrite an entity as part of an update operation.
            return(new DynamicTableEntity("Dispatcher" + DatePartition(), ev.TraceId, "*", dict));
        }
Beispiel #14
0
        public static string LoggerMakeFolder(EventHolder ev, MicroserviceId msId)
        {
            var    e     = ev.Data as LogEvent;
            string level = Enum.GetName(typeof(LoggingLevel), e.Level);

            return(string.Format("{0}/{1}/{2:yyyy-MM-dd}/{2:HH}", msId.Name, level, DateTime.UtcNow));

            //if (e is ILogStoreName)
            //    return ((ILogStoreName)logEvent).StorageId;

            //// If there is a category specified and it contains valid digits or characters then make it part of the log name to make it easier to filter log events
            //if (!string.IsNullOrEmpty(logEvent.Category) && logEvent.Category.Any(char.IsLetterOrDigit))
            //    return string.Format("{0}_{1}_{2}", logEvent.GetType().Name, new string(logEvent.Category.Where(char.IsLetterOrDigit).ToArray()), Guid.NewGuid().ToString("N"));

            //return string.Format("{0}_{1}", logEvent.GetType().Name, Guid.NewGuid().ToString("N"));
        }
Beispiel #15
0
        /// <summary>
        /// This method writes to the incoming event to the underlying storage technology.
        /// </summary>
        /// <param name="e">The event.</param>
        /// <param name="id">The microservice metadata.</param>
        /// <returns>
        /// This is an async task.
        /// </returns>
        public override async Task Write(EventHolder e, MicroserviceId id)
        {
            var output = Serializer(e, id);

            //Encrypt the payload when required.
            if (EncryptionPolicy != AzureStorageEncryption.None && Encryptor != null)
            {
                //The checks for always encrypt are done externally.
                output.Blob = Encryptor(output.Blob);
            }

            // Create a message and add it to the queue.
            CloudQueueMessage message = new CloudQueueMessage(Convert.ToBase64String(output.Blob));

            // Async enqueue the message
            await Queue.AddMessageAsync(message);
        }
Beispiel #16
0
        /// <summary>
        /// This is the Microservice constructor.
        /// </summary>
        /// <param name="name">The Microservice name.</param>
        /// <param name="serviceId">The service id.</param>
        /// <param name="description">An optional description for the Microservice.</param>
        /// <param name="policySettings">The policy settings.</param>
        /// <param name="properties">Any additional property key.</param>
        /// <param name="serviceVersionId">This is the version id of the calling assembly as a string.</param>
        public Microservice(
            string name          = null
            , string serviceId   = null
            , string description = null
            , IEnumerable <PolicyBase> policySettings          = null
            , IEnumerable <Tuple <string, string> > properties = null
            , string serviceVersionId = null
            )
            : base(name)
        {
            Policy = new PolicyWrapper(policySettings, () => Status);
            //Id
            if (string.IsNullOrEmpty(name))
            {
                name = GetType().Name;
            }

            Id = new MicroserviceId(name
                                    , serviceId: serviceId
                                    , description: description
                                    , serviceVersionId: serviceVersionId ?? Assembly.GetCallingAssembly().GetName().Version.ToString()
                                    , serviceEngineVersionId: GetType().Assembly.GetName().Version.ToString()
                                    , properties: properties);
            //Security
            mSecurity = InitialiseSecurityContainer();
            Security  = new SecurityWrapper(mSecurity, () => Status);
            //Communication
            mCommunication = InitialiseCommunicationContainer();
            Communication  = new CommunicationWrapper(mCommunication, () => Status);
            //Commands
            mCommands = InitialiseCommandContainer();
            Commands  = new CommandWrapper(mCommands, () => Status);
            //Resources
            mResourceMonitor = InitialiseResourceMonitor();
            ResourceMonitor  = new ResourceWrapper(mResourceMonitor, () => Status);
            //Data Collection
            mDataCollection = InitialiseDataCollectionContainer();
            DataCollection  = new DataCollectionWrapper(mDataCollection, () => Status);
            //Events
            mEventsWrapper = new EventsWrapper(this, mDataCollection, () => Status);
            Events         = mEventsWrapper;
            //Serializer
            mSerializer   = InitialiseSerializationContainer();
            Serialization = new SerializationWrapper(mSerializer, () => Status);
        }
Beispiel #17
0
        public static ITableEntity ToTableBoundaryEvent(EventHolder e, MicroserviceId msId)
        {
            var ev = e.Data as BoundaryEvent;

            var dict = new Dictionary <string, EntityProperty>();

            dict.Add("Type", GetEnum <BoundaryEventType>(ev.Type));
            dict.Add("Direction", GetEnum <ChannelDirection>(ev.Direction));
            dict.Add("ChannelId", new EntityProperty(ev.ChannelId));
            dict.Add("ChannelPriority", new EntityProperty(ev.ChannelPriority));
            dict.Add("Id", new EntityProperty(ev.Id));
            dict.Add("BatchId", new EntityProperty(ev.BatchId));
            dict.Add("Requested", new EntityProperty(ev.Requested));
            dict.Add("Actual", new EntityProperty(ev.Actual));
            dict.Add("Ex", new EntityProperty(ev.Ex?.Message));
            dict.AddPayloadCommon(ev.Payload);

            return(new DynamicTableEntity("Boundary" + DatePartition(), ev.TraceId, "*", dict));
        }
Beispiel #18
0
        public static ITableEntity ToTableLogEvent(EventHolder e, MicroserviceId id)
        {
            var ev = e.Data as LogEvent;

            var dict = new Dictionary <string, EntityProperty>();

            dict.Add("Machine", new EntityProperty(id.MachineName));
            dict.Add("Name", new EntityProperty(id.Name));
            dict.Add("ServiceId", new EntityProperty(id.ServiceId));

            dict.Add("Level", GetEnum <LoggingLevel>(ev.Level));
            dict.Add("Category", new EntityProperty(ev.Category));
            dict.Add("Message", new EntityProperty(ev.Message));

            dict.Add("Ex", new EntityProperty(ev.Ex?.Message));

            //ETag: Set this value to '*' to blindly overwrite an entity as part of an update operation.
            return(new DynamicTableEntity("Logger" + DatePartition(), ev.TraceId, "*", dict));
        }
Beispiel #19
0
        /// <summary>
        /// This method writes the event holder to table storage.
        /// </summary>
        /// <param name="e">The event holder.</param>
        /// <param name="id">The service identifier class.</param>
        /// <returns>The is an async task.</returns>
        public override async Task Write(EventHolder e, MicroserviceId id)
        {
            string storageId     = MakeId(e, id);
            string storageFolder = MakeFolder(e, id);
            var    output        = Serializer(e, id);

            //Encrypt the payload when required.
            if (EncryptionPolicy != AzureStorageEncryption.None && Encryptor != null)
            {
                //The checks for always encrypt are done externally.
                output.Blob = Encryptor(output.Blob);
            }

            var refEntityDirectory = Container.GetDirectoryReference(storageFolder);

            var Blob = refEntityDirectory.GetBlockBlobReference(storageId);

            Blob.Properties.ContentType = output.ContentType;

            Blob.Properties.ContentEncoding = output.ContentEncoding;

            await Blob.UploadFromByteArrayAsync(output.Blob, 0, output.Blob.Length);
        }
Beispiel #20
0
        public static ITableEntity ToTableGeneric(EventHolder e, MicroserviceId id)
        {
            var dict = new Dictionary <string, EntityProperty>();

            return(new DynamicTableEntity(e.GetType().Name + DatePartition(), e.Data.TraceId, "*", dict));
        }
Beispiel #21
0
 /// <summary>
 /// This method writes to the incoming event to the underlying storage technology.
 /// </summary>
 /// <param name="e">The event.</param>
 /// <param name="id">The microservice metadata.</param>
 /// <returns>This is an async task.</returns>
 public abstract Task Write(EventHolder e, MicroserviceId id);
Beispiel #22
0
 public override Task Write(EventHolder e, MicroserviceId id)
 {
     throw new NotImplementedException();
 }
Beispiel #23
0
        /// <summary>
        /// Makes a folder for a boundary event
        /// </summary>
        /// <param name="ev"></param>
        /// <param name="msId"></param>
        /// <returns></returns>
        public static string BoundaryMakeFolder(EventHolder ev, MicroserviceId msId)
        {
            var e = ev.Data as BoundaryEvent;

            return(string.Format("{0}/{2:yyyy-MM-dd}/{2:HH}", msId.Name, DateTime.UtcNow));
        }
Beispiel #24
0
        public static string EventSourceMakeFolder(EventHolder ev, MicroserviceId msId)
        {
            var e = ev.Data as EventSourceEvent;

            return($"{msId.Name}/{e.UtcTimeStamp:yyyy-MM-dd}/{e.Entry.EntityType}");
        }
Beispiel #25
0
        //Event Source
        public static string EventSourceMakeId(EventHolder ev, MicroserviceId msId)
        {
            var e = ev.Data as EventSourceEvent;

            return($"{string.Join("_", e.Entry.Key.Split(Path.GetInvalidFileNameChars()))}.json");
        }
Beispiel #26
0
        //Statistics
        public static string StatisticsMakeId(EventHolder ev, MicroserviceId msId)
        {
            var e = ev.Data as MicroserviceStatistics;

            return($"{e.StorageId}.json");
        }
Beispiel #27
0
        //Logger
        public static string LoggerMakeId(EventHolder ev, MicroserviceId msId)
        {
            var e = ev.Data as LogEvent;

            return($"{e.TraceId}.json");
        }
Beispiel #28
0
        public static string StatisticsMakeFolder(EventHolder ev, MicroserviceId msId)
        {
            var e = ev.Data as MicroserviceStatistics;

            return(string.Format("{0}/{1:yyyy-MM-dd}/{1:HH}", msId.Name, DateTime.UtcNow));
        }