예제 #1
0
        static IDisposable OperationLogic_SurroundOperation(IOperation operation, OperationLogEntity log, Entity?entity, object?[]?args)
        {
            if (entity != null && ShouldLog.Invoke(entity, operation))
            {
                if (operation.OperationType == OperationType.Execute && !entity.IsNew && ((IEntityOperation)operation).CanBeModified)
                {
                    entity = RetrieveFresh(entity);
                }

                using (CultureInfoUtils.ChangeBothCultures(Schema.Current.ForceCultureInfo))
                {
                    log.Mixin <DiffLogMixin>().InitialState = entity.Dump();
                }
            }

            return(new Disposable(() =>
            {
                var target = log.GetTemporalTarget();

                if (target != null && ShouldLog.Invoke(target, operation) && operation.OperationType != OperationType.Delete)
                {
                    using (CultureInfoUtils.ChangeBothCultures(Schema.Current.ForceCultureInfo))
                    {
                        log.Mixin <DiffLogMixin>().FinalState = target.Dump();
                    }
                }
            }));
        }
예제 #2
0
        public static OperationLogEntity ToDataModel(this OperationLog log)
        {
            var retVal = new OperationLogEntity();

            retVal.InjectFrom(log);
            retVal.OperationType = log.OperationType.ToString();
            return(retVal);
        }
예제 #3
0
        public static OperationLog ToCoreModel(this OperationLogEntity entity)
        {
            var retVal = new OperationLog();

            retVal.InjectFrom(entity);
            retVal.OperationType = (EntryState)Enum.Parse(typeof(EntryState), entity.OperationType);
            return(retVal);
        }
예제 #4
0
 public ControllerBase()
 {
     log = new OperationLogEntity()
     {
         operationIP = Net.Ip,
         logThread   = Thread.CurrentThread.ToString()
     };
 }
예제 #5
0
        public static MinMax <OperationLogEntity?> OperationLogNextPrev(OperationLogEntity log)
        {
            var logs = Database.Query <OperationLogEntity>().Where(a => a.Exception == null && a.Target == log.Target);

            return(new MinMax <OperationLogEntity?>(
                       log.Mixin <DiffLogMixin>().InitialState == null ? null : logs.Where(a => a.End < log.Start).OrderByDescending(a => a.End).FirstOrDefault(),
                       log.Mixin <DiffLogMixin>().FinalState == null ? null : logs.Where(a => a.Start > log.End).OrderBy(a => a.Start).FirstOrDefault()));
        }
        public async Task AddLogAsync(IOperationLog log)
        {
            var logEntity = OperationLogEntity.Create(log, _dateService.Now());

            using (var conn = new SqlConnection(_connectionString))
            {
                await conn.ExecuteAsync(
                    $"insert into {_tableName} ({GetColumns}) values ({GetFields})", logEntity);
            }
        }
예제 #7
0
        /// <summary>
        /// States the entry2 operation log.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="createdDate">The createdDate.</param>
        /// <param name="objectId">The key value.</param>
        /// <param name="state">The state.</param>
        /// <returns>
        /// OperationLog object
        /// </returns>
        private OperationLogEntity StateEntry2OperationLog(string objectType, DateTime createdDate, string objectId, EntityState state)
        {
            var retVal = new OperationLogEntity
            {
                ObjectId      = objectId,
                ObjectType    = objectType,
                OperationType = state.ToString()
            };

            return(retVal);
        }
예제 #8
0
        public static void Patch(this OperationLogEntity source, OperationLogEntity target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            var patchInjection = new PatchInjection <OperationLogEntity>(x => x.ModifiedBy, x => x.ModifiedDate, x => x.Detail);

            target.InjectFrom(patchInjection, source);
        }
예제 #9
0
        public static void SaveLog(this OperationLogEntity log)
        {
            if (!LogOperation(log))
            {
                return;
            }


            using (ExecutionMode.Global())
                log.Save();
        }
예제 #10
0
        /// <summary>
        /// States the entry2 operation log.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="createdDate">The createdDate.</param>
        /// <param name="objectId">The key value.</param>
        /// <param name="state">The state.</param>
        /// <returns>
        /// OperationLog object
        /// </returns>
        private OperationLogEntity StateEntry2OperationLog(string objectType, DateTime createdDate, string objectId, EntityState state)
        {
            var retVal = new OperationLogEntity
            {
                Id            = Guid.NewGuid().ToString("N"),
                CreatedDate   = createdDate,
                ObjectId      = objectId,
                ObjectType    = objectType,
                CreatedBy     = CurrentPrincipal.GetCurrentUserName(),
                OperationType = state.ToString()
            };

            return(retVal);
        }
예제 #11
0
 static LoginController()
 {
     log = new OperationLogEntity()
     {
         operationIP         = Net.Ip,
         logType             = "Login",
         operationTable      = "Account",
         operationModuleGuid = "0",
         operationType       = "0",
         operationDesc       = "0",
         logLevel            = "INFO",
         logThread           = Thread.CurrentThread.ToString(),
         logName             = "LoginController"
     };
 }
예제 #12
0
        private void SaveChangesToLog(IPlatformRepository repository, EntityState entityState, IEnumerable <Entity> entities)
        {
            foreach (var entity in entities)
            {
                var entityType = entity.GetType();
                if (entityType.BaseType != null && entityType.Namespace == "System.Data.Entity.DynamicProxies")
                {
                    entityType = entityType.BaseType;
                }

                // This line allows you to use the base types to check that the current object type is matches the specified patterns
                var inheritanceChain   = entityType.GetTypeInheritanceChainTo(typeof(Entity));
                var suitableEntityType = inheritanceChain.FirstOrDefault(x => IsMatchInExpression(_entityTypes, x.Name));

                if (suitableEntityType != null)
                {
                    var operationLogEntity = new OperationLogEntity
                    {
                        ObjectId      = entity.Id,
                        ObjectType    = suitableEntityType.Name,
                        OperationType = entityState.ToString()
                    };

                    if (_policy == ChangeLogPolicy.Cumulative)
                    {
                        var existingLogEntity = repository.OperationLogs.OrderByDescending(x => x.ModifiedDate)
                                                .FirstOrDefault(x => x.ObjectId == operationLogEntity.ObjectId && x.ObjectType == operationLogEntity.ObjectType);
                        if (existingLogEntity != null)
                        {
                            existingLogEntity.ModifiedDate  = DateTime.UtcNow;
                            existingLogEntity.OperationType = operationLogEntity.OperationType;
                        }
                        else
                        {
                            repository.Add(operationLogEntity);
                        }
                    }
                    else
                    {
                        repository.Add(operationLogEntity);
                    }
                }
            }
        }
예제 #13
0
 static IDisposable OperationLogic_SurroundOperation(IOperation operation, OperationLogEntity log, Entity entity, object[] args)
 {
     return(IsolationEntity.Override(entity?.TryIsolation() ?? args.TryGetArgC <Lite <IsolationEntity> >()));
 }
예제 #14
0
 public void SubmitForm(OperationLogEntity entity, string keyValue)
 {
     throw new NotImplementedException();
 }
예제 #15
0
 public async Task <int> SubmitFormAsync(OperationLogEntity entity, string keyValue)
 {
     return(await logRepository.InsertAsync(entity));
 }
 public async Task AddLogAsync(IOperationLog logEntity)
 {
     var entity = OperationLogEntity.Create(logEntity);
     await _tableStorage.InsertAndGenerateRowKeyAsTimeAsync(entity, DateTime.UtcNow);
 }
예제 #17
0
파일: Graph.cs 프로젝트: sizzles/framework
            void IDeleteOperation.Delete(IEntity entity, params object[] args)
            {
                using (HeavyProfiler.Log("Delete", () => Symbol.Symbol.Key))
                {
                    OperationLogic.AssertOperationAllowed(Symbol.Symbol, inUserInterface: false);

                    string error = OnCanDelete((T)entity);
                    if (error != null)
                    {
                        throw new ApplicationException(error);
                    }

                    OperationLogEntity log = new OperationLogEntity
                    {
                        Operation = Symbol.Symbol,
                        Start     = TimeZoneManager.Now,
                        User      = UserHolder.Current?.ToLite()
                    };

                    using (OperationLogic.AllowSave(entity.GetType()))
                        OperationLogic.OnSuroundOperation(this, log, entity, args).EndUsing(_ =>
                        {
                            try
                            {
                                using (Transaction tr = new Transaction())
                                {
                                    OnDelete((T)entity, args);

                                    log.SetTarget(entity);
                                    log.End = TimeZoneManager.Now;

                                    using (ExecutionMode.Global())
                                        log.Save();

                                    tr.Commit();
                                }
                            }
                            catch (Exception ex)
                            {
                                OperationLogic.SetExceptionData(ex, Symbol.Symbol, (Entity)entity, args);

                                if (Transaction.InTestTransaction)
                                {
                                    throw;
                                }

                                var exLog = ex.LogException();

                                using (Transaction tr2 = Transaction.ForceNew())
                                {
                                    log.Target    = entity.ToLite();
                                    log.Exception = exLog.ToLite();

                                    using (ExecutionMode.Global())
                                        log.Save();

                                    tr2.Commit();
                                }

                                throw;
                            }
                        });
                }
            }
