Beispiel #1
0
        private EntityTable EnsureDirectoryForType(Type t)
        {
            EntityTable table;

            if (!_subDirs.TryGetValue(t.Name, out table))
            {
                var di = _rootDirectoryInfo.CreateSubdirectory(t.Name);
                table             = new EntityTable(di);
                _subDirs [t.Name] = table;
            }

            return(table);
        }
Beispiel #2
0
        public Guid WriteEntity <T>(T e) where T : Entity
        {
            // Ensure the GUID here, we can be sure that they will call base
            if (e.Id == Guid.Empty)
            {
                e.Id = Guid.NewGuid();
            }

            EntityTable table = EnsureDirectoryForType(e.GetType());

            using (StreamWriter writer = new StreamWriter(PathForDirectoryAndID(table.Directory, e.Id)))
            {
                var serializer = MessagePackSerializer.Get <T> ();
                serializer.Pack(writer.BaseStream, e);
            }

            return(e.Id);
        }
Beispiel #3
0
        public T RetrieveEntity <T>(Guid id) where T : Entity
        {
            EntityTable table = EnsureDirectoryForType(typeof(T));

            return(InternalRead <T>(table.Directory, id));
        }