public void Test() { var name = "ServerTest.Test"; var context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name"); context.GetType().GetMethod("DeleteFile", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(context, null); context.Add(new MyDataItem() { Name = "MyName1", Company = "Microsoft" }); context.Add(new MyDataItem() { Name = "MyName2", Company = "abc" }); context.Dispose(); context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name"); if (context.Count != 2) { throw new Exception("数量不对"); } if (context.FirstOrDefault(m => m.Name == "MyName2") == null) { throw new Exception("数据不对"); } context.Dispose(); }
public void RepeatCheck() { var filepath = "RepeatCheck"; var context = new StorageContext <MyDataItem>(filepath, "Name", true); context.Add(new MyDataItem() { Name = "MyName1", Company = "Microsoft" }); try { context.Add(new MyDataItem() { Name = "MyName1", Company = "Microsoft" }); throw new Exception("重复数据也能添加"); } catch { } context.Dispose(); System.IO.File.Delete(filepath); }
public IActionResult NewUser(ValidatedUser validatedUser) { if (ModelState.IsValid) { var users = context.users.Where(x => x.email == validatedUser.email).ToList(); if (users.Count == 0) { var user = new User { first_name = validatedUser.first_name, last_name = validatedUser.last_name, email = validatedUser.email, }; var hasher = new PasswordHasher <User>(); user.password = hasher.HashPassword(user, validatedUser.password); context.Add(user); context.SaveChanges(); HttpContext.Session.SetInt32("user", user.id); return(RedirectToAction("Main")); } else { } } return(View("Register")); }
public void Add() { var name = "ServerTest.Add"; var context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name"); context.GetType().GetMethod("DeleteFile", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(context, null); System.Threading.Tasks.Parallel.For(0, 100, (i) => { var item = new MyDataItem(); item.Name = "Jack" + i; context.Add(item); }); context.Dispose(); context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name"); if (context.Count != 100) { throw new Exception("数量不对,当前数量:" + context.Count); } for (int i = 0; i < 100; i++) { if (context.Any(m => m.Name == "Jack" + i) == false) { throw new Exception("没有这个对象"); } } context.Dispose(); }
public void AddAsync() { var filepath = "server.PerformanceTest.async"; var total = 1000000; var context = new StorageContext <MyDataItem>("localhost", 8227, filepath, "Name", true); context.GetType().GetMethod("DeleteFile", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(context, null); var item2 = new MyDataItem(); item2.Name = "awef0"; context.Add(item2); context.Dispose(); context = new StorageContext <MyDataItem>("localhost", 8227, filepath, "Name", true); System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); System.Diagnostics.Stopwatch watch2 = new System.Diagnostics.Stopwatch(); watch2.Start(); watch.Start(); for (int i = 0; i < total; i++) { var item = new MyDataItem(); item.Name = "Jack" + i; context.Add(item); } watch.Stop(); Debug.WriteLine($"{total/10000}万数据写入总耗时:{watch.ElapsedMilliseconds}ms"); context.Dispose(); watch2.Stop(); Debug.WriteLine($"写入文件总耗时:{watch2.ElapsedMilliseconds}ms"); }
public void Read() { var filepath = "server.PerformanceTest2"; var context = new StorageContext <MyDataItem>("localhost", 8227, filepath, "Name"); context.GetType().GetMethod("DeleteFile", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(context, null); var item2 = new MyDataItem(); item2.Name = "awef0"; context.Add(item2); context.Dispose(); System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); context = new StorageContext <MyDataItem>("localhost", 8227, filepath, "Name"); for (int i = 0; i < 100000; i++) { var item = new MyDataItem(); item.Name = "Jack" + i; context.Add(item); } watch.Stop(); Debug.WriteLine($"总耗时:{watch.ElapsedMilliseconds}ms"); watch.Reset(); watch.Start(); var list = context.Where(m => m.Name.Contains("ack1")).ToArray(); watch.Stop(); Debug.WriteLine($"读取总耗时:{watch.ElapsedMilliseconds}ms"); }
public void SyncAdd() { var filepath = "PerformanceTest"; var context = new StorageContext <MyDataItem>(filepath, "Name", false); var item2 = new MyDataItem(); item2.Name = "awef0"; context.Add(item2); context.Dispose(); System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); context = new StorageContext <MyDataItem>(filepath, "Name"); for (int i = 0; i < 1000000; i++) { var item = new MyDataItem(); item.Name = "Jack" + i; context.Add(item); } watch.Stop(); Debug.WriteLine($"同步写入总耗时:{watch.ElapsedMilliseconds}ms"); context.Dispose(); System.IO.File.Delete(filepath); }
public void Read() { var filepath = "PerformanceTest2"; var context = new StorageContext <MyDataItem>(filepath, "Name"); var item2 = new MyDataItem(); item2.Name = "awef0"; context.Add(item2); context.Dispose(); System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); context = new StorageContext <MyDataItem>(filepath, "Name"); for (int i = 0; i < 1000000; i++) { var item = new MyDataItem(); item.Name = "Jack" + i; context.Add(item); } watch.Stop(); Debug.WriteLine($"总耗时:{watch.ElapsedMilliseconds}ms"); watch.Reset(); watch.Start(); var list = context.Where(m => m.Name.Contains("ack1")).ToArray(); watch.Stop(); Debug.WriteLine($"读取总耗时:{watch.ElapsedMilliseconds}ms"); System.IO.File.Delete(filepath); }
public async Task<IActionResult> Create([Bind("Id,Name,Price,OrderDate,Shelf,Count,Description,Category")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); } return View(product); }
public async Task <IActionResult> Create([Bind("Id,ItemName,ItemWeight,StorageSector,PlacementDate")] StorageItem storageItem) { if (ModelState.IsValid) { _context.Add(storageItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(storageItem)); }
public async Task <IActionResult> Create([Bind("Id,Name,Amount")] StockItem stockItem) { if (ModelState.IsValid) { _context.Add(stockItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(stockItem)); }
public async Task <IActionResult> Create([Bind("Id,StorageName,StreetName,City,Postal,Telephone")] Storage storage) { if (ModelState.IsValid) { _context.Add(storage); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(storage)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,DateOfBirth,Phone,ClientType")] StorageClient storageClient) { if (ModelState.IsValid) { _context.Add(storageClient); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(storageClient)); }
public async Task <IActionResult> Create([Bind("Id,RackPosition")] PalletItemsViewModel palletItem) { if (ModelState.IsValid) { _context.Add(new Pallet()); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(palletItem.Pallet)); }
public async Task <IActionResult> Create([Bind("Id,Name,Price,Orderdate,Category,Count,Shelf,Description")] Product product) { if (ModelState.IsValid) { db.Add(product); await db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("Rental_Number,Rental_StartDate,Rental_EndDate,Rental_Price,Rental_Locator,Rental_CheckedIn,Size_ID,Venue_ID,Student_ID")] DBStorageRental dBStorageRental) { if (ModelState.IsValid) { _context.Add(dBStorageRental); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(dBStorageRental)); }
public async Task <IActionResult> Create([Bind("Id,Available,PalletId,Height,Width,RackPosition")] Position position) { if (ModelState.IsValid) { _context.Add(position); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PalletId"] = new SelectList(_context.Pallets, "Id", "Id", position.PalletId); return(View(position)); }
public async Task <IActionResult> Create([Bind("Id,Name,Price,OrderDate,Category,Shelf,Count,Description")] Product product) { if (ModelState.IsValid) { _context.Add(product); if (!_context.Categories.ToList().Contains(new Category() { Name = product.Name })) { _context.Add(new Category() { Name = product.Name }); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public void Normal() { var filepath = "temp"; var context = new StorageContext <MyDataItem>(filepath, "Name"); context.Add(new MyDataItem() { Name = "MyName1", Company = "Microsoft" }); context.Add(new MyDataItem() { Name = "MyName1", Company = "Microsoft" }); context.Remove(context.Where(m => m.Name.Contains("My"))); context.Dispose(); System.IO.File.Delete(filepath); }
public void Remove() { var name = "ServerTest.Remove"; var context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name"); context.GetType().GetMethod("DeleteFile", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(context, null); System.Threading.Tasks.Parallel.For(0, 100, (i) => { var item = new MyDataItem(); item.Name = "Jack" + i; context.Add(item); }); if (context.Count != 100) { throw new Exception("数量不对"); } context.Dispose(); context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name"); if (context.Count != 100) { throw new Exception("数量不对"); } var datas = context.ToArray(); System.Threading.Tasks.Parallel.For(0, datas.Length, (i) => { context.Remove(datas[i]); }); context.Dispose(); context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name"); if (context.Count != 0) { throw new Exception("数量不对"); } context.Dispose(); }
public void Remove() { var filepath = "Remove"; var context = new StorageContext <MyDataItem>(filepath, "Name"); System.Threading.Tasks.Parallel.For(0, 10000, (i) => { var item = new MyDataItem(); item.Name = "Jack" + i; context.Add(item); }); if (context.Count != 10000) { throw new Exception("数量不对"); } context.Dispose(); context = new StorageContext <MyDataItem>(filepath, "Name"); if (context.Count != 10000) { throw new Exception("数量不对"); } var datas = context.ToArray(); System.Threading.Tasks.Parallel.For(0, datas.Length, (i) => { context.Remove(datas[i]); }); context.Dispose(); context = new StorageContext <MyDataItem>(filepath, "Name"); if (context.Count != 0) { throw new Exception("数量不对"); } System.IO.File.Delete(filepath); }
public void Update() { var name = "ServerTest.Update"; var context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name"); context.GetType().GetMethod("DeleteFile", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(context, null); System.Threading.Tasks.Parallel.For(0, 10, (i) => { var item = new MyDataItem(); item.Name = "Jack" + i; context.Add(item); }); if (context.Count != 10) { throw new Exception("数量不对"); } var obj = context.FirstOrDefault(m => m.Name == "Jack5"); obj.Company = "abc"; context.Update(obj); context.Dispose(); context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name"); if (context.Count != 10) { throw new Exception("数量不对"); } obj = context.FirstOrDefault(m => m.Name == "Jack5"); if (obj.Company != "abc") { throw new Exception("数据错误"); } context.Dispose(); }
public void Update() { var filepath = "Update"; var context = new StorageContext <MyDataItem>(filepath, "Name"); System.Threading.Tasks.Parallel.For(0, 10, (i) => { var item = new MyDataItem(); item.Name = "Jack" + i; context.Add(item); }); if (context.Count != 10) { throw new Exception("数量不对"); } var obj = context.FirstOrDefault(m => m.Name == "Jack5"); obj.Company = "abc"; context.Update(obj); context.Dispose(); context = new StorageContext <MyDataItem>(filepath, "Name"); if (context.Count != 10) { throw new Exception("数量不对"); } obj = context.FirstOrDefault(m => m.Name == "Jack5"); if (obj.Company != "abc") { throw new Exception("数据错误"); } System.IO.File.Delete(filepath); }
public void Add() { var filepath = "Add"; var context = new StorageContext <MyDataItem>(filepath, "Name"); System.Threading.Tasks.Parallel.For(0, 10000, (i) => { var item = new MyDataItem(); item.Name = "Jack" + i; context.Add(item); }); if (context.Count != 10000) { throw new Exception("数量不对"); } context.Dispose(); context = new StorageContext <MyDataItem>(filepath, "Name"); if (context.Count != 10000) { throw new Exception("数量不对"); } for (int i = 0; i < 10000; i++) { if (context.Any(m => m.Name == "Jack" + i) == false) { throw new Exception("没有这个对象"); } } System.IO.File.Delete(filepath); }