public void Find_Specification_Sort_User() { var orderRepository = LocalServiceLocator.GetService <IYmtUserRepository>(); var result = orderRepository.Find(e => e.ModifyTime, System.Data.SqlClient.SortOrder.Descending); Assert.AreEqual(result.First().Id, result.First().Id); }
public override TaskContinuation Execute() { LocalLoggingService.Info("开始初始化持久化服务"); try { BuildManagerWrapper.Current.PublicTypes.Where(e => e != null && e.IsSubclassOf(typeof(StorageContext)) && !e.IsAbstract) .Each(e => { using (StorageContext context = LocalServiceLocator.GetService <IDbContextFactory>().CreateContext(e)) { context.Database.CreateIfNotExists(); var script = ((IObjectContextAdapter)context).ObjectContext.CreateDatabaseScript(); if (!string.IsNullOrEmpty(script)) { try { context.Database.ExecuteSqlCommand(script); } catch (Exception ex) { LocalLoggingService.Warning(ex.ToString()); } } //Console.WriteLine(script); } }); LocalLoggingService.Info("初始化持久化服务完成"); } catch (Exception ex) { LocalLoggingService.Error("开始初始化持久化服务失败,异常信息:{0}", ex); return(TaskContinuation.Break); } return(TaskContinuation.Continue); }
public void Find_S_S_D_User() { var orderRepository = LocalServiceLocator.GetService <IYmtUserRepository>(); var result = orderRepository.Find(Specifications.Specification <YmtUser> .Parse(e => e.IsDelete).SatisfiedBy(), e => e.ModifyTime, System.Data.SqlClient.SortOrder.Descending); Assert.AreEqual(2, result.Count()); }
public void TestConnectionProvider() { IConnectionProvider connectionProvider = LocalServiceLocator.GetService <IConnectionProvider>(); IDbConnection conn = connectionProvider.GetConnection("CustomerDbContext"); Console.WriteLine(conn.ConnectionString); }
public void Ef_Stats_Count() { var orderRepository = LocalServiceLocator.GetService <IYmtOrderRepository>(); var sumPrice = orderRepository.Count(Specifications.AnySpecification <YmtOrder> .CreateAnySpecification().SatisfiedBy()); Console.WriteLine(sumPrice); }
public JsonResult Register(RegisterDTO registerInfo) { return(new JsonResult() { Data = LocalServiceLocator.GetService <IPassportService>().Register(registerInfo) }); }
public void TestStorageContext() { string customerId = null; using (MySqlContext context = LocalServiceLocator.GetService <IDbContextFactory>().CreateContext <MySqlContext>()) { context.Customers.Each(e => context.Customers.Remove(e)); context.SaveChanges(); } using (MySqlContext context = LocalServiceLocator.GetService <IDbContextFactory>().CreateContext <MySqlContext>()) { Customer c = new Customer(); c.FirstName = "James"; c.LastName = "Chan"; context.Customers.Add(c); context.SaveChanges(); customerId = c.Id; } using (MySqlContext context = LocalServiceLocator.GetService <IDbContextFactory>().CreateContext <MySqlContext>()) { Customer c = context.Customers.Find(customerId); if (c != null) { c.FirstName = "Alex"; context.SaveChanges(); } } }
public GetAlarmItemsResult GetAlarmItems(AlarmStatus status, MongodbAdminConfigurationItem admin, int pageSize, int pageIndex) { try { var databases = admin.MongodbAdminDatabaseConfigurationItems.Values.Select(b => b.DatabasePrefix).Distinct().ToList(); var tables = admin.MongodbAdminDatabaseConfigurationItems.Values.SelectMany(b => b.MongodbAdminTableConfigurationItems).Select(c => c.Value.TableName).Distinct().ToList(); GetAlarmItemsResult r = new GetAlarmItemsResult(); var dbContextFactory = LocalServiceLocator.GetService <IDbContextFactory>(); using (var context = dbContextFactory.CreateContext <AlarmDbContext>()) { var q = context.AlarmItems.Where(_ => _.AlarmStatusId == (int)status); if (!databases.Contains("*")) { q = q.Where(_ => databases.Contains(_.AlarmDatabaseName)); } if (!tables.Contains("*")) { q = q.Where(_ => tables.Contains(_.AlarmTableName)); } r.Count = q.Count(); r.Data = q.OrderByDescending(_ => _.OpenTime) .Skip(pageIndex * pageSize).Take(pageSize).ToList(); return(r); } } catch (Exception ex) { ex.Handle("GetAlarmItems"); throw; } }
private static bool AlarmIsHandling(string configName) { try { var dbContextFactory = LocalServiceLocator.GetService <IDbContextFactory>(); using (var context = dbContextFactory.CreateContext <AlarmDbContext>()) { var item = context.AlarmItems.FirstOrDefault(a => a.AlarmStatusId != (int)AlarmStatus.Closed && a.AlarmConfigName == configName); if (item != null) { if (item.AlarmStatus != AlarmStatus.Closed) { item.AlarmTimes++; context.SaveChanges(); } if (item.AlarmStatus == AlarmStatus.Handling) { return(true); } } return(false); } } catch (Exception ex) { ex.Handle(AlarmConfigurationBase.ModuleName, "AlarmService", "AlarmIsHandling"); return(false); } }
public void Conncrete_Table_Inheritance_TPC() { var t11 = new T11(Guid.NewGuid().ToString("N")); t11.T111 = 12; t11.T112 = "ok"; Assert.AreEqual(true, t11.Validator().Success); var t11Repository = LocalServiceLocator.GetService <IT11Repository>(); t11Repository.Add(t11); var result = t11Repository.Context.Commit(); Assert.AreEqual(1, result.ResultData); var t12 = new T12(Guid.NewGuid().ToString("N")); t12.T111 = t11.T111; t12.T112 = t11.T112; t12.T121 = 12; Assert.AreEqual(true, t12.Validator().Success); var t12Repository = LocalServiceLocator.GetService <IT11Repository>(); t12Repository.Add(t12); result = t12Repository.Context.Commit(); Assert.AreEqual(1, result.ResultData); }
private static void CreateAlarmEvent(AlarmConfigurationItemBase configItem) { try { var dbContextFactory = LocalServiceLocator.GetService <IDbContextFactory>(); using (var context = dbContextFactory.CreateContext <AlarmDbContext>()) { var item = context.AlarmItems.FirstOrDefault(a => a.AlarmStatusId != (int)AlarmStatus.Closed && a.AlarmConfigName == configItem.ConfigName); if (item == null) { item = new AlarmItem() { AlarmDatabaseName = configItem.DatabasePrefix, AlarmTableName = configItem.TableName, AlarmConfigName = configItem.ConfigName, AlarmStatus = AlarmStatus.Open, OpenTime = DateTime.Now, }; context.AlarmItems.Add(item); context.SaveChanges(); } } } catch (Exception ex) { ex.Handle(AlarmConfigurationBase.ModuleName, "AlarmService", "CreateAlarmEvent"); } }
public void TestStorageContext() { AdhesiveFramework.Start(); IDbContextFactory dbContextFactory = LocalServiceLocator.GetService <IDbContextFactory>(); //string customerId = null; //using (CustomerDbContext context = dbContextFactory.CreateContext<CustomerDbContext>()) //{ // context.Customers.Each(e => context.Customers.Remove(e)); // context.SaveChanges(); //} using (CustomerDbContext context = dbContextFactory.CreateContext <CustomerDbContext>()) { Customer c = new Customer(); c.FirstName = "James"; c.LastName = "Chan"; context.Customers.Add(c); context.SaveChanges(); //customerId = c.Id; } //using (CustomerDbContext context = dbContextFactory.CreateContext<CustomerDbContext>()) //{ // Customer c = context.Customers.Find(customerId); // if (c != null) // { // c.FirstName = "Alex"; // context.SaveChanges(); // } //} AdhesiveFramework.End(); }
public JsonResult NewArticlePost(ArticleDTO articleDTO) { var result = new Result <string>(); if (String.IsNullOrEmpty(articleDTO.articleTitle)) { result.IsSuccess = false; result.ReturnMessage = "没有标题"; } else if (String.IsNullOrEmpty(articleDTO.articleCopyright)) { result.IsSuccess = false; result.ReturnMessage = "没有来源"; } else if (String.IsNullOrEmpty(articleDTO.articleContain)) { result.IsSuccess = false; result.ReturnMessage = "没有填写内容"; } else { var data = LocalServiceLocator.GetService <IMyBlogService>().AddNewArticle(articleDTO); result.IsSuccess = data.IsSuccess; result.ReturnMessage = data.ReturnMessage; result.ReturnValue = data.ReturnValue.ToString(); } return(new JsonResult() { Data = result }); }
public void FindList_Order() { var orderRepository = LocalServiceLocator.GetService <IYmtOrderRepository>(); var allList = orderRepository.Find(Specifications.Specification <YmtOrder> .CreateAnySpecification().SatisfiedBy()); Assert.IsNotNull(allList); }
public void TestRepository() { AdhesiveFramework.Start(); Customer c2 = null; IDbContextFactory dbContextFactory = LocalServiceLocator.GetService <IDbContextFactory>(); IRepositoryFactory repositoryFactory = LocalServiceLocator.GetService <IRepositoryFactory>(); using (IAdhesiveUnitOfwork adhesiveUnitOfWork = dbContextFactory.CreateContext <AdhesiveUnitOfwork>()) { ICustomerRepository customerRepository = repositoryFactory.CreateRepository <Customer, CustomerRepository>(adhesiveUnitOfWork); var c1 = new Customer { FirstName = "James", LastName = "Chan" }; customerRepository.Add(c1); customerRepository.UnitOfWork.Commit(); c2 = customerRepository.Get(c1.Id); Assert.IsNotNull(c2); } using (IAdhesiveUnitOfwork adhesiveUnitOfWork = dbContextFactory.CreateContext <AdhesiveUnitOfwork>()) { ICustomerRepository customerRepository = repositoryFactory.CreateRepository <Customer, CustomerRepository>(adhesiveUnitOfWork); customerRepository.TrackItem(c2); c2.FirstName = "James"; customerRepository.UnitOfWork.Commit(); } AdhesiveFramework.End(); }
public void FindAll_User() { var userRepository = LocalServiceLocator.GetService <IYmtUserRepository>(); var allUser = userRepository.FindAll(); Assert.NotNull(allUser); }
public JsonResult CheckLogin(LoginModel loginInfo) { Result <UserInfoDTO> result; var svc = LocalServiceLocator.GetService <IPassportService>(); if (loginInfo.action == "login") { result = svc.CheckLogin(loginInfo.userName, loginInfo.password); } else if (loginInfo.action == "check") { result = svc.CheckUser(loginInfo.passport); } else { result = new Result <UserInfoDTO>() { IsSuccess = false, ReturnMessage = "不能识别的操作" }; } return(new JsonResult() { Data = result }); }
public void Find_Specification_User() { var orderRepository = LocalServiceLocator.GetService <IYmtUserRepository>(); var result = orderRepository.Find(Specifications.Specification <YmtUser> .Parse(e => !e.IsDelete).SatisfiedBy()); Assert.AreEqual(result.Count(), result.Count()); }
public void Multiple_UnitofWorkCommit() { Action work1 = () => { var t14Repo = LocalServiceLocator.GetService <IT14Repository>(); t14Repo.Add(new T14(Guid.NewGuid().ToString("N"), "ok")); t14Repo.Context.Commit(); //return t14Repo.Context; }; Action work2 = () => { var orderRepository = LocalServiceLocator.GetService <IYmtOrderRepository>(); var order = new YmtOrder("aacd0bc4-34e5-4c0f-a255-214d567698cd", "test_order", 77); order.AddOrderLine(new OrderLine(100)) .AddOrderLine(new OrderLine(120)) .AddOrderLine(new OrderLine(150)) .SetAddress(new ReceiptAddress { City = "A", Zip = "B", Street = "C" }); var verify = order.Validator(); Console.WriteLine(verify.Message); Assert.AreEqual(true, verify.Success); orderRepository.AddOrUpdate(e => e.Id, order); orderRepository.Context.Commit(); //return orderRepository.Context; }; MultipleUnitOfWorkBuilder.Instance.Commit(work1, work2); //using (MultipleUnitOfWorkBuilder.Instance.Append(work1).Append(work2).Commit()) //{ //}; }
public void FindPageList_Order() { var orderRepository = LocalServiceLocator.GetService <IYmtOrderRepository>(); var allList = orderRepository.Find(Specifications.Specification <YmtOrder> .CreateAnySpecification().SatisfiedBy(), e => e.Id, System.Data.SqlClient.SortOrder.Ascending, 1, 5); Assert.AreEqual(5, allList.Data.Count()); }
public Result <ArticleDTO> GetArticleByArticleID(int articleID) { var data = DbUtilityFactory.GetDbUtility().GetSingle <ArticleEntity>(a => a.articleID == articleID); if (data != null) { return(new Result <ArticleDTO>() { IsSuccess = true, ReturnMessage = "成功", ReturnValue = new ArticleDTO() { articleAbstract = data.articleAbstract, articleContain = data.articleContain, articleCopyright = data.articleCopyright, articleDate = data.articleDate, articleID = articleID, articleTitle = data.articleTitle, categoryID = data.categoryID, categoryName = LocalServiceLocator.GetService <IMyBlogService>().GetCategoryNameByCategoryID(data.categoryID).ReturnValue, userID = data.userID } }); } else { return(new Result <ArticleDTO>() { IsSuccess = false, ReturnMessage = "没有找到文章" }); } }
public void SaveBath_Order() { var orderRepository = LocalServiceLocator.GetService <IYmtOrderRepository>(); //var orderList = new HashSet<Ymt_OrderLine>(); for (var i = 0; i < 50000; i++) { //1. var order = new YmtOrder(Guid.NewGuid().ToString(), "ok", 20M); order.SetAddress(new ReceiptAddress { City = "A", Street = "B", Zip = "CCC" }); //2. //这里是DTO映射到实体 //var order = orderDto.MapTo<OrderDto, Ymt_Order>(); //3. //这里是实体验证(实体需要继承 IValidatableObject 接口),主意:如果不显示执行xx.Validatory 方法,程序会自动隐式执行实体验证 var val = order.Validator(); Assert.AreEqual(true, val.Success, val.Message); //验证的原始写法 //var entityValidator = EntityValidatorFactory.CreateValidator(); //Assert.AreEqual(false, entityValidator.IsValid(order)); //3. // orderRepository.Add(order); } //4 var result = orderRepository.Context.Commit(); Assert.AreEqual(true, result.Success); Assert.AreEqual(3, result.ResultData); }
public void Ef_Stats_Group() { var orderRepository = LocalServiceLocator.GetService <IYmtOrderRepository>(); var sumPrice = orderRepository.Group(Specifications.AnySpecification <YmtOrder> .CreateAnySpecification().SatisfiedBy(), e => e.Price).Select(e => e.Key); sumPrice.Each(e => Console.WriteLine(e)); //Console.WriteLine(sumPrice); }
public void Find_Include_Order() { var orderRepository = LocalServiceLocator.GetService <IYmtOrderRepository>(); var result = orderRepository.Find(Specifications.AnySpecification <YmtOrder> .CreateAnySpecification().SatisfiedBy() , e => e.OrderLineList , e => e.RAddress); //Assert.AreEqual(100006, result.Count()); }
public TResult OrderRepo <TResult>(Func <IYmtOrderRepository, TResult> repoAction) { using (var unitOfWork = LocalServiceLocator.GetService <IDbContextFactory>().CreateContext <YmtTradingUnitOfwork>(e => new YmtTradingUnitOfwork(e))) { var orderRepository = LocalServiceLocator.GetService <IRepositoryFactory>().CreateRepository <YmtOrder, YmtOrderRepository>(unitOfWork); return(repoAction(orderRepository)); } }
public void FindOne_Order() { var orderRepository = LocalServiceLocator.GetService <IRepositoryFactory>().CreateRepository <YmtOrder, YmtTradingUnitOfwork, YmtOrderRepository>(e => new YmtOrderRepository(e));// LocalServiceLocator.GetService<IYmtOrderRepository>(); var order = orderRepository.FindOne("97ec2cd1-650a-422a-af72-1b19c1bbc5d8"); Assert.AreEqual(null, order); }
public void Find_ExecuteScript() { var orderRepository = LocalServiceLocator.GetService <IYmtUserRepository>(); var result = orderRepository.ExecuteQuery("select * from [ymt_trading_user_3] with(nolock)"); Assert.NotNull(result); //Assert.AreEqual("2cfa3f9c-dd6d-4eb0-93f3-1750dd726e02", result.First().Id); }
public void OrderRepo(Action <IYmtOrderRepository> repoAction) { using (var unitOfWork = LocalServiceLocator.GetService <IEFUnitOfWork>("order")) { var orderRepository = LocalServiceLocator.GetService <IRepositoryFactory>().CreateRepository <YmtOrder, YmtOrderRepository>(unitOfWork); repoAction(orderRepository); } }
public void Ef_Stats_SyncSum() { var stopwatch = Stopwatch.StartNew(); var orderRepository = LocalServiceLocator.GetService <IYmtOrderRepository>(); var sumPrice = orderRepository.SumSync(Specifications.AnySpecification <YmtOrder> .CreateAnySpecification().SatisfiedBy(), e => e.Price); Console.WriteLine("结果:{0},耗时:{1} 毫秒", sumPrice, stopwatch.Elapsed.TotalMilliseconds); }
public void ExecuteSql() { var orderRepository = LocalServiceLocator.GetService <IYmtOrderRepository>(); orderRepository.ExecuteCommand(" update [ymt_trading_order_2] set Price=@price where id =@id" , new SqlParameter("@price", "1000") , new SqlParameter("@id", "aacd0bc4-34e5-4c0f-a255-214d567698cd")); }