Beispiel #1
0
        public virtual async Task Handle(OrderChangedEvent message)
        {
            var operationLogs = new List <OperationLog>();

            foreach (var changedEntry in message.ChangedEntries)
            {
                operationLogs.AddRange(await GetChangedEntryOperationLogsAsync(changedEntry));
            }
            if (!operationLogs.IsNullOrEmpty())
            {
                await _changeLogService.SaveChangesAsync(operationLogs.ToArray());
            }
        }
Beispiel #2
0
 protected virtual async Task SaveOperationLogAsync(string objectId, string detail, EntryState entryState)
 {
     var operation = new OperationLog
     {
         ObjectId      = objectId,
         ObjectType    = typeof(ApplicationUser).Name,
         OperationType = entryState,
         Detail        = detail
     };
     await _changeLogService.SaveChangesAsync(operation);
 }
        public async Task Handle(LicenseChangedEvent message)
        {
            foreach (var changedEntry in message.ChangedEntries)
            {
                var original = changedEntry.OldEntry;
                var modified = changedEntry.NewEntry;

                if (changedEntry.EntryState == EntryState.Modified)
                {
                    var operationLogs = new List <OperationLog>();

                    if (original.CustomerName != modified.CustomerName)
                    {
                        operationLogs.Add(GetLogRecord(modified.Id, "Customer name changed from '{0}' to '{1}'", original.CustomerName, modified.CustomerName));
                    }
                    if (original.CustomerEmail != modified.CustomerEmail)
                    {
                        operationLogs.Add(GetLogRecord(modified.Id, "Customer email changed from '{0}' to '{1}'", original.CustomerEmail, modified.CustomerEmail));
                    }
                    if (original.ExpirationDate != modified.ExpirationDate)
                    {
                        operationLogs.Add(GetLogRecord(modified.Id, "Expiration date changed from '{0}' to '{1}'", original.ExpirationDate, modified.ExpirationDate));
                    }
                    if (original.Type != modified.Type)
                    {
                        operationLogs.Add(GetLogRecord(modified.Id, "License type changed from '{0}' to '{1}'", original.Type, modified.Type));
                    }
                    if (original.ActivationCode != modified.ActivationCode)
                    {
                        operationLogs.Add(GetLogRecord(modified.Id, "Activation code changed from '{0}' to '{1}'", original.ActivationCode, modified.ActivationCode));
                    }

                    await _changeLogService.SaveChangesAsync(operationLogs.ToArray());
                }
            }
        }
        // (!) Do not make this method async, it causes improper user recorded into the log! It happens because the user stored in the current thread. If the thread switched, the user info will lost.
        public void TryToLogChangesBackgroundJob(OrderChangedEvent @event)
        {
            var operationLogs = new List <OperationLog>();

            foreach (var changedEntry in @event.ChangedEntries.Where(x => x.EntryState == EntryState.Modified))
            {
                var originalOperations = changedEntry.OldEntry.GetFlatObjectsListWithInterface <IOperation>().Distinct();
                var modifiedOperations = changedEntry.NewEntry.GetFlatObjectsListWithInterface <IOperation>().Distinct();

                modifiedOperations.ToList().CompareTo(originalOperations.ToList(), EqualityComparer <IOperation> .Default,
                                                      (state, modified, original) => operationLogs.AddRange(GetChangedEntryOperationLogs(new GenericChangedEntry <IOperation>(modified, original, state))));
            }
            if (!operationLogs.IsNullOrEmpty())
            {
                _changeLogService.SaveChangesAsync(operationLogs.ToArray()).GetAwaiter().GetResult();
            }
        }
 // "DisableConcurrentExecutionAttribute" prevents to start simultaneous job payloads.
 // Should have short timeout, because this attribute implemented by following manner: newly started job falls into "processing" state immediately.
 // Then it tries to receive job lock during timeout. If the lock received, the job starts payload.
 // When the job is awaiting desired timeout for lock release, it stucks in "processing" anyway. (Therefore, you should not to set long timeouts (like 24*60*60), this will cause a lot of stucked jobs and performance degradation.)
 // Then, if timeout is over and the lock NOT acquired, the job falls into "scheduled" state (this is default fail-retry scenario).
 // Failed job goes to "Failed" state (by default) after retries exhausted.
 public void LogEntityChangesInBackground(OperationLog[] operationLogs)
 {
     _changeLogService.SaveChangesAsync(operationLogs).GetAwaiter().GetResult();
 }
 // "DisableConcurrentExecutionAttribute" prevents to start simultaneous job payloads.
 // Should have short timeout, because this attribute implemented by following manner: newly started job falls into "processing" state immediately.
 // Then it tries to receive job lock during timeout. If the lock received, the job starts payload.
 // When the job is awaiting desired timeout for lock release, it stucks in "processing" anyway. (Therefore, you should not to set long timeouts (like 24*60*60), this will cause a lot of stucked jobs and performance degradation.)
 // Then, if timeout is over and the lock NOT acquired, the job falls into "scheduled" state (this is default fail-retry scenario).
 // Failed job goes to "Failed" state (by default) after retries exhausted.
 public void LogEntityChangesInBackground(List <OperationLog> operationLogs)
 {
     _changeLogService.SaveChangesAsync(operationLogs.ToArray()).GetAwaiter().GetResult();
 }