예제 #18
0
파일: Graph.cs 프로젝트: sizzles/framework
            IEntity IConstructOperation.Construct(params object[] args)
            {
                using (HeavyProfiler.Log("Construct", () => Symbol.Symbol.Key))
                {
                    OperationLogic.AssertOperationAllowed(Symbol.Symbol, inUserInterface: false);

                    OperationLogEntity log = new OperationLogEntity
                    {
                        Operation = Symbol.Symbol,
                        Start     = TimeZoneManager.Now,
                        User      = UserHolder.Current?.ToLite()
                    };

                    try
                    {
                        using (Transaction tr = new Transaction())
                        {
                            T result = null;
                            using (OperationLogic.AllowSave <T>())
                                OperationLogic.OnSuroundOperation(this, null, log, args).EndUsing(_ =>
                                {
                                    result = Construct(args);

                                    AssertEntity(result);

                                    if ((result != null && !result.IsNew) || LogAlsoIfNotSaved)
                                    {
                                        log.SetTarget(result);
                                        log.End = TimeZoneManager.Now;
                                    }
                                    else
                                    {
                                        log = null;
                                    }
                                });

                            if (log != null)
                            {
                                using (ExecutionMode.Global())
                                    log.Save();
                            }

                            return(tr.Commit(result));
                        }
                    }
                    catch (Exception ex)
                    {
                        OperationLogic.SetExceptionData(ex, Symbol.Symbol, null, args);

                        if (LogAlsoIfNotSaved)
                        {
                            if (Transaction.InTestTransaction)
                            {
                                throw;
                            }

                            var exLog = ex.LogException();

                            using (Transaction tr2 = Transaction.ForceNew())
                            {
                                log.Exception = exLog.ToLite();

                                using (ExecutionMode.Global())
                                    log.Save();

                                tr2.Commit();
                            }
                        }

                        throw;
                    }
                }
            }
예제 #19
0
파일: Graph.cs 프로젝트: sizzles/framework
            void IExecuteOperation.Execute(IEntity entity, params object[] args)
            {
                using (HeavyProfiler.Log("Execute", () => Symbol.Symbol.Key))
                {
                    OperationLogic.AssertOperationAllowed(Symbol.Symbol, inUserInterface: false);

                    string error = OnCanExecute((T)entity);
                    if (error != null)
                    {
                        throw new ApplicationException(error);
                    }

                    OperationLogEntity log = new OperationLogEntity
                    {
                        Operation = Symbol.Symbol,
                        Start     = TimeZoneManager.Now,
                        User      = UserHolder.Current?.ToLite()
                    };

                    try
                    {
                        using (Transaction tr = new Transaction())
                        {
                            using (OperationLogic.AllowSave(entity.GetType()))
                                OperationLogic.OnSuroundOperation(this, log, entity, args).EndUsing(_ =>
                                {
                                    Execute((T)entity, args);

                                    AssertEntity((T)entity);

                                    entity.Save(); //Nothing happens if already saved

                                    log.SetTarget(entity);
                                    log.End = TimeZoneManager.Now;
                                });

                            using (ExecutionMode.Global())
                                log.Save();

                            tr.Commit();
                        }
                    }
                    catch (Exception ex)
                    {
                        OperationLogic.SetExceptionData(ex, Symbol.Symbol, (Entity)entity, args);

                        if (Transaction.InTestTransaction)
                        {
                            throw;
                        }

                        var exLog = ex.LogException();

                        using (Transaction tr2 = Transaction.ForceNew())
                        {
                            OperationLogEntity newLog = new OperationLogEntity //Transaction chould have been rollbacked just before commiting
                            {
                                Operation = log.Operation,
                                Start     = log.Start,
                                User      = log.User,
                                Target    = entity.IsNew ? null : entity.ToLite(),
                                Exception = exLog.ToLite(),
                            };

                            using (ExecutionMode.Global())
                                newLog.Save();

                            tr2.Commit();
                        }

                        throw;
                    }
                }
            }
예제 #20
0
파일: Graph.cs 프로젝트: m-adi/framework
            IEntity IConstructorFromManyOperation.Construct(IEnumerable <Lite <IEntity> > lites, params object[] args)
            {
                using (HeavyProfiler.Log("ConstructFromMany", () => operationSymbol.Key))
                {
                    foreach (var type in lites.Select(a => a.EntityType).Distinct())
                    {
                        OperationLogic.AssertOperationAllowed(operationSymbol, type, inUserInterface: false);
                    }

                    OperationLogEntity log = new OperationLogEntity
                    {
                        Operation = operationSymbol,
                        Start     = TimeZoneManager.Now,
                        User      = UserHolder.Current?.ToLite()
                    };

                    try
                    {
                        using (Transaction tr = new Transaction())
                        {
                            T result = null;

                            using (OperationLogic.AllowSave <F>())
                                using (OperationLogic.AllowSave <T>())
                                    OperationLogic.OnSuroundOperation(this, log, null, args).EndUsing(_ =>
                                    {
                                        result = OnConstruct(lites.Cast <Lite <F> >().ToList(), args);

                                        AssertEntity(result);

                                        if ((result != null && !result.IsNew) || LogAlsoIfNotSaved)
                                        {
                                            log.End = TimeZoneManager.Now;
                                            log.SetTarget(result);
                                        }
                                        else
                                        {
                                            log = null;
                                        }
                                    });

                            if (log != null)
                            {
                                log.SaveLog();
                            }

                            return(tr.Commit(result));
                        }
                    }
                    catch (Exception ex)
                    {
                        OperationLogic.SetExceptionData(ex, operationSymbol, null, args);

                        if (LogAlsoIfNotSaved)
                        {
                            if (Transaction.InTestTransaction)
                            {
                                throw;
                            }

                            var exLog = ex.LogException();

                            using (Transaction tr2 = Transaction.ForceNew())
                            {
                                log.Exception = exLog.ToLite();

                                log.SaveLog();

                                tr2.Commit();
                            }
                        }

                        throw;
                    }
                }
            }
예제 #21
0
파일: Graph.cs 프로젝트: m-adi/framework
            IEntity IConstructorFromOperation.Construct(IEntity origin, params object[] args)
            {
                using (HeavyProfiler.Log("ConstructFrom", () => operationSymbol.Key))
                {
                    OperationLogic.AssertOperationAllowed(operationSymbol, origin.GetType(), inUserInterface: false);

                    string error = OnCanConstruct(origin);
                    if (error != null)
                    {
                        throw new ApplicationException(error);
                    }

                    OperationLogEntity log = new OperationLogEntity
                    {
                        Operation = operationSymbol,
                        Start     = TimeZoneManager.Now,
                        User      = UserHolder.Current?.ToLite(),
                        Origin    = origin.ToLite(origin.IsNew),
                    };

                    try
                    {
                        using (Transaction tr = new Transaction())
                        {
                            T result = null;
                            using (OperationLogic.AllowSave(origin.GetType()))
                                using (OperationLogic.AllowSave <T>())
                                    OperationLogic.OnSuroundOperation(this, log, origin, args).EndUsing(_ =>
                                    {
                                        result = Construct((F)origin, args);

                                        AssertEntity(result);

                                        if ((result != null && !result.IsNew) || LogAlsoIfNotSaved)
                                        {
                                            log.End = TimeZoneManager.Now;
                                            log.SetTarget(result);
                                        }
                                        else
                                        {
                                            log = null;
                                        }
                                    });

                            if (log != null)
                            {
                                log.SaveLog();
                            }

                            return(tr.Commit(result));
                        }
                    }
                    catch (Exception ex)
                    {
                        OperationLogic.SetExceptionData(ex, operationSymbol, (Entity)origin, args);

                        if (LogAlsoIfNotSaved)
                        {
                            if (Transaction.InTestTransaction)
                            {
                                throw;
                            }

                            var exLog = ex.LogException();

                            using (Transaction tr2 = Transaction.ForceNew())
                            {
                                log.Exception = exLog.ToLite();

                                log.SaveLog();

                                tr2.Commit();
                            }
                        }

                        throw;
                    }
                }
            }
예제 #22
0
 internal static IDisposable OnSuroundOperation(IOperation operation, OperationLogEntity log, IEntity entity, object[] args)
 {
     return(Disposable.Combine(SurroundOperation, f => f(operation, log, (Entity)entity, args)));
 }
예제 #23
0
        void OperationLog_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            tabs.Items.Clear();

            OperationLogEntity log = (OperationLogEntity)e.NewValue;

            if (log == null)
            {
                return;
            }

            var mixin = log.Mixin <DiffLogMixin>();

            var minMax = Server.Return((IDiffLogServer s) => s.OperationLogNextPrev(log));

            TabItem selected     = null;
            TabItem bestSelected = null;

            if (mixin.InitialState != null)
            {
                var prev = minMax.Min;

                if (prev != null && prev.Mixin <DiffLogMixin>().FinalState != null)
                {
                    tabs.Items.Add(new LinkTabItem
                    {
                        Header = TextWithLinkIcon(DiffLogMessage.PreviousLog.NiceToString())
                                 .Do(a => a.ToolTip = DiffLogMessage.NavigatesToThePreviousOperationLog.NiceToString()),
                        DataContext = prev,
                    });

                    tabs.Items.Add(new TabItem
                    {
                        Header = IconPair("fast-back.png", "back.png", prev.Mixin <DiffLogMixin>().FinalState == mixin.InitialState)
                                 .Do(a => a.ToolTip = DiffLogMessage.DifferenceBetweenFinalStateOfPreviousLogAndTheInitialState.NiceToString()),
                        Content = Diff(prev.Mixin <DiffLogMixin>().FinalState, mixin.InitialState),
                    });
                }

                tabs.Items.Add(selected = new TabItem
                {
                    Header = new TextBlock {
                        Text = ReflectionTools.GetPropertyInfo(() => mixin.InitialState).NiceName()
                    }
                    .Do(a => a.ToolTip = DiffLogMessage.StateWhenTheOperationStarted.NiceToString()),
                    Content            = new TextBlock(new Run(mixin.InitialState))
                    {
                        FontFamily = font
                    },
                });
            }

            if (mixin.InitialState != null && mixin.FinalState != null)
            {
                tabs.Items.Add(bestSelected = new TabItem
                {
                    Header = IconPair("back.png", "fore.png", mixin.InitialState == mixin.FinalState)
                             .Do(a => a.ToolTip = DiffLogMessage.DifferenceBetweenInitialStateAndFinalState.NiceToString()),
                    Content = Diff(mixin.InitialState, mixin.FinalState),
                });
            }

            if (mixin.FinalState != null)
            {
                tabs.Items.Add(selected = new TabItem
                {
                    Header = new TextBlock {
                        Text = ReflectionTools.GetPropertyInfo(() => mixin.FinalState).NiceName()
                    }
                    .Do(a => a.ToolTip = DiffLogMessage.StateWhenTheOperationFinished.NiceToString()),
                    Content            = new TextBlock(new Run(mixin.FinalState))
                    {
                        FontFamily = font
                    },
                });

                var next = minMax.Max;
                if (next != null && next.Mixin <DiffLogMixin>().InitialState != null)
                {
                    tabs.Items.Add(new TabItem
                    {
                        Header = IconPair("fore.png", "fast-fore.png", mixin.FinalState == next.Mixin <DiffLogMixin>().InitialState)
                                 .Do(a => a.ToolTip = DiffLogMessage.DifferenceBetweenFinalStateAndTheInitialStateOfNextLog.NiceToString()),
                        Content = Diff(mixin.FinalState, next.Mixin <DiffLogMixin>().InitialState),
                    });

                    tabs.Items.Add(new LinkTabItem
                    {
                        Header = TextWithLinkIcon(DiffLogMessage.NextLog.NiceToString())
                                 .Do(a => a.ToolTip = DiffLogMessage.NavigatesToTheNextOperationLog.NiceToString()),
                        DataContext = next,
                    });
                }
                else
                {
                    var entity = Server.Exists(log.Target) ? log.Target.RetrieveAndForget() : null;

                    if (entity != null)
                    {
                        var dump = entity.Dump();

                        tabs.Items.Add(new TabItem
                        {
                            Header = IconPair("fore.png", "fast-fore.png", mixin.FinalState == dump)
                                     .Do(a => a.ToolTip = DiffLogMessage.DifferenceBetweenFinalStateAndTheInitialStateOfNextLog.NiceToString()),
                            Content = Diff(mixin.FinalState, dump),
                        });

                        tabs.Items.Add(new LinkTabItem
                        {
                            Header = TextWithLinkIcon(DiffLogMessage.CurrentEntity.NiceToString())
                                     .Do(a => a.ToolTip = DiffLogMessage.NavigatesToTheCurrentEntity.NiceToString()),
                            DataContext = entity,
                        });
                    }
                }
            }

            tabs.SelectedItem = bestSelected ?? selected;
        }