public void ResolveAndInvoke(string mainModule, string moduleId, Form container) { ClientModuleElement moduleCfg = ConfigInstance.Modules.FirstOrDefault(m => m.Name.Equals(mainModule, StringComparison.InvariantCultureIgnoreCase)); if (moduleCfg == null) { throw new System.Configuration.ConfigurationErrorsException("主模块在模块配置中不存在!"); } SubModuleBuildElement sub = moduleCfg.MoubleBuild.FirstOrDefault(s => s.ModuleId == moduleId); if (sub == null) { throw new System.Configuration.ConfigurationErrorsException("子模块在模块配置中不存在!"); } using (ModuleRunScope scope = new ModuleRunScope()) { scope.SetVariable("mainForm", container); ModuleBuilder.BuildAndInvoke(sub, scope); if (scope.LastError != null) { throw scope.LastError; } } }
StepBasedExpressionItem <string> TempStrGetExpression() { StepBasedExpressionItem <string> item = new StepBasedExpressionItem <string>(); SubModuleBuildElement builder = new SubModuleBuildElement(); builder.BuildInstance = false; builder.Target = BuildTarget.ScopeResult; builder.Type = "XMLCrlLanTest.ClientDBobj, XMLCrlLanTest"; //目标类型 builder.AddStep(GetParamValueElement()); builder.AddStep(new ModuleMethodCallElement("ToText", new TypeValueElement[] { new TypeValueElement { Type = "object", Value = "$StepSwap" } } )); item.Builder = builder; return(item); }
public void DisposableScopeItemTest() { SubModuleBuildElement myBuilder = new SubModuleBuildElement { BuildInstance = true, ModuleId = "sc", Type = "", Target = BuildTarget.Instance }; myBuilder.AddStep(new ModuleConstructorElement { Arguments = new TypeValueElement[0] }); DisposableScopeItem item = new DisposableScopeItem { Builder = myBuilder }; using (ModuleRunScope scope = new ModuleRunScope()) { scope.SetVariable(item.Builder.ModuleId, item); using (item.Invoke(scope)) { //IExpressionItem<Target> } } }
public void CompositeModuleBuildTest() { SubModuleBuildElement wholeModule = new SubModuleBuildElement { BuildInstance = true, ModuleId = "KQ0430", Target = BuildTarget.Instance, Type = typeof(DBHR.ClientModule.BaseEditCalenderForm).GetNoVersionTypeName() }; ModuleBranch branch = getBranchTest(); #region 修正作为子集的数据设置 branch.Else.BuildInstance = false; branch.Else.ModuleId = null; branch.Else.Type = typeof(ModuleBuildStepElement).GetNoVersionTypeName(); branch.Else.Target = BuildTarget.ScopeResult; #endregion wholeModule.AddStep(branch); wholeModule.AddStep(new ModuleMethodCallElement { MethodName = "SetCalenderObjType", Parameters = new ModuleConstructorElement { Arguments = new TypeValueElement[] { new TypeValueElement { Type = "System.Type", Value = "DBHR.WinFormUnity.TestModule1, DBHR.WinFormUnity" } } } }); wholeModule.AddStep(new ModuleMethodCallElement { MethodName = "DoCreateFormControls" }); wholeModule.AddStep(new ModulePropertyElement { Name = "MdiParent", Value = "$mainForm" }); wholeModule.AddStep(new ModuleMethodCallElement { MethodName = "Show" }); string xmlStr = wholeModule.GetXmlDocString(true); SubModuleBuildElement restore = wholeModule.GetXmlDoc(true).GetObject <SubModuleBuildElement>(); Assert.AreEqual(restore.ModuleId, wholeModule.ModuleId); using (Form container = new Form1()) { using (ModuleRunScope scope = new ModuleRunScope()) { scope.SetVariable("mainForm", container); wholeModule.InvokeInScope(scope); if (scope.LastError != null) { throw scope.LastError; } } } }
ModuleBranch getBranchTest(bool sharedMoudle = false) { ModuleBranch branch = new ModuleBranch { }; //if (sharedMoudle) // branch = ModuleBranch.GetScopeSharedModule(""); ModuleWhen myWhen = new ModuleWhen(); ConditionalElement match = new ConditionalElement(); match.AddItem(new StringConditionItem { ExpressionLeft = TempStrGetExpression(), ComparisonMode = StringComparison.InvariantCultureIgnoreCase, BooleanCompareDelegate = "XmlClrLan.ConditionalElement.StringNotEqual, XmlClrLan", ExpressionRight = (StringExpressItem)"1", }); myWhen.Match = match; myWhen.AddStep(new ModuleMethodCallElement { MethodName = "AddMainType", Parameters = new ModuleConstructorElement { Arguments = new TypeValueElement[] { new TypeValueElement { Type = "System.Type", Value = "DBHR.WinFormUnity.TestModule2, DBHR.WinFormUnity" } } } }); branch.Conditions = new ModuleWhen[] { myWhen, myWhen }; //Else SubModuleBuildElement elseModule = new SubModuleBuildElement { }; elseModule.AddStep(new ModuleMethodCallElement { MethodName = "AddDetailType", Parameters = new ModuleConstructorElement { Arguments = new TypeValueElement[] { new TypeValueElement { Type = "System.Type", Value = "DBHR.WinFormUnity.TestModule1, DBHR.WinFormUnity" }, new TypeValueElement { Type = "System.Type", Value = "DBHR.WinFormUnity.TestModule2, DBHR.WinFormUnity" } } } }); branch.Else = elseModule; return(branch); }
public void ConfigTest() { ContainerConfiguration cfg = new ContainerConfiguration(); List <ClientModuleElement> mList = new List <ClientModuleElement>(); SubModuleBuildElement builder = new SubModuleBuildElement { Type = "DBHR.ClientModule.BaseEditForm, DBHR.ClientModule", ModuleId = "SP1010" }; #region 方法调用 builder.AddStep(new ModuleMethodCallElement { MethodName = "AddMainType", //When = new ConditionalElement { // Executable = false //}, Parameters = new ModuleConstructorElement { Arguments = new TypeValueElement[] { new TypeValueElement { Type = "System.Type", Value = "DBHR.WinFormUnity.TestModule1, DBHR.WinFormUnity" } } } }); builder.AddStep(new ModuleMethodCallElement { MethodName = "AddMainType", Parameters = new ModuleConstructorElement { Arguments = new TypeValueElement[] { new TypeValueElement { Type = "System.Type", Value = "DBHR.WinFormUnity.TestModule2, DBHR.WinFormUnity" } } } }); builder.AddStep(new ModuleMethodCallElement { MethodName = "AddDetailType", Parameters = new ModuleConstructorElement { Arguments = new TypeValueElement[] { new TypeValueElement { Type = "System.Type", Value = "DBHR.WinFormUnity.TestModule1, DBHR.WinFormUnity" }, new TypeValueElement { Type = "System.Type", Value = "DBHR.WinFormUnity.TestModule2, DBHR.WinFormUnity" } } } }); builder.AddStep(new ModuleMethodCallElement { MethodName = "DoCreateFormControls" }); #endregion #region 属性设置 builder.AddStep(new ModulePropertyElement { Name = "MdiParent", Value = "$mainForm" }); #endregion #region 方法调用 builder.AddStep(new ModuleMethodCallElement { MethodName = "Show" }); #endregion ClientModuleElement m = new ClientModuleElement() { Name = "SP", Type = "DBHR.ClientModule.StartUpModule, DBHR.ClientModule", MoubleBuild = new SubModuleBuildElement[] { builder } }; mList.Add(m); cfg.Modules = mList.ToArray(); XmlDocument xDoc = cfg.GetXmlDoc(true); var xmlstr = cfg.GetXmlDocString(true); //cfg.GetXmlDoc().WriteIndentedContent(Console.Out); var cfgObj = xDoc.GetObject <ContainerConfiguration>(); string xmlStr2 = cfgObj.GetXmlDocString(true); Assert.AreEqual(xmlstr.XmlUtf8BOMClear(), xmlStr2.XmlUtf8BOMClear()); }