Esempio n. 1
0
        public virtual bool Update()
        {
            if (!Loaded)
            {
                Load();
            }

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

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

            loaded = true;
        }
Esempio n. 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);
 }
 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);
     }
 }
Esempio n. 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);
        }
Esempio n. 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);
        }
        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);
                    }
                }
            }
        }