Esempio n. 1
0
 /// <summary>
 /// 执行所有命令
 /// </summary>
 /// <param name="configInfo"></param>
 public void execByConfigInfo(ConfigInfo configInfo)
 {
     LogOutput.logConsoleNow("********start  exec command **********");
     List<List<Dictionary<string, object>>> allTargetList = configInfo.AllTargetList;
     int allTarLen = allTargetList.Count;
     string exStr = string.Empty;
     for (int i = 0; i < allTarLen; i++) {
         //单个target内信息集合,可能包括多个concat,route,delete等
         List<Dictionary<string, object>> singleTargetList = allTargetList[i];
         int dictListLen = singleTargetList.Count;
         for (int j = 0; j < dictListLen; j++) {
             //具体操作信息节点concat,delete
             Dictionary<string, object> dictItem = singleTargetList[j];
             //原则上只有1个<key,value>节点,dictionary的键值对不是按序排列的
             foreach (string dictKey in dictItem.Keys) {
                 //定义switch中公共变量
                 object dictValue = dictItem[dictKey];
                 Object2StringCmd o2scmd = new Object2StringCmd();
                 //执行属性节点
                 switch (dictKey) {
                     case "route":
                         try {
                             ConfigTargetRoute confTarRoute = (ConfigTargetRoute)dictValue;
                             o2scmd.execRouteMergeCmd(confTarRoute, configInfo.RootPath);
                             LogOutput.logConsoleNow("route finished");
                         } catch (LogException logEx) {
                             handleRuntimeEx(logEx);
                         }
                         break;
                     case "concat":
                         try {
                             ConfigTargetConcat confTarConcat = (ConfigTargetConcat)dictValue;
                             o2scmd.execConcatCmd(confTarConcat, configInfo.RootPath);
                             LogOutput.logConsoleNow("concat finished");
                         } catch (LogException logEx) {
                             handleRuntimeEx(logEx);
                         }
                         break;
                     case "delete":
                         try {
                             ConfigTargetDelete confTarDelete = (ConfigTargetDelete)dictValue;
                             o2scmd.execDeleteCmd(confTarDelete, configInfo.RootPath);
                             LogOutput.logConsoleNow("delete finished");
                         } catch (LogException logEx) {
                             handleRuntimeEx(logEx);
                         }
                         break;
                     case "compress":
                         try {
                             ConfigTargetCompress confTarCompress = (ConfigTargetCompress)dictValue;
                             o2scmd.execCompressCmd(confTarCompress, configInfo.RootPath);
                             LogOutput.logConsoleNow("compress finished");
                         } catch (LogException logEx) {
                             handleRuntimeEx(logEx);
                         }
                         break;
                     case "command":
                         try {
                             ConfigTargetCommand confTarCommand = (ConfigTargetCommand)dictValue;
                             o2scmd.execCommandCmd(confTarCommand, configInfo.RootPath);
                             LogOutput.logConsoleNow("command finished");
                         } catch (LogException logEx) {
                             handleRuntimeEx(logEx);
                         }
                         break;
                     case "batch":
                         try {
                             List<ConfigTargetBatch> confTarBatchList = (List<ConfigTargetBatch>)dictValue;
                             o2scmd.execBatchCmd(confTarBatchList, configInfo.RootPath);
                             LogOutput.logConsoleNow("batch finished");
                         } catch (LogException logEx) {
                             handleRuntimeEx(logEx);
                         }
                         break;
                     case "replace":
                         try {
                             ConfigTargetReplace confTarReplace = (ConfigTargetReplace)dictValue;
                             o2scmd.execReplaceCmd(confTarReplace, configInfo.RootPath);
                             LogOutput.logConsoleNow("replace finished");
                         } catch (LogException logEx) {
                             handleRuntimeEx(logEx);
                         }
                         break;
                     default: break;
                 }
             }
         }
     }
     LogOutput.logConsoleNow("********All command  finished!**********");
 }
Esempio n. 2
0
        /// <summary>
        /// 读取build配置文件,生成属性集合
        /// </summary>
        /// <param name="path"></param>
        /// <param name="rootpath">执行环境所在的相对根目录,xml中节点属性值相对的根目录,默认与xml文件夹一致</param>
        /// <returns></returns>
        public ConfigInfo getConfigInfo(string path, string rootpath)
        {
            ConfigInfo confInfo = new ConfigInfo();
            try {
                LogOutput.logConsoleNow("start read config info");
                path = Path.GetFullPath(Path.Combine(GlobalCurrent.PROJECT_WORKSPACE, path));
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(path);
                if (rootpath != string.Empty) {
                    confInfo.RootPath = rootpath;
                } else {
                    confInfo.RootPath = path.Substring(0, path.LastIndexOf('\\'));
                }
                XmlNode projectNode = xmlDoc.SelectSingleNode("project");
                XmlNodeList projectChildNodes = projectNode.ChildNodes;

                //property集合
                Dictionary<string, string> dictProperty = new Dictionary<string, string>();
                //target节点集合
                List<XmlNode> targetList = new List<XmlNode>();

                int projectChildNodesLen = projectChildNodes.Count;
                XmlNode currentNode;

                for (int i = 0; i < projectChildNodesLen; i++) {
                    currentNode = projectChildNodes[i];
                    switch (currentNode.Name) {
                        case "property":
                            string proKey = string.Empty;
                            string proValue = string.Empty;
                            //property节点 必须有name,value属性
                            if (currentNode.Attributes["name"] != null) {
                                proKey = currentNode.Attributes["name"].Value;

                                string dynamic = getXmlNodeAttrVal(currentNode, "dynamic");
                                if (dynamic == "true") {
                                    string type = getXmlNodeAttrVal(currentNode, "type");
                                    //动态版本号
                                    switch (type) {
                                        case "datetime":
                                            //时间格式
                                            string _format = getXmlNodeAttrVal(currentNode, "format");
                                            if (_format == string.Empty) _format = "yyyyMMddHHmmss";
                                            proValue = DateTime.Now.ToString(_format);
                                            break;
                                        case "number":
                                            proValue = Math.Floor((new Random().NextDouble() * 1e8)).ToString();
                                            break;
                                        case "guid":
                                            proValue = Guid.NewGuid().ToString();
                                            break;
                                        default:
                                            proValue = DateTime.Now.ToString();
                                            break;
                                    }
                                    dictProperty[proKey] = proValue;
                                    break;
                                }
                                proValue = getXmlNodeAttrVal(currentNode, "value");
                                if (proValue == string.Empty) {
                                    proValue = getXmlNodeAttrVal(currentNode, "location");
                                }

                                //无则添加key,有则覆盖value
                                dictProperty[proKey] = proValue;

                            }
                            break;
                        case "target":
                            //target节点
                            targetList.Add(currentNode);
                            break;
                        default: break;

                    }
                }

                confInfo.DictProperty = repKeyInValue(dictProperty);
                //所有target节点属性的集合,有顺序
                List<List<Dictionary<string, object>>> allTargetNodesList = new List<List<Dictionary<string, object>>>();
                //读取target
                foreach (XmlNode targetNode in targetList) {
                    allTargetNodesList.Add(getTargetNodeInfo(targetNode, confInfo.DictProperty, confInfo.RootPath));
                }
                confInfo.AllTargetList = allTargetNodesList;
                LogOutput.logConsoleNow("end   read config info");
            } catch (Exception ex) {
                throw new LogException("读取配置文件" + path, ex);
            }
            return confInfo;
        }