Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Impeltech.Bank.Models.NBKI;
- using System;
- using System.IO;
- using System.ServiceModel;
- using System.Xml;
- using System.Xml.Serialization;
- using EleWise.ELMA.Logging;
- using Impeltech.Bank;
- using Impeltech.Bank.Helpers;
- using Impeltech.Bank.Models;
- using Impeltech.Bank.Orchard;
- using Parameters = EleWise.ELMA.Workflow.Models.Parameters.CA_PerezaprositjVNBKIDlyaLimit;
- using EleWise.ELMA.Services;
- namespace EleWise.ELMA.Model.Scripts
- {
- /// <summary>
- /// Модуль сценариев пользовательского расширения "Перезапросить в НБКИ"
- /// </summary>
- //Внимание! Для корректной работы программы не изменяйте название класса
- public class CA_PerezaprositjVNBKIDlyaLimit_Scripts
- {
- //Внимание! В классе должен быть метод Execute с данной сигнатурой
- public void Execute(Parameters parameters)
- {
- var service = Locator.GetServiceNotNull<BankSettingsModule>();
- var url = string.Format("{0}/API/Elma/basic", service.Settings.UriPlatform);
- var endpointAdress = new EndpointAddress(url);
- var binding = service.Settings.UseSSL ? new BasicHttpBinding(BasicHttpSecurityMode.Transport) : new BasicHttpBinding(BasicHttpSecurityMode.None);
- binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
- binding.MaxReceivedMessageSize = long.MaxValue;
- var timeout = new TimeSpan(0, 10, 0);
- binding.OpenTimeout = timeout;
- binding.CloseTimeout = timeout;
- binding.SendTimeout = timeout;
- binding.ReceiveTimeout = timeout;
- binding.MaxBufferSize = int.MaxValue;
- binding.MaxBufferPoolSize = long.MaxValue;
- binding.TransferMode = TransferMode.Streamed;
- var myReaderQuotas = new XmlDictionaryReaderQuotas
- {
- MaxStringContentLength = int.MaxValue,
- MaxArrayLength = int.MaxValue,
- MaxBytesPerRead = int.MaxValue,
- MaxDepth = int.MaxValue,
- MaxNameTableCharCount = int.MaxValue
- };
- binding.ReaderQuotas = myReaderQuotas;
- using (var client = new ElmaServiceClient(binding, endpointAdress))
- {
- if (parameters.Request == null) return;
- var result = client.NBKIRequest(service.Settings?.PlatformPassword, (int)parameters.Request.OrhardContentId);
- if (result == null) return;
- if (string.IsNullOrWhiteSpace(result.SignFileHash) &&
- string.IsNullOrWhiteSpace(result.ContentFileHash))
- {
- result.SignFileHash = result.ContentFileHash = "1";
- }
- parameters.Request.NBKIResponse = result.ToEntity(parameters.Request, "NBKIResponse", parameters.Request.NBKIResponse) as SignedFile;
- var response = result.ToEntity(parameters.Request, "NBKIResponse", parameters.Request.NBKIResponse);
- if (parameters.Request.NBKIResponse == response) return;
- parameters.Request.NBKIResponse = response as SignedFile;
- try
- {
- var serializer = new XmlSerializer(typeof(ProductType));
- if (parameters.Request.NBKIResponse == null) return;
- using (var stream = new FileStream(parameters.Request.NBKIResponse.File.ContentFilePath,
- FileMode.Open))
- {
- var responseReader = XmlReader.Create(stream);
- var productNbki =
- serializer.Deserialize(responseReader) as
- Impeltech.Bank.Models.NBKI.Contracts.ProductType;
- var productNbkielma = productNbki?.ToEntity();
- if (productNbkielma == null) return;
- productNbkielma.RequestLimit = parameters.Request;
- productNbkielma.Save();
- }
- }
- catch (Exception ex)
- {
- Logger.Log.Log(LogLevel.Error, ex);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement