示例#1
0
        public async Task RecordEventAsync <TEvent>(AuditTrailContext <TEvent> context) where TEvent : class, new()
        {
            if (_shellSettings.State == TenantState.Initializing && String.IsNullOrEmpty(context.UserName))
            {
                var feature = _httpContextAccessor.HttpContext.Features.Get <RecipeEnvironmentFeature>();
                if (feature != null && feature.Properties.TryGetValue(SetupConstants.AdminUsername, out var adminUsername))
                {
                    context.UserName = (string)adminUsername;
                }
            }

            var descriptor = DescribeEvent(context.Name, context.Category);

            if (descriptor == null || !await IsEventEnabledAsync(descriptor))
            {
                return;
            }

            var createContext = new AuditTrailCreateContext <TEvent>(
                context.Name,
                context.Category,
                context.CorrelationId,
                context.UserId,
                context.UserName,
                context.AuditTrailEventItem
                );

            await _auditTrailEventHandlers.InvokeAsync((handler, context) => handler.CreateAsync(context), createContext, _logger);

            var auditTrailEvent = new AuditTrailEvent
            {
                EventId            = _auditTrailIdGenerator.GenerateUniqueId(),
                Category           = createContext.Category,
                Name               = createContext.Name,
                CorrelationId      = createContext.CorrelationId,
                UserId             = createContext.UserId,
                UserName           = createContext.UserName ?? "",
                NormalizedUserName = String.IsNullOrEmpty(createContext.UserName) ? "" : _keyNormalizer.NormalizeName(createContext.UserName),
                ClientIpAddress    = String.IsNullOrEmpty(createContext.ClientIpAddress)
                    ? await GetClientIpAddressAsync()
                    : createContext.ClientIpAddress,
                CreatedUtc = createContext.CreatedUtc ?? _clock.UtcNow
            };

            auditTrailEvent.Put(createContext.AuditTrailEventItem);

            await _auditTrailEventHandlers.InvokeAsync((handler, context, auditTrailEvent) => handler.AlterAsync(context, auditTrailEvent), createContext, auditTrailEvent, _logger);

            _session.Save(auditTrailEvent, AuditTrailEvent.Collection);
        }
        public async Task AddAuditTrailEventAsync <TAuditTrailEventProvider>(AuditTrailContext auditTrailContext)
            where TAuditTrailEventProvider : IAuditTrailEventProvider
        {
            var eventDescriptors = DescribeEvents(auditTrailContext.EventName, typeof(TAuditTrailEventProvider).FullName);

            foreach (var eventDescriptor in eventDescriptors)
            {
                if (!await IsEventEnabledAsync(eventDescriptor))
                {
                    return;
                }

                var auditTrailCreateContext = new AuditTrailCreateContext(
                    auditTrailContext.EventName,
                    auditTrailContext.UserName,
                    auditTrailContext.EventData,
                    auditTrailContext.EventFilterKey,
                    auditTrailContext.EventFilterData);

                _auditTrailEventHandlers.Invoke((handler, context)
                                                => handler.CreateAsync(context), auditTrailCreateContext, Logger);

                var auditTrailEvent = new AuditTrailEvent
                {
                    Id              = _iidGenerator.GenerateUniqueId(),
                    Category        = eventDescriptor.CategoryDescriptor.Category,
                    EventName       = auditTrailCreateContext.EventName,
                    FullEventName   = eventDescriptor.FullEventName,
                    UserName        = !string.IsNullOrEmpty(auditTrailCreateContext.UserName) ? auditTrailContext.UserName : T["[empty]"],
                    CreatedUtc      = auditTrailCreateContext.CreatedUtc ?? _clock.UtcNow,
                    Comment         = auditTrailCreateContext.Comment.NewlinesToHtml(),
                    EventFilterData = auditTrailCreateContext.EventFilterData,
                    EventFilterKey  = auditTrailCreateContext.EventFilterKey,
                    ClientIpAddress = string.IsNullOrEmpty(auditTrailCreateContext.ClientIpAddress) ?
                                      await GetClientAddressAsync() : auditTrailCreateContext.ClientIpAddress
                };

                eventDescriptor.BuildAuditTrailEvent(auditTrailEvent, auditTrailCreateContext.EventData);

                _session.Save(auditTrailEvent);
            }
        }
 public AuditTrailBaseFilter(JToken node) : base(node)
 {
     if (node["idEqual"] != null)
     {
         this._IdEqual = ParseInt(node["idEqual"].Value <string>());
     }
     if (node["createdAtGreaterThanOrEqual"] != null)
     {
         this._CreatedAtGreaterThanOrEqual = ParseInt(node["createdAtGreaterThanOrEqual"].Value <string>());
     }
     if (node["createdAtLessThanOrEqual"] != null)
     {
         this._CreatedAtLessThanOrEqual = ParseInt(node["createdAtLessThanOrEqual"].Value <string>());
     }
     if (node["parsedAtGreaterThanOrEqual"] != null)
     {
         this._ParsedAtGreaterThanOrEqual = ParseInt(node["parsedAtGreaterThanOrEqual"].Value <string>());
     }
     if (node["parsedAtLessThanOrEqual"] != null)
     {
         this._ParsedAtLessThanOrEqual = ParseInt(node["parsedAtLessThanOrEqual"].Value <string>());
     }
     if (node["statusEqual"] != null)
     {
         this._StatusEqual = (AuditTrailStatus)ParseEnum(typeof(AuditTrailStatus), node["statusEqual"].Value <string>());
     }
     if (node["statusIn"] != null)
     {
         this._StatusIn = node["statusIn"].Value <string>();
     }
     if (node["auditObjectTypeEqual"] != null)
     {
         this._AuditObjectTypeEqual = (AuditTrailObjectType)StringEnum.Parse(typeof(AuditTrailObjectType), node["auditObjectTypeEqual"].Value <string>());
     }
     if (node["auditObjectTypeIn"] != null)
     {
         this._AuditObjectTypeIn = node["auditObjectTypeIn"].Value <string>();
     }
     if (node["objectIdEqual"] != null)
     {
         this._ObjectIdEqual = node["objectIdEqual"].Value <string>();
     }
     if (node["objectIdIn"] != null)
     {
         this._ObjectIdIn = node["objectIdIn"].Value <string>();
     }
     if (node["relatedObjectIdEqual"] != null)
     {
         this._RelatedObjectIdEqual = node["relatedObjectIdEqual"].Value <string>();
     }
     if (node["relatedObjectIdIn"] != null)
     {
         this._RelatedObjectIdIn = node["relatedObjectIdIn"].Value <string>();
     }
     if (node["relatedObjectTypeEqual"] != null)
     {
         this._RelatedObjectTypeEqual = (AuditTrailObjectType)StringEnum.Parse(typeof(AuditTrailObjectType), node["relatedObjectTypeEqual"].Value <string>());
     }
     if (node["relatedObjectTypeIn"] != null)
     {
         this._RelatedObjectTypeIn = node["relatedObjectTypeIn"].Value <string>();
     }
     if (node["entryIdEqual"] != null)
     {
         this._EntryIdEqual = node["entryIdEqual"].Value <string>();
     }
     if (node["entryIdIn"] != null)
     {
         this._EntryIdIn = node["entryIdIn"].Value <string>();
     }
     if (node["masterPartnerIdEqual"] != null)
     {
         this._MasterPartnerIdEqual = ParseInt(node["masterPartnerIdEqual"].Value <string>());
     }
     if (node["masterPartnerIdIn"] != null)
     {
         this._MasterPartnerIdIn = node["masterPartnerIdIn"].Value <string>();
     }
     if (node["partnerIdEqual"] != null)
     {
         this._PartnerIdEqual = ParseInt(node["partnerIdEqual"].Value <string>());
     }
     if (node["partnerIdIn"] != null)
     {
         this._PartnerIdIn = node["partnerIdIn"].Value <string>();
     }
     if (node["requestIdEqual"] != null)
     {
         this._RequestIdEqual = node["requestIdEqual"].Value <string>();
     }
     if (node["requestIdIn"] != null)
     {
         this._RequestIdIn = node["requestIdIn"].Value <string>();
     }
     if (node["userIdEqual"] != null)
     {
         this._UserIdEqual = node["userIdEqual"].Value <string>();
     }
     if (node["userIdIn"] != null)
     {
         this._UserIdIn = node["userIdIn"].Value <string>();
     }
     if (node["actionEqual"] != null)
     {
         this._ActionEqual = (AuditTrailAction)StringEnum.Parse(typeof(AuditTrailAction), node["actionEqual"].Value <string>());
     }
     if (node["actionIn"] != null)
     {
         this._ActionIn = node["actionIn"].Value <string>();
     }
     if (node["ksEqual"] != null)
     {
         this._KsEqual = node["ksEqual"].Value <string>();
     }
     if (node["contextEqual"] != null)
     {
         this._ContextEqual = (AuditTrailContext)ParseEnum(typeof(AuditTrailContext), node["contextEqual"].Value <string>());
     }
     if (node["contextIn"] != null)
     {
         this._ContextIn = node["contextIn"].Value <string>();
     }
     if (node["entryPointEqual"] != null)
     {
         this._EntryPointEqual = node["entryPointEqual"].Value <string>();
     }
     if (node["entryPointIn"] != null)
     {
         this._EntryPointIn = node["entryPointIn"].Value <string>();
     }
     if (node["serverNameEqual"] != null)
     {
         this._ServerNameEqual = node["serverNameEqual"].Value <string>();
     }
     if (node["serverNameIn"] != null)
     {
         this._ServerNameIn = node["serverNameIn"].Value <string>();
     }
     if (node["ipAddressEqual"] != null)
     {
         this._IpAddressEqual = node["ipAddressEqual"].Value <string>();
     }
     if (node["ipAddressIn"] != null)
     {
         this._IpAddressIn = node["ipAddressIn"].Value <string>();
     }
     if (node["clientTagEqual"] != null)
     {
         this._ClientTagEqual = node["clientTagEqual"].Value <string>();
     }
 }
