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

Language C# Lines 305
MD5 Hash a8154ad0feda578212aa9470140e0fb3
Repository https://github.com/thecc4re/sipsorcery-mono.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.ServiceModel;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SIPSorcery.SIP;
using SIPSorcery.SIP.App;
using SIPSorcery.Persistence;
using SIPSorcery.Silverlight.Messaging;
using SIPSorcery.UIControls;
using SIPSorcery.SIPSorceryProvisioningClient;

namespace SIPSorcery
{   
    public partial class SIPCallManager : UserControl
	{
        private const int SIPCALLS_DISPLAY_COUNT = 25;
        private const int SIPCDRS_DISPLAY_COUNT = 25;

        private ActivityMessageDelegate LogActivityMessage_External;
        private ActivityProgressDelegate ShowActivityProgress_External;
        private SIPSorceryPersistor m_persistor;

        private ObservableCollection<SIPDialogueAsset> m_sipCalls;
        private SIPDialogueAsset m_selectedSIPCall;
        private int m_sipCallsPanelOffset;
        private int m_sipCallsPanelCount;
        private int m_sipCDRsPanelOffset;
        private int m_sipCDRsPanelCount;

        private string m_owner;
        private string m_sipCallsWhere;     // Used when filtering is enabled.
        private string m_sipCDRsWhere = "AnsweredStatus != 401 && AnsweredStatus != 407";      // Used when filtering is enabled.

        public bool Initialised;
        private bool m_initialLoadComplete;
        private bool m_sipCallsLoaded;
        private bool m_sipCDRsLoaded;
        private bool m_sipCallLoadInProgress;
        private bool m_sipCallsPanelRefreshInProgress;
        private bool m_sipCDRsPanelRefreshInProgress;

        public SIPCallManager()
        {
            InitializeComponent();
        }

        public SIPCallManager(
            ActivityMessageDelegate logActivityMessage,
            ActivityProgressDelegate showActivityProgress,
            SIPSorceryPersistor persistor,
            string owner)
		{
			InitializeComponent();

            LogActivityMessage_External = logActivityMessage;
            ShowActivityProgress_External = showActivityProgress;
            m_persistor = persistor;
            m_owner = owner;

            m_sipCallsPanel.SetTitle("Calls");
            m_sipCallsPanel.DisplayCount = SIPCALLS_DISPLAY_COUNT;
            m_sipCallsPanel.MenuEnableAdd(false);
            m_sipCallsPanel.MenuEnableFilter(false);
            m_sipCallsPanel.MenuEnableDelete(false);
            m_sipCallsPanel.GetAssetList = GetSIPCalls;

            m_sipCDRsPanel.SetTitle("CDRs");
            m_sipCDRsPanel.DisplayCount = SIPCDRS_DISPLAY_COUNT;
            m_sipCDRsPanel.MenuEnableAdd(false);
            m_sipCDRsPanel.MenuEnableFilter(false);
            m_sipCDRsPanel.MenuEnableDelete(false);
            m_sipCDRsPanel.GetAssetList = GetSIPCDRs;
		}

        public void Initialise()
        {
            Initialised = true;

            m_persistor.GetCallsComplete += new GetCallsCompleteDelegate(GetCallsComplete);
            m_persistor.GetCallsCountComplete += new GetCallsCountCompleteDelegate(GetCallsCountComplete);
            m_persistor.GetCDRsCountComplete += new GetCDRsCountCompleteDelegate(GetCDRsCountComplete);
            m_persistor.GetCDRsComplete += new GetCDRsCompleteDelegate(GetCDRsComplete);

           Load();
        }

        private void Load()
        {
            try
            {
                if (!m_sipCallsLoaded)
                {
                    ShowActivityProgress_External(50);
                    LogActivityMessage_External(MessageLevelsEnum.Info, "Loading in progress calls...");
                    m_sipCallsPanel.RefreshAsync();
                }
                else if (!m_sipCDRsLoaded)
                {
                    ShowActivityProgress_External(75);
                    LogActivityMessage_External(MessageLevelsEnum.Info, "Loading CDRs...");
                    m_sipCDRsPanel.RefreshAsync();
                }
                else
                {
                    ShowActivityProgress_External(null);
                    m_initialLoadComplete = true;
                }
            }
            catch (Exception excp)
            {
                LogActivityMessage_External(MessageLevelsEnum.Error, "Exception thrown loading the SIP Account Manager. " + excp.Message);
            }
        }

        public void Close()
        {
            m_persistor.GetCallsComplete -= new GetCallsCompleteDelegate(GetCallsComplete);
            m_persistor.GetCallsCountComplete -= new GetCallsCountCompleteDelegate(GetCallsCountComplete);
            m_persistor.GetCDRsCountComplete -= new GetCDRsCountCompleteDelegate(GetCDRsCountComplete);
            m_persistor.GetCDRsComplete -= new GetCDRsCompleteDelegate(GetCDRsComplete);
        }

        public void SIPMonitorMachineEventHandler(SIPMonitorMachineEvent machineEvent)
        {
            // Update the calls display.
            if (m_initialLoadComplete && !m_sipCallsPanelRefreshInProgress)
            {
                m_sipCallsPanel.RefreshAsync();
            }
        }

        #region SIP Calls functions.

        private void GetSIPCalls(int offset, int count)
        {
            if (!m_sipCallsPanelRefreshInProgress)
            {
                m_sipCallsPanelRefreshInProgress = true;
                m_sipCallLoadInProgress = true;

                m_sipCallsPanelOffset = offset;
                m_sipCallsPanelCount = count;
                m_persistor.GetCallsCountAsync(m_sipCallsWhere);
            }
            else
            {
                LogActivityMessage_External(MessageLevelsEnum.Warn, "A SIP calls refresh is already in progress.");
            }
        }

        private void GetCallsCountComplete(GetCallsCountCompletedEventArgs e)
        {
            try
            {
                m_sipCallsPanel.AssetListTotal = e.Result;
                m_persistor.GetCallsAsync(m_sipCallsWhere, m_sipCallsPanelOffset, m_sipCallsPanelCount);
            }
            catch (Exception excp)
            {
                string excpMessage = (excp.InnerException != null) ? excp.InnerException.Message : excp.Message;
                LogActivityMessage_External(MessageLevelsEnum.Error, "There was an error retrieving the number of in progress calls. " + excpMessage);

                m_sipCallLoadInProgress = false;
                m_sipCallsPanelRefreshInProgress = false;
            }
        }

        private void GetCallsComplete(GetCallsCompletedEventArgs e)
        {
            m_sipCallsLoaded = true;

            try
            {
                m_sipCalls = e.Result;
                m_sipCallsPanel.SetAssetListSource(m_sipCalls);

                if (!m_initialLoadComplete)
                {
                    Load();
                }

                LogActivityMessage_External(MessageLevelsEnum.Info, "In progress calls successfully loaded " + DateTime.Now.ToString("dd MMM yyyy HH:mm:ss") + ".");
            }
            catch (Exception excp)
            {
                string excpMessage = (excp.InnerException != null) ? excp.InnerException.Message : excp.Message;
                LogActivityMessage_External(MessageLevelsEnum.Error, "There was an error retrieving the in progress calls. " + excpMessage);
            }
            finally
            {
                m_sipCallLoadInProgress = false;
                m_sipCallsPanelRefreshInProgress = false;
            }
        }

        private void SIPCallsDataGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (m_initialLoadComplete && !m_sipCallLoadInProgress && m_sipCalls.Count > 0)
                {
                    DataGrid dataGrid = (DataGrid)sender;
                    SIPDialogueAsset sipCall = (SIPDialogueAsset)m_sipCallsDataGrid.SelectedItem;

                    if (m_selectedSIPCall == null || m_selectedSIPCall != sipCall)
                    {
                        m_selectedSIPCall = sipCall;
                        //m_sipCallsPanel.SetDetailsElement(editControl);
                    }
                }
            }
            catch (Exception excp)
            {
                string excpMessage = (excp.InnerException != null) ? excp.InnerException.Message : excp.Message;
                LogActivityMessage_External(MessageLevelsEnum.Error, "Exception showing Call details. " + excpMessage);
                m_selectedSIPCall = null;
            }
        }

        #endregion

        #region SIP CDR Functions.

        private void GetSIPCDRs(int offset, int count)
        {
            if (!m_sipCDRsPanelRefreshInProgress)
            {
                m_sipCDRsPanelRefreshInProgress = true;

                m_sipCDRsPanelOffset = offset;
                m_sipCDRsPanelCount = count;
                m_persistor.GetCDRsCountAsync(m_sipCDRsWhere);
            }
            else
            {
                LogActivityMessage_External(MessageLevelsEnum.Warn, "A SIP CDRs refresh is already in progress.");
            }
        }

        private void GetCDRsCountComplete(GetCDRsCountCompletedEventArgs e)
        {
            try
            {
                m_sipCDRsPanel.AssetListTotal = e.Result;
                LogActivityMessage_External(MessageLevelsEnum.Info, e.Result + " CDRs found.");
                m_persistor.GetCDRsAsync(m_sipCDRsWhere, m_sipCDRsPanelOffset, m_sipCDRsPanelCount);
            }
            catch (Exception excp)
            {
                string excpMessage = (excp.InnerException != null) ? excp.InnerException.Message : excp.Message;
                LogActivityMessage_External(MessageLevelsEnum.Error, "There was an error retrieving the number of SIP CDRs. " + excpMessage);

                m_sipCDRsPanelRefreshInProgress = false;
            }
        }

        private void GetCDRsComplete(GetCDRsCompletedEventArgs e)
        {
            m_sipCDRsLoaded = true;

            try
            {
                m_sipCDRsPanel.SetAssetListSource(e.Result);

                if (!m_initialLoadComplete)
                {
                    Load();
                }

                LogActivityMessage_External(MessageLevelsEnum.Info, "CDRs successfully loaded.");
            }
            catch (Exception excp)
            {
                string excpMessage = (excp.InnerException != null) ? excp.InnerException.Message : excp.Message;
                LogActivityMessage_External(MessageLevelsEnum.Error, "There was an error retrieving SIP CDRs. " + excpMessage);
            }
            finally
            {
                m_sipCDRsPanelRefreshInProgress = false;
            }
        }

        #endregion

        private void DetailsControlClosed()
        {
            m_selectedSIPCall = null;
            m_sipCallsPanel.CloseDetailsPane();
        }
	}
}
Back to Top