コード例 #1
0
ファイル: CoreDispatcher.cs プロジェクト: karthi1015/Revit
        /// <summary>
        /// 由Id唤醒方法
        /// </summary>
        /// <param name="commandData"></param>
        /// <param name="message"></param>
        /// <param name="elements"></param>
        /// <param name="strUseId"></param>
        /// <returns></returns>
        private Result InvokeById(ExternalCommandData commandData, ref string message, ElementSet elements, string strUseId)
        {
            //实际处理器
            IExternalCommand tempCommand = null;

            //设置addinId
            DEBUGUtility.SetAddInId(strUseId);

            //缓存判断
            if (!m_useCommandObject.ContainsKey(strUseId))
            {
                //获取命令对象
                var useCommandPacker = m_useCMDDic[strUseId];

                object tempCommandObj = CreatObjByHandlerInfo(useCommandPacker);

                //多态转换
                tempCommand = tempCommandObj as IExternalCommand;

                m_useCommandObject.Add(strUseId, tempCommand);
            }
            else
            {
                tempCommand = m_useCommandObject[strUseId];
            }

            //若是debug模式不单例命令对象
            if (DEBUGUtility.IfDebugModel)
            {
                //清除已缓存命令对象
                m_useCommandObject.Remove(strUseId);
            }

            return(tempCommand.Execute(commandData, ref message, elements));
        }
コード例 #2
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]);
        }
コード例 #3
0
        /// <summary>
        /// AOP切面
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public override IMessage Invoke(IMessage msg)
        {
            //挂接程序集解析事件
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            //新增Guid
            DEBUGUtility.CreatGuid();
            try
            {
                IMethodCallMessage callmessage = (IMethodCallMessage)msg;

                //调用真实方法
                object returnValue = callmessage.MethodBase.Invoke(this.m_useCore, callmessage.Args);

                //制作返回值
                ReturnMessage returnmessage = new ReturnMessage(returnValue, new object[0], 0, null, callmessage);

                return(returnmessage);
            }
            catch (Exception ex)
            {
                //添加日志信息
                LogUtility.AppendLog(ex);
                //生成日志文件
                LogUtility.CreatLogFile();
                //异常上抛
                throw ex;
            }
            finally
            {
                //卸载事件
                AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
                //清除guid
                DEBUGUtility.DropGuid();
                //重置状态
                DEBUGUtility.ResetCondition();
            }
        }
コード例 #4
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));
        }
コード例 #5
0
ファイル: CoreDispatcher.cs プロジェクト: karthi1015/Revit
 /// <summary>
 /// 关闭一个应用封装
 /// </summary>
 /// <param name="inputIndex"></param>
 /// <param name="inputApplication"></param>
 public void ShutDownOneApplication(int inputIndex, UIControlledApplication inputApplication)
 {
     //设置位置
     DEBUGUtility.SetApplicaionIndex(inputIndex);
     m_useLstApp[inputIndex].OnShutdown(inputApplication);
 }
コード例 #6
0
ファイル: CoreDispatcher.cs プロジェクト: karthi1015/Revit
 /// <summary>
 /// 启动一个应用封装
 /// </summary>
 /// <param name="inputIndex"></param>
 /// <param name="inputApplication"></param>
 public void StartUpOneApplication(int inputIndex, UIControlledApplication inputApplication)
 {
     //设置位置
     DEBUGUtility.SetApplicaionIndex(inputIndex);
     m_useLstApp[inputIndex].OnStartup(inputApplication);
 }
コード例 #7
0
ファイル: CoreDispatcher.cs プロジェクト: karthi1015/Revit
 /// <summary>
 /// 准备一个应用封装
 /// </summary>
 /// <param name="inputIndex"></param>
 public void PrepareOneApplication(int inputIndex)
 {
     //设置位置
     DEBUGUtility.SetApplicaionIndex(inputIndex, m_useLstAppInfo[inputIndex].StrUseAssemblePath);
     m_useLstApp.Add(CreatObjByHandlerInfo(m_useLstAppInfo[inputIndex]) as IExternalApplication);
 }