Пример #1
0
        private IPersistable LoadObject(string name, IPersistable obj)
        {
            string   fileName = PersistenceUtils.GetFilename(_scope, _path, name, _extension);
            FileInfo file     = _scope.Context.GetResource(fileName).File;

            if (!file.Exists)
            {
                return(null);               // No such file
            }
            IPersistable result = obj;

            lock (this.SyncRoot)
            {
                using (FileStream fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    AMFReader reader   = new AMFReader(fs);
                    string    typeName = reader.ReadData() as string;
                    result = ObjectFactory.CreateInstance(typeName) as IPersistable;
                    //result.Path = GetObjectPath(name, result.Name);
                    //result = amfDeserializer.ReadData() as IPersistable;
                    result.Deserialize(reader);
                }
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Get filename for persistable object.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private string GetObjectFilename(IPersistable obj)
        {
            string name = obj.Name;

            if (name == null)
            {
                name = MemoryStore.PersistenceNoName;
            }
            return(PersistenceUtils.GetFilename(_scope, _path, name, _extension));
        }
Пример #3
0
        public override bool Remove(string name)
        {
            base.Remove(name);
            string   fileName = PersistenceUtils.GetFilename(_scope, _path, name, _extension);
            FileInfo file     = _scope.Context.GetResource(fileName).File;

            if (!file.Exists)
            {
                // File already deleted
                return(true);
            }
            lock (this.SyncRoot)
            {
                file.Delete();
            }
            return(true);
        }