예제 #1
0
        public MemoryTest()
        {
            _store = new MemoryStore();
            _session = _store.CreateSession();

            // Ensure the identity cache is fresh
            IdentityFactory.Clear();
        }
예제 #2
0
        public void GenericTools_Data_MemorySession()
        {
            using (var session = new MemorySession())
            {
                var db = session.Database <SampleModel>();
                db.Add(new SampleModel());

                var db2 = session.Database <SampleModel>();
                MakeSure.That(db2.Count).Is(1);
            }
        }
예제 #3
0
        public ItemRepositoryMongo(IMongoDatabase database, MemorySession <ItemDataModelBase> memorySession,
                                   IDataBlob mongoBlob, ICacheRepository cacheRepository)
        {
            _memorySession   = memorySession;
            _mongoBlob       = mongoBlob;
            _cacheRepository = cacheRepository;
            var collectionSettings = new MongoCollectionSettings {
                GuidRepresentation = GuidRepresentation.CSharpLegacy
            };

            _collection = database.GetCollection <Item>("site.item", collectionSettings);
        }
 public ItemRepositoryMock(MemorySession <ItemDataModelBase> memorySession)
 {
     this.memorySession = memorySession;
 }
예제 #5
0
파일: MemoryTest.cs 프로젝트: abaxas/Stored
 public MemoryTest()
 {
     _store = new MemoryStore();
     _session = _store.CreateSession();
 }
예제 #6
0
        public static void SaveChange(MemorySession <ItemDataModelBase> memorySession)
        {
            lock (database)
            {
                foreach (ItemDataModel o in memorySession.DatabaseDelete)
                {
                    var item = Database.FirstOrDefault(d => d.Id == o.Id);
                    Database.Remove(item);
                }

                foreach (ItemDataModel itemDataModel in memorySession.DatabaseAdd)
                {
                    var item = new Item();
                    item.Index       = itemDataModel.Index;
                    item.IsTemporary = itemDataModel.IsTemporary;
                    if (itemDataModel.Data != null)
                    {
                        item.Json = JsonConvert.SerializeObject(itemDataModel.Data);
                        //item.Type = itemDataModel.Data.GetType().FullName;
                    }
                    item.Module       = itemDataModel.Module;
                    item.ParentId     = itemDataModel.ParentId;
                    item.PropertyName = itemDataModel.PropertyName;
                    item.SiteId       = itemDataModel.SiteId;
                    item.CreateDate   = DateTime.Now;

                    if (string.IsNullOrEmpty(itemDataModel.Id))
                    {
                        item.Id = (Guid.NewGuid()).ToString();
                    }
                    else
                    {
                        item.Id = itemDataModel.Id;
                    }
                    itemDataModel.Id = item.Id;

                    Database.Add(item);
                    itemDataModel.Id = item.Id;
                }

                foreach (var itemDataModelBase in memorySession.DatabaseAdd)
                {
                    var itemDataModel = (ItemDataModel)itemDataModelBase;
                    if (itemDataModel.Childs != null)
                    {
                        foreach (var dataModel in itemDataModel.Childs)
                        {
                            if (dataModel.Parent == null)
                            {
                                dataModel.ParentId = itemDataModel.Id;
                            }
                            // TODO Code rapide moche + risque bug
                            var item = Database.FirstOrDefault(d => d.Id == dataModel.Id);
                            item.ParentId = itemDataModel.Id;
                        }
                    }
                }

                memorySession.DatabaseDelete.Clear();
                memorySession.DatabaseAdd.Clear();

                foreach (var itemDataModelBase in memorySession.DatabaseLoaded)
                {
                    var itemDataModel = (ItemDataModel)itemDataModelBase;
                    var item          = Database.FirstOrDefault(d => d.Id == itemDataModel.Id);

                    if (item == null)
                    {
                        continue;
                    }

                    item.Index       = itemDataModel.Index;
                    item.IsTemporary = itemDataModel.IsTemporary;
                    if (itemDataModel.Data != null)
                    {
                        item.Json = JsonConvert.SerializeObject(itemDataModel.Data);
                        //item.Type = itemDataModel.Data.GetType().FullName;
                    }
                    item.Module       = itemDataModel.Module;
                    item.ParentId     = itemDataModel.ParentId;
                    item.PropertyName = itemDataModel.PropertyName;
                    item.SiteId       = itemDataModel.SiteId;
                    item.UpdateDate   = DateTime.Now;
                    item.Id           = itemDataModel.Id;
                }

                Save();
            }
        }