📄 conversation.cs
字号:
namespace Imps.Client.Core
{
using Imps.Base.Sipc;
using Imps.Client.Base;
using Imps.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
public class Conversation : UserItemBase
{
private AsyncBizOperation _bizOperation;
private long _callId;
private int _cSeq;
private Dialog _currentDialog;
private DialogCollection _dialogs;
private bool _hasCreateTempGroup;
private Guid _id;
private bool _isClosed;
private bool _ownerFormCreated;
public event EventHandler<DialogEventArgs> AddDialog;
public event EventHandler Closed;
internal Conversation(User owner) : this(owner, null)
{
}
internal Conversation(User owner, long? callId) : base(owner)
{
this._cSeq = 1;
this._id = Guid.NewGuid();
if (callId.get_HasValue())
{
this._callId = callId.get_Value();
}
else
{
this._callId = base.Owner.SipConnection.NextCallId();
}
this._dialogs = new DialogCollection();
}
internal void AsyncCreateTemporaryGroup(List<Contact> contacts)
{
lock (this)
{
if (this._hasCreateTempGroup)
{
return;
}
this._hasCreateTempGroup = true;
}
SipRequest req = base.CreateSipRequest("S", this._callId, this._cSeq++);
req.Message.AddHeader(new SipcEventHeader("CreateTemporaryGroup"));
req.Message.AddHeader(new SipcSupportedHeader("text/html-fragment"));
StringWriter tw = new StringWriter();
XmlHelper.CreateXmlWriterForSipRequest(tw, null, delegate (XmlWriter writer, object context) {
writer.WriteStartElement("participants");
List<Contact>.Enumerator enumerator = contacts.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
Contact contact = enumerator.get_Current();
writer.WriteStartElement("participant");
writer.WriteAttributeString("uri", contact.Uri.Raw);
writer.WriteEndElement();
}
}
finally
{
enumerator.Dispose();
}
writer.WriteEndElement();
});
req.Message.Body = tw.ToString();
req.FinalResponseReceived += new EventHandler<SipResponseReceivedEventArgs>(this, (IntPtr) this.<AsyncCreateTemporaryGroup>b__1);
ErrorHelper.HandleSendRequestErrorAndTimeout(req);
base.SendSipMessage(req);
}
public void Close()
{
lock (this)
{
if (!this._isClosed)
{
if ((this.CurrentDialog != null) && (this.CurrentDialog.WaitingMessageResponseCount > 0))
{
this.CurrentDialog.WaitingClose = true;
}
else
{
this._isClosed = true;
this.Dialogs.Clear();
lock (base.Owner.ConversationManager.Conversations)
{
if (base.Owner.ConversationManager.Conversations.Contains(this))
{
base.Owner.ConversationManager.Conversations.Remove(this);
}
}
FuncDispatcher.InvokeEventHandlerInUiThread(this, this.Closed, EventArgs.Empty);
}
}
}
}
public Dialog FindDialog(string to)
{
using (IEnumerator<Dialog> enumerator = this.Dialogs.GetEnumerator())
{
while (enumerator.MoveNext())
{
Dialog dialog = enumerator.get_Current();
if (dialog.To == to)
{
return dialog;
}
}
}
return null;
}
internal void RaiseAddDialog(DialogEventArgs e)
{
if (this.AddDialog != null)
{
FuncDispatcher.InvokeEventHandlerInUiThread<DialogEventArgs>(this, this.AddDialog, e);
}
}
public AsyncBizOperation BizOperation
{
get
{
if (this._bizOperation == null)
{
this._bizOperation = new AsyncBizOperation();
}
return this._bizOperation;
}
set
{
this._bizOperation = value;
}
}
public long CallId
{
get
{
return this._callId;
}
}
public Dialog CurrentDialog
{
get
{
if (this.Dialogs.Count > 0)
{
return this.Dialogs[this.Dialogs.Count - 1];
}
return this._currentDialog;
}
internal set
{
this._currentDialog = value;
}
}
public DialogCollection Dialogs
{
get
{
return this._dialogs;
}
}
public Guid Id
{
get
{
return this._id;
}
}
public bool IsClosed
{
get
{
return this._isClosed;
}
set
{
this._isClosed = value;
}
}
public bool OwnerFormCreated
{
get
{
return this._ownerFormCreated;
}
set
{
this._ownerFormCreated = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -