public static CoreHistory CreateCoreHistory(IEntityExtend entity, HistoryActionType action, DateTime?timestamp, DecorateCoreHistory decorate)
        {
            if (!InformationCenter.States.TransactionInfo.ApplicationTransactionIdentifier.HasValue)
            {
                //TODO: throw;
            }

            CoreHistory ret = null;

            ret = new CoreHistory();
            ret.ApplicationTransactionID = InformationCenter.States.TransactionInfo.ApplicationTransactionIdentifier.Value;
            ret.EntityTypeID             = entity.EntityTypeID;
            ret.EntityID   = entity.EntityID;
            ret.ActionType = action;
            if (!timestamp.HasValue)
            {
                timestamp = DateTime.Now;
            }
            ret.Timestamp = timestamp.Value;
            if (decorate != null)
            {
                decorate(ret);
            }

            using (HistoryContext ctx = HistoryContext.CreateInstance())
            {
                ctx.AddToCoreHistorySet(ret);
                ctx.SaveChanges();
            }

            return(ret);
        }
 private void AssertCoreHistoryCommon(CoreHistory hist, IWithHistory ent, HistoryActionType action, DateTime dtLower, DateTime dtUpper)
 {
     Assert.AreEqual(InformationCenter.States.TransactionInfo.ApplicationTransactionIdentifier.Value, hist.ApplicationTransactionID);
     Assert.AreEqual(ent.EntityTypeID, hist.EntityTypeID);
     Assert.AreEqual(ent.EntityID, hist.EntityID);
     Assert.AreEqual(action, hist.ActionType);
     Assert.Greater(TimeSpan.FromSeconds(1), dtLower.Subtract(hist.Timestamp));
     Assert.Greater(TimeSpan.FromSeconds(1), hist.Timestamp.Subtract(dtUpper));
 }
Exemplo n.º 3
0
        public void AddNewHistoryEntry(HistoryActionType action, string name, string detail, string path)
        {
            switch (action)
            {
            case HistoryActionType.Added:
                name = "ADDED '" + name + "'";
                break;

            case HistoryActionType.Changed:
                name = "CHANGED '" + name + "'";
                break;

            default:
                name = "REMOVED '" + name + "'";
                break;
            }
            Histories.Add(new HistoryItemViewModel(path, name, detail, DateTime.Now));
            NotifyPropertyChanged("Histories");
        }
        private void AddEntityHistories(ObjectContext ctx, EntityState state, HistoryActionType action)
        {
            IEnumerable <EntityWrapper> entities = this.Entities.Where(x => x.State == state);

            foreach (EntityWrapper entityWrapper in entities)
            {
                if ((entityWrapper.Entity is EntityObject) && (entityWrapper.Entity is IEntityExtend))
                {
                    CoreHistory coreHistory = HistoryManager.CreateCoreHistory((IEntityExtend)entityWrapper.Entity, action, null, null);
                    if (entityWrapper.Entity is IWithHistory)
                    {
                        IList <IHistory> histories = ((IWithHistory)entityWrapper.Entity).CreateHistoryEntities(coreHistory);
                        foreach (IHistory history in histories)
                        {
                            this.GetHistoryEntities(entityWrapper.Key).Add(history);
                            ctx.AddObject(history.EntitySetName, history);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
 partial void OnActionTypeChanging(HistoryActionType value);
Exemplo n.º 6
0
 public HistoryItem(HistoryActionType type)
 {
     Type = type;
 }