Ejemplo n.º 1
0
        private void DropReferences(object instance)
        {
            IPersistentObject managed = (IPersistentObject)instance;

            this.uow.Objects.Remove(managed.Id);
            IList     references = managed.GetReferences();
            ArrayList tmp        = new ArrayList(references);

            foreach (ObjectReference reference in tmp)
            {
                if (!IsLoaded(reference.ObjectId))
                {
                    continue;
                }

                IPersistentObject referencedObject = (IPersistentObject)this.Get(reference.ObjectId);
                referencedObject.SetUnloaded(reference.Property, true);
                Type         referencedObjectType = referencedObject.GetType();
                PropertyInfo pi        = referencedObjectType.GetProperty(reference.Property);
                bool         stackMute = referencedObject.Mute;
                referencedObject.Mute = true;
                pi.SetValue(referencedObject, null, null);
                referencedObject.Mute = stackMute;
            }
        }
Ejemplo n.º 2
0
        public string GetExpression(Dictionary <string, object> parameters, string variable)
        {
            object obj     = parameters["Handle"];
            Array  handles = null;

            if (obj.GetType().IsArray)
            {
                handles = obj as Array;
            }
            else
            {
                handles = new Object[] { obj }
            };

            List <IGeometryEntity> geometry = new List <IGeometryEntity>();

            foreach (var item in handles)
            {
                IPersistentObject persitentObject = HostFactory.PersistenceManager.GetPersistentObjectFromHandle(item);
                if (null != persitentObject)
                {
                    geometry.Add(persitentObject.Geometry);
                }
            }

            return(GeometryExpressionBuilder.GetExpression(geometry.ToArray(), variable));
        }
    }
Ejemplo n.º 3
0
        public int ExecuteInsert(IPersistentObject persistentObject, DbConnection connection, DbTransaction transaction, string sql, params DbParameter[] parameters)
        {
            bool close  = connection == null;
            int  result = 0;

            try
            {
                connection = Db.Get.Connection(connection);
                using (DbCommand command = Db.Get.Command(sql, connection, transaction))
                {
                    foreach (DbParameter parameter in parameters)
                    {
                        command.Parameters.Add(parameter);
                    }

                    result = command.ExecuteNonQuery();
                    int id = Db.Get.Identity(command);
                    if (id > -1)
                    {
                        persistentObject.Id = id;
                    }
                }
            }
            finally
            {
                if (close && connection != null)
                {
                    connection.Close();
                }
            }
            return(result);
        }
 public bool HasSamePersistenceId(IPersistentObject other)
 {
     return other == null
                ? false
                : other.PersistenceId == null || PersistenceId == null
                      ? false
                      : PersistenceId.Value == other.PersistenceId.Value;
 }
Ejemplo n.º 5
0
        public static Geometry FromObject(long ptr)
        {
            IPersistentObject obj  = HostFactory.PersistenceManager.FromObject(ptr);
            Geometry          geom = Geometry.ToGeometry(obj.Geometry);

            geom.mPersistent = obj;
            return(geom);
        }
 public virtual void RemoveFromNewObjects(IPersistentObject newObject)
 {
     lock (_lock)
     {
         if (_newObjects.Contains(newObject))
             _newObjects.Remove(newObject);
     }
 }
Ejemplo n.º 7
0
        private void Load(IPersistentObject obj)
        {
            var data = persistenceManager.PersistenceStrategy.TryLoad(CompositeKey.CollectionId, CompositeKey.Key);

            if (!string.IsNullOrWhiteSpace(data))
            {
                persistenceManager.SerializationStrategy.PopulateFromSerialized(obj, data);
            }
        }
Ejemplo n.º 8
0
        private object Create <T>(string id, object[] args)
        {
            IPersistentObject instance = (IPersistentObject)engine.CreateProxyWithState <T>(this, args);

            uow.NewObjects.Add(instance);
            ((IPersistentObject)instance).Id = id;
            RegisterObject(instance);
            return(instance);
        }
        private static void InjectInterceptableList(IPersistentObject target, PropertyInfo property, Type propertyType)
        {
            Type subType = propertyType.GetGenericArguments()[0];
            Type genericType = typeof(PersistentList<>).MakeGenericType(subType);
            Object instance = Activator.CreateInstance(genericType);
            property.SetValue(target, instance, null);

            IPersistentList persistentList = (IPersistentList)instance;
            persistentList.Owner = target;
        }
Ejemplo n.º 10
0
        public void CommitObject(object instance)
        {
            IPersistentObject managed        = (IPersistentObject)instance;
            string            serializedData = managed.Serialize();

            System.IO.StreamWriter sw = new System.IO.StreamWriter(GetObjectFile(managed), false);
            sw.WriteLine(serializedData);
            sw.Close();
            this.uow.DirtyObjects.Remove(managed.Id);
        }
Ejemplo n.º 11
0
        void CustomerPositionChanged(object sender, EventArgs e)
        {
            IPersistentObject pc = SelectedCustomer;

            if (pc != null)
            {
                this.orderList = SelectedCustomer.Orders;
                orderBindingSource.DataSource = this.orderList;
            }
        }
Ejemplo n.º 12
0
        void OrderPositionChanged(object sender, EventArgs e)
        {
            IPersistentObject pc = SelectedOrder as IPersistentObject;

            if (pc != null)
            {
                this.orderDetailList = SelectedOrder.OrderDetails;
                orderDetailBindingSource.DataSource = this.orderDetailList;
            }
        }
Ejemplo n.º 13
0
 public static void SaveTemporary(IPersistentObject obj)
 {
     using (var stream = new FileStream(GetTempLocation().FullName, FileMode.Create))
         using (var writer = new BinaryWriter(stream))
         {
             writer.Write(KTempVersion);
             writer.Write((byte)SaveType.Temporary);
             BackEnd.Persist(stream, obj.EnumeratePersistedObjects());
         }
 }
Ejemplo n.º 14
0
        void EmployeePositionChanged(object sender, EventArgs e)
        {
            IPersistentObject pc = SelectedEmployee as IPersistentObject;

            if (pc != null)
            {
                this.orderList = SelectedEmployee.Orders;
                orderBindingSource.DataSource = this.orderList;
            }
        }
