本文整理汇总了C#中ASC.Xmpp.Core.protocol.client.IQ.SwitchDirection方法的典型用法代码示例。如果您正苦于以下问题:C# IQ.SwitchDirection方法的具体用法?C# IQ.SwitchDirection怎么用?C# IQ.SwitchDirection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ASC.Xmpp.Core.protocol.client.IQ
的用法示例。
在下文中一共展示了IQ.SwitchDirection方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleIQ
public override IQ HandleIQ(XmppStream stream, IQ iq, XmppHandlerContext context)
{
Unique unique = (Unique)iq.SelectSingleElement(typeof(Unique));
if (unique != null)
{
// Gen unique id
unique.Value = UniqueId.CreateNewId(16);
iq.Type = IqType.result;
iq.SwitchDirection();
return iq;
}
iq.SwitchDirection();
iq.Type = IqType.error;
iq.Error = new Error(ErrorType.cancel, ErrorCondition.ItemNotFound);
return iq;
}
示例2: GetPrivate
private IQ GetPrivate(XmppStream stream, IQ iq, XmppHandlerContext context)
{
var privateStore = (Private)iq.Query;
if (!privateStore.HasChildElements) return XmppStanzaError.ToNotAcceptable(iq);
var retrived = new List<Element>();
foreach (var childNode in privateStore.ChildNodes)
{
if (childNode is Element)
{
var elementToRetrive = (Element)childNode;
var elementRestored = context.StorageManager.PrivateStorage.GetPrivate(iq.From, elementToRetrive);
retrived.Add(elementRestored ?? elementToRetrive);
}
}
privateStore.RemoveAllChildNodes();
foreach (var element in retrived)
{
privateStore.AddChild(element);
}
iq.SwitchDirection();
iq.Type = IqType.result;
return iq;
}
示例3: SetRegister
private IQ SetRegister(XmppStream stream, IQ iq, XmppHandlerContext context)
{
var register = (Register)iq.Query;
iq.Type = IqType.result;
if (register.RemoveAccount)
{
if (!stream.Authenticated || !iq.From.HasUser) context.Sender.SendToAndClose(stream, XmppStreamError.NotAuthorized);
context.UserManager.RemoveUser(iq.From);
foreach (var s in context.SessionManager.GetBareJidSessions(iq.From))
{
if (s.Stream.Id == stream.Id) continue;
context.Sender.SendToAndClose(s.Stream, XmppStreamError.Conflict);
}
//TODO: remove roster subscriptions
register.RemoveAllChildNodes();
iq.SwitchDirection();
return iq;
}
if (string.IsNullOrEmpty(register.Username) ||
string.IsNullOrEmpty(register.Password) ||
Stringprep.NamePrep(register.Username) != register.Username)
{
var error = XmppStanzaError.ToNotAcceptable(iq);
if (string.IsNullOrEmpty(register.Username)) error.Error.Message = "Empty required field Username.";
else if (string.IsNullOrEmpty(register.Password)) error.Error.Message = "Empty required field Password.";
else if (Stringprep.NamePrep(register.Username) != register.Username) error.Error.Message = "Invalid character.";
return error;
}
var userJid = new Jid(register.Username, stream.Domain, null);
if (context.UserManager.IsUserExists(userJid))
{
return XmppStanzaError.ToConflict(iq);
}
var user = new User(userJid, register.Password);
context.UserManager.SaveUser(user);
register.RemoveAllChildNodes();
if (stream.Authenticated) iq.SwitchDirection();
else iq.To = null;
iq.From = null;
return iq;
}
示例4: HandleIQ
public override IQ HandleIQ(ASC.Xmpp.Server.Streams.XmppStream stream, IQ iq, XmppHandlerContext context)
{
if (iq.Vcard!=null && iq.Type==IqType.get)
{
//Handle vcard
iq.Vcard = Member.GetVcard();
iq.Type = IqType.result;
iq.SwitchDirection();
return iq;
}
return base.HandleIQ(stream, iq, context);
}
示例5: SetPrivate
private IQ SetPrivate(XmppStream stream, IQ iq, XmppHandlerContext context)
{
var @private = (Private)iq.Query;
if ([email protected]) return XmppStanzaError.ToNotAcceptable(iq);
foreach (var childNode in @private.ChildNodes)
{
if (childNode is Element)
{
context.StorageManager.PrivateStorage.SetPrivate(iq.From, (Element)childNode);
}
}
iq.Query = null;
iq.SwitchDirection();
iq.Type = IqType.result;
return iq;
}
示例6: GetRegister
private IQ GetRegister(XmppStream stream, IQ iq, XmppHandlerContext context)
{
var register = (Register)iq.Query;
register.Username = string.Empty;
register.Password = string.Empty;
iq.Type = IqType.result;
if (iq.From.HasUser && context.UserManager.IsUserExists(iq.From))
{
register.Username = iq.From.User;
register.AddChild(new Element("registered"));
iq.SwitchDirection();
iq.From = null;
}
else
{
iq.From = iq.To = null;
}
return iq;
}
示例7: HandleIQ
public override IQ HandleIQ(XmppStream stream, IQ iq, XmppHandlerContext context)
{
//Admins iq
//New member
MucRoomMember member = Room.GetRealMember(iq.From);
if (member!=null)
{
if (iq.Query!=null)
{
if (iq.Query is Admin && (member.Affiliation==Affiliation.admin || member.Affiliation==Affiliation.owner))
{
Room.AdminCommand(iq, member);
}
else if (iq.Query is Owner && (member.Affiliation == Affiliation.owner))
{
Room.OwnerCommand(iq, member);
}
else
{
XmppStanzaError.ToForbidden(iq);
}
}
else
{
XmppStanzaError.ToBadRequest(iq);
}
}
else
{
XmppStanzaError.ToForbidden(iq);
}
if (!iq.Switched)
{
iq.SwitchDirection();
}
iq.From = Room.Jid;
return iq;
}
示例8: HandleIQ
public override IQ HandleIQ(XmppStream stream, IQ iq, XmppHandlerContext context)
{
if (iq.Type != IqType.get || !iq.HasTo) return XmppStanzaError.ToNotAcceptable(iq);
var currSession = context.SessionManager.GetSession(iq.From);
if (currSession == null || !currSession.Available) return XmppStanzaError.ToForbidden(iq);
double seconds = 0;//available
if (iq.To.IsServer)
{
seconds = (DateTime.UtcNow - startedTime).TotalSeconds;
}
else
{
var session = context.SessionManager.GetSession(iq.To);
if (session == null || !session.Available)
{
var lastActivity = context.StorageManager.OfflineStorage.GetLastActivity(iq.To);
if (lastActivity != null)
{
seconds = (DateTime.UtcNow - lastActivity.LogoutDateTime).TotalSeconds;
iq.Query.Value = lastActivity.Status;
}
else
{
return XmppStanzaError.ToRecipientUnavailable(iq);
}
}
}
((Last)(iq.Query)).Seconds = (int)seconds;
iq.Type = IqType.result;
iq.SwitchDirection();
return iq;
}
示例9: OwnerCommand
public void OwnerCommand(IQ iq, MucRoomMember member)
{
Owner owner = iq.Query as Owner;
// look for destroy
if (owner != null)
{
Destroy destroy = owner.SelectSingleElement(typeof(Destroy)) as Destroy;
if (destroy != null)
{
DestroyRoom(destroy);
return;
}
if (!owner.HasChildElements)
{
// Return config
owner.AddChild(RoomSettings.GetDataForm(member.Jid));
}
Data dataSubmit = (Data)owner.SelectSingleElement(typeof(Data));
// form config
if (dataSubmit != null && dataSubmit.Type == XDataFormType.submit)
{
RoomSettings.SubmitForm(dataSubmit);
SettingsSave();
iq.Query.RemoveAllChildNodes();
}
}
iq.Type = IqType.result;
iq.SwitchDirection();
}
示例10: ToResult
private IQ ToResult(IQ iq)
{
if (!iq.Switched) iq.SwitchDirection();
iq.Type = IqType.result;
return iq;
}
示例11: GetHistory
private IQ GetHistory(XmppStream stream, IQ iq, XmppHandlerContext context)
{
if (!iq.HasTo) return XmppStanzaError.ToServiceUnavailable(iq);
FlushMessageBuffer();
var history = (History)iq.Query;
history.RemoveAllChildNodes();
foreach (var m in archiveStore.GetMessages(iq.From, iq.To, history.From, history.To, history.Count))
{
history.AddChild(HistoryItem.FromMessage(m));
}
iq.Type = IqType.result;
iq.SwitchDirection();
return iq;
}
示例12: SetPrivateLog
private IQ SetPrivateLog(XmppStream stream, IQ iq, XmppHandlerContext context)
{
var privateLog = (PrivateLog)iq.Query;
foreach (var item in privateLog.SelectElements<PrivateLogItem>())
{
archiveStore.SetMessageLogging(iq.From, item.Jid, item.Log);
var to = new Jid(item.Jid.Bare);
var session = context.SessionManager.GetSession(to);
if (session != null)
{
var info = new IQ(IqType.set);
info.Id = UniqueId.CreateNewId();
info.From = iq.From;
info.To = session.Jid;
info.Query = new PrivateLog();
info.Query.AddChild(new PrivateLogItem() { Jid = iq.From, Log = item.Log });
context.Sender.SendTo(session, info);
}
}
privateLog.RemoveAllChildNodes();
iq.SwitchDirection();
iq.Type = IqType.result;
return iq;
}
示例13: GetPrivateLog
private IQ GetPrivateLog(XmppStream stream, IQ iq, XmppHandlerContext context)
{
if (!iq.HasTo) return XmppStanzaError.ToBadRequest(iq);
var privateLog = (PrivateLog)iq.Query;
privateLog.RemoveAllChildNodes();
var logging = archiveStore.GetMessageLogging(iq.From, iq.To);
privateLog.AddChild(new PrivateLogItem() { Jid = iq.To, Log = logging });
iq.SwitchDirection();
iq.Type = IqType.result;
return iq;
}