Exemplo n.º 1
0
        public static Hashtable InvokeExe_Once(string searchPath, string exeFullName, string[] paras)
        {
            AppDomain domain    = null;
            string    text      = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Guid.NewGuid().ToString().Replace("-", "");
            Hashtable hashtable = null;

            try
            {
                domain = MainUtil.CreateShadowAppDomain(text, searchPath);
                RemoteUtil remoteUtil = MainUtil.CreateRemoteUtil(domain);
                hashtable = remoteUtil.InvokeExe(exeFullName, 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);
        }
Exemplo n.º 2
0
        /// <summary>一次性动态调用一个exe程序
        /// </summary>
        /// <param name="searchPath">程序集的搜索路径</param>
        /// <param name="exeFullName">程序集的全称如:Demo2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</param>
        /// <param name="paras">参数为字符串数组</param>
        /// <returns></returns>
        public static Hashtable InvokeExe_Once(string searchPath, string exeFullName, string[] paras, string appconfigpath = null)
        {
            AppDomain  domain     = null;
            RemoteUtil remote     = null;
            string     tmpAppName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Guid.NewGuid().ToString().Replace("-", "");
            Hashtable  ht         = null;

            try
            {
                domain = CreateShadowAppDomain(tmpAppName, searchPath, appconfigpath);
                remote = CreateRemoteUtil(domain);
                //调用指定类的指定方法
                ht = remote.InvokeExe(exeFullName, 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);
        }