Ejemplo n.º 15
0
        private static void InjectInterceptableList(IPersistentObject target, PropertyInfo property, Type propertyType)
        {
            Type   subType     = propertyType.GetGenericArguments()[0];
            Type   genericType = typeof(PersistentList <>).MakeGenericType(subType);
            Object instance    = Activator.CreateInstance(genericType);

            property.SetValue(target, instance, null);

            IPersistentList persistentList = (IPersistentList)instance;

            persistentList.Owner = target;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Helper Method for Linq queries.
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public static ObjectId Oid(this object o)
        {
            // If Oid() is used at the right side of a comparison
            // we try to return the NDOObjectId.
            IPersistentObject po = o as IPersistentObject;

            if (po == null)
            {
                return(default(ObjectId));
            }
            return(po.NDOObjectId);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Helper Method for Linq queries. Used to query for columns of multikey oids.
        /// </summary>
        /// <param name="o"></param>
        /// <param name="index">The index of the Multikey value to compare with</param>
        /// <returns></returns>
        public static object Oid(this object o, int index)
        {
            // If Oid() is used at the right side of a comparison
            // we try to return the NDOObjectId.
            IPersistentObject po = o as IPersistentObject;

            if (po == null)
            {
                return(null);
            }
            return(po.NDOObjectId.Id.Values[index]);
        }
 /// <summary> Commits any changes to a specified object to the database. </summary>
 /// <param name="instance"> the object instance to create/update. </param>
 public virtual void CommitChanges(IPersistentObject instance)
 {
     if (_session is null)
     {
         using (var session = SessionFactory.OpenSession())
             CommitChanges(session, instance);
     }
     else
     {
         CommitChanges(_session, instance);
     }
 }
        public IPersistentObject Create(IPersistentObject po)
        {
            Task task = po as Task;

            if (task != null)
            {
                // Make sure that IsTransient contract check will not fail...
                po.PersistenceId = 0;
                m_Tasks.Add(task);
            }
            return(task);
        }
 /// <summary>
 /// Returns the extension for the given persistent object
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 /// <exception cref="NotSupportedException"></exception>
 public static string GetFileExtension(IPersistentObject obj)
 {
     if (obj is UTinyProject)
     {
         return(ProjectFileExtension);
     }
     if (obj is UTinyModule)
     {
         return(ModuleFileExtension);
     }
     throw new NotSupportedException($"Persitent object of type {obj.GetType()} has no known file extension");
 }
        public static string GetLocation(IPersistentObject p)
        {
            var guid = p.PersistenceId;

            if (string.IsNullOrEmpty(guid))
            {
                return(null);
            }

            var path = AssetDatabase.GUIDToAssetPath(guid);

            return(string.IsNullOrEmpty(path) ? null : path);
        }
        public static string PersistObject(IPersistentObject obj)
        {
            var path = GetLocation(obj);

            // No persistent path exists for this object
            // Default to `Assets/{NAME}`
            if (string.IsNullOrEmpty(path))
            {
                path = Path.Combine(Application.dataPath, GetFileName(obj));
            }

            return(PersistObjectAs(obj, path));
        }
        public void ReadPacketStream(NetDataReader stream)
        {
            ushort repObjId = stream.GetUShort();

            while (repObjId != 0)
            {
                Log.Debug($"Reading ghost with id: {repObjId}");
                // first read if there is a status change
                if (stream.GetByte() == 1)
                {
                    // read the status change
                    if (stream.GetByte() == 1)
                    {
                        Log.Debug("status changed: ADDED");
                        // added so read the persistent obj id
                        byte objRepId = stream.GetByte();

                        // Create new instance of the object
                        IPersistentObject obj = PersistentObjectManager.CreatePersistentObject(objRepId);

                        // unpack stream data
                        obj.Deserialize(stream);

                        ReplicatedObjects[repObjId] = new ReplicationRecord
                        {
                            Id     = repObjId,
                            Entity = obj as ReplicatableObject
                        };
                    }
                    else
                    {
                        Log.Debug("status changed: REMOVED");
                        // remove the record but also need to destroy game object or queue it to be destroyed..
                        if (ReplicatedObjects.TryGetValue(repObjId, out ReplicationRecord record))
                        {
                            Log.Debug($"Removing record: {record.Id}");
                            //GameObject.Destroy(record.Entity);
                            ReplicatedObjects.Remove(repObjId);
                        }
                    }
                }
                else
                {
                    Log.Debug("State update");
                    // no status change just new state information  so unpack into existing replicated obj
                    ReplicatedObjects[repObjId].Entity.Deserialize(stream);
                }

                repObjId = stream.GetUShort();
            }
        }
        public static string PersistObjectAs(IPersistentObject obj, string path)
        {
            path = PersistObjectsAs(obj.EnumeratePersistedObjects(), path);

            var assetPath = FullPathToAssetPath(path);

            AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceSynchronousImport);
            s_ChangedAssetPaths.Remove(assetPath);
            var assetGuid = AssetDatabase.AssetPathToGUID(assetPath);

            obj.PersistenceId = assetGuid;

            return(path);
        }
Ejemplo n.º 25
0
        public void Delete(object instance)
        {
            IPersistentObject managed = (IPersistentObject)instance;

            uow.DeletedObjects[managed.Id] = managed;
            DropReferences(instance);
            uow.DirtyObjects[managed.Id] = null; //clear object from dirty list
            string filePath = dbPath + @"\" + managed.Id.ToString() + ".txt";

            if (System.IO.File.Exists(filePath))
            {
                System.IO.File.Delete(filePath);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Get or create an entity for a business object
        /// </summary>
        /// <param name="unitOfWork">An open database unit of work</param>
        /// <param name="obj">The business object</param>
        /// <typeparam name="TEntity">The entity type to use</typeparam>
        public static TEntity GetEntity <TEntity>(this IUnitOfWork unitOfWork, IPersistentObject obj)
            where TEntity : class, IEntity
        {
            var repository = unitOfWork.GetRepository <IRepository <TEntity> >();
            var entity     = repository.GetByKey(obj.Id);

            if (entity == null)
            {
                entity = repository.Create();
                EntityIdListener.Listen(entity, obj);
            }

            return(entity);
        }
Ejemplo n.º 27
0
        public object HandleCall(Puzzle.NAspect.Framework.MethodInvocation call)
        {
            if (call.Method.DeclaringType == typeof(IPersistentObject))
            {
                return(call.Proceed());
            }

            string            property = GetPropertyName(call);
            IPersistentObject managed  = (IPersistentObject)call.Target;
            object            res      = managed.GetPropertyValue(property);

            call.Proceed();
            return(res);
        }
        /// <summary> Commits any changes to a specified object to the database. </summary>
        /// <param name="session"> The session in whose scope to commit. </param>
        /// <param name="instance"> The object instance to create/update. </param>
        protected void CommitChanges(ISession session, IPersistentObject instance)
        {
            LogDebug(EDatabaseLogMessage.CommittingChangesTo.Format(instance.ToString()));

            lock (_lock)
            {
                using (var transaction = session.BeginTransaction())
                {
                    session.Save(instance);
                    transaction.Commit();
                }
                RemoveFromNewObjects(instance);
            }

            LogDebug(EDatabaseLogMessage.ChangesCommitted);
        }
Ejemplo n.º 29
0
        protected static void AssetNameField(IPersistentObject obj)
        {
            using (new EditorGUILayout.VerticalScope())
            {
                EditorGUILayout.LabelField("Project Name", obj.Name);

                var path = AssetDatabase.GUIDToAssetPath(obj.PersistenceId);

                using (new EditorGUILayout.HorizontalScope())
                {
                    GUI.enabled = false;
                    EditorGUILayout.ObjectField("Project Asset", AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object)), typeof(UnityEngine.Object), false);
                    GUI.enabled = true;
                }
            }
        }
        /// <summary>
        /// Get or create an entity for a business object
        /// </summary>
        /// <param name="dbSet">An open database set</param>
        /// <param name="obj">The business object</param>
        /// <typeparam name="TEntity">The entity type to use</typeparam>
        public static TEntity GetEntity <TEntity>(this IDbSet <TEntity> dbSet, IPersistentObject obj)
            where TEntity : class, IEntity
        {
            var entity = dbSet.FirstOrDefault(e => e.Id == obj.Id);

            if (entity != null)
            {
                return(entity);
            }

            entity = dbSet.Create();
            dbSet.Add(entity);
            EntityIdListener.Listen(entity, obj);

            return(entity);
        }
Ejemplo n.º 31
0
        private IPersistentObject UpdateTask(IPersistentObject po)
        {
            Contract.Requires(po != null);
            Contract.Requires(po is Task);
            Contract.Ensures(Contract.Result <IPersistentObject>() != null);

            CheckObjectAlreadyDisposed();
            Task task = po as Task;

            CheckTask(task);
            if (s_Logger.IsDebugEnabled)
            {
                s_Logger.Debug(string.Format("{0}({1})", MethodBase.GetCurrentMethod().Name, task));
            }
            return(BaseUpdate(task));
        }
        private void Initialize(IPersistentObject target)
        {
            Type type = target.GetType().BaseType;
            PropertyInfo[] properties = type.GetProperties();
            target.Initializing = true;

            foreach (PropertyInfo property in properties)
            {
                Type propertyType = property.PropertyType;

                if (propertyType.IsGenericType && propertyType.IsInterface)
                {
                    InjectInterceptableList(target, property, propertyType);
                }
            }
            target.Initializing = false;
        }
Ejemplo n.º 33
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (null != mPersistent && !Object.ReferenceEquals(mPersistent, base.HostImpl))
                {
                    mPersistent.Dispose();
                }

                DSGeometryExtension.DisposeObject(ref mContext);
                DSGeometryExtension.DisposeObject(ref mContextCS);
            }

            mPersistent        = null;
            mDisplayAttributes = null;
            base.Dispose(disposing); //allow base class to release it's resources
        }
 public ICollection<IPersistentObject> GetChildren(IPersistentObject po, string propertyName)
 {
     // NOP
     return null;
 }
        public IPersistentObject Delete(IPersistentObject po)
        {
            Contract.Requires(Transaction.Current != null);
            Contract.Requires(Transaction.Current.TransactionInformation.DistributedIdentifier == Guid.Empty);
            //Contract.Requires(IsOperational);
            Contract.Requires(po != null);
            Contract.Requires(po.PersistenceId.HasValue);

            Contract.Ensures(Contract.Result<IPersistentObject>() != null);
            Contract.Ensures(Contract.Result<IPersistentObject>().GetType() == po.GetType());
            Contract.Ensures(!Contract.Result<IPersistentObject>().PersistenceId.HasValue);

            return default(IPersistentObject);
        }
        private IPersistentObject UpdateTask(IPersistentObject po)
        {
            Contract.Requires(po != null);
            Contract.Requires(po is Task);
            Contract.Ensures(Contract.Result<IPersistentObject>() != null);

            CheckObjectAlreadyDisposed();
            Task task = po as Task;
            CheckTask(task);
            if (s_Logger.IsDebugEnabled)
            {
                s_Logger.Debug(string.Format("{0}({1})", MethodBase.GetCurrentMethod().Name, task));
            }
            return BaseUpdate(task);
        }
 public IPersistentObject Update(IPersistentObject po)
 {
     // NOP
     return null;
 }
        public IPersistentObject Delete(IPersistentObject po)
        {
            Contract.Requires(Transaction.Current != null);
            //Contract.Requires(IsOperational);
            Contract.Requires(po != null);
            Contract.Requires(po.PersistenceId.HasValue);

            Contract.Ensures(Contract.Result<IPersistentObject>() != null);
            Contract.Ensures(Contract.Result<IPersistentObject>().GetType() == po.GetType());
            Contract.Ensures(!Contract.Result<IPersistentObject>().PersistenceId.HasValue);

            return default(IPersistentObject);
        }
        public object GetPropertyValue(IPersistentObject po, string PropertyName)
        {
            Contract.Requires(Transaction.Current != null);
            Contract.Requires(!string.IsNullOrEmpty(PropertyName));
            //Contract.Requires(IsOperational);

            //Contract.Ensures(Contract.Result<ICollection<IPersistentObject>>() != null);
            //// TODO: Tests if ICollection<IPersistenObject> contains elements of type described by the PropertyName
            ////       (This PropertyName should point in the first version to an ICollection).
            //Contract.Ensures(Contract.ForAll<IPersistentObject>(
            //    Contract.Result<ICollection<IPersistentObject>>(),
            //    a => Contract.Result<ICollection<IPersistentObject>>()
            //            .Where(b => Type.ReferenceEquals(a, b))
            //            .Count() == 1));
            //Contract.Ensures(Contract.ForAll<IPersistentObject>(
            //    Contract.Result<ICollection<IPersistentObject>>(),
            //    a => Contract.Result<ICollection<IPersistentObject>>()
            //            .Where(b => b.HasSamePersistenceId(a))
            //            .Count() == 1));

            return default(object);
        }
        private IPersistentObject UpdateTask(IPersistentObject po)
        {
            Contract.Requires(typeof(Task).IsAssignableFrom(po.GetType()));

            const string MethodName = "UpdateTask";

            CheckObjectAlreadyDisposed();

            Task task = po as Task;

            CheckTask(task);

            if (s_Logger.IsDebugEnabled)
            {
                s_Logger.Debug(string.Format("{0}({1})", MethodName, task));
            }
            return BaseUpdate(task);
        }
 public abstract bool HasSamePersistenceId(IPersistentObject other);
 public abstract IPersistentObject Create(IPersistentObject po);
 public abstract IPersistentObject Update(IPersistentObject po);
 public abstract IPersistentObject Delete(IPersistentObject po);
 public object GetPropertyValue(IPersistentObject po, string propertyName)
 {
     // NOP
     return null;
 }
        public ICollection<IPersistentObject> GetChildren(IPersistentObject po, string PropertyName)
        {
            Contract.Requires(Transaction.Current != null);
            Contract.Requires(!string.IsNullOrEmpty(PropertyName));
            //Contract.Requires(IsOperational);

            return default(ICollection<IPersistentObject>);
        }
 public IPersistentObject Delete(IPersistentObject po)
 {
     // NOP
     return null;
 }
 public void SetProxy(IAopProxy target)
 {
     this.target = (IPersistentObject)target;
 }
        public bool HasSamePersistenceId(IPersistentObject other)
        {
            Contract.Ensures(Contract.Result<bool>() ==
                             (other == null
                                  ? false
                                  : !other.PersistenceId.HasValue || !PersistenceId.HasValue
                                        ? false
                                        : PersistenceId.Value == other.PersistenceId.Value));

            return default(bool);
        }
        public IPersistentObject Create(IPersistentObject po)
        {
            Task task = po as Task;

            if (task != null)
            {
                // Make sure that IsTransient contract check will not fail...
                po.PersistenceId = 0;
                m_Tasks.Add(task);
            }
            return task;
        }
 public abstract object GetPropertyValue(IPersistentObject po, string PropertyName);
 public abstract ICollection<IPersistentObject> GetChildren(IPersistentObject po, string PropertyName);