/// <summary> /// The load keys. /// </summary> /// <param name="configFile"> /// The config file. /// </param> /// <param name="subTypes"> /// The sub types. /// </param> /// <param name="FieldNameResolver"> /// The field name resolver. /// </param> /// <returns> /// The <see cref="List"/>. /// </returns> /// <exception cref="Exception"> /// </exception> public static List <LoadedKey> LoadKeys( Stream configFile, out Dictionary <string, string> subTypes, SearchFieldNameResolver FieldNameResolver = null) { var keys = new List <LoadedKey>(); subTypes = new Dictionary <string, string>(); using (var reader = XmlReader.Create(configFile)) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { try { switch (reader.Name) { case "Key": case "key": var xKey = XElement.Load(reader.ReadSubtree()); var key = new LoadedKey { name = xKey.Attribute("name").Value, type = int.Parse(xKey.Attribute("type").Value), formula = GetFieldsTypes(xKey.Attribute("value").Value, FieldNameResolver) }; if (xKey.Attribute("subtype") != null) { key.subtype = int.Parse(xKey.Attribute("subtype").Value); } keys.Add(key); break; case "subtype": case "subType": var xsubtype = XElement.Load(reader.ReadSubtree()); subTypes.Add(xsubtype.Attribute("name").Value, xsubtype.Attribute("value").Value); break; } } catch (Exception ex) { throw new Exception("Ошибка при чтении ключей из конфигурационного файла: ", ex); } } } } return(keys); }
/// <summary> /// The build keys by pol. /// </summary> /// <param name="key"> /// The key. /// </param> /// <param name="fio"> /// The fio. /// </param> private void BuildKeysByPol(LoadedKey key, FIO fio) { if (preparedFields.FirstOrDefault(field => field.fieldType == FieldTypes.PolicyType) == null) { return; } var _preparedString = new StringBuilder(); foreach (var keyField in key.formula) { var currentField = GetFieldValue(keyField, fio); if (currentField != null) { _preparedString.Append(currentField); _preparedString.Append(fieldsSeparator); } else if (keyField != FieldTypes.FamilyName && keyField != FieldTypes.FirstName && keyField != FieldTypes.MiddleName) { return; } } ; preparedKeys.Add( new PreparedKey { fullName = GetKeyName(key.name), type = key.type, subtype = GetKeySubType( key.name, subtypes, preparedFields.FirstOrDefault( field => field.fieldType == FieldTypes.PolicyType).value), preparedString = _preparedString.ToString().Trim(';'), idCardNumber = GetFieldValue(FieldTypes.PolicyNumber), idCardDate = GetFieldValue(FieldTypes.PolicyActualFrom), idCardDateExp = GetFieldValue(FieldTypes.PolicyActualTo) }); }
/// <summary> /// The build keys by doc. /// </summary> /// <param name="key"> /// The key. /// </param> /// <param name="fio"> /// The fio. /// </param> private void BuildKeysByDoc(LoadedKey key, FIO fio) { var _preparedString = new StringBuilder(); foreach (var document in preparedDocuments) { if (document.idCardType == null) { continue; } foreach (var keyField in key.formula) { var currentField = GetFieldValue(keyField, fio, document); if (currentField != null) { _preparedString.Append(currentField); _preparedString.Append(fieldsSeparator); } else if (keyField != FieldTypes.FamilyName && keyField != FieldTypes.FirstName && keyField != FieldTypes.MiddleName) { return; } } ; preparedKeys.Add( new PreparedKey { fullName = GetKeyName(key.name, document.idCardType.value), type = key.type, subtype = GetKeySubType(key.name, subtypes, document.idCardType.value), preparedString = _preparedString.ToString().Trim(';'), idCardDate = document.idCardDate != null ? document.idCardDate.value : null, idCardDateExp = document.idCardDateExp != null ? document.idCardDateExp.value : null, idCardOrg = document.idCardOrg != null ? document.idCardOrg.value : null, idCardNumber = document.idCardNumber != null ? document.idCardNumber.value : null }); _preparedString.Remove(0, _preparedString.Length); } _preparedString.Remove(0, _preparedString.Length); foreach (var keyField in key.formula) { var currentField = GetFieldValue(keyField, fio, realIdentifier: FieldTypes.ENP); if (currentField != null) { _preparedString.Append(currentField); _preparedString.Append(fieldsSeparator); } else if (keyField != FieldTypes.FamilyName && keyField != FieldTypes.FirstName && keyField != FieldTypes.MiddleName) { return; } } ; preparedKeys.Add( new PreparedKey { fullName = GetKeyName(key.name, "NI"), type = key.type, subtype = GetKeySubType(key.name, subtypes, "NI"), preparedString = _preparedString.ToString().Trim(';'), idCardNumber = GetFieldValue(FieldTypes.ENP) }); _preparedString.Remove(0, _preparedString.Length); foreach (var keyField in key.formula) { var currentField = GetFieldValue(keyField, fio, realIdentifier: FieldTypes.SNILS); if (currentField != null) { _preparedString.Append(currentField); _preparedString.Append(fieldsSeparator); } else if (keyField != FieldTypes.FamilyName && keyField != FieldTypes.FirstName && keyField != FieldTypes.MiddleName) { return; } } ; preparedKeys.Add( new PreparedKey { fullName = GetKeyName(key.name, "PEN"), type = key.type, subtype = GetKeySubType(key.name, subtypes, "PEN"), preparedString = _preparedString.ToString().Trim(';'), idCardNumber = GetFieldValue(FieldTypes.SNILS) }); _preparedString.Remove(0, _preparedString.Length); foreach (var keyField in key.formula) { var currentField = GetFieldValue(keyField, fio, realIdentifier: FieldTypes.UEC); if (currentField != null) { _preparedString.Append(currentField); _preparedString.Append(fieldsSeparator); } else if (keyField != FieldTypes.FamilyName && keyField != FieldTypes.FirstName && keyField != FieldTypes.MiddleName) { return; } } ; preparedKeys.Add( new PreparedKey { fullName = GetKeyName(key.name, "CZ"), type = key.type, subtype = GetKeySubType(key.name, subtypes, "CZ"), preparedString = _preparedString.ToString().Trim(';'), idCardNumber = GetFieldValue(FieldTypes.UEC) }); }