示例#1
0
        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;
                }
            }
        }
示例#2
0
        public void ModuleFieldElementTest()
        {
            string             method1 = "XMLCrlLanTest.TestClass.TestAction, XMLCrlLanTest";
            string             method2 = "DBHR.WinFormUnity.SPRun.TestMethod2, DBHR.WinFormUnity";
            ModuleFieldElement ml      = new ModuleFieldElement
            {
                Name      = "ActionTest",
                ValueType = new TypeValueElement {
                    Type = "System.Action<string,string>", Value = method2
                },
                Flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.SetField
            };

            SPRun sp = new SPRun();

            using (ModuleRunScope scope = new ModuleRunScope())
            {
                ml.InvokeInScope(sp.GetType(), sp, scope);
            }

            SPRun.ActionTest?.Invoke("Test public static Field", "Test");

            /*
             * <?xml version="1.0" encoding="utf-8"?>
             * <Binding name="ActionTest" flags="Static|Public|SetField">
             *          <ValueType type="System.Action&lt;System.String, System.String&gt;" value="DBHR.WinFormUnity.SPRun.TestMethod2, DBHR.WinFormUnity" />
             * </Binding>
             */
            string xmlStr = ml.GetXmlDocString(true);

            ModuleFieldElement restore = ml.GetXmlDoc(true).GetObject <ModuleFieldElement>();

            Assert.AreEqual(restore.Name, ml.Name);
        }
示例#3
0
        public void IndirectTypeValueElementTest()
        {
            IndirectTypeValueElement itv = new IndirectTypeValueElement
            {
                Value       = "FuncString",
                StaticField = true,
                Type        = "XMLCrlLanTest.TestClass, XMLCrlLanTest"
            };

            itv.AddStep(new ModuleMethodCallElement
            {
                MethodName = "Instance",
                StaticType = "XMLCrlLanTest.TestClass2, XMLCrlLanTest"
            });

            itv.AddStep(new InstanceMethodGetElement
            {
                MethodName            = "TestDelegate",
                OriginType            = InstanceOrigin.Context,
                MethodDelegatePattern = typeof(TestClass.MyFuncString).GetNoVersionTypeName(),
            });

            using (ModuleRunScope scope = new ModuleRunScope())
            {
                object testObj = itv.GetObjectValue(scope);
            }

            XmlDocument xDoc = itv.GetXmlDoc(true);
            IndirectTypeValueElement restore = xDoc.GetObject <IndirectTypeValueElement>();
        }
示例#4
0
        public void ConditionalTest()
        {
            ConditionalElement when = new ConditionalElement();

            when.AddItem(new StringConditionItem
            {
                ExpressionLeft  = TempStrGetExpression(),
                ExpressionRight = (StringExpressItem)"1",
            });

            using (ModuleRunScope scope = new ModuleRunScope())
            {
                Assert.IsTrue(when.CanRunInScope(scope));
            }

            XmlDocument xDoc   = when.GetXmlDoc(true);
            string      xmlStr = xDoc.GetXmlDocString(true);

            Trace.Write(xmlStr);

            ConditionalElement restore = xDoc.GetObject <ConditionalElement>();
            string             xmlStr2 = restore.GetXmlDocString(true);

            Trace.Write(xmlStr2);

            Assert.AreEqual(xmlStr.XmlUtf8BOMClear(), xmlStr2.XmlUtf8BOMClear());
        }
 /// <summary>
 /// 执行模块调用逻辑
 /// </summary>
 /// <param name="moduleId">模块完整编号</param>
 /// <param name="mainForm">窗体容器</param>
 /// <param name="customWhere">附加条件</param>
 /// <exception cref="NotImplementedException"></exception>
 public void RunModule(string moduleId, Form mainForm, string customWhere)
 {
     using (ModuleRunScope scope = new ModuleRunScope())
     {
         IModuleRun run = ClientMoudleContainer.Instance.Resolve <IModuleRun>(moduleId);
     }
 }
        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>
                }
            }
        }
示例#7
0
        public void ModuleAnyMatchTest()
        {
            using (ModuleRunScope scope = new ModuleRunScope())
            {
                string[] arrTest = new string[] { "1", "2", "3", "4", "5" };
                scope.SetVariable("$Arr", arrTest);

                ModuleAnyMatch anyMatch = new ModuleAnyMatch
                {
                    BuildInstance            = false,
                    Target                   = BuildTarget.ScopeResult,
                    Type                     = typeof(System.Diagnostics.Trace).AssemblyQualifiedName,
                    ScopeIEnumerableInstance = "$Arr"
                };

                anyMatch.AddStep(new ModuleMethodCallElement
                {
                    MethodName = "WriteLine",
                    Parameters = new ModuleConstructorElement
                    {
                        Arguments = new TypeValueElement[]
                        {
                            new TypeValueElement {
                                Type = "System.String", Value = "$StepSwap"
                            }
                        }
                    }
                });
                anyMatch.AddStep(new ExpressionReturnElement());

                ConditionalElement when = new ConditionalElement();
                when.AddItem(new InstanceIsTypeConditionItem {
                    ScopeInstanceKey = "$StepSwap", CompareType = "string"
                });
                when.AddItem(new StringConditionItem
                {
                    ComparisonMode         = StringComparison.InvariantCultureIgnoreCase,
                    BooleanCompareDelegate = "XmlClrLan.ConditionalElement.StringNotEqual",
                    Logic           = LogicExpression.AND,
                    ExpressionLeft  = (StringExpressItem)"3",
                    ExpressionRight = (StringExpressItem)"$StepSwap",
                });
                anyMatch.Match = when;

                anyMatch.InvokeInScope(scope);

                if (scope.LastError != null)
                {
                    throw scope.LastError;
                }


                XmlDocument    xDoc    = anyMatch.GetXmlDoc(true);
                ModuleAnyMatch restore = xDoc.GetObject <ModuleAnyMatch>();

                Assert.AreEqual(restore.ModuleId, anyMatch.ModuleId);
            }
        }
示例#8
0
        public void StringExpressItemTest()
        {
            StepBasedExpressionItem <string> item = TempStrGetExpression();

            using (ModuleRunScope scope = new ModuleRunScope())
            {
                string    ret   = item.Invoke(scope);
                Exception error = scope.LastError;
                Assert.IsTrue(ret == "1");
            }

            XmlDocument xDoc   = item.GetXmlDoc(true);
            string      expStr = item.GetXmlDocString(true);

            StepBasedExpressionItem <string> restore = xDoc.GetObject <StepBasedExpressionItem <string> >();
            string xmlStr2 = restore.GetXmlDocString(true);

            Assert.AreEqual(expStr.XmlUtf8BOMClear(), xmlStr2.XmlUtf8BOMClear());
        }
示例#9
0
        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;
                    }
                }
            }
        }
示例#10
0
 public VOID Invoke(ModuleRunScope scope)
 {
     return(VOID.Empty);
 }