PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/sipsorcery-core/SIPSorcery.Web.Services/CallManager/CallManagerPassThruService.cs

https://github.com/thecc4re/sipsorcery-mono
C# | 134 lines | 116 code | 18 blank | 0 comment | 12 complexity | 16d1185de2b5709fbff0e63002224964 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.ServiceModel;
  5. using System.ServiceModel.Channels;
  6. using System.Text;
  7. using System.Threading;
  8. using SIPSorcery.SIP.App;
  9. using SIPSorcery.Sys;
  10. using log4net;
  11. namespace SIPSorcery.Web.Services
  12. {
  13. public class CallManagerPassThruService : ICallManagerServices
  14. {
  15. private const int OPERATION_TIMEOUT = 5000;
  16. private static ILog logger = AppState.logger;
  17. private CallManagerProxy m_callManagerClient;
  18. private ISIPCallDispatcher m_sipCallDispatcher;
  19. public CallManagerPassThruService()
  20. {
  21. m_callManagerClient = new CallManagerProxy();
  22. }
  23. public CallManagerPassThruService(ISIPCallDispatcher sipCallDispatcher)
  24. {
  25. m_sipCallDispatcher = sipCallDispatcher;
  26. }
  27. public bool IsAlive()
  28. {
  29. try
  30. {
  31. logger.Debug("CallManagerPassThruService IsAlive.");
  32. CallManagerProxy client = (m_sipCallDispatcher != null) ? m_sipCallDispatcher.GetCallManagerClient() : m_callManagerClient;
  33. if (client != null)
  34. {
  35. logger.Debug("Sending isalive request to client endpoint at " + client.Endpoint.Address.ToString() + ".");
  36. return client.IsAlive();
  37. }
  38. else
  39. {
  40. throw new ApplicationException("Call Manager Pass Thru service could not create a client.");
  41. }
  42. }
  43. catch (Exception excp)
  44. {
  45. logger.Error("Exception CallManagerPassThruService IsAlive. " + excp.Message);
  46. return false;
  47. }
  48. }
  49. public string WebCallback(string username, string number)
  50. {
  51. try
  52. {
  53. logger.Debug("CallManagerPassThruService WebCallback, username=" + username + ", number=" + number + ".");
  54. CallManagerProxy client = (m_sipCallDispatcher != null) ? m_sipCallDispatcher.GetCallManagerClient() : m_callManagerClient;
  55. if (client != null)
  56. {
  57. logger.Debug("Sending WebCallback request to client endpoint at " + client.Endpoint.Address.ToString() + ".");
  58. return client.WebCallback(username, number);
  59. }
  60. else
  61. {
  62. throw new ApplicationException("Call Manager Pass Thru service could not create a client.");
  63. }
  64. }
  65. catch (Exception excp)
  66. {
  67. logger.Error("Exception CallManagerPassThruService WebCallback. " + excp.Message);
  68. return "Sorry there was an unexpected error, the web callback was not initiated.";
  69. }
  70. }
  71. public string BlindTransfer(string username, string destination, string replacesCallID)
  72. {
  73. try
  74. {
  75. logger.Debug("CallManagerPassThruService BlindTransfer, username=" + username + ", destination=" + destination + ".");
  76. CallManagerProxy client = (m_sipCallDispatcher != null) ? m_sipCallDispatcher.GetCallManagerClient() : m_callManagerClient;
  77. if (client != null)
  78. {
  79. logger.Debug("Sending BlindTransfer request to client endpoint at " + client.Endpoint.Address.ToString() + ".");
  80. return client.BlindTransfer(username, destination, replacesCallID);
  81. }
  82. else
  83. {
  84. throw new ApplicationException("Call Manager Pass Thru service could not create a client.");
  85. }
  86. }
  87. catch (Exception excp)
  88. {
  89. logger.Error("Exception CallManagerPassThruService BlindTransfer. " + excp.Message);
  90. return "Sorry there was an unexpected error, the blind transfer was not initiated.";
  91. }
  92. }
  93. public string DualTransfer(string username, string callID1, string callID2)
  94. {
  95. try
  96. {
  97. logger.Debug("CallManagerPassThruService DualTransfer, callID1=" + callID1 + ", callID2=" + callID2 + ".");
  98. CallManagerProxy client = (m_sipCallDispatcher != null) ? m_sipCallDispatcher.GetCallManagerClient() : m_callManagerClient;
  99. if (client != null)
  100. {
  101. logger.Debug("Sending DualTransfer request to client endpoint at " + client.Endpoint.Address.ToString() + ".");
  102. return client.DualTransfer(username, callID1, callID2);
  103. }
  104. else
  105. {
  106. throw new ApplicationException("Call Manager Pass Thru service could not create a client.");
  107. }
  108. }
  109. catch (Exception excp)
  110. {
  111. logger.Error("Exception CallManagerPassThruService DualTransfer. " + excp.Message);
  112. return "Sorry there was an unexpected error, the dual transfer was not initiated.";
  113. }
  114. }
  115. }
  116. }