public void Add(ProductVariant item) { var path = GetFilePath(item.UUID); IOUtility.EnsureDirectoryExists(Path.GetDirectoryName(path)); locker.EnterWriteLock(); try { Serialization.Serialize<ProductVariant>(item, path); } finally { locker.ExitWriteLock(); } }
public void Test_Add_Get_Update_Remove_ProductVariantProvider() { ProductVariantProvider provider = new ProductVariantProvider(new CommerceDataDir(new BaseDir())); var productVariant1 = new ProductVariant { UUID = "111", ProductId = 111 }; foreach(ProductVariant item in provider.All()) { provider.Remove(item); } //Add Get provider.Add(productVariant1); var productVariantActual = provider.Get(productVariant1); Assert.IsNotNull(productVariantActual); Console.WriteLine("Add ok!"); Console.WriteLine("Get ok!"); //All var productVariantAll = provider.All(); Assert.AreEqual(1, productVariantAll.Count()); Console.WriteLine("All ok!"); //Update var productVariant2 = new ProductVariant { UUID = "222", ProductId = 111, }; provider.Update(@productVariant2, productVariant1); var productVariantActual1 = provider.Get(productVariant1); Assert.IsNull(productVariantActual1); var productVariantActual2 = provider.Get(productVariant2); Assert.IsNotNull(productVariantActual2); Console.WriteLine("Update OK!"); //Remove provider.Remove(productVariant2); var productVariantActual3 = provider.Get(productVariant2); Assert.IsNull(productVariantActual3); Console.WriteLine("Remove OK!"); }
public void AddProductVariant(ProductVariant productVariant) { throw new NotImplementedException(); }
public ProductVariant Get(ProductVariant dummy) { var filepath = GetFilePath(dummy.UUID); if (File.Exists(filepath)) { locker.EnterReadLock(); try { var item = (ProductVariant)Serialization.Deserialize(dummy.GetType(), KnownTypes, filepath); return item; } finally { locker.ExitReadLock(); } } return default(ProductVariant); }
public void Update(ProductVariant @new, ProductVariant old) { Remove(old); Add(@new); }
public void Remove(ProductVariant item) { locker.EnterWriteLock(); try { var file = GetFilePath(item.UUID); if (File.Exists(file)) { File.Delete(file); } } finally { locker.ExitWriteLock(); } }