示例#4
0
 public SwitchCabinetService(AuditTrailContext dbContext)
 {
     this.dbContext = dbContext;
 }
示例#5
0
 public App(AuditTrailContext dbContext, ISwitchCabinetService switchCabinetService)
 {
     this.dbContext            = dbContext;
     this.switchCabinetService = switchCabinetService;
 }
示例#6
0
        public AuditTrailBaseFilter(XmlElement node) : base(node)
        {
            foreach (XmlElement propertyNode in node.ChildNodes)
            {
                switch (propertyNode.Name)
                {
                case "idEqual":
                    this._IdEqual = ParseInt(propertyNode.InnerText);
                    continue;

                case "createdAtGreaterThanOrEqual":
                    this._CreatedAtGreaterThanOrEqual = ParseInt(propertyNode.InnerText);
                    continue;

                case "createdAtLessThanOrEqual":
                    this._CreatedAtLessThanOrEqual = ParseInt(propertyNode.InnerText);
                    continue;

                case "parsedAtGreaterThanOrEqual":
                    this._ParsedAtGreaterThanOrEqual = ParseInt(propertyNode.InnerText);
                    continue;

                case "parsedAtLessThanOrEqual":
                    this._ParsedAtLessThanOrEqual = ParseInt(propertyNode.InnerText);
                    continue;

                case "statusEqual":
                    this._StatusEqual = (AuditTrailStatus)ParseEnum(typeof(AuditTrailStatus), propertyNode.InnerText);
                    continue;

                case "statusIn":
                    this._StatusIn = propertyNode.InnerText;
                    continue;

                case "auditObjectTypeEqual":
                    this._AuditObjectTypeEqual = (AuditTrailObjectType)StringEnum.Parse(typeof(AuditTrailObjectType), propertyNode.InnerText);
                    continue;

                case "auditObjectTypeIn":
                    this._AuditObjectTypeIn = propertyNode.InnerText;
                    continue;

                case "objectIdEqual":
                    this._ObjectIdEqual = propertyNode.InnerText;
                    continue;

                case "objectIdIn":
                    this._ObjectIdIn = propertyNode.InnerText;
                    continue;

                case "relatedObjectIdEqual":
                    this._RelatedObjectIdEqual = propertyNode.InnerText;
                    continue;

                case "relatedObjectIdIn":
                    this._RelatedObjectIdIn = propertyNode.InnerText;
                    continue;

                case "relatedObjectTypeEqual":
                    this._RelatedObjectTypeEqual = (AuditTrailObjectType)StringEnum.Parse(typeof(AuditTrailObjectType), propertyNode.InnerText);
                    continue;

                case "relatedObjectTypeIn":
                    this._RelatedObjectTypeIn = propertyNode.InnerText;
                    continue;

                case "entryIdEqual":
                    this._EntryIdEqual = propertyNode.InnerText;
                    continue;

                case "entryIdIn":
                    this._EntryIdIn = propertyNode.InnerText;
                    continue;

                case "masterPartnerIdEqual":
                    this._MasterPartnerIdEqual = ParseInt(propertyNode.InnerText);
                    continue;

                case "masterPartnerIdIn":
                    this._MasterPartnerIdIn = propertyNode.InnerText;
                    continue;

                case "partnerIdEqual":
                    this._PartnerIdEqual = ParseInt(propertyNode.InnerText);
                    continue;

                case "partnerIdIn":
                    this._PartnerIdIn = propertyNode.InnerText;
                    continue;

                case "requestIdEqual":
                    this._RequestIdEqual = propertyNode.InnerText;
                    continue;

                case "requestIdIn":
                    this._RequestIdIn = propertyNode.InnerText;
                    continue;

                case "userIdEqual":
                    this._UserIdEqual = propertyNode.InnerText;
                    continue;

                case "userIdIn":
                    this._UserIdIn = propertyNode.InnerText;
                    continue;

                case "actionEqual":
                    this._ActionEqual = (AuditTrailAction)StringEnum.Parse(typeof(AuditTrailAction), propertyNode.InnerText);
                    continue;

                case "actionIn":
                    this._ActionIn = propertyNode.InnerText;
                    continue;

                case "ksEqual":
                    this._KsEqual = propertyNode.InnerText;
                    continue;

                case "contextEqual":
                    this._ContextEqual = (AuditTrailContext)ParseEnum(typeof(AuditTrailContext), propertyNode.InnerText);
                    continue;

                case "contextIn":
                    this._ContextIn = propertyNode.InnerText;
                    continue;

                case "entryPointEqual":
                    this._EntryPointEqual = propertyNode.InnerText;
                    continue;

                case "entryPointIn":
                    this._EntryPointIn = propertyNode.InnerText;
                    continue;

                case "serverNameEqual":
                    this._ServerNameEqual = propertyNode.InnerText;
                    continue;

                case "serverNameIn":
                    this._ServerNameIn = propertyNode.InnerText;
                    continue;

                case "ipAddressEqual":
                    this._IpAddressEqual = propertyNode.InnerText;
                    continue;

                case "ipAddressIn":
                    this._IpAddressIn = propertyNode.InnerText;
                    continue;

                case "clientTagEqual":
                    this._ClientTagEqual = propertyNode.InnerText;
                    continue;
                }
            }
        }
示例#7
0
 public AuditTrail(JToken node) : base(node)
 {
     if (node["id"] != null)
     {
         this._Id = ParseInt(node["id"].Value <string>());
     }
     if (node["createdAt"] != null)
     {
         this._CreatedAt = ParseInt(node["createdAt"].Value <string>());
     }
     if (node["parsedAt"] != null)
     {
         this._ParsedAt = ParseInt(node["parsedAt"].Value <string>());
     }
     if (node["status"] != null)
     {
         this._Status = (AuditTrailStatus)ParseEnum(typeof(AuditTrailStatus), node["status"].Value <string>());
     }
     if (node["auditObjectType"] != null)
     {
         this._AuditObjectType = (AuditTrailObjectType)StringEnum.Parse(typeof(AuditTrailObjectType), node["auditObjectType"].Value <string>());
     }
     if (node["objectId"] != null)
     {
         this._ObjectId = node["objectId"].Value <string>();
     }
     if (node["relatedObjectId"] != null)
     {
         this._RelatedObjectId = node["relatedObjectId"].Value <string>();
     }
     if (node["relatedObjectType"] != null)
     {
         this._RelatedObjectType = (AuditTrailObjectType)StringEnum.Parse(typeof(AuditTrailObjectType), node["relatedObjectType"].Value <string>());
     }
     if (node["entryId"] != null)
     {
         this._EntryId = node["entryId"].Value <string>();
     }
     if (node["masterPartnerId"] != null)
     {
         this._MasterPartnerId = ParseInt(node["masterPartnerId"].Value <string>());
     }
     if (node["partnerId"] != null)
     {
         this._PartnerId = ParseInt(node["partnerId"].Value <string>());
     }
     if (node["requestId"] != null)
     {
         this._RequestId = node["requestId"].Value <string>();
     }
     if (node["userId"] != null)
     {
         this._UserId = node["userId"].Value <string>();
     }
     if (node["action"] != null)
     {
         this._Action = (AuditTrailAction)StringEnum.Parse(typeof(AuditTrailAction), node["action"].Value <string>());
     }
     if (node["data"] != null)
     {
         this._Data = ObjectFactory.Create <AuditTrailInfo>(node["data"]);
     }
     if (node["ks"] != null)
     {
         this._Ks = node["ks"].Value <string>();
     }
     if (node["context"] != null)
     {
         this._Context = (AuditTrailContext)ParseEnum(typeof(AuditTrailContext), node["context"].Value <string>());
     }
     if (node["entryPoint"] != null)
     {
         this._EntryPoint = node["entryPoint"].Value <string>();
     }
     if (node["serverName"] != null)
     {
         this._ServerName = node["serverName"].Value <string>();
     }
     if (node["ipAddress"] != null)
     {
         this._IpAddress = node["ipAddress"].Value <string>();
     }
     if (node["userAgent"] != null)
     {
         this._UserAgent = node["userAgent"].Value <string>();
     }
     if (node["clientTag"] != null)
     {
         this._ClientTag = node["clientTag"].Value <string>();
     }
     if (node["description"] != null)
     {
         this._Description = node["description"].Value <string>();
     }
     if (node["errorDescription"] != null)
     {
         this._ErrorDescription = node["errorDescription"].Value <string>();
     }
 }
示例#8
0
        public static void AddAuditTrailEntry <T>(this IAuditTrailable <T> auditTrailable, AuditTrailContext dbContext) where T : Entity
        {
            var entityEntry = dbContext.Entry(auditTrailable);
            AuditTrailEntry <T> auditTrailEntry;

            if (EntityState.Added == entityEntry.State)
            {
                auditTrailEntry = new AuditTrailEntry <T>
                {
                    Subject   = auditTrailable.GetEntity(),
                    Timestamp = SystemClock.Instance.GetCurrentInstant(),
                    EntryType = AuditTrailEntryType.Insert,
                    FromValue = "",
                    ToValue   = JsonConvert.SerializeObject(entityEntry.Entity, Formatting.Indented, new JsonSerializerSettings {
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                    }),
                };
                auditTrailable.AuditTrailEntries.Add(auditTrailEntry);
                return;
            }

            var changedProperties = entityEntry.Properties.Where(p => p.IsModified).ToList();

            if (changedProperties.Count == 0)
            {
                return;
            }
            var(from, to) = changedProperties.Aggregate((From: "", To: ""), (carry, p) =>
            {
                if (!p.IsModified || p.CurrentValue.GetType() == typeof(ICollection <AuditTrailEntry <T> >))
                {
                    return(carry);
                }

                return($"{carry.From}{Environment.NewLine}{p.Metadata.Name}: {p.OriginalValue}",
                       $"{carry.To}{Environment.NewLine}{p.Metadata.Name}: {p.CurrentValue}");
            });


            auditTrailable.AuditTrailEntries ??= new List <AuditTrailEntry <T> >();
            auditTrailEntry = new AuditTrailEntry <T>
            {
                Subject   = auditTrailable.GetEntity(),
                Timestamp = SystemClock.Instance.GetCurrentInstant(),
                EntryType = entityEntry.State switch
                {
                    EntityState.Added => AuditTrailEntryType.Insert,
                    EntityState.Modified => AuditTrailEntryType.Update,
                    EntityState.Deleted => AuditTrailEntryType.Delete,
                    _ => AuditTrailEntryType.Update,
                },
示例#9
0
        public AuditTrail(XmlElement node) : base(node)
        {
            foreach (XmlElement propertyNode in node.ChildNodes)
            {
                switch (propertyNode.Name)
                {
                case "id":
                    this._Id = ParseInt(propertyNode.InnerText);
                    continue;

                case "createdAt":
                    this._CreatedAt = ParseInt(propertyNode.InnerText);
                    continue;

                case "parsedAt":
                    this._ParsedAt = ParseInt(propertyNode.InnerText);
                    continue;

                case "status":
                    this._Status = (AuditTrailStatus)ParseEnum(typeof(AuditTrailStatus), propertyNode.InnerText);
                    continue;

                case "auditObjectType":
                    this._AuditObjectType = (AuditTrailObjectType)StringEnum.Parse(typeof(AuditTrailObjectType), propertyNode.InnerText);
                    continue;

                case "objectId":
                    this._ObjectId = propertyNode.InnerText;
                    continue;

                case "relatedObjectId":
                    this._RelatedObjectId = propertyNode.InnerText;
                    continue;

                case "relatedObjectType":
                    this._RelatedObjectType = (AuditTrailObjectType)StringEnum.Parse(typeof(AuditTrailObjectType), propertyNode.InnerText);
                    continue;

                case "entryId":
                    this._EntryId = propertyNode.InnerText;
                    continue;

                case "masterPartnerId":
                    this._MasterPartnerId = ParseInt(propertyNode.InnerText);
                    continue;

                case "partnerId":
                    this._PartnerId = ParseInt(propertyNode.InnerText);
                    continue;

                case "requestId":
                    this._RequestId = propertyNode.InnerText;
                    continue;

                case "userId":
                    this._UserId = propertyNode.InnerText;
                    continue;

                case "action":
                    this._Action = (AuditTrailAction)StringEnum.Parse(typeof(AuditTrailAction), propertyNode.InnerText);
                    continue;

                case "data":
                    this._Data = ObjectFactory.Create <AuditTrailInfo>(propertyNode);
                    continue;

                case "ks":
                    this._Ks = propertyNode.InnerText;
                    continue;

                case "context":
                    this._Context = (AuditTrailContext)ParseEnum(typeof(AuditTrailContext), propertyNode.InnerText);
                    continue;

                case "entryPoint":
                    this._EntryPoint = propertyNode.InnerText;
                    continue;

                case "serverName":
                    this._ServerName = propertyNode.InnerText;
                    continue;

                case "ipAddress":
                    this._IpAddress = propertyNode.InnerText;
                    continue;

                case "userAgent":
                    this._UserAgent = propertyNode.InnerText;
                    continue;

                case "clientTag":
                    this._ClientTag = propertyNode.InnerText;
                    continue;

                case "description":
                    this._Description = propertyNode.InnerText;
                    continue;

                case "errorDescription":
                    this._ErrorDescription = propertyNode.InnerText;
                    continue;
                }
            }
        }