/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Gets field names from export table description. /// </summary> /// <param name="reader">Export structure reader to decsription access.</param> /// <param name="type">Export type.</param> /// <param name="readedNames">Readed unique names (in\out).</param> private void _GetFieldNames(ExportStructureReader reader, ExportType type, IList<string> readedNames) { Debug.Assert(null != reader); Debug.Assert(null != readedNames); ICollection<TableInfo> tableInfos = reader.GetPattern(type); foreach (TableInfo tableInfo in tableInfos) { if ((TableType.Stops != tableInfo.Type) && (TableType.Orders != tableInfo.Type)) continue; // NOTE: skip other tables TableDescription descr = reader.GetTableDescription(tableInfo.Type); foreach (string name in descr.GetFieldNames()) { if (!readedNames.Contains(name)) { readedNames.Add(name); } } } }
/// <summary> /// Loads <c>Profile</c>. /// </summary> /// <param name="nodeProfile">Profile node.</param> /// <param name="structureKeeper"><see cref="P:ESRI.ArcLogistics.Export.ExportStructureReader" />.</param> /// <returns>Loaded <see cref="P:ESRI.ArcLogistics.Export.Profile" />.</returns> private Profile _LoadProfile(XmlNode nodeProfile, ExportStructureReader structureKeeper) { var type = (ExportType)Enum.Parse(typeof(ExportType), nodeProfile.Attributes[ATTRIBUTE_NAME_TYPE].Value); string filePath = nodeProfile.Attributes[ATTRIBUTE_NAME_FILE].Value; bool isDefault = false; if (null != nodeProfile.Attributes[ATTRIBUTE_NAME_DEFAULT]) isDefault = bool.Parse(nodeProfile.Attributes[ATTRIBUTE_NAME_DEFAULT].Value); var profile = new Profile(structureKeeper, type, filePath, isDefault); profile.Name = nodeProfile.Attributes[ATTRIBUTE_NAME_NAME].Value; ICollection<ITableDefinition> tables = profile.TableDefinitions; foreach (XmlNode node in nodeProfile.ChildNodes) { if (node.NodeType != XmlNodeType.Element) continue; // skip comments and other non element nodes if (node.Name.Equals(NODE_NAME_DESCRIPTION, StringComparison.OrdinalIgnoreCase)) { if (null != node.FirstChild) profile.Description = node.FirstChild.Value; } else if (node.Name.Equals(NODE_NAME_TABLES, StringComparison.OrdinalIgnoreCase)) _LoadTables(node, tables); } return profile; }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Loads export profiles from file. /// </summary> /// <param name="fileName">Storage file path.</param> /// <param name="structureKeeper">Export structure reader.</param> /// <returns>Loaded list of <see cref="P:ESRI.ArcLogistics.Export.Profile" />.</returns> /// <exception cref="T:ESRI.ArcLogistics.SettingsException"> Export file is invalid. /// In property "Source" there is path to invalid export file.</exception> public List<Profile> Load(string fileName, ExportStructureReader structureKeeper) { if (string.IsNullOrEmpty(fileName)) throw new ArgumentNullException(); // exception var profiles = new List<Profile> (); if (File.Exists(fileName)) { var doc = new XmlDocument(); // Try to load file. try { doc.Load(fileName); // create navigation tree in memory profiles = _LoadContent(doc.DocumentElement, structureKeeper); } catch (Exception ex ) { // If XML corrupted - wrap exception and save path to file. if (ex is XmlException || ex is NotSupportedException) { SettingsException settingsException = new SettingsException(ex.Message, ex); settingsException.Source = fileName; throw settingsException; } } } return profiles; }
/// <summary> /// Loads <c>Profiles</c> from file. /// </summary> /// <param name="nodeProfiles">Profiles node.</param> /// <param name="structureKeeper"><see cref="P:ESRI.ArcLogistics.Export.ExportStructureReader" />.</param> /// <returns>Loaded list of <see cref="P:ESRI.ArcLogistics.Export.Profile" />.</returns> /// <exception cref="T:System.NotSupportedException.NotSupportedException"> /// XML file is invalid.</exception> private List<Profile> _LoadContent(XmlElement nodeProfiles, ExportStructureReader structureKeeper) { var profiles = new List<Profile> (); foreach (XmlNode node in nodeProfiles.ChildNodes) { if (node.NodeType != XmlNodeType.Element) continue; // skip comments and other non element nodes if (node.Name.Equals(NODE_NAME_PROFILE, StringComparison.OrdinalIgnoreCase)) profiles.Add(_LoadProfile(node, structureKeeper)); else throw new NotSupportedException(); // exception } return profiles; }