예제 #1
0
        public virtual bool Update()
        {
            if (!Loaded)
            {
                Load();
            }

            UnifiedSystem.HandleObjectChange <T>(this);
            return(Provider.UpdateObject <T>((T)this));
        }
예제 #2
0
        private static void InitializeDatabase()
        {
            database = new TSList <T>(Provider.GetAllObjects <T>());

            database.ForEach((x) =>
            {
                UnifiedSystem.HandleObjectCreation <T>(x);
            });

            loaded = true;
        }
예제 #3
0
 public virtual bool Load()
 {
     if (!initializing)
     {
         initializing = true;
         bool b = Provider.LoadCollection <T>();
         UnifiedSystem.RegisterType(typeof(T));
         if (b && !loaded)
         {
             InitializeDatabase();
         }
         return(b);
     }
     return(true);
 }
예제 #4
0
 internal static void HandleObjectDeletion <T>(IUnifiedIMObject obj)
 {
     if (UnifiedSystem.AllowReferences)
     {
         UnifiedSystem.DeleteReferences(obj);
     }
     if (UnifiedSystem.UseOmniBase)
     {
         lock (UnifiedSystem.OmniBase)
             UnifiedSystem.OmniBase.Remove(obj.ObjectID);
     }
     if (UnifiedSystem.AllowIndexes)
     {
         UnifiedSystem.DeleteIndexes(obj);
     }
 }
예제 #5
0
        public virtual bool Delete()
        {
            if (!Loaded)
            {
                Load();
            }
            bool result = Provider.DeleteObject <T>(ObjectID);

            if (result)
            {
                database.Remove((T)this);
            }

            UnifiedSystem.HandleObjectDeletion <T>(this);

            return(result);
        }
예제 #6
0
        public virtual bool Insert()
        {
            if (!Loaded)
            {
                Load();
            }
            bool result = Provider.InsertObject <T>((T)this);

            if (result)
            {
                database.Add((T)this);
            }

            UnifiedSystem.HandleObjectCreation <T>(this);

            return(result);
        }
예제 #7
0
        internal static void HandleObjectCreation <T>(IUnifiedIMObject obj)
        {
            if (UnifiedSystem.AllowReferences)
            {
                UnifiedSystem.ResolveReferences(obj, typeof(T));
            }
            if (UnifiedSystem.UseOmniBase)
            {
                lock (UnifiedSystem.OmniBase)
                    UnifiedSystem.OmniBase.Add(obj.ObjectID, obj);
            }

            List <string> indexesToAdd = new List <string>();

            if (UnifiedSystem.AllowReferences)
            {
                List <UnifiedIMReference> refs = new List <UnifiedIMReference>();
                if (TypeReferences.ContainsKey(typeof(T)))
                {
                    refs = TypeReferences[typeof(T)];
                }

                /*
                 * ObjectIndex<IUnifiedIMObject> oi = null;
                 * if (CreateReferenceIndexes)
                 *  if (Indexes.ContainsKey(typeof(T)))
                 *      oi = Indexes[typeof(T)];*/

                foreach (UnifiedIMReference reff in refs)
                {
                    if (reff.HostType == typeof(T))
                    {
                        //object value = reff.GetHostProperty(obj);
                        //if(!obj.PropertyStates.ContainsKey(reff.HostProperty))
                        //obj.PropertyStates.Add(reff.HostProperty, new UIMPropertyState(value));
                        if (CreateReferenceIndexes && reff.HostProperty != "ObjectID")
                        {
                            // oi.AddIndex(reff.HostProperty, value, obj);
                            indexesToAdd.Add(reff.HostProperty);
                        }
                    }

                    else if (reff.TargetType == typeof(T))
                    {
                        //object value = reff.GetTargetProperty(obj);
                        //if (!obj.PropertyStates.ContainsKey(reff.TargetProperty))
                        //    obj.PropertyStates.Add(reff.TargetProperty, new UIMPropertyState(value));
                        if (CreateReferenceIndexes && reff.TargetProperty != "ObjectID")
                        {
                            //oi.AddIndex(reff.TargetProperty, value, obj);
                            indexesToAdd.Add(reff.TargetProperty);
                        }
                    }
                }
            }

            if (AllowIndexes)
            {
                if (IndexProperties.ContainsKey(typeof(T)))
                {
                    indexesToAdd.AddRange(IndexProperties[typeof(T)]);
                }

                ObjectIndexer <IUnifiedIMObject> oi = null;
                if (Indexes.ContainsKey(typeof(T)))
                {
                    oi = Indexes[typeof(T)];
                }

                if (oi != null)
                {
                    foreach (string idx in indexesToAdd.Distinct())
                    {
                        object value = Property.Get(obj, idx);
                        if (!obj.PropertyStates.ContainsKey(idx))
                        {
                            obj.PropertyStates.Add(idx, new UIMPropertyState(value));
                        }
                        oi.AddIndex(idx, value, obj);
                    }
                }
            }
        }