예제 #1
0
        /// <summary>
        /// This method logs entities to the event source. This method will try indefinitely
        /// as we do not want the Event Source to fail.
        /// </summary>
        /// <typeparam Name="KT">The key type.</typeparam>
        /// <param name="actionType"></param>
        /// <param name="originatorKey"></param>
        /// <param name="key"></param>
        /// <param name="entity"></param>
        /// <param name="settings"></param>
        protected async virtual Task LogEventSource <KT>(string actionType, string originatorKey, KT key, E entity, RepositorySettings settings)
        {
            try
            {
                var data = new EventSourceEntry <KT, E>
                {
                    EntityType       = typeof(E).Name,
                    EventType        = actionType,
                    Entity           = entity,
                    EntityKey        = key,
                    EntitySource     = settings?.Source,
                    EntitySourceId   = settings?.SourceId,
                    EntitySourceName = settings?.SourceName
                };

                if (settings != null)
                {
                    data.BatchId          = settings.BatchId;
                    data.CorrelationId    = settings.CorrelationId;
                    data.EntityVersionOld = settings.VersionId;

                    data.EntityVersion = settings.VersionId;
                }

                await EventSource.Write(originatorKey, data, sync : true);
            }
            catch (Exception ex)
            {
                Logger.LogException($"Exception thrown for log to event source on {typeof (E).Name}-{actionType}-{originatorKey}", ex);
            }
        }
예제 #2
0
        private void WriteSync <K, E>(IEventSource eventSource, string originatorId, EventSourceEntry <K, E> entry, DateTime?utcTimeStamp)
        {
            int numberOfRetries = 0;

            while (true)
            {
                try
                {
                    eventSource.Write(originatorId, entry, utcTimeStamp).Wait();

                    return;
                }
                catch (Exception ex)
                {
                    if (numberOfRetries >= mPolicy.EventSourceRetryLimit)
                    {
                        this.LogException(string.Format("Unable to log to event source {0} for {1}-{2}-{3}", eventSource.GetType().Name, entry.EntityType, entry.Key, entry.EntityVersion), ex);
                        throw;
                    }
                }

                Task.Delay(TimeSpan.FromMilliseconds(numberOfRetries * 100)).Wait();

                numberOfRetries++;
            }
        }
 public async Task Write <K, E>(string originatorId, EventSourceEntry <K, E> entry, DateTime?utcTimeStamp = default(DateTime?), bool sync = false)
 {
     try
     {
         await mActionHolder(originatorId, entry, utcTimeStamp);
     }
     catch
     {
     }
 }
        public async Task Write <K, E>(string originatorId, EventSourceEntry <K, E> entry, DateTime?utcTimeStamp = default(DateTime?), bool sync = false)
        {
            var esw = new EventSourceWrapper <K, E>()
            {
                OriginatorId = originatorId, Entry = entry, Timestamp = utcTimeStamp ?? DateTime.UtcNow
            };
            JObject jObj = JObject.FromObject(esw);

            jObj["id"] = mInstance + Guid.NewGuid().ToString("N");

            await mDocDb.Collection.Create(jObj.ToString());
        }
예제 #5
0
        public async Task Write <K, E>(string originatorId, EventSourceEntry <K, E> entry, DateTime?utcTimeStamp = default(DateTime?), bool sync = false)
        {
            try
            {
                var client  = ClientResolve(1);
                var payload = TransmissionPayload.Create();
                payload.Message.Blob.SetObject(entry);

                payload.Message.OriginatorServiceId = originatorId;
                if (utcTimeStamp.HasValue)
                {
                    entry.UTCTimeStamp = utcTimeStamp.Value;
                }

                client.Transmit(payload);
            }
            catch (Exception ex)
            {
                LogExceptionLocation("Write EventSource (Unhandled)", ex);
                //OK, not sure what happened here, so we need to throw the exception.
                //throw ex;
            }
        }
예제 #6
0
 public async Task Write <K, E>(string originatorId, EventSourceEntry <K, E> entry, DateTime?utcTimeStamp = default(DateTime?), bool sync = false)
 {
     await Output(mIdMaker(entry), mDirectoryMaker(entry), entry);
 }
예제 #7
0
 /// <summary>
 /// This is the external method to submit events to the event source.
 /// </summary>
 /// <typeparam name="K"></typeparam>
 /// <typeparam name="E"></typeparam>
 /// <param name="originatorId"></param>
 /// <param name="entry"></param>
 /// <param name="utcTimeStamp"></param>
 /// <param name="sync"></param>
 /// <returns></returns>
 public async Task Write <K, E>(string originatorId, EventSourceEntry <K, E> entry, DateTime?utcTimeStamp = default(DateTime?), bool sync = false)
 {
     Write(new EventSourceEvent {
         OriginatorId = originatorId, Entry = entry, UtcTimeStamp = utcTimeStamp
     }, DataCollectionSupport.EventSource, sync);
 }
예제 #8
0
 public async Task Write <K, E>(string originatorId, EventSourceEntry <K, E> entry, DateTime?utcTimeStamp = default(DateTime?), bool sync = false)
 {
 }