123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /* ==============================================================================
- * 功能描述:RevitCmdExecutor
- * 创 建 者:Garrett
- * 创建日期:2019/4/16 11:46:37
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using Newtonsoft.Json.Linq;
- using System.Windows.Forms;
- using SAGA.DotNetUtils;
- using ServiceMBI.Modes;
- namespace Client.Start
- {
- /// <summary>
- /// RevitCmdExecutor
- /// </summary>
- public class RevitCmdExecutor : IRevitCommandExcutor
- {
- public string ExecuteCmd(string revitCmd, string param, HashSet<string> filePathList)
- {
- //由revitCmd生成实体类
- //实体类传入参数、参考楼层列表
- //执行方法,返回执行结果
- Console.WriteLine("准备执行命令");
- IServiceCommand command = GetServiceCommand(revitCmd);
- if (command == null) return $"命令 {revitCmd} 解析异常";
- CustomMessage addMessage = null;
- string combineParam = AddFilePathParam(param, filePathList, ref addMessage);
- if (addMessage?.Result == false) return addMessage.ResultMsg;
- string msg = "";
- msg=command.Execute(combineParam);
- MessageBox.Show("命令执行完成 ");
- return msg;
- }
- /// <summary>
- /// 由Command的字符串转化为相应的命令
- /// </summary>
- /// <param name="revitCmd"></param>
- /// <returns></returns>
- private IServiceCommand GetServiceCommand(string revitCmd)
- {
- IServiceCommand command = null;
- string dllName = "ServiceMBI.dll";
- string className = "ServiceMBI.Commands." + revitCmd;
- string path = Path.Combine(AppBaseInfo.DllRunPath, dllName);
- Console.WriteLine(path);
- if (File.Exists(path))
- {
- Assembly tempAsembly = Assembly.LoadFrom(path);
- command = (tempAsembly.CreateInstance(className)) as IServiceCommand;
- }
- return command;
- }
- /// <summary>
- /// 将ReferFloors参数,添加至参数列表中
- /// </summary>
- /// <param name="param"></param>
- /// <param name="filePathList"></param>
- /// <param name="message"></param>
- /// <returns></returns>
- private string AddFilePathParam(string param, HashSet<string> filePathList, ref CustomMessage message)
- {
- string floorskey = ServiceMBIBuiltInParameter.ReferFloors;
- message = new CustomMessage(true, "Add Success");
- try
- {
- JObject jObject = JObject.Parse(param);
- //解析字符串获取Json存储树结构
- var keys = ServiceMBIBuiltInParameter.ReferFloors.Split('.');
- if (keys.Length == 2)
- {
- JArray checkItemsJArray = new JArray();
- foreach (string filePath in filePathList)
- {
- checkItemsJArray.Add(filePath);
- }
- if (jObject.ContainsKey(keys[0]))
- {
- var jcriteria = (JObject)jObject[keys[0]];
- jcriteria.Add(keys[1], checkItemsJArray);
- }
- else
- {
- JObject checkItemsJObject = new JObject();
- checkItemsJObject.Add(keys[1], checkItemsJArray);
- jObject.Add(keys[0], checkItemsJObject);
- }
- }
- return jObject.ToString();
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- message = new CustomMessage(false, "添加ReferFloors参数异常");
- }
- return null;
- }
- }
- }
|