PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/sipsorcery-silverlight/SIPSorcery.GUI/UserInterface/CallManager/SIPCallManager.xaml.cs

https://github.com/thecc4re/sipsorcery-mono
C# | 305 lines | 264 code | 39 blank | 2 comment | 21 complexity | a8154ad0feda578212aa9470140e0fb3 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Net.Sockets;
  8. using System.ServiceModel;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Documents;
  14. using System.Windows.Ink;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Animation;
  18. using System.Windows.Shapes;
  19. using SIPSorcery.SIP;
  20. using SIPSorcery.SIP.App;
  21. using SIPSorcery.Persistence;
  22. using SIPSorcery.Silverlight.Messaging;
  23. using SIPSorcery.UIControls;
  24. using SIPSorcery.SIPSorceryProvisioningClient;
  25. namespace SIPSorcery
  26. {
  27. public partial class SIPCallManager : UserControl
  28. {
  29. private const int SIPCALLS_DISPLAY_COUNT = 25;
  30. private const int SIPCDRS_DISPLAY_COUNT = 25;
  31. private ActivityMessageDelegate LogActivityMessage_External;
  32. private ActivityProgressDelegate ShowActivityProgress_External;
  33. private SIPSorceryPersistor m_persistor;
  34. private ObservableCollection<SIPDialogueAsset> m_sipCalls;
  35. private SIPDialogueAsset m_selectedSIPCall;
  36. private int m_sipCallsPanelOffset;
  37. private int m_sipCallsPanelCount;
  38. private int m_sipCDRsPanelOffset;
  39. private int m_sipCDRsPanelCount;
  40. private string m_owner;
  41. private string m_sipCallsWhere; // Used when filtering is enabled.
  42. private string m_sipCDRsWhere = "AnsweredStatus != 401 && AnsweredStatus != 407"; // Used when filtering is enabled.
  43. public bool Initialised;
  44. private bool m_initialLoadComplete;
  45. private bool m_sipCallsLoaded;
  46. private bool m_sipCDRsLoaded;
  47. private bool m_sipCallLoadInProgress;
  48. private bool m_sipCallsPanelRefreshInProgress;
  49. private bool m_sipCDRsPanelRefreshInProgress;
  50. public SIPCallManager()
  51. {
  52. InitializeComponent();
  53. }
  54. public SIPCallManager(
  55. ActivityMessageDelegate logActivityMessage,
  56. ActivityProgressDelegate showActivityProgress,
  57. SIPSorceryPersistor persistor,
  58. string owner)
  59. {
  60. InitializeComponent();
  61. LogActivityMessage_External = logActivityMessage;
  62. ShowActivityProgress_External = showActivityProgress;
  63. m_persistor = persistor;
  64. m_owner = owner;
  65. m_sipCallsPanel.SetTitle("Calls");
  66. m_sipCallsPanel.DisplayCount = SIPCALLS_DISPLAY_COUNT;
  67. m_sipCallsPanel.MenuEnableAdd(false);
  68. m_sipCallsPanel.MenuEnableFilter(false);
  69. m_sipCallsPanel.MenuEnableDelete(false);
  70. m_sipCallsPanel.GetAssetList = GetSIPCalls;
  71. m_sipCDRsPanel.SetTitle("CDRs");
  72. m_sipCDRsPanel.DisplayCount = SIPCDRS_DISPLAY_COUNT;
  73. m_sipCDRsPanel.MenuEnableAdd(false);
  74. m_sipCDRsPanel.MenuEnableFilter(false);
  75. m_sipCDRsPanel.MenuEnableDelete(false);
  76. m_sipCDRsPanel.GetAssetList = GetSIPCDRs;
  77. }
  78. public void Initialise()
  79. {
  80. Initialised = true;
  81. m_persistor.GetCallsComplete += new GetCallsCompleteDelegate(GetCallsComplete);
  82. m_persistor.GetCallsCountComplete += new GetCallsCountCompleteDelegate(GetCallsCountComplete);
  83. m_persistor.GetCDRsCountComplete += new GetCDRsCountCompleteDelegate(GetCDRsCountComplete);
  84. m_persistor.GetCDRsComplete += new GetCDRsCompleteDelegate(GetCDRsComplete);
  85. Load();
  86. }
  87. private void Load()
  88. {
  89. try
  90. {
  91. if (!m_sipCallsLoaded)
  92. {
  93. ShowActivityProgress_External(50);
  94. LogActivityMessage_External(MessageLevelsEnum.Info, "Loading in progress calls...");
  95. m_sipCallsPanel.RefreshAsync();
  96. }
  97. else if (!m_sipCDRsLoaded)
  98. {
  99. ShowActivityProgress_External(75);
  100. LogActivityMessage_External(MessageLevelsEnum.Info, "Loading CDRs...");
  101. m_sipCDRsPanel.RefreshAsync();
  102. }
  103. else
  104. {
  105. ShowActivityProgress_External(null);
  106. m_initialLoadComplete = true;
  107. }
  108. }
  109. catch (Exception excp)
  110. {
  111. LogActivityMessage_External(MessageLevelsEnum.Error, "Exception thrown loading the SIP Account Manager. " + excp.Message);
  112. }
  113. }
  114. public void Close()
  115. {
  116. m_persistor.GetCallsComplete -= new GetCallsCompleteDelegate(GetCallsComplete);
  117. m_persistor.GetCallsCountComplete -= new GetCallsCountCompleteDelegate(GetCallsCountComplete);
  118. m_persistor.GetCDRsCountComplete -= new GetCDRsCountCompleteDelegate(GetCDRsCountComplete);
  119. m_persistor.GetCDRsComplete -= new GetCDRsCompleteDelegate(GetCDRsComplete);
  120. }
  121. public void SIPMonitorMachineEventHandler(SIPMonitorMachineEvent machineEvent)
  122. {
  123. // Update the calls display.
  124. if (m_initialLoadComplete && !m_sipCallsPanelRefreshInProgress)
  125. {
  126. m_sipCallsPanel.RefreshAsync();
  127. }
  128. }
  129. #region SIP Calls functions.
  130. private void GetSIPCalls(int offset, int count)
  131. {
  132. if (!m_sipCallsPanelRefreshInProgress)
  133. {
  134. m_sipCallsPanelRefreshInProgress = true;
  135. m_sipCallLoadInProgress = true;
  136. m_sipCallsPanelOffset = offset;
  137. m_sipCallsPanelCount = count;
  138. m_persistor.GetCallsCountAsync(m_sipCallsWhere);
  139. }
  140. else
  141. {
  142. LogActivityMessage_External(MessageLevelsEnum.Warn, "A SIP calls refresh is already in progress.");
  143. }
  144. }
  145. private void GetCallsCountComplete(GetCallsCountCompletedEventArgs e)
  146. {
  147. try
  148. {
  149. m_sipCallsPanel.AssetListTotal = e.Result;
  150. m_persistor.GetCallsAsync(m_sipCallsWhere, m_sipCallsPanelOffset, m_sipCallsPanelCount);
  151. }
  152. catch (Exception excp)
  153. {
  154. string excpMessage = (excp.InnerException != null) ? excp.InnerException.Message : excp.Message;
  155. LogActivityMessage_External(MessageLevelsEnum.Error, "There was an error retrieving the number of in progress calls. " + excpMessage);
  156. m_sipCallLoadInProgress = false;
  157. m_sipCallsPanelRefreshInProgress = false;
  158. }
  159. }
  160. private void GetCallsComplete(GetCallsCompletedEventArgs e)
  161. {
  162. m_sipCallsLoaded = true;
  163. try
  164. {
  165. m_sipCalls = e.Result;
  166. m_sipCallsPanel.SetAssetListSource(m_sipCalls);
  167. if (!m_initialLoadComplete)
  168. {
  169. Load();
  170. }
  171. LogActivityMessage_External(MessageLevelsEnum.Info, "In progress calls successfully loaded " + DateTime.Now.ToString("dd MMM yyyy HH:mm:ss") + ".");
  172. }
  173. catch (Exception excp)
  174. {
  175. string excpMessage = (excp.InnerException != null) ? excp.InnerException.Message : excp.Message;
  176. LogActivityMessage_External(MessageLevelsEnum.Error, "There was an error retrieving the in progress calls. " + excpMessage);
  177. }
  178. finally
  179. {
  180. m_sipCallLoadInProgress = false;
  181. m_sipCallsPanelRefreshInProgress = false;
  182. }
  183. }
  184. private void SIPCallsDataGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  185. {
  186. try
  187. {
  188. if (m_initialLoadComplete && !m_sipCallLoadInProgress && m_sipCalls.Count > 0)
  189. {
  190. DataGrid dataGrid = (DataGrid)sender;
  191. SIPDialogueAsset sipCall = (SIPDialogueAsset)m_sipCallsDataGrid.SelectedItem;
  192. if (m_selectedSIPCall == null || m_selectedSIPCall != sipCall)
  193. {
  194. m_selectedSIPCall = sipCall;
  195. //m_sipCallsPanel.SetDetailsElement(editControl);
  196. }
  197. }
  198. }
  199. catch (Exception excp)
  200. {
  201. string excpMessage = (excp.InnerException != null) ? excp.InnerException.Message : excp.Message;
  202. LogActivityMessage_External(MessageLevelsEnum.Error, "Exception showing Call details. " + excpMessage);
  203. m_selectedSIPCall = null;
  204. }
  205. }
  206. #endregion
  207. #region SIP CDR Functions.
  208. private void GetSIPCDRs(int offset, int count)
  209. {
  210. if (!m_sipCDRsPanelRefreshInProgress)
  211. {
  212. m_sipCDRsPanelRefreshInProgress = true;
  213. m_sipCDRsPanelOffset = offset;
  214. m_sipCDRsPanelCount = count;
  215. m_persistor.GetCDRsCountAsync(m_sipCDRsWhere);
  216. }
  217. else
  218. {
  219. LogActivityMessage_External(MessageLevelsEnum.Warn, "A SIP CDRs refresh is already in progress.");
  220. }
  221. }
  222. private void GetCDRsCountComplete(GetCDRsCountCompletedEventArgs e)
  223. {
  224. try
  225. {
  226. m_sipCDRsPanel.AssetListTotal = e.Result;
  227. LogActivityMessage_External(MessageLevelsEnum.Info, e.Result + " CDRs found.");
  228. m_persistor.GetCDRsAsync(m_sipCDRsWhere, m_sipCDRsPanelOffset, m_sipCDRsPanelCount);
  229. }
  230. catch (Exception excp)
  231. {
  232. string excpMessage = (excp.InnerException != null) ? excp.InnerException.Message : excp.Message;
  233. LogActivityMessage_External(MessageLevelsEnum.Error, "There was an error retrieving the number of SIP CDRs. " + excpMessage);
  234. m_sipCDRsPanelRefreshInProgress = false;
  235. }
  236. }
  237. private void GetCDRsComplete(GetCDRsCompletedEventArgs e)
  238. {
  239. m_sipCDRsLoaded = true;
  240. try
  241. {
  242. m_sipCDRsPanel.SetAssetListSource(e.Result);
  243. if (!m_initialLoadComplete)
  244. {
  245. Load();
  246. }
  247. LogActivityMessage_External(MessageLevelsEnum.Info, "CDRs successfully loaded.");
  248. }
  249. catch (Exception excp)
  250. {
  251. string excpMessage = (excp.InnerException != null) ? excp.InnerException.Message : excp.Message;
  252. LogActivityMessage_External(MessageLevelsEnum.Error, "There was an error retrieving SIP CDRs. " + excpMessage);
  253. }
  254. finally
  255. {
  256. m_sipCDRsPanelRefreshInProgress = false;
  257. }
  258. }
  259. #endregion
  260. private void DetailsControlClosed()
  261. {
  262. m_selectedSIPCall = null;
  263. m_sipCallsPanel.CloseDetailsPane();
  264. }
  265. }
  266. }