Ejemplo n.º 1
0
        public virtual IHasId Get(IStoredObjectId soId)
        {
            IHasId rv = null;

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

            this.Dictionary.TryGetValue(StoredObjectId.New(soId.ObjectType, soId.ObjectId), out rv);


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

            return(rv);
        }
Ejemplo n.º 2
0
        public static T Get <T>(this IGettableStore store, object id) where T : IHasId
        {
            if (store == null)
            {
                return(default(T));
            }

            StoredObjectId soId = StoredObjectId.New(typeof(T), id);
            var            item = store.Get(soId);

            if (item == null)
            {
                return(default(T));
            }

            return((T)item);
        }
Ejemplo n.º 3
0
        public ICommitBag MarkItemSaved(IHasId obj)
        {
            if (obj == null)
            {
                return(this);
            }

            //we don't allow StoredObjectIds...we have to be dealing with actual objects
            if (obj is StoredObjectId)
            {
                throw new InvalidOperationException("StoredObjectId type is not allowed");
            }

            lock (this._stateLock)
            {
                List <IHasId> list = this.ItemsToSave as List <IHasId>;

                list.RemoveAll(x => StoredObjectId.New(x).Equals(StoredObjectId.New(obj)));

                this.ItemsToSave.Add(obj);
            }
            return(this);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// creates a stored object id for ContextualAsId
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public static StoredObjectId CreateSOID4ContextualAsId <TId, TContext>(this TId obj)
 {
     return(StoredObjectId.New(typeof(ContextualId <TId, TContext>), obj));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// creates a stored object id that points to AsHasId instance
 /// </summary>
 /// <typeparam name="TId"></typeparam>
 /// <typeparam name="T"></typeparam>
 /// <param name="obj"></param>
 /// <returns></returns>
 public static StoredObjectId CreateSOID4AsHasId <TId, T>(this TId obj)
 {
     return(StoredObjectId.New(typeof(AsHasId <TId, T>), obj));
 }