예제 #1
0
        /// <summary>
        /// Add an <see cref="object"/> <c>instance</c> to the script environment.
        /// The <c>instance</c> may be addressed from within a script by means
        /// of the <c>name</c>.
        /// </summary>
        /// <param name="name">global variable name to be used from within a script.</param>
        /// <param name="instance">instance that may be addressed from within a script.</param>
        /// <returns>Success</returns>
        public bool AddGlobalInstance(string name, object instance)
        {
            if (name == null)
            {
                throw new System.ArgumentNullException();
            }
            if (instance == null)
            {
                throw new System.ArgumentNullException();
            }

            if (!this._VsaEngine.IsValidIdentifier(name))
            {
                return(false);
            }

            try
            {
                //
                // Remove old VsaGlobalItem from engine and site.
                //
                this.RemoveGlobalInstance(name);
                //
                // Add new VsaGlobalItem to engine and site.
                //
                this._VsaSite.AddGlobalInstance(name, instance);
                Microsoft.Vsa.IVsaGlobalItem vsaGlobalItem =
                    (Microsoft.Vsa.IVsaGlobalItem)
                    this._VsaEngine.Items.CreateItem(
                        name,
                        Microsoft.Vsa.VsaItemType.AppGlobal,
                        Microsoft.Vsa.VsaItemFlag.None);
                vsaGlobalItem.TypeString = instance.GetType().ToString();
            }
            catch (Microsoft.Vsa.VsaException e)
            {
                throw new System.ApplicationException(
                          string.Format(
                              (
                                  "A VsaException occurred\n" +
                                  "ErrorCode {0}\n"
                              ),
                              e.ErrorCode.ToString()
                              )
                          );
            }
            return(true);
        }
예제 #2
0
 /// <summary>
 /// 向脚本添加全局对象
 /// </summary>
 /// <param name="strName">全局对象的名称</param>
 /// <param name="strTypeName">全局对象的类型名称</param>
 public void AddGlobalItem(string strName, string strTypeName)
 {
     Microsoft.Vsa.IVsaGlobalItem myGolItem = this.InnerCreateItem(strName, Microsoft.Vsa.VsaItemType.AppGlobal, Microsoft.Vsa.VsaItemFlag.None) as Microsoft.Vsa.IVsaGlobalItem;
     myGolItem.TypeString = strTypeName;
 }