📄 ivrmanager.cs
字号:
namespace Imps.Client.Core
{
using Imps.Client;
using Imps.Client.Base;
using Imps.Common.Permission;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
public class IVRManager : UserItemBase
{
private bool _isStart;
private List<DateTime> _iVRStartTime;
private List<IVRDialog> _list;
public int InviteTimeOut;
public event EventHandler<IVRDialogEventArgs> ReceiveIVRInvite;
public IVRManager(User owner) : base(owner)
{
this.InviteTimeOut = 120;
this._list = new List<IVRDialog>();
owner.SipRequestReceived += new EventHandler<SipRequestReceivedEventArgs>(this, (IntPtr) this.owner_SipRequestReceived);
owner.StatusChanged += new EventHandler<UserSatusChangedEventArgs>(this, (IntPtr) this.owner_StatusChanged);
}
private void DoReceiveInvite(SipRequest req)
{
EventHandler handler = null;
Contact contact = base.Owner.ContactList.FindOrCreateContact(req.Message.From.Value, new AsyncBizOperation());
List<IVRDialog>.Enumerator enumerator = this.IVRDialogList.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
IVRDialog dialog = enumerator.get_Current();
if (((dialog.IsBeInvite && (dialog.IVRList.get_Count() == 1)) && ((dialog.IVRList.get_Item(0).Contact == contact) && !dialog.IsCanceled)) && (!dialog.IsAccepted && !dialog.IsOvertime))
{
return;
}
}
}
finally
{
enumerator.Dispose();
}
List<Contact> contacts = new List<Contact>();
contacts.Add(contact);
IVRDialog dialog = new IVRDialog(base.Owner, contacts);
List<IVR>.Enumerator enumerator2 = dialog.IVRList.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
enumerator2.get_Current().IvrRequest = req;
}
}
finally
{
enumerator2.Dispose();
}
dialog.IsBeInvite = true;
dialog.InviteContactIVR = dialog.IVRList.get_Item(0);
List<Contact>.Enumerator enumerator3 = this.GetContactsBySDP(req.Message.Body).GetEnumerator();
try
{
while (enumerator3.MoveNext())
{
Contact contact2 = enumerator3.get_Current();
if (!dialog.ContainsContact(contact2))
{
IVR ivr2 = new IVR(contact2, base.Owner, dialog);
dialog.IVRList.Add(ivr2);
}
}
}
finally
{
enumerator3.Dispose();
}
if (dialog.IVRList.get_Count() > 1)
{
dialog.IsMultiDialog = true;
}
this._list.Add(dialog);
IVR inviteContactIVR = dialog.InviteContactIVR;
if (inviteContactIVR.Contact.IsBlocked)
{
inviteContactIVR.Status = IVRParticipantStatus.Decline;
}
else
{
switch (inviteContactIVR.Contact.Permissions[PermissionPointName.Ivr].FinalValue)
{
case 0:
inviteContactIVR.Status = IVRParticipantStatus.Decline;
goto Label_0239;
case 1:
inviteContactIVR.Status = IVRParticipantStatus.Accept;
goto Label_0239;
}
}
Label_0239:
if (inviteContactIVR.Status != IVRParticipantStatus.Decline)
{
if (inviteContactIVR.Status == IVRParticipantStatus.Accept)
{
dialog.AcceptInvite();
}
else
{
dialog.InviteContactIVR.RegisterRing();
if (handler == null)
{
handler = delegate {
dialog.InviteContactIVR.UnRegisterRing();
};
}
dialog.Closed += handler;
}
FuncDispatcher.InvokeEventHandlerInUiThread<IVRDialogEventArgs>(this, this.ReceiveIVRInvite, new IVRDialogEventArgs(dialog));
}
else
{
dialog.Close();
}
}
private List<Contact> GetContactsBySDP(string sdp)
{
List<Contact> list = new List<Contact>();
using (StringReader reader = new StringReader(sdp))
{
while (reader.Peek() >= 0)
{
string text = reader.ReadLine();
if (text.StartsWith("a=user:"))
{
string uri = text.Replace("a=user:", "");
if (base.Owner.Uri.Raw != uri)
{
Contact contact = base.Owner.ContactList.FindOrCreateContact(uri, new AsyncBizOperation());
if (contact != null)
{
list.Add(contact);
}
}
}
}
}
return list;
}
public IVRDialog OpenIVRDialog(List<Contact> contacts)
{
IVRDialog dialog = new IVRDialog(base.Owner, contacts);
this._list.Add(dialog);
return dialog;
}
private void owner_SipRequestReceived(object sender, SipRequestReceivedEventArgs e)
{
if ((e.Request.Message.Method == "I") && (e.Request.Message.Body.IndexOf("s=VoiceChat") > -1))
{
this.DoReceiveInvite(e.Request);
}
}
private void owner_StatusChanged(object sender, UserSatusChangedEventArgs e)
{
if (((e.NewStatus == UserAccountStatus.Disconnected) || (e.NewStatus == UserAccountStatus.Logoff)) || (e.NewStatus == UserAccountStatus.None))
{
this.IVRStartTime.Clear();
}
}
public bool IsStart
{
get
{
return this._isStart;
}
internal set
{
this._isStart = value;
}
}
public List<IVRDialog> IVRDialogList
{
get
{
return this._list;
}
}
public List<DateTime> IVRStartTime
{
get
{
if (this._iVRStartTime == null)
{
this._iVRStartTime = new List<DateTime>();
}
return this._iVRStartTime;
}
}
public IVRDialog OwnerStartIVRDialog
{
get
{
List<IVRDialog>.Enumerator enumerator = this._list.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
IVRDialog dialog = enumerator.get_Current();
if (!dialog.IsBeInvite)
{
return dialog;
}
}
}
finally
{
enumerator.Dispose();
}
return null;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -