Esempio n. 1
0
        public bool TryGet(object instance, Type type, string id, out Target target)
        {
            var confirmedId = id ?? _idCollector.Extract(instance);

            return(string.IsNullOrEmpty(confirmedId)
                ? TryGet(instance, out target)
                : TryGet(type, id, out target));
        }
Esempio n. 2
0
        public async Task <string> Parse(string id, string actionName, IEnumerable <Target> targets)
        {
            Code.Require(() => !string.IsNullOrEmpty(id), nameof(id));
            Code.Require(() => !string.IsNullOrEmpty(actionName), nameof(actionName));

            var payload = new AuditableEntry
            {
                Id       = id,
                Action   = actionName,
                DateTime = SystemDateTime.UtcNow,

                Environment = await _environmentCollector.Extract(),
                Initiator   = await _initiatorCollector.Extract(),
                Request     = await _requestContextCollector.Extract(),
                Targets     = targets.Select(x => new AuditableTarget
                {
                    Delta = x.Delta,
                    Id    = x.Id ?? _entityIdCollector.Extract(x),
                    Type  = x.Type,
                    Style = x.ActionStyle,
                    Audit = x.ActionStyle == ActionStyle.Explicit
                        ? x.AuditType
                        : x.Delta == null ? AuditType.Read : AuditType.Modified
                })
            };

            return(_serializer.Serialize(payload));
        }
Esempio n. 3
0
        public void WatchTargets(params object[] targets)
        {
            foreach (var instance in targets)
            {
                var copy = _serializer.Serialize(instance);
                var id   = _entityIdCollector.Extract(instance);
                var type = instance.GetType();

                var target = new Target
                {
                    Type        = type.FullName,
                    Id          = id,
                    Before      = copy,
                    Instance    = instance,
                    ActionStyle = ActionStyle.Observed
                };

                _target.Add(instance, target);
            }
        }