Esempio n. 1
0
        /// <summary>
        /// 程序集加载底层(主动)
        /// </summary>
        /// <param name="inputPath"></param>
        /// <param name="ifUseDebugUtility"></param>
        /// <returns></returns>
        internal static Assembly LoadAssembly(string inputPath, bool ifUseDebugUtility = true)
        {
            if (ifUseDebugUtility)
            {
                inputPath = DEBUGUtility.CopyFileAndChangePath(inputPath);
            }

            if (!m_dicPathAssembly.ContainsKey(inputPath))
            {
                //目录变更
                m_dicPathAssembly.Add(inputPath, Assembly.LoadFile(inputPath));
            }

            return(m_dicPathAssembly[inputPath]);
        }
Esempio n. 2
0
        /// <summary>
        /// 程序集加载底层方法
        /// </summary>
        /// <param name="inputEventArgs"></param>
        /// <param name="ifUseDebug"></param>
        /// <returns></returns>
        private static Assembly UseLoadAssemblyMehtod(ResolveEventArgs inputEventArgs, bool ifUseDebug = true)
        {
            var allNames = inputEventArgs.Name.Split(',');
            //获得请求程序集
            var wantAssemblyName = allNames[0];

            if (allNames.Count() > 2)
            {
                var wantAssemblyCulture = inputEventArgs.Name.Split(',')[2];

                if (wantAssemblyName.EndsWith(".resources") && !wantAssemblyCulture.EndsWith("neutral"))
                {
                    return(null);
                }
            }

            //转换请求文件路径
            FileInfo useFileInfo;

            if (ifUseDebug)
            {
                useFileInfo = new FileInfo(DEBUGUtility.ResetApplicationLocation(inputEventArgs.RequestingAssembly.Location));
            }
            else
            {
                useFileInfo = new FileInfo(inputEventArgs.RequestingAssembly.Location);
            }


            //文件名转换
            string wantAssemblyFileName = wantAssemblyName;

            if (m_AssemblyNameAndFileNameMap.ContainsKey(wantAssemblyName))
            {
                wantAssemblyFileName = m_AssemblyNameAndFileNameMap[wantAssemblyName];
            }

            string usePath;

            //是否是RevitAPI
            if (m_useVersionAssemblyName.Contains(wantAssemblyName) && !string.IsNullOrEmpty(m_versionNum))
            {
                var createdDirectory = Directory.CreateDirectory(useFileInfo.Directory + @"\" + m_versionNum);
                usePath = createdDirectory.FullName + @"\" + wantAssemblyFileName + ".dll";
            }
            else
            {
                usePath = useFileInfo.Directory + @"\" + wantAssemblyFileName + ".dll";
            }

            //程序集与文件不同名时更改路径名称

            if (ifUseDebug)
            {
                //目录变更设置
                usePath = DEBUGUtility.CopyFileAndChangePath(usePath);
            }



            //加载
            return(LoadAssembly(usePath, ifUseDebug));
        }