/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <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> /// Creates instance. /// </summary> /// <param name="structureKeeper">Export structure keeper.</param> /// <param name="type">Export type.</param> /// <param name="filePath">Export file path.</param> /// <param name="isDefault">Is profile default.</param> internal Profile(ExportStructureReader structureKeeper, ExportType type, string filePath, bool isDefault) { Debug.Assert(null != structureKeeper); _structureKeeper = structureKeeper; _InitTables(type); _name = System.IO.Path.GetFileNameWithoutExtension(filePath); _type = type; _file = filePath; _isDefault = isDefault; }
/// <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> /// Creates and inits a new instance of the <c>ExportStructureReader</c> class. /// </summary> /// <param name="capacitiesInfo">Capacities information.</param> /// <param name="orderCustomPropertiesInfo">Order custom properties infromation.</param> /// <param name="addressFields">Geocoder address fields.</param> /// <returns>Created and inited Export Structure Reader.</returns> internal static ExportStructureReader GetReader(CapacitiesInfo capacitiesInfo, OrderCustomPropertiesInfo orderCustomPropertiesInfo, AddressField[] addressFields) { Debug.Assert(null != capacitiesInfo); Debug.Assert(null != orderCustomPropertiesInfo); Debug.Assert(null != addressFields); // load export structure var structure = ResourceLoader.ReadFileAsString(EXPORT_STRUCTURE_FILE_NAME); var exportStructureDoc = new System.Xml.XmlDocument(); exportStructureDoc.LoadXml(structure); ExportStructureReader reader = new ExportStructureReader(); reader.Load(exportStructureDoc, capacitiesInfo, orderCustomPropertiesInfo, addressFields); return(reader); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes a new instance of ExportValidator. /// </summary> /// <param name="capacitiesInfo">Current capacities info.</param> /// <param name="addressFields">Current address fields.</param> public ExportValidator(CapacitiesInfo capacitiesInfo, AddressField[] addressFields) { if (null == capacitiesInfo) { throw new ArgumentNullException("capacitiesInfo"); // exception } if (null == addressFields) { throw new ArgumentNullException("addressFields"); // exception } // load export structure ExportStructureReader reader = Exporter.GetReader(capacitiesInfo, new OrderCustomPropertiesInfo(), addressFields); _readedNames = new List <string>(); _GetFieldNames(reader, ExportType.Access, _readedNames); _GetFieldNames(reader, ExportType.TextOrders, _readedNames); _GetFieldNames(reader, ExportType.TextStops, _readedNames); _description = reader.GetTableDescription(TableType.Stops); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <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>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); }