예제 #1
0
        /// <summary>
        /// Расчитывает ключ для указанных параметров
        /// </summary>
        /// <param name="searchKeyTypeXml">
        /// </param>
        /// <param name="insuredPersonDataXml">
        /// </param>
        /// <param name="documentXml">
        /// </param>
        /// <param name="address1Xml">
        /// </param>
        /// <param name="address2Xml">
        /// </param>
        /// <param name="medicalInsuranceXml">
        /// </param>
        /// <param name="okato">
        /// </param>
        /// <returns>
        /// The <see cref="byte[]"/>.
        /// </returns>
        public byte[] CalculateUserSearchKey(
            string searchKeyTypeXml,
            string insuredPersonDataXml,
            string documentXml,
            string address1Xml,
            string address2Xml,
            string medicalInsuranceXml,
            string okato)
        {
            // Парсинг
            ModelAdapter model = null;

            try
            {
                model = new ModelAdapter
                {
                    SearchKeyType    = SearchKeyType.FromXML(searchKeyTypeXml),
                    PersonData       = InsuredPersonDatum.FromXML(insuredPersonDataXml),
                    Document         = Document.FromXML(documentXml),
                    Address1         = address.FromXML(address1Xml),
                    Address2         = address.FromXML(address2Xml),
                    MedicalInsurance = MedicalInsurance.FromXML(medicalInsuranceXml),
                    Okato            = okato
                };
            }
            catch (Exception ex)
            {
                throw new Exception("Ошибка парсинга xml", ex);
            }

            return(CalculateUserSearchKey(model));
        }
예제 #2
0
        /// <summary>
        /// Расчитывает ключ для указанных параметров
        /// </summary>
        /// <param name="searchKeyTypeXml">
        /// </param>
        /// <param name="exchangeXml">
        /// The exchange Xml.
        /// </param>
        /// <param name="documentXml">
        /// The document Xml.
        /// </param>
        /// <param name="addressXml">
        /// The address Xml.
        /// </param>
        /// <returns>
        /// The <see cref="byte[]"/>.
        /// </returns>
        public byte[] CalculateUserSearchKeyExchange(
            string searchKeyTypeXml,
            string exchangeXml,
            string documentXml,
            string addressXml)
        {
            // Парсинг
            ModelAdapter model = null;

            try
            {
                model = new ModelAdapter
                {
                    SearchKeyType = SearchKeyType.FromXML(searchKeyTypeXml),
                    PersonData    = InsuredPersonDatum.FromXML(exchangeXml),
                    Document      = Document.FromXML(documentXml),
                    Address1      = address.FromXML(addressXml)
                };
            }
            catch (Exception ex)
            {
                throw new Exception("Ошибка парсинга xml", ex);
            }

            // создание внешнего hash алгоритма
            var hashAlgorithm = new HashAlgorithm();

            byte[] hash = null;
            using (var stream = new MemoryStream())
            {
                using (var currentWriter = new BinaryWriter(stream, Encoding.Unicode))
                {
                    // Персональные данные
                    WriteField(model, x => x.PersonData.LastName, currentWriter);
                    WriteField(model, x => x.PersonData.FirstName, currentWriter);
                    WriteField(model, x => x.PersonData.MiddleName, currentWriter);
                    WriteField(model, x => x.PersonData.Birthday, currentWriter);
                    WriteField(model, x => x.PersonData.Birthplace, currentWriter);
                    WriteField(model, x => x.PersonData.Snils, currentWriter);

                    // Документ УДЛ
                    WriteField(model, x => x.Document.DocumentTypeId, currentWriter);
                    WriteField(model, x => x.Document.Series, currentWriter);
                    WriteField(model, x => x.Document.Number, currentWriter);

                    // расчет ключа с помощью внешнего алгоритма
                    stream.Flush();
                    stream.Position = 0;
                    hash            = hashAlgorithm.ComputeHash(stream);
                }
            }

            return(hash);
        }