Ejemplo n.º 1
0
        public void Run(ScriptCode code, CompilerOutputDelegate cod, PermissionSet permissionSet)
        {
            var resultAssembly = this.Compile(code.SourceCode, cod).CompiledAssembly;

            if (resultAssembly != null)
            {
                if (permissionSet != null)
                {
                    permissionSet.PermitOnly();
                }
                //// run script
                foreach (var item in code.StartUpList.OrderBy(row => row.order))
                {
                    if (resultAssembly.GetType(item.ClassName) == null || resultAssembly.GetType(item.ClassName).GetMethod(item.MethordName) == null)
                    {
                        throw new Exception(string.Format("没有找到公共的{0}.{0}", item.ClassName, item.MethordName));
                    }
                    MethodInfo methordInfo = resultAssembly.GetType(item.ClassName).GetMethod(item.MethordName);
                    methordInfo.Invoke(item.Instance, item.MethordParameters);
                }
                if (permissionSet != null)
                {
                    CodeAccessPermission.RevertPermitOnly();
                }
            }
        }
Ejemplo n.º 2
0
        private void btnDebug_Click(object sender, EventArgs e)
        {
            ScriptCode code = new ScriptCode();

            code.SourceCode = txtCode.Text;
            code.StartUpList.Add(new StartUpInfo() { ClassName = "ConsoleApplication1.Program", MethordName = "Test", order = 0, MethordParameters = new object[] { this }, Instance = this, });

            CodeCompilerWraper csWrapper = new CSharpCompilerWraper();
            csWrapper.FrameworkVersion = FrameworkVersion.Version20;
            csWrapper.CustomeAssemblies = null;

            csWrapper.Run(code, new CompilerOutputDelegate(HandleCompilerOutput));
        }
Ejemplo n.º 3
0
        public void Run(ScriptCode code, CompilerOutputDelegate cod, PermissionSet permissionSet)
        {
            var resultAssembly = this.Compile(code.SourceCode, cod).CompiledAssembly;
            if (resultAssembly != null)
            {
                if (permissionSet != null)
                {
                    permissionSet.PermitOnly();
                }
                //// run script
                foreach (var item in code.StartUpList.OrderBy(row => row.order))
                {
                    if (resultAssembly.GetType(item.ClassName) == null || resultAssembly.GetType(item.ClassName).GetMethod(item.MethordName) == null)
                    {
                        throw new Exception(string.Format("没有找到公共的{0}.{0}", item.ClassName, item.MethordName));
                    }
                    MethodInfo methordInfo = resultAssembly.GetType(item.ClassName).GetMethod(item.MethordName);
                    methordInfo.Invoke(item.Instance, item.MethordParameters);

                }
                if (permissionSet != null)
                {
                    CodeAccessPermission.RevertPermitOnly();
                }
            }
        }
Ejemplo n.º 4
0
 public void Run(ScriptCode code, CompilerOutputDelegate cod)
 {
     this.Run(code, cod, null);
 }
Ejemplo n.º 5
0
        public static void InitElementChildren(Type elementType, object element, List<Tuple<ChildElementAttribute, PropertyInfo>> childElementProperties)
        {
            StringBuilder sb = new StringBuilder();
            foreach (var item in childElementProperties.Where(row => row.Item1.ChildCategory == ChildCategory.ChildrenColection).OrderBy(row => row.Item1.Order))
            {
                sb.AppendFormat(itemFormat, item.Item2.Name).AppendLine();
            }
            Element elementInstance = element as Element;
            elementInstance.Items = null;
            elementInstance.ItemTypes = null;

            List<Element> elementList = new List<Element>();
            foreach (var item in childElementProperties.Where(row => row.Item1.ChildCategory == ChildCategory.ChildrenList || row.Item1.ChildCategory == ChildCategory.ChildrenColection))
            {

                object o = item.Item2.GetValue(element, null);
                if (o != null)
                {
                    IEnumerable<Element> elements = o as IEnumerable<Element>;

                    if (elements != null && elements.Count() > 0)
                    {
                        foreach (Element tempelement in elements)
                        {
                            //++???????????
                            // tempelement.PrepareChildrenElements();
                        }
                        if (item.Item1.ChildCategory == ChildCategory.ChildrenColection)
                        {
                            elementList.AddRange(elements);
                        }
                    }
                }
            }
            if (elementList.Count > 0)
            {
                elementInstance.Items = elementList.ToArray();
                elementInstance.ItemTypes = elementList.Select(row => row.ElementType).ToArray();
            }

            string code = string.Format(format, elementType.Name, sb.ToString());

            CSharpCompilerWraper codeWrapper = new CSharpCompilerWraper();
            codeWrapper.FrameworkVersion = FrameworkVersion.Version20;
            codeWrapper.CustomeAssemblies = null;

            ScriptCode scriptCode = new ScriptCode();
            scriptCode.SourceCode = code;
            scriptCode.StartUpList.Add(new StartUpInfo() { ClassName = "Justin.BI.DBLibrary.Compiler.MondrianCompiler", Instance = element, MethordName = "InitChildren", order = 0, MethordParameters = new object[] { element } });
            // codeWrapper.Run(scriptCode, null);
        }
Ejemplo n.º 6
0
 public void Run(ScriptCode code, CompilerOutputDelegate cod)
 {
     this.Run(code, cod, null);
 }