Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. namespace MyOrganization.EventSender
  2. {
  3. using MyOrganization.EventSender.DTOs;
  4. using MyOrganization.EventSender.Proxy;
  5. using MyOrganization.EventSender.Utilities;
  6. using log4net;
  7. using Newtonsoft.Json;
  8. using System;
  9. using System.ServiceModel;
  10. using System.ServiceProcess;
  11.  
  12. /// <summary>
  13. /// The User Session Detail Sender
  14. /// </summary>
  15. public class SessionDataSender : ISessionDataSender
  16. {
  17. private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  18. private SessionDataDTO _sessionDataDTO;
  19.  
  20. public SessionDataSender(SessionDataDTO sessionDataDTO)
  21. {
  22. _sessionDataDTO = sessionDataDTO;
  23. }
  24.  
  25.  
  26. public bool Send()
  27. {
  28. try
  29. {
  30. Proxy.MessageProcessorProxy.SessionDetails sd = new Proxy.MessageProcessorProxy.SessionDetails();
  31. sd.ChangeTime = _sessionDataDTO.ChangeTime;
  32. sd.ChangeType = _sessionDataDTO.ChangeType;
  33. sd.Username = _sessionDataDTO.Username;
  34. sd.SessionId = _sessionDataDTO.SessionId;
  35.  
  36. log.Info($"Sending SessionEvent [{sd.ChangeType}] to Web-Srver.");
  37.  
  38. var client = new Proxy.MessageProcessorProxy.MessageProcessorClient();
  39. var response = client.LogEventDetails(sd);
  40.  
  41. Proxy.ProxyFactory.CloseProxy(client as ICommunicationObject);
  42.  
  43. log.Info($"Web-Server Response: [{response.ResponseMessage}]. Reference: [ {JsonConvert.SerializeObject(sd)} ] ");
  44.  
  45. return true;
  46. }
  47. catch (Exception ex)
  48. {
  49. log.Error($"Exception: [{ex.ToString()}]");
  50.  
  51. return false;
  52. }
  53. }
  54. }
  55. }
  56.  
  57. [LogEntryExitAndErrorAnnotation]
  58. public void Send()
  59. {
  60. var sd = mapper.Map<Proxy.MessageProcessorProxy.SessionDetails>(_sessionDataDTO);
  61.  
  62. using (var client = new Proxy.MessageProcessorProxy.MessageProcessorClient())
  63. client.LogEventDetails(sd);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement