Ejemplo n.º 1
0
        public override bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types)
        {
            IAuditable auditable = entity as IAuditable;
            if (auditable != null)
            {
                IClock clock = kernel.Resolve<IClock>();
                IApplicationContext appContext = kernel.Resolve<IApplicationContext>();

                currentState[Array.IndexOf<string>(propertyNames, "UpdatedAt")] = clock.Now;
                currentState[Array.IndexOf<string>(propertyNames, "UpdatedBy")] = appContext.FullUserName;

                Project auditProject = auditable.AuditProject;
                if (auditProject != null)
                {
                    ProjectHistoryStep historyStep = new ProjectHistoryStep();
                    historyStep.Description = string.Format("Updated {0}", auditable.HistoryDescription);
                    historyStep.At = clock.Now;
                    historyStep.By = appContext.FullUserName;
                    historyStep.Project = auditProject;
                    historyStep.Create();
                }

                return true;
            }
            return false;
        }
        public Execution AsyncBeginApply(Migration migration, Instance instance)
        {
            ProjectHistoryStep historyStep = new ProjectHistoryStep();
            historyStep.Description = string.Format("Applying migration {0} ({1}) on instance {2}.", migration.Id, migration.Description, instance.FullName);
            historyStep.At = clock.Now;
            historyStep.By = appContext.FullUserName;
            historyStep.Project = migration.AuditProject;
            historyStep.Create();

            Execution execution = new Execution();
            execution.At = clock.Now;
            execution.By = appContext.FullUserName;
            execution.Migration = migration;
            execution.Instance = instance;
            execution.ExecutionState = ExecutionState.Pending;
            execution.AppendLog("Starting migration {0}({1}) on {2}...", migration.Id, migration.Description, instance.FullName);
            execution.CreateAndFlush();
            try
            {
                migrationTablesManager.CheckAndCreateMigrationTable(instance, execution);
                execution.UpdateAndFlush();
                if (!migrationTablesManager.IsMigrationAlreadyApplied(migration, instance, execution))
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object arg)
                    {
                        SyncApplyMigration(migration, instance, execution);
                    }));
                }
                else
                {
                    execution.ExecutionState = ExecutionState.Completed;
                    execution.UpdateAndFlush();
                }

            }
            catch (Exception ex)
            {
                execution.AppendLogException(ex);
                execution.UpdateAndFlush();
            }

            return execution;
        }
Ejemplo n.º 3
0
        public override void OnDelete(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types)
        {
            IAuditable auditable = entity as IAuditable;
            if (auditable != null)
            {
                IClock clock = kernel.Resolve<IClock>();
                IApplicationContext appContext = kernel.Resolve<IApplicationContext>();

                Project auditProject = auditable.AuditProject;
                if (auditProject != null)
                {
                    ProjectHistoryStep historyStep = new ProjectHistoryStep();
                    historyStep.Description = string.Format("Deleted {0}", auditable.HistoryDescription);
                    historyStep.At = clock.Now;
                    historyStep.By = appContext.FullUserName;
                    historyStep.Project = auditProject;
                    historyStep.Create();
                }
            }
        }