public void IOCFactoryTest() { //无参构造函数测试 var f = new IOCFactory(); Assert.IsNotNull(f.Assemblies); Assert.AreEqual(0, f.Assemblies.Length); Assert.IsNull(f.Container); Assert.IsNull(f.Builder); f.Dispose(); //操作选项传递测试 var op = new FactoryOption(); f = new IOCFactory(op, this.GetType().Assembly); Assert.IsNotNull(f.Assemblies); Assert.AreEqual(op, f.Option); Assert.IsNull(f.Container); Assert.IsNull(f.Builder); f.Dispose(); //测试无任何操作 op = new FactoryOption { InitOption = InitOptionEnum.None }; f = new IOCFactory(op, this.GetType().Assembly); Assert.IsNotNull(f.Assemblies); Assert.AreEqual(op, f.Option); Assert.IsNull(f.Container); Assert.IsNull(f.Builder); f.Dispose(); }
public void AssemblyRegisterTest() { using (var f = new IOCFactory("CommonClass.FactoryTestHelperAssembly")) { f.Init(); Assert.IsTrue(f.Container.IsRegistered <FactoryTestHelperAssembly.II1>(), "检测IC1注册失败"); } }
static void Main(string[] args) { try { //1:初始化容器和服务 IOCFactory.InitContainer(); ICategoryService categoryService = IOCFactory.Resolve <ICategoryService>(); //2:初始化数据库 InitDb(categoryService); //3:插入类别数据 LoadCategory(categoryService); //4:加载明细数据并将数据插入到db中 LoadCommodty(categoryService); } catch (Exception ex) { //如果其中一个线程出现异常,那么就终止所有其他线程 cts.Cancel(); ctsPrice.Cancel(); //出现异常中断其他运行的线程 Console.WriteLine("页面抓取出现异常:{0}", ex.Message); } Console.ReadLine(); }
public CompensationFacade(ModelName model, IBusinessAPI _api, IOCparamters _parameters, int _channel_num) { api = _api; parameters = _parameters; channel_num = _channel_num; factory = GetFactory(model); flash = GetFlashObject(model); }
public void DisposeTest() { var f = new IOCFactory(); f.Init(); Assert.IsNotNull(f.Container); f.Dispose(); Assert.IsNull(f.Container); }
public void InitTest() { var f = new IOCFactory(); Assert.AreEqual(InitOptionEnum.BuildContainer, f.Option.InitOption); f.Init(); Assert.IsNull(f.Builder); Assert.IsNotNull(f.Container); var c = f.Container.Resolve <ITestClass>(); Assert.IsNotNull(c); f.Dispose(); }
public void EventTest() { //BeforeBuild测试 using (var f = new IOCFactory()) { f.Init(); Assert.IsFalse(f.Container.IsRegistered <ITest2>()); } using (var f = new IOCFactory()) { f.BeforeBuild += (fa, c) => { c.Register(m => new TestClass2()).As <ITest2>(); }; f.Init(); Assert.IsTrue(f.Container.IsRegistered <ITest2>()); } }
public void DisposeTest() { var f = new IOCFactory(); f.Init(); Assert.IsNotNull(f.Container); var o = f.Container.Resolve <ITestClass>(); if (o is TestClass oc) { Assert.AreEqual(1, oc.Count); } f.Dispose(); var ooo = new TestClass(); Assert.AreEqual(1, ooo.Count); }
static void Main(string[] args) { try { #region 1.0 特性封装 Console.WriteLine("*************特性封装********************"); string strAndroid = MobileEnum.Android.GetRemark(); string strIOS = MobileEnum.IOS.GetRemark(); Console.WriteLine($"android备注:{strAndroid},ios的备注{strIOS}"); #endregion #region 2.0 封装方法 Console.WriteLine("*************Unity 使用********************"); //初始化unity IOCFactory.InitContainer(); Person person = new Person(); person.Address = "哈哈哈11111111"; person.Name = "dark"; person.Email = "*****@*****.**"; person.Phone = "18652428020"; ISQLHelper sqlHelper = IOCFactory.Resolve <ISQLHelper>(); sqlHelper.Insert <Person>(person); #endregion } catch (Exception ex) { Console.WriteLine($"系统异常:{ex.Message.ToString()}"); throw; } Console.ReadLine(); }
static void Main(string[] args) { IOCFactory iOCFactory = new IOCFactory(); iOCFactory.LoadAssmaly("MyIOC"); // 1、创建老师对象 // Teacher teacher = (Teacher)iOCFactory.GetObject("Teacher"); // 2、创建学生对象 Student student = (Student)iOCFactory.GetObject("Student"); //student.Teacher = teacher;//IOCFactory实现了属性的注入 //Undone:没有实现的功能 //1.实例生命周期的问题,实例作用域的问题 //2.循环依赖的问他:Student类中有Teacher属性,若是Teacher类中有Student类属性,则会因为递归实现属性的注入而造成内存移除 student.Study(); Console.ReadKey(); }
static void Main(string[] args) { try { #region 1.0 爬虫 //1:初始化容器和服务 IOCFactory.InitContainer(); ICategoryService categoryService = IOCFactory.Resolve <ICategoryService>(); ICommodityService commodityService = IOCFactory.Resolve <ICommodityService>(); //这个是爬虫的demo //CrawlerDemo(categoryService, commodityService); #endregion #region 2.0 lucene.net Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"*****************lucene.net demo*****************"); LuceneTools luceneTools = new LuceneTools(commodityService); //luceneTools.InitLucene(); luceneTools.QueryList("Title:asus", new Page() { Sort = "Price" }, "[100,200]"); #endregion #region 3.0 redis 异步队列 //3.1 启动异步队列 Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine($"*****************启动一个异步队列*****************"); RedisTools.Current.Start(luceneTools); //3.2 添加一个实体 Console.WriteLine($"1.0 添加一个实体到数据"); GM_Commodity commodity = new GM_Commodity() { Title = "华硕(asus),测试数据", ImageUrl = "", Price = 150, ProductId = "11", SkuId = "11", Url = "http://www.baidu.com" }; int id = commodityService.Insert(commodity); Console.WriteLine($"2.0 添加一个实体到数据库,得到的Id={id}"); commodity.Id = id; //将该数据添加到异步队列中 Console.WriteLine($"3.0 更新实体到索引中"); RedisTools.Current.Add(commodity); //停留2秒中等待redis中的数据更新到index 中 Thread.Sleep(2000); Console.WriteLine($"4.0 在查询包含 asus的索引"); luceneTools.QueryList("Title:asus", new Page() { Sort = "Price" }, "[100,200]"); #endregion } catch (Exception ex) { //如果其中一个线程出现异常,那么就终止所有其他线程 cts?.Cancel(); ctsPrice?.Cancel(); //出现异常中断其他运行的线程 Console.WriteLine("页面抓取出现异常:{0}", ex.Message); } Console.ReadLine(); }
public override string ToString() { stamps = new List <SingleStamp>(); IApplicationAction appaction = IOCFactory.GetInstance <IApplicationAction>(); IApplication application = IOCFactory.GetInstance <IApplication>(); ApplicationUI app = application.GetpplicationByID(this.applicationId); List <ApplicationActionUI> appcationList = appaction.GetApplicationActionByAppID(this.applicationId, action); if (appcationList != null && appcationList.Count > 0) { foreach (var item in appcationList) { var actionuser = item.ActionUserName; if (item.Action == (int)ApprovalAction.Create && !string.IsNullOrEmpty(item.AgentToUserName) && item.AgentToUserName != item.ActionUserName) { actionuser = item.AgentToUserName.Trim(); } stamps.Add(new SingleStamp() { ImgPath = imgPathBase + GetAppActionPicture((ApprovalAction)item.Action), Line1 = actionuser, Line2 = item.ActionTime.ToString("yyyy-MM-dd"), ToolTips = EnumDataSource <ApprovalAction> .GetDisplayValue(item.Action, "zh-cn") }); } if (action != ApprovalAction.Approve) { IAttendance leave = IOCFactory.GetInstance <IAttendance>(); IApplication iapplication = IOCFactory.GetInstance <IApplication>(); List <TaskUserExtendUI> taskListuser = iapplication.GetApplicationToDoTaskWithUser(this.applicationId); List <TaskGroupExtendUI> taskListgroup = iapplication.GetApplicationToDoTaskWithGroup(this.applicationId); if (app.Status == (int)ApplicationStatus.Pending) { string todouser = string.Empty; if (taskListuser != null && taskListuser.Count > 0) { int length = taskListuser.Count; for (int i = 0; i < length; i++) { todouser = todouser + taskListuser[i].vwEmpBasicInfo.ChineseName + ";"; } } if (taskListgroup != null && taskListgroup.Count > 0) { int length = taskListgroup.Count; for (int i = 0; i < length; i++) { todouser = todouser + taskListgroup[i].AuthorizationGroup.NAME + ";"; } } todouser = todouser.Trim(';'); stamps.Add(new SingleStamp() { ImgPath = imgPathBase + imgPending, Line1 = todouser, Line2 = "", ToolTips = "待处理" }); } } //string CNTitle = "<p>" + Resources.NameResource.Process + " (" + Resources.NameResource.Current + ":"; //int count = appcationList.Count - 1; //string Status = appcationList[count].ActionUserName + " " + EnumDataSource<ApprovalAction>.GetDisplayValue(appcationList[count].Action, "zh-cn"); //string TotalContent = CNTitle + Status + ")</p>"; //return TotalContent + base.ToString(); return(base.ToString()); } else { return(string.Empty); } }