public void ReadFromXml(XmlNode xml) { if (xml == null) { return; } if (xml.Attributes != null) { _name = xml.Attributes["Name"] == null ? "" : xml.Attributes["Name"].Value; _code = xml.Attributes["Code"] == null ? "" : xml.Attributes["Code"].Value; _classCode = xml.Attributes["ClassCode"] == null ? "" : xml.Attributes["ClassCode"].Value; _autoNames = xml.Attributes["AutoNames"] == null ? "" : xml.Attributes["AutoNames"].Value; } XmlNodeList nodeList = xml.SelectNodes($"/PipelineConfig/PipelineLayers/PipelineLayer[@Name='{_name}']/Layers/Layer"); foreach (XmlNode node in nodeList) { string template = node.Attributes["Template"]?.Value; IBasicLayerInfo layerInfo; if (_templates == null || string.IsNullOrWhiteSpace(template)) { layerInfo = new BasicLayerInfo(node); } else { IPipelineTemplate pipelineTemplate = _templates.FirstOrDefault(c => c.Name == template); if (pipelineTemplate != null) { layerInfo = new BasicLayerInfo(node, pipelineTemplate); } else { layerInfo = new BasicLayerInfo(node); } } _layers.Add(layerInfo); } }
public IBasicLayerInfo Clone(bool keepClass) { IBasicLayerInfo pClone = new BasicLayerInfo(this, keepClass); return(pClone); }
public List <IPipelineLayer> ReadLayersFromDatabase() { List <IPipelineLayer> layers = new List <IPipelineLayer>(); ITable pCodeTable = _workspace.OpenTable("YT_PIPE_CODE"); ITableSort tableSort = new TableSortClass(); tableSort.Table = pCodeTable; tableSort.Fields = "Priority"; tableSort.Sort(null); ICursor pCursor = tableSort.Rows; IRow pRow = pCursor.NextRow(); int codeIdx = pCursor.FindField("PipeCode"); int classIdx = pCursor.FindField("ClassCode"); int nameIdx = pCursor.FindField("PipeName"); int autoIdx = pCursor.FindField("AutoNames"); int priIdx = pCursor.FindField("Priority"); while (pRow != null) { IPipelineLayer oneLayer = new PipelineLayer() { Code = pRow.Value[codeIdx].ToString(), Name = pRow.Value[nameIdx].ToString(), AutoNames = pRow.Value[autoIdx].ToString(), Layers = new List <IBasicLayerInfo>(), ClassCode = pRow.Value[classIdx].ToString() }; layers.Add(oneLayer); pRow = pCursor.NextRow(); } Marshal.ReleaseComObject(pCursor); Marshal.ReleaseComObject(tableSort); Marshal.ReleaseComObject(pCodeTable); List <IYTDomain> domains = new List <IYTDomain>(); pCodeTable = _workspace.OpenTable("YT_PIPE_DOMAIN"); pCursor = pCodeTable.Search(null, false); pRow = pCursor.NextRow(); nameIdx = pCursor.FindField("DomainName"); autoIdx = pCursor.FindField("DomainValues"); while (pRow != null) { string domainName = pRow.Value[nameIdx].ToString(); string domainValues = pRow.Value[autoIdx].ToString(); IYTDomain onedomain = new YTDomain(domainName, domainValues); domains.Add(onedomain); pRow = pCursor.NextRow(); } Marshal.ReleaseComObject(pCursor); Marshal.ReleaseComObject(pCodeTable); List <IPipelineTemplate> templates = new List <IPipelineTemplate>(); //! 先读取模板 pCodeTable = _workspace.OpenTable("YT_PIPE_FIELD"); tableSort = new TableSortClass(); tableSort.Table = pCodeTable; tableSort.Fields = "TemplateName"; tableSort.Sort(null); pCursor = tableSort.Rows; string oldTemplate = ""; int[] fieldIndexes = new int[10]; pRow = pCursor.NextRow(); fieldIndexes[0] = pRow.Fields.FindField("TemplateName"); fieldIndexes[1] = pRow.Fields.FindField("TypeName"); fieldIndexes[2] = pRow.Fields.FindField("FieldName"); fieldIndexes[3] = pRow.Fields.FindField("FieldAliasName"); fieldIndexes[4] = pRow.Fields.FindField("FieldType"); fieldIndexes[5] = pRow.Fields.FindField("FieldLength"); fieldIndexes[6] = pRow.Fields.FindField("FieldPrecision"); fieldIndexes[7] = pRow.Fields.FindField("AllowNull"); fieldIndexes[8] = pRow.Fields.FindField("AutoValues"); fieldIndexes[9] = pRow.Fields.FindField("IsKey"); // fieldIndexes[10] = pRow.Fields.FindField("Domains"); IPipelineTemplate oneTemplate = null; while (pRow != null) { string templateName = pRow.Value[fieldIndexes[0]].ToString(); if (!templateName.Equals(oldTemplate)) { if (oneTemplate != null) { templates.Add(oneTemplate); } oneTemplate = new PipelineTemplate() { Name = templateName, Fields = new List <IYTField>() }; oldTemplate = templateName; } IYTField field = new YTField() { TypeName = pRow.Value[fieldIndexes[1]].ToString(), Name = pRow.Value[fieldIndexes[2]].ToString(), AliasName = pRow.Value[fieldIndexes[3]].ToString(), Length = Convert.ToInt32(pRow.Value[fieldIndexes[5]].ToString()), Precision = Convert.ToInt32(pRow.Value[fieldIndexes[6]].ToString()), AllowNull = Convert.ToInt32(pRow.Value[fieldIndexes[7]].ToString()) == -1 ? true : false, AutoNames = pRow.Value[fieldIndexes[8]].ToString(), FieldType = FieldHelper.ConvertFromString(pRow.Value[fieldIndexes[4]].ToString()) }; oneTemplate.Fields.Add(field); pRow = pCursor.NextRow(); } if (oneTemplate != null) { templates.Add(oneTemplate); } Marshal.ReleaseComObject(pCursor); Marshal.ReleaseComObject(tableSort); Marshal.ReleaseComObject(pCodeTable); List <IBasicLayerInfo> basicInfos = new List <IBasicLayerInfo>(); pCodeTable = _workspace.OpenTable("YT_PIPE_LAYER"); tableSort = new TableSortClass(); tableSort.Table = pCodeTable; tableSort.Fields = "Priority,LayerName"; tableSort.Sort(null); pCursor = tableSort.Rows; pRow = pCursor.NextRow(); fieldIndexes = new int[8]; fieldIndexes[0] = pRow.Fields.FindField("PipeCode"); fieldIndexes[1] = pRow.Fields.FindField("BasicName"); fieldIndexes[2] = pRow.Fields.FindField("LayerName"); fieldIndexes[3] = pRow.Fields.FindField("AutoNames"); fieldIndexes[4] = pRow.Fields.FindField("Priority"); fieldIndexes[5] = pRow.Fields.FindField("DataType"); fieldIndexes[6] = pRow.Fields.FindField("Template"); fieldIndexes[7] = pRow.Fields.FindField("Domains"); while (pRow != null) { string pipeCode = pRow.Value[fieldIndexes[0]].ToString(); IPipelineLayer oneLayer = layers.Find(c => c.Code == pipeCode); if (oneLayer == null) { pRow = pCursor.NextRow(); continue; } enumPipelineDataType dataType = Yutai.Pipeline.Config.Helpers.EnumHelper.ConvertDataTypeFromString( pRow.Value[fieldIndexes[5]].ToString().Trim()); IBasicLayerInfo basicLayer = new BasicLayerInfo() { Name = pRow.Value[fieldIndexes[1]].ToString(), AliasName = pRow.Value[fieldIndexes[2]].ToString(), AutoNames = pRow.Value[fieldIndexes[3]].ToString(), DataType = dataType, TemplateName = pRow.Value[fieldIndexes[6]].ToString(), Fields = new List <IYTField>() }; if (pRow.Value[fieldIndexes[6]] != null) { IPipelineTemplate template = templates.Find(c => c.Name == basicLayer.TemplateName); if (template != null) { foreach (IYTField field in template.Fields) { basicLayer.Fields.Add(new YTField(field)); } } } string domainStr = pRow.Value[fieldIndexes[7]] == DBNull.Value ? string.Empty : pRow.Value[fieldIndexes[7]].ToString(); if (!string.IsNullOrEmpty(domainStr)) { //获得Domainzhi值 string[] domainPairs = domainStr.Split('/'); for (int j = 0; j < domainPairs.Length; j++) { string[] domainPair = domainPairs[j].Split(':'); string fieldName = domainPair[0]; string domainName = domainPair[1]; IYTDomain findDomain = domains.FirstOrDefault(c => c.DomainName == domainName); if (findDomain != null) { IYTField pField = basicLayer.Fields.FirstOrDefault(c => c.TypeName == fieldName); if (pField != null) { pField.Domain = new YTDomain(findDomain.DomainName, findDomain.DomainValues); } } } } oneLayer.Layers.Add(basicLayer); pRow = pCursor.NextRow(); } Marshal.ReleaseComObject(pCursor); Marshal.ReleaseComObject(tableSort); Marshal.ReleaseComObject(pCodeTable); return(layers); }