Advertisement
yambroskin

Untitled

Sep 1st, 2017
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. using Impeltech.Bank.Models.NBKI;
  2. using System;
  3. using System.IO;
  4. using System.ServiceModel;
  5. using System.Xml;
  6. using System.Xml.Serialization;
  7. using EleWise.ELMA.Logging;
  8. using Impeltech.Bank;
  9. using Impeltech.Bank.Helpers;
  10. using Impeltech.Bank.Models;
  11. using Impeltech.Bank.Orchard;
  12. using Parameters = EleWise.ELMA.Workflow.Models.Parameters.CA_PerezaprositjVNBKIDlyaLimit;
  13. using EleWise.ELMA.Services;
  14.  
  15. namespace EleWise.ELMA.Model.Scripts
  16. {
  17.  
  18. /// <summary>
  19. /// Модуль сценариев пользовательского расширения "Перезапросить в НБКИ"
  20. /// </summary>
  21. //Внимание! Для корректной работы программы не изменяйте название класса
  22. public class CA_PerezaprositjVNBKIDlyaLimit_Scripts
  23. {
  24.  
  25. //Внимание! В классе должен быть метод Execute с данной сигнатурой
  26. public void Execute(Parameters parameters)
  27. {
  28. var service = Locator.GetServiceNotNull<BankSettingsModule>();
  29. var url = string.Format("{0}/API/Elma/basic", service.Settings.UriPlatform);
  30. var endpointAdress = new EndpointAddress(url);
  31. var binding = service.Settings.UseSSL ? new BasicHttpBinding(BasicHttpSecurityMode.Transport) : new BasicHttpBinding(BasicHttpSecurityMode.None);
  32. binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
  33. binding.MaxReceivedMessageSize = long.MaxValue;
  34. var timeout = new TimeSpan(0, 10, 0);
  35. binding.OpenTimeout = timeout;
  36. binding.CloseTimeout = timeout;
  37. binding.SendTimeout = timeout;
  38. binding.ReceiveTimeout = timeout;
  39. binding.MaxBufferSize = int.MaxValue;
  40. binding.MaxBufferPoolSize = long.MaxValue;
  41. binding.TransferMode = TransferMode.Streamed;
  42. var myReaderQuotas = new XmlDictionaryReaderQuotas
  43. {
  44. MaxStringContentLength = int.MaxValue,
  45. MaxArrayLength = int.MaxValue,
  46. MaxBytesPerRead = int.MaxValue,
  47. MaxDepth = int.MaxValue,
  48. MaxNameTableCharCount = int.MaxValue
  49. };
  50. binding.ReaderQuotas = myReaderQuotas;
  51. using (var client = new ElmaServiceClient(binding, endpointAdress))
  52. {
  53. if (parameters.Request == null) return;
  54. var result = client.NBKIRequest(service.Settings?.PlatformPassword, (int)parameters.Request.OrhardContentId);
  55. if (result == null) return;
  56. if (string.IsNullOrWhiteSpace(result.SignFileHash) &&
  57. string.IsNullOrWhiteSpace(result.ContentFileHash))
  58. {
  59. result.SignFileHash = result.ContentFileHash = "1";
  60. }
  61. parameters.Request.NBKIResponse = result.ToEntity(parameters.Request, "NBKIResponse", parameters.Request.NBKIResponse) as SignedFile;
  62. var response = result.ToEntity(parameters.Request, "NBKIResponse", parameters.Request.NBKIResponse);
  63. if (parameters.Request.NBKIResponse == response) return;
  64. parameters.Request.NBKIResponse = response as SignedFile;
  65. try
  66. {
  67. var serializer = new XmlSerializer(typeof(ProductType));
  68. if (parameters.Request.NBKIResponse == null) return;
  69. using (var stream = new FileStream(parameters.Request.NBKIResponse.File.ContentFilePath,
  70. FileMode.Open))
  71. {
  72. var responseReader = XmlReader.Create(stream);
  73. var productNbki =
  74. serializer.Deserialize(responseReader) as
  75. Impeltech.Bank.Models.NBKI.Contracts.ProductType;
  76. var productNbkielma = productNbki?.ToEntity();
  77. if (productNbkielma == null) return;
  78. productNbkielma.RequestLimit = parameters.Request;
  79. productNbkielma.Save();
  80. }
  81. }
  82. catch (Exception ex)
  83. {
  84. Logger.Log.Log(LogLevel.Error, ex);
  85. }
  86. }
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement