Esempio n. 1
0
        public static Hashtable InvokeSrc_Once(string searchPath, string srcCodePath, string classFullName, string methodName, Type[] paraTypes, object[] paras)
        {
            Hashtable hashtable = null;
            AppDomain domain    = null;
            string    text      = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Guid.NewGuid().ToString().Replace("-", "");

            try
            {
                domain = MainUtil.CreateShadowAppDomain(text, searchPath);
                RemoteUtil remoteUtil = MainUtil.CreateRemoteUtil(domain);
                hashtable = remoteUtil.InvokeSrc(srcCodePath, classFullName, methodName, paraTypes, paras);
            }
            catch (Exception ex)
            {
                hashtable            = new Hashtable();
                hashtable["Success"] = false;
                hashtable["Data"]    = ex.ToString();
            }
            finally
            {
                AppDomain.Unload(domain);
                try
                {
                    Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "DynamicCache/" + text, true);
                }
                catch (Exception)
                {
                }
            }
            return(hashtable);
        }
Esempio n. 2
0
        /// <summary>只调用一次,不考虑连续调用的性能,这将会临时创建影子程序域调用结束后就卸载
        /// </summary>
        /// <param name="searchPath">程序集的搜索路径</param>
        /// <param name="dllFullName">程序集的全称如:Demo2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</param>
        /// <param name="classFullName">执行类名</param>
        /// <param name="methodName">执行方法名</param>
        /// <param name="paraTypes">方法参数类型</param>
        /// <param name="paras">方法参数</param>
        /// <returns></returns>
        public static Hashtable InvokeDll_Once(string searchPath, string dllFullName, string classFullName, string methodName, Type[] paraTypes, object[] paras, string appconfigpath = null)
        {
            AppDomain  domain     = null;
            RemoteUtil remote     = null;
            Hashtable  ht         = null;
            string     tmpAppName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Guid.NewGuid().ToString().Replace("-", "");

            try
            {
                domain = CreateShadowAppDomain(tmpAppName, searchPath, appconfigpath);
                remote = CreateRemoteUtil(domain);

                //调用指定类的指定方法
                ht = remote.InvokeDll(dllFullName, classFullName, methodName, paraTypes, paras);
            }
            catch (Exception ex)
            {
                ht            = new Hashtable();
                ht["Success"] = false;
                ht["Data"]    = ex.ToString();
            }
            finally
            {
                AppDomain.Unload(domain);
                try
                {
                    Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "DynamicCache/" + tmpAppName, true);
                }
                catch (Exception) { }
            }
            return(ht);
        }
Esempio n. 3
0
        /// <summary>从影子程序域中创建代理对象
        /// </summary>
        /// <param name="domain">影子程序域</param>
        /// <returns></returns>
        private static RemoteUtil CreateRemoteUtil(AppDomain domain)
        {
            string     path   = typeof(MainlUtil).Assembly.CodeBase;
            RemoteUtil remote = (RemoteUtil)domain.CreateInstanceFromAndUnwrap(path, "DynamicUtil.RemoteUtil");

            return(remote);
        }
Esempio n. 4
0
        public static Hashtable InvokeSrc_Direct(string srcCodePath, string typename, string methodName, Type[] paraTypes, object[] paras)
        {
            Hashtable hashtable = null;

            try
            {
                RemoteUtil remoteUtil = new RemoteUtil();
                hashtable = remoteUtil.InvokeSrc(srcCodePath, typename, methodName, paraTypes, paras);
            }
            catch (Exception ex)
            {
                hashtable            = new Hashtable();
                hashtable["Success"] = false;
                hashtable["Data"]    = ex.ToString();
            }
            return(hashtable);
        }
Esempio n. 5
0
        /// <summary>在当前应用程序域中直接调用,为IIS提供,因为IIS中本身就是卷影复制的
        /// </summary>
        /// <param name="typeName">类型名,比如:"System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"</param>
        /// <param name="methodName">方法名</param>
        /// <param name="paraTypes">参数类型数组</param>
        /// <param name="paras">参数数组</param>
        /// <returns></returns>
        public static Hashtable InvokeDll_Direct(string typeName, string methodName, Type[] paraTypes, object[] paras)
        {
            Hashtable ht = null;

            try
            {
                RemoteUtil remote = new RemoteUtil();
                //调用指定类的指定方法
                ht = remote.InvokeDll(Type.GetType(typeName), methodName, paraTypes, paras);
            }
            catch (Exception ex)
            {
                ht            = new Hashtable();
                ht["Success"] = false;
                ht["Data"]    = ex.ToString();
            }
            return(ht);
        }
Esempio n. 6
0
        public Hashtable InvokeSrc(string srcCodePath, string classFullName, string methodName, Type[] paraTypes, object[] args)
        {
            string text  = RemoteUtil.GeneLastFlag(srcCodePath);
            object @lock = RemoteUtil.GetLock(srcCodePath);

            lock (@lock)
            {
                object obj2;
                if (RemoteUtil.ht_last_flags.TryGetValue(srcCodePath, out obj2))
                {
                    if (obj2.ToString() != text)
                    {
                        RemoteUtil.ht_last_assem[srcCodePath] = this.Compile(srcCodePath);
                        RemoteUtil.ht_last_flags[srcCodePath] = text;
                    }
                }
                else
                {
                    RemoteUtil.ht_last_assem.TryAdd(srcCodePath, this.Compile(srcCodePath));
                    RemoteUtil.ht_last_flags.TryAdd(srcCodePath, text);
                }
            }
            return(this.InvokeDll(RemoteUtil.ht_last_assem[srcCodePath] as Assembly, classFullName, methodName, paraTypes, args));
        }