Example #1
0
        public override void Commit(ICommitBag bag)
        {
            try
            {
                bag.ItemsToSave.WithEach(x =>
                {
                    this.StoreOfIndices.SetIndex(x);
                });
                bag.ItemsToDelete.WithEach(x =>
                {
                    this.StoreOfIndices.RemoveIndex(x);
                });

                //do actual commit
                this.Decorated.Commit(bag);
            }
            catch
            {
                //reverse
                bag.ItemsToSave.WithEach(x =>
                {
                    this.StoreOfIndices.RemoveIndex(x.GetStoredObjectId());
                });
            }
        }
Example #2
0
        public override void Commit(ICommitBag bag)
        {
            try
            {
                bag.ItemsToSave.WithEach(x =>
                {
                    this.StoreOfIndices.SetIndex(x);
                });
                bag.ItemsToDelete.WithEach(x =>
                {
                    this.StoreOfIndices.RemoveIndex(x);
                });

                //do actual commit
                this.Decorated.Commit(bag);
            }
            catch
            {
                //reverse
                bag.ItemsToSave.WithEach(x =>
                {
                    this.StoreOfIndices.RemoveIndex(x.GetStoredObjectId());
                });
            }
        }
Example #3
0
        public override void Commit(ICommitBag bag)
        {
            if (!this.AllowedOperations.Has(StoreOperation.Commit))
                throw new InvalidOperationException("operation masked");

            this.Decorated.Commit(bag);
        }
Example #4
0
        /// <summary>
        /// registers an item with a specific eviction condition.  If the condition is mutable, every touch/get of the item will result
        /// in a condition mutation.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="evictionCondition">may be null</param>
        public virtual void Commit(ICommitBag cb, IExpirable evictionCondition)
        {
            lock (this._stateLock)
            {
                //commit first. if it kacks we don't do anything
                this.Decorated.Commit(cb);

                //build and commit the conditions
                CommitBag conditionCommitBag = new CommitBag();

                //foreach add, register a condition
                cb.ItemsToSave.WithEach(x =>
                {
                    //save the eviction condition in the eviction store, keyed by the storedobjectid of the item to save
                    var conditionToSave = x.GetStoredObjectId().BuildAsId().HasContext(evictionCondition);
                    conditionCommitBag.MarkItemSaved(conditionToSave);
                });

                //foreach remove, remove a condition
                cb.ItemsToDelete.WithEach(x =>
                {
                    var delId = StoredObjectId.New(typeof(ContextualIHasIdDecoration), x);
                    conditionCommitBag.MarkItemDeleted(delId);
                });

                this.ExpirableStore.Commit(conditionCommitBag);
            }
        }
Example #5
0
        public override void Commit(ICommitBag bag)
        {
            //update the cache
            this.CachingStore.Commit(bag);

            //do reg commit
            this.Decorated.Commit(bag);
        }
Example #6
0
        public override void Commit(ICommitBag bag)
        {
            if (!this.AllowedOperations.Has(StoreOperation.Commit))
            {
                throw new InvalidOperationException("operation masked");
            }

            this.Decorated.Commit(bag);
        }
Example #7
0
        public override void Commit(ICommitBag bag)
        {
            //update the cache
            this.CachingStore.Commit(bag);

            //do reg commit
            this.Decorated.Commit(bag);

        }
        //#region IHasHydrationMap
        //public virtual IHydrationMap GetHydrationMap()
        //{
        //    var hydrationMap = new HydrationMapValueManager<ValidatingDecoration>();
        //    hydrationMap.RegisterDefault("ItemValidator", x => x.ItemValidator, (x, y) => { x.ItemValidator = y as IItemValidator; }); 
        //    return hydrationMap;
        //}
        //#endregion

        //#region IDecorationHydrateable
        //public override string DehydrateDecoration(IGraph uow = null)
        //{
        //    return this.GetHydrationMap().DehydrateValue(this, uow);
        //}
        //public override void HydrateDecoration(string text, IGraph uow = null)
        //{
        //    this.GetHydrationMap().HydrateValue(this, text, uow);
        //}
        //#endregion

        #region Overrides
        public override void Commit(ICommitBag bag)
        {
            //examine the stuff we're saving (not deleting - item would have been validated as a prerequisite to saving)
            bag.ItemsToSave.WithEach(x =>
            {
                if (!this.ItemValidator.IsValidCondition.Evaluate(x).GetValueOrDefault())
                    throw new InvalidOperationException("invalid item " + new StoredObjectId(x).ToString());
            });

            this.Decorated.Commit(bag);
        }
Example #9
0
        public override void Commit(ICommitBag bag)
        {
            var uow = this.CommitOperationIntercept.Perform(bag);

            if (uow.Error != null)
            {
                var errorStack = string.Join(Environment.NewLine, uow.LogEntries.ToArray());
                this.Logger.LogError("intercept error", errorStack, uow.Error);

                throw new InvalidOperationException("intercept error", uow.Error);
            }
        }
Example #10
0
        //#region IHasHydrationMap
        //public virtual IHydrationMap GetHydrationMap()
        //{
        //    var hydrationMap = new HydrationMapValueManager<ValidatingDecoration>();
        //    hydrationMap.RegisterDefault("ItemValidator", x => x.ItemValidator, (x, y) => { x.ItemValidator = y as IItemValidator; });
        //    return hydrationMap;
        //}
        //#endregion

        //#region IDecorationHydrateable
        //public override string DehydrateDecoration(IGraph uow = null)
        //{
        //    return this.GetHydrationMap().DehydrateValue(this, uow);
        //}
        //public override void HydrateDecoration(string text, IGraph uow = null)
        //{
        //    this.GetHydrationMap().HydrateValue(this, text, uow);
        //}
        //#endregion

        #region Overrides
        public override void Commit(ICommitBag bag)
        {
            //examine the stuff we're saving (not deleting - item would have been validated as a prerequisite to saving)
            bag.ItemsToSave.WithEach(x =>
            {
                if (!this.ItemValidator.IsValidCondition.Evaluate(x).GetValueOrDefault())
                {
                    throw new InvalidOperationException("invalid item " + new StoredObjectId(x).ToString());
                }
            });

            this.Decorated.Commit(bag);
        }
Example #11
0
        public override void Commit(ICommitBag bag)
        {
            this.Decorated.Commit(bag);

            bag.ItemsToSave.WithEach(x =>
            {
                this.BuildAndSaveAuditPoint(StoredItemAccessMode.Save, x);
            });

            bag.ItemsToDelete.WithEach(x =>
            {
                this.BuildAndSaveAuditPoint(StoredItemAccessMode.Delete, x);
            });
        }
        public override void Commit(ICommitBag bag)
        {
            this.Logger.LogVerbose("Commit started", null);

            try
            {
                Decorated.Commit(bag);
            }
            catch (Exception ex)
            {
                this.Logger.LogError(ex.Message, null, ex);
                throw;
            }
            finally
            {
                this.Logger.LogVerbose("Commit completed", null);
            }
        }
        public override void Commit(ICommitBag bag)
        {
            this.Logger.LogVerbose("Commit started", null);

            try
            {
                Decorated.Commit(bag);
            }
            catch (Exception ex)
            {
                this.Logger.LogError(ex.Message, null, ex);
                throw;
            }
            finally
            {
                this.Logger.LogVerbose("Commit completed", null);
            }
        }
Example #14
0
        public virtual void Commit(ICommitBag bag)
        {
            Condition.Requires(bag).IsNotNull();

            //lock the store
            lock (this._stateLock)
            {
                bag.ItemsToDelete.WithEach(x =>
                {
                    this.JSONObject.Remove(x.ToString());
                });
                bag.ItemsToSave.WithEach(x =>
                {
                    SerializedIHasId item = SerializedIHasId.New(x);
                    this.JSONObject[item.Id.ToString()] = JsonSerializer.SerializeToString <SerializedIHasId>(item);
                });
            }
        }
Example #15
0
        public virtual void Commit(ICommitBag bag)
        {
//#if DEBUG
//            Debug.WriteLine(string.Format("Id:{0}  Thread:{1}  Type:{2} Store commit starts", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName));

//            bag.ItemsToSave.WithEach(x =>
//            {
//                Debug.WriteLine(string.Format("Id:{0}  Thread:{1}  Type:{2} Store saving {3}", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName, x.GetStoredObjectId().ToString()));
//            });
//            bag.ItemsToDelete.WithEach(x =>
//            {
//                Debug.WriteLine(string.Format("Id:{0}  Thread:{1}  Type:{2} Store deleting {3}", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName, x.ToString()));
//            });
//#endif
            this.Decorated.Commit(bag);

//#if DEBUG
//            Debug.WriteLine(string.Format("Id:{0}  Thread:{1}  Type:{2} Store commit ends", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName));
//#endif
        }
Example #16
0
        /// <summary>
        /// overrides, supplies the default condition
        /// </summary>
        /// <param name="bag"></param>
        public override void Commit(ICommitBag cb)
        {
            lock (this._stateLock)
            {
                //commit first. if it kacks we don't do anything
                base.Commit(cb);

                //build and commit the conditions
                CommitBag conditionCommitBag = new CommitBag();

                //foreach add, register a condition
                if (this.ExpirableFactory != null)
                {
                    cb.ItemsToSave.WithEach(x =>
                    {
                        //generate the eviction condition
                        var evictionConditionLogic = this.ExpirableFactory.Perform(x) as LogicOfTo <IHasId, IExpirable>;

                        //save the eviction condition in the eviction store, keyed by the storedobjectid of the item to save
                        var conditionToSave = x.GetStoredObjectId().BuildAsId().HasContext(evictionConditionLogic.Result);
                        //var soid = conditionToSave.GetStoredObjectId();
                        //var soid2 = StoredObjectId.New(typeof(ContextualIHasIdDecoration), x.GetStoredObjectId());
                        //bool isEq = soid.Equals(soid2);
                        conditionCommitBag.MarkItemSaved(conditionToSave);
                    });
                }

                //foreach remove, remove a condition
                cb.ItemsToDelete.WithEach(x =>
                {
                    var delId = StoredObjectId.New(typeof(ContextualIHasIdDecoration), x);
                    conditionCommitBag.MarkItemDeleted(delId);
                });

                this.ExpirableStore.Commit(conditionCommitBag);
            }
        }
Example #17
0
        public virtual void Commit(ICommitBag bag)
        {
            Condition.Requires(bag).IsNotNull();

            //#if DEBUG
            //            Debug.WriteLine(string.Format("Id:{0}  Thread:{1}  Type:{2} Store commit starts", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName));

            //            bag.ItemsToSave.WithEach(x =>
            //            {
            //                Debug.WriteLine(string.Format("Id:{0}  Thread:{1}  Type:{2} Store saving {3}", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName, x.GetStoredObjectId().ToString()));
            //            });
            //            bag.ItemsToDelete.WithEach(x =>
            //            {
            //                Debug.WriteLine(string.Format("Id:{0}  Thread:{1}  Type:{2} Store deleting {3}", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName, x.ToString()));
            //            });
            //#endif

            //lock the store
            lock (this._stateLock)
            {
                bag.ItemsToDelete.WithEach(x =>
                {
                    //we have no filter, assume things are ok
                    this.Dictionary.Remove(x);
                });
                bag.ItemsToSave.WithEach(x =>
                {
                    //we have no filter, assume things are ok
                    this.Dictionary[x.GetStoredObjectId()] = x;
                });
            }

            //#if DEBUG
            //            Debug.WriteLine(string.Format("Id:{0}  Thread:{1}  Type:{2} Store commit ends", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName));
            //#endif
        }
Example #18
0
 public void Commit(ICommitBag bag)
 {
     this.Store.Commit(bag);
 }
        public override void Commit(ICommitBag bag)
        {
            var uow = this.CommitOperationIntercept.Perform(bag);
            if (uow.Error != null)
            {
                var errorStack = string.Join(Environment.NewLine, uow.LogEntries.ToArray());
                this.Logger.LogError("intercept error", errorStack, uow.Error);

                throw new InvalidOperationException("intercept error", uow.Error);
            }
        }
 public void Commit(ICommitBag cb, Conditions.ICondition evictionCondition)
 {
     this.FindDecoratorOf <EvictDecoration>(true).Commit(cb, evictionCondition);
 }
Example #21
0
 public void Commit(ICommitBag cb, IExpirable expirable)
 {
     this.As<EvictingDecoration>(true).Commit(cb, expirable);
 }
Example #22
0
        public virtual void Commit(ICommitBag bag)
        {
            Condition.Requires(bag).IsNotNull();

            //#if DEBUG
            //            Debug.WriteLine(string.Format("Id:{0}  Thread:{1}  Type:{2} Store commit starts", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName));

            //            bag.ItemsToSave.WithEach(x =>
            //            {
            //                Debug.WriteLine(string.Format("Id:{0}  Thread:{1}  Type:{2} Store saving {3}", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName, x.GetStoredObjectId().ToString()));
            //            });
            //            bag.ItemsToDelete.WithEach(x =>
            //            {
            //                Debug.WriteLine(string.Format("Id:{0}  Thread:{1}  Type:{2} Store deleting {3}", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName, x.ToString()));
            //            });
            //#endif

            //lock the store
            lock (this._stateLock)
            {
                bag.ItemsToDelete.WithEach(x =>
                {
                    //we have no filter, assume things are ok
                    this.Dictionary.Remove(x);
                });
                bag.ItemsToSave.WithEach(x =>
                {
                    //we have no filter, assume things are ok
                    this.Dictionary[x.GetStoredObjectId()] = x;
                });
            }

            //#if DEBUG
            //            Debug.WriteLine(string.Format("Id:{0}  Thread:{1}  Type:{2} Store commit ends", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName));
            //#endif
        }
Example #23
0
        /// <summary>
        /// overrides, supplies the default condition 
        /// </summary>
        /// <param name="bag"></param>
        public override void Commit(ICommitBag cb)
        {
            lock (this._stateLock)
            {
                //commit first. if it kacks we don't do anything
                base.Commit(cb);

                //build and commit the conditions
                CommitBag conditionCommitBag = new CommitBag();

                //foreach add, register a condition
                if (this.ExpirableFactory != null)
                {
                    cb.ItemsToSave.WithEach(x =>
                    {
                        //generate the eviction condition
                        var evictionConditionLogic = this.ExpirableFactory.Perform(x) as LogicOfTo<IHasId, IExpirable>;

                        //save the eviction condition in the eviction store, keyed by the storedobjectid of the item to save
                        var conditionToSave = x.GetStoredObjectId().BuildAsId().HasContext(evictionConditionLogic.Result);
                        //var soid = conditionToSave.GetStoredObjectId();
                        //var soid2 = StoredObjectId.New(typeof(ContextualIHasIdDecoration), x.GetStoredObjectId());
                        //bool isEq = soid.Equals(soid2);
                        conditionCommitBag.MarkItemSaved(conditionToSave);

                    });
                }

                //foreach remove, remove a condition
                cb.ItemsToDelete.WithEach(x =>
                {
                    var delId = StoredObjectId.New(typeof(ContextualIHasIdDecoration), x);
                    conditionCommitBag.MarkItemDeleted(delId);
                });

                this.ExpirableStore.Commit(conditionCommitBag);
            }
        }
Example #24
0
 public void Commit(ICommitBag cb, IExpirable expirable)
 {
     this.As <EvictingDecoration>(true).Commit(cb, expirable);
 }
 public void Commit(ICommitBag cb, Conditions.ICondition evictionCondition)
 {
     this.FindDecoratorOf<EvictDecoration>(true).Commit(cb, evictionCondition);
 }
Example #26
0
        /// <summary>
        /// registers an item with a specific eviction condition.  If the condition is mutable, every touch/get of the item will result
        /// in a condition mutation.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="evictionCondition">may be null</param>
        public virtual void Commit(ICommitBag cb, IExpirable evictionCondition)
        {
            lock (this._stateLock)
            {
                //commit first. if it kacks we don't do anything
                this.Decorated.Commit(cb);

                //build and commit the conditions
                CommitBag conditionCommitBag = new CommitBag();

                //foreach add, register a condition
                cb.ItemsToSave.WithEach(x =>
                {
                    //save the eviction condition in the eviction store, keyed by the storedobjectid of the item to save
                    var conditionToSave = x.GetStoredObjectId().BuildAsId().HasContext(evictionCondition);
                    conditionCommitBag.MarkItemSaved(conditionToSave);
                });

                //foreach remove, remove a condition
                cb.ItemsToDelete.WithEach(x =>
                {
                    var delId = StoredObjectId.New(typeof(ContextualIHasIdDecoration), x);
                    conditionCommitBag.MarkItemDeleted(delId);
                });

                this.ExpirableStore.Commit(conditionCommitBag);
            }
        }