Exemplo n.º 1
0
 /// <summary>
 /// 刷新VBA方法列表
 /// </summary>
 protected void RefreshMethodList()
 {
     myVBAMethods.Clear();
     System.Reflection.Assembly myAssembly = this.Assembly;
     foreach (object obj in this.Items)
     {
         if (obj is Microsoft.Vsa.IVsaCodeItem)
         {
             Microsoft.Vsa.IVsaCodeItem CodeItem = (Microsoft.Vsa.IVsaCodeItem)obj;
             System.Type t = myAssembly.GetType(this.RootNamespace + "." + CodeItem.Name);
             System.Reflection.MethodInfo[] ms = t.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
             foreach (System.Reflection.MethodInfo m in ms)
             {
                 VBAScriptMethodItem MethodItem = new VBAScriptMethodItem();
                 myVBAMethods.Add(MethodItem);
                 MethodItem.ModuleName   = CodeItem.Name;
                 MethodItem.MethodName   = m.Name;
                 MethodItem.MethodObject = m;
                 MethodItem.ReturnType   = m.ReturnType;
                 if (m.GetParameters().Length == 0)
                 {
                     System.Type dt = SlowAndSteadyParser.DelegateHelper.GetDelegateType(m.ReturnType);
                     if (dt != null)
                     {
                         MethodItem.MethodDelegate = System.Delegate.CreateDelegate(dt, m);
                     }
                 }
             }                    //foreach
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 向引擎添加代码模块
 /// </summary>
 /// <param name="ModuleName">模块名称</param>
 /// <param name="SourceCode">源代码</param>
 /// <returns>操作是否成功</returns>
 public bool AddSourceCode(string ModuleName, string SourceCode)
 {
     if (HasContent(SourceCode))
     {
         Microsoft.Vsa.IVsaCodeItem CodeItem = (Microsoft.Vsa.IVsaCodeItem)InnerCreateItem(ModuleName, Microsoft.Vsa.VsaItemType.Code, Microsoft.Vsa.VsaItemFlag.None);
         CodeItem.SourceText = this.ToRuntimeScriptText(ModuleName, SourceCode);
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
0
        internal VsaScriptHost(
            string language,
            string moniker,
            string nameSpace)
        {
            if (language == null)
            {
                throw new System.ArgumentNullException();
            }
            if (moniker == null)
            {
                throw new System.ArgumentNullException();
            }
            if (nameSpace == null)
            {
                throw new System.ArgumentNullException();
            }

            try
            {
                // Store the language
                this._Language = language;
                // Create the Script Engine based on the language
                _CreateEngine();
                // The moniker, or root moniker,
                // is the unique name by which a script engine is identified
                // Set the moniker to be something relatively unique
                this._VsaEngine.RootMoniker = moniker;
                // Create a new instance of the VSA Site
                this._VsaSite = new VsaSite();
                this._VsaSite.CompilerErrorEvent += new CompilerErrorEventHandler(_VsaSite_CompilerErrorEvent);
                // Get the instance of the site
                this._VsaEngine.Site = this._VsaSite;
                // Initialize the engine
                this._VsaEngine.InitNew();
                // Set the rootnamespace
                this._VsaEngine.RootNamespace = nameSpace;
                // Set the engine (display) name
                this._VsaEngine.Name = this._VsaEngine.RootNamespace;
            }
            catch (Microsoft.Vsa.VsaException e)
            {
                throw new System.ApplicationException(
                          string.Format(
                              (
                                  "A VsaException occurred\n" +
                                  "ErrorCode {0}\n"
                              ),
                              e.ErrorCode.ToString()
                              )
                          );
            }
            try
            {
                // Create a blank codeItem
                if (this.Language == "JScript.NET")
                {
                    this._VsaCodeItem =
                        (Microsoft.Vsa.IVsaCodeItem)
                        this._VsaEngine.Items.CreateItem(
                            "ScriptCode",
                            Microsoft.Vsa.VsaItemType.Code,
                            Microsoft.Vsa.VsaItemFlag.Module);
                }
                else
                {
                    this._VsaCodeItem =
                        (Microsoft.Vsa.IVsaCodeItem)
                        this._VsaEngine.Items.CreateItem(
                            "ScriptCode",
                            Microsoft.Vsa.VsaItemType.Code,
                            Microsoft.Vsa.VsaItemFlag.None);
                }
            }
            catch (Microsoft.Vsa.VsaException e)
            {
                throw new System.ApplicationException(
                          string.Format(
                              (
                                  "A VsaException occurred\n" +
                                  "ErrorCode {0}\n"
                              ),
                              e.ErrorCode.ToString()
                              )
                          );
            }
            // Create a reference to system
            this.AddReference("System", "System.dll");
            // Create a reference to Windows
            this.AddReference("Forms", "System.Windows.Forms.dll");
            // Create a reference to Drawing
            this.AddReference("Drawing", "System.Drawing.dll");
            // Create a reference to Xml
            this.AddReference("Xml", "System.Xml.dll");
            // Add an import to system
            this._AddImport("System");
            // Add an import to system
            this._AddImport("System.Windows.Forms");
        }
Exemplo n.º 4
0
        internal VsaScriptHost(
            string language,
            string moniker,
            string nameSpace)
        {
            if (language == null) throw new System.ArgumentNullException();
            if (moniker == null) throw new System.ArgumentNullException();
            if (nameSpace == null) throw new System.ArgumentNullException();

            try
            {
                // Store the language
                this._Language = language;
                // Create the Script Engine based on the language
                _CreateEngine();
                // The moniker, or root moniker,
                // is the unique name by which a script engine is identified
                // Set the moniker to be something relatively unique
                this._VsaEngine.RootMoniker = moniker;
                // Create a new instance of the VSA Site
                this._VsaSite = new VsaSite();
                this._VsaSite.CompilerErrorEvent +=new CompilerErrorEventHandler(_VsaSite_CompilerErrorEvent);
                // Get the instance of the site
                this._VsaEngine.Site = this._VsaSite;
                // Initialize the engine
                this._VsaEngine.InitNew();
                // Set the rootnamespace
                this._VsaEngine.RootNamespace = nameSpace;
                // Set the engine (display) name
                this._VsaEngine.Name = this._VsaEngine.RootNamespace;
            }
            catch (Microsoft.Vsa.VsaException e)
            {
                throw new System.ApplicationException(
                    string.Format(
                    (
                    "A VsaException occurred\n" +
                    "ErrorCode {0}\n"
                    ),
                    e.ErrorCode.ToString()
                    )
                    );
            }
            try
            {
                // Create a blank codeItem
                if (this.Language == "JScript.NET")
                {
                    this._VsaCodeItem =
                        (Microsoft.Vsa.IVsaCodeItem)
                        this._VsaEngine.Items.CreateItem(
                        "ScriptCode",
                        Microsoft.Vsa.VsaItemType.Code,
                        Microsoft.Vsa.VsaItemFlag.Module);
                }
                else
                {
                    this._VsaCodeItem =
                        (Microsoft.Vsa.IVsaCodeItem)
                        this._VsaEngine.Items.CreateItem(
                        "ScriptCode",
                        Microsoft.Vsa.VsaItemType.Code,
                        Microsoft.Vsa.VsaItemFlag.None);
                }
            }
            catch (Microsoft.Vsa.VsaException e)
            {
                throw new System.ApplicationException(
                    string.Format(
                    (
                    "A VsaException occurred\n" +
                    "ErrorCode {0}\n"
                    ),
                    e.ErrorCode.ToString()
                    )
                    );
            }
            // Create a reference to system
            this.AddReference("System", "System.dll");
            // Create a reference to Windows
            this.AddReference("Forms", "System.Windows.Forms.dll");
            // Add an import to system
            this._AddImport("System");
            // Add an import to system
            this._AddImport("System.Windows.Forms");
        }