本文整理匯總了C#中WhatsAppApi.Helper.ProtocolTreeNode.GetChild方法的典型用法代碼示例。如果您正苦於以下問題:C# ProtocolTreeNode.GetChild方法的具體用法?C# ProtocolTreeNode.GetChild怎麽用?C# ProtocolTreeNode.GetChild使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類WhatsAppApi.Helper.ProtocolTreeNode
的用法示例。
在下文中一共展示了ProtocolTreeNode.GetChild方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: WappMessage
public WappMessage(ProtocolTreeNode node, string jid)
{
ProtocolTreeNode body = node.GetChild("body");
ProtocolTreeNode media = node.GetChild("media");
if (node.tag == "message")
{
if (node.GetAttribute("type") == "subject")
{
Contact c = ContactStore.GetContactByJid(node.GetAttribute("author"));
this.data = c.ToString() + " changed subject to \"" + Encoding.ASCII.GetString(node.GetChild("body").GetData()) + "\"";
}
else
{
if (body != null)
{
this.data = Encoding.ASCII.GetString(node.GetChild("body").GetData());
this.type = "text";
}
else if (media != null)
{
this.type = media.GetAttribute("type");
if (media.data != null && media.data.Length > 0)
{
this.preview = Convert.ToBase64String(media.data);
}
this.data = media.GetAttribute("url");
}
}
this.from_me = false;
this.timestamp = DateTime.UtcNow;
this.jid = jid;
}
}
示例2: WaUploadResponse
public WaUploadResponse(ProtocolTreeNode node)
{
node = node.GetChild("duplicate");
if (node != null)
{
int oSize, oWidth, oHeight, oDuration, oAsampfreq, oAbitrate;
this.url = node.GetAttribute("url");
this.mimetype = node.GetAttribute("mimetype");
Int32.TryParse(node.GetAttribute("size"), out oSize);
this.filehash = node.GetAttribute("filehash");
this.type = node.GetAttribute("type");
Int32.TryParse(node.GetAttribute("width"), out oWidth);
Int32.TryParse(node.GetAttribute("height"), out oHeight);
Int32.TryParse(node.GetAttribute("duration"), out oDuration);
this.acodec = node.GetAttribute("acodec");
Int32.TryParse(node.GetAttribute("asampfreq"), out oAsampfreq);
this.asampfmt = node.GetAttribute("asampfmt");
Int32.TryParse(node.GetAttribute("abitrate"), out oAbitrate);
this.size = oSize;
this.width = oWidth;
this.height = oHeight;
this.duration = oDuration;
this.asampfreq = oAsampfreq;
this.abitrate = oAbitrate;
}
}
示例3: WappMessage
public WappMessage(ProtocolTreeNode node, string jid)
{
if (node.tag == "message")
{
if (node.GetAttribute("type") == "subject")
{
Contact c = ContactStore.GetContactByJid(node.GetAttribute("author"));
this.data = c.ToString() + " changed subject to \"" + Encoding.ASCII.GetString(node.GetChild("body").GetData()) + "\"";
}
else
{
this.data = Encoding.ASCII.GetString(node.GetChild("body").GetData());
}
this.from_me = false;
this.timestamp = DateTime.UtcNow;
this.jid = jid;
}
}
示例4: handleNotification
protected void handleNotification(ProtocolTreeNode node)
{
if (!String.IsNullOrEmpty(node.GetAttribute("notify")))
{
this.fireOnGetContactName(node.GetAttribute("from"), node.GetAttribute("notify"));
}
string type = node.GetAttribute("type");
switch (type)
{
case "picture":
ProtocolTreeNode child = node.children.FirstOrDefault();
this.fireOnNotificationPicture(child.tag,
child.GetAttribute("jid"),
child.GetAttribute("id"));
break;
case "status":
ProtocolTreeNode child2 = node.children.FirstOrDefault();
this.fireOnGetStatus(node.GetAttribute("from"),
child2.tag,
node.GetAttribute("notify"),
System.Text.Encoding.UTF8.GetString(child2.GetData()));
break;
case "subject":
//fire username notify
this.fireOnGetContactName(node.GetAttribute("participant"),
node.GetAttribute("notify"));
//fire subject notify
this.fireOnGetGroupSubject(node.GetAttribute("from"),
node.GetAttribute("participant"),
node.GetAttribute("notify"),
System.Text.Encoding.UTF8.GetString(node.GetChild("body").GetData()),
GetDateTimeFromTimestamp(node.GetAttribute("t")));
break;
case "contacts":
//TODO
break;
case "participant":
string gjid = node.GetAttribute("from");
string t = node.GetAttribute("t");
foreach (ProtocolTreeNode child3 in node.GetAllChildren())
{
if (child3.tag == "add")
{
this.fireOnGetParticipantAdded(gjid,
child3.GetAttribute("jid"),
GetDateTimeFromTimestamp(t));
}
else if (child3.tag == "remove")
{
this.fireOnGetParticipantRemoved(gjid,
child3.GetAttribute("jid"),
child3.GetAttribute("author"),
GetDateTimeFromTimestamp(t));
}
else if (child3.tag == "modify")
{
this.fireOnGetParticipantRenamed(gjid,
child3.GetAttribute("remove"),
child3.GetAttribute("add"),
GetDateTimeFromTimestamp(t));
}
}
break;
}
this.SendNotificationAck(node);
}
示例5: handleIq
protected void handleIq(ProtocolTreeNode node)
{
if (node.GetAttribute("type") == "error")
{
this.fireOnError(node.GetAttribute("id"), node.GetAttribute("from"), Int32.Parse(node.GetChild("error").GetAttribute("code")), node.GetChild("error").GetAttribute("text"));
}
if (node.GetChild("sync") != null)
{
//sync result
ProtocolTreeNode sync = node.GetChild("sync");
ProtocolTreeNode existing = sync.GetChild("in");
ProtocolTreeNode nonexisting = sync.GetChild("out");
//process existing first
Dictionary<string, string> existingUsers = new Dictionary<string, string>();
if (existing != null)
{
foreach (ProtocolTreeNode child in existing.GetAllChildren())
{
existingUsers.Add(System.Text.Encoding.UTF8.GetString(child.GetData()), child.GetAttribute("jid"));
}
}
//now process failed numbers
List<string> failedNumbers = new List<string>();
if (nonexisting != null)
{
foreach (ProtocolTreeNode child in nonexisting.GetAllChildren())
{
failedNumbers.Add(System.Text.Encoding.UTF8.GetString(child.GetData()));
}
}
int index = 0;
Int32.TryParse(sync.GetAttribute("index"), out index);
this.fireOnGetSyncResult(index, sync.GetAttribute("sid"), existingUsers, failedNumbers.ToArray());
}
if (node.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase)
&& node.GetChild("query") != null
)
{
//last seen
DateTime lastSeen = DateTime.Now.AddSeconds(double.Parse(node.children.FirstOrDefault().GetAttribute("seconds")) * -1);
this.fireOnGetLastSeen(node.GetAttribute("from"), lastSeen);
}
if (node.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase)
&& (node.GetChild("media") != null || node.GetChild("duplicate") != null)
)
{
//media upload
this.uploadResponse = node;
}
if (node.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase)
&& node.GetChild("picture") != null
)
{
//profile picture
string from = node.GetAttribute("from");
string id = node.GetChild("picture").GetAttribute("id");
byte[] dat = node.GetChild("picture").GetData();
string type = node.GetChild("picture").GetAttribute("type");
if (type == "preview")
{
this.fireOnGetPhotoPreview(from, id, dat);
}
else
{
this.fireOnGetPhoto(from, id, dat);
}
}
if (node.GetAttribute("type").Equals("get", StringComparison.OrdinalIgnoreCase)
&& node.GetChild("ping") != null)
{
this.SendPong(node.GetAttribute("id"));
}
if (node.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase)
&& node.GetChild("group") != null)
{
//group(s) info
List<WaGroupInfo> groups = new List<WaGroupInfo>();
foreach (ProtocolTreeNode group in node.children)
{
groups.Add(new WaGroupInfo(
group.GetAttribute("id"),
group.GetAttribute("owner"),
group.GetAttribute("creation"),
group.GetAttribute("subject"),
group.GetAttribute("s_t"),
group.GetAttribute("s_o")
));
}
this.fireOnGetGroups(groups.ToArray());
}
if (node.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase)
&& node.GetChild("participant") != null)
{
//group participants
List<string> participants = new List<string>();
foreach (ProtocolTreeNode part in node.GetAllChildren())
{
if (part.tag == "participant" && !string.IsNullOrEmpty(part.GetAttribute("jid")))
{
participants.Add(part.GetAttribute("jid"));
//.........這裏部分代碼省略.........
示例6: handleMessage
protected void handleMessage(ProtocolTreeNode node, bool autoReceipt)
{
if (!string.IsNullOrEmpty(node.GetAttribute("notify")))
{
string name = node.GetAttribute("notify");
this.fireOnGetContactName(node.GetAttribute("from"), name);
}
if (node.GetAttribute("type") == "error")
{
throw new NotImplementedException(node.NodeString());
}
if (node.GetChild("body") != null)
{
//text message
this.fireOnGetMessage(node, node.GetAttribute("from"), node.GetAttribute("id"), node.GetAttribute("notify"), System.Text.Encoding.UTF8.GetString(node.GetChild("body").GetData()), autoReceipt);
if (autoReceipt)
{
this.sendMessageReceived(node);
}
}
if (node.GetChild("media") != null)
{
ProtocolTreeNode media = node.GetChild("media");
//media message
//define variables in switch
string file, url, from, id;
int size;
byte[] preview, dat;
id = node.GetAttribute("id");
from = node.GetAttribute("from");
switch (media.GetAttribute("type"))
{
case "image":
url = media.GetAttribute("url");
file = media.GetAttribute("file");
size = Int32.Parse(media.GetAttribute("size"));
preview = media.GetData();
this.fireOnGetMessageImage(node, from, id, file, size, url, preview);
break;
case "audio":
file = media.GetAttribute("file");
size = Int32.Parse(media.GetAttribute("size"));
url = media.GetAttribute("url");
preview = media.GetData();
this.fireOnGetMessageAudio(node, from, id, file, size, url, preview);
break;
case "video":
file = media.GetAttribute("file");
size = Int32.Parse(media.GetAttribute("size"));
url = media.GetAttribute("url");
preview = media.GetData();
this.fireOnGetMessageVideo(node, from, id, file, size, url, preview);
break;
case "location":
double lon = double.Parse(media.GetAttribute("longitude"), System.Globalization.CultureInfo.InvariantCulture);
double lat = double.Parse(media.GetAttribute("latitude"), System.Globalization.CultureInfo.InvariantCulture);
preview = media.GetData();
name = media.GetAttribute("name");
url = media.GetAttribute("url");
this.fireOnGetMessageLocation(node, from, id, lon, lat, url, name, preview);
break;
case "vcard":
ProtocolTreeNode vcard = media.GetChild("vcard");
name = vcard.GetAttribute("name");
dat = vcard.GetData();
this.fireOnGetMessageVcard(node, from, id, name, dat);
break;
}
this.sendMessageReceived(node);
}
}
示例7: TypeSubject
/// <summary>
/// Type subject
/// </summary>
/// <param name="messageNode"></param>
/// <param name="tmpFrom"></param>
/// <param name="uJid"></param>
/// <param name="tmpId"></param>
/// <param name="tmpT"></param>
private void TypeSubject(ProtocolTreeNode messageNode, string tmpFrom, string uJid, string tmpId, string tmpT)
{
bool flag = false;
foreach (ProtocolTreeNode item in messageNode.GetAllChildren("request"))
{
if (item.GetAttribute("xmlns").Equals("urn:xmpp:receipts"))
{
flag = true;
}
}
ProtocolTreeNode child = messageNode.GetChild("body");
string subject = (child == null) ? null : WhatsApp.SYSEncoding.GetString(child.GetData());
if (subject != null)
{
WhatsEventHandler.OnGroupNewSubjectEventHandler(tmpFrom, uJid, subject, int.Parse(tmpT, CultureInfo.InvariantCulture));
}
if (flag)
{
this.sendHandler.SendSubjectReceived(tmpFrom, tmpId);
}
}
示例8: sendMessageReceived
protected void sendMessageReceived(ProtocolTreeNode msg)
{
//this.WhatsParser.WhatsSendHandler.SendMessageReceived();
ProtocolTreeNode requestNode = msg.GetChild("request");
if (requestNode == null ||
!requestNode.GetAttribute("xmlns").Equals("urn:xmpp:receipts", StringComparison.OrdinalIgnoreCase))
return;
FMessage tmpMessage = new FMessage(new FMessage.Key(msg.GetAttribute("from"), true, msg.GetAttribute("id")));
this.WhatsParser.WhatsSendHandler.SendMessageReceived(tmpMessage);
//var receivedNode = new ProtocolTreeNode("received",
// new[] {new KeyValue("xmlns", "urn:xmpp:receipts")});
//var messageNode = new ProtocolTreeNode("message",
// new[]
// {
// new KeyValue("to", msg.GetAttribute("from")),
// new KeyValue("type", "chat"),
// new KeyValue("id", msg.GetAttribute("id"))
// },
// new[] {receivedNode});
//this.whatsNetwork.SendNode(messageNode);
}
示例9: ParseProtocolNode
/// <summary>
/// Parse a tree node
/// </summary>
/// <param name="protNode">An instance of the ProtocolTreeNode class that needs to be parsed.</param>
public void ParseProtocolNode(ProtocolTreeNode protNode)
{
if (ProtocolTreeNode.TagEquals(protNode, "iq"))
{
string attributeValue = protNode.GetAttribute("type");
string id = protNode.GetAttribute("id");
string str3 = protNode.GetAttribute("from");
if (attributeValue == null)
{
throw new Exception("Message-Corrupt: missing 'type' attribute in iq stanza");
}
if (!attributeValue.Equals("result"))
{
if (!attributeValue.Equals("get"))
{
if (!attributeValue.Equals("set"))
{
throw new Exception("Message-Corrupt: unknown iq type attribute: " + attributeValue);
}
ProtocolTreeNode child = protNode.GetChild("query");
if (child != null)
{
string str8 = child.GetAttribute("xmlns");
if ("jabber:iq:roster" == str8)
{
foreach (ProtocolTreeNode node5 in child.GetAllChildren("item"))
{
node5.GetAttribute("jid");
node5.GetAttribute("subscription");
node5.GetAttribute("ask");
}
}
}
}
else
{
ProtocolTreeNode node3 = protNode.GetChild("ping");
if ((!ProtocolTreeNode.TagEquals(node3, "query") || (str3 == null)) && (ProtocolTreeNode.TagEquals(node3, "relay") && (str3 != null)))
{
int num;
string pin = node3.GetAttribute("pin");
string tmpTimeout = node3.GetAttribute("timeout");
if ( !int.TryParse(tmpTimeout ?? "0", WhatsConstants.WhatsAppNumberStyle, CultureInfo.InvariantCulture, out num))
{
throw new CorruptStreamException("relay-iq exception parsing timeout attribute: " + tmpTimeout);
}
}
}
}
}
else if (ProtocolTreeNode.TagEquals(protNode, "presence"))
{
string str9 = protNode.GetAttribute("xmlns");
string jid = protNode.GetAttribute("from");
if (((str9 == null) || "urn:xmpp".Equals(str9)) && (jid != null))
{
string str11 = protNode.GetAttribute("type");
}
else if ("w".Equals(str9) && (jid != null))
{
string str12 = protNode.GetAttribute("add");
string str13 = protNode.GetAttribute("remove");
string str14 = protNode.GetAttribute("status");
if (str12 == null)
{
if (str13 == null)
{
if ("dirty".Equals(str14))
{
Dictionary<string, long> categories = ParseCategories(protNode);
}
}
}
}
}
else if (ProtocolTreeNode.TagEquals(protNode, "message"))
{
this.messResponseHandler.ParseMessageRecv(protNode);
}
}
示例10: UploadResponse
public UploadResponse(ProtocolTreeNode node)
{
node = node.GetChild("duplicate");
if (node != null)
{
this.url = node.GetAttribute("url");
this.mimetype = node.GetAttribute("mimetype");
this.size = Int32.Parse(node.GetAttribute("size"));
this.filehash = node.GetAttribute("filehash");
this.type = node.GetAttribute("type");
this.width = Int32.Parse(node.GetAttribute("width"));
this.height = Int32.Parse(node.GetAttribute("height"));
}
}
示例11: ParseProtocolNode
public void ParseProtocolNode(ProtocolTreeNode protNode)
{
if (ProtocolTreeNode.TagEquals(protNode, "iq"))
{
string attributeValue = protNode.GetAttribute("type");
string id = protNode.GetAttribute("id");
string str3 = protNode.GetAttribute("from");
if (attributeValue == null)
{
throw new Exception("Message-Corrupt: missing 'type' attribute in iq stanza");
}
if (!attributeValue.Equals("result"))
{
if (attributeValue.Equals("error"))
{
//IqResultHandler handler2 = this.PopIqHandler(id);
//if (handler2 != null)
//{
// handler2.ErrorNode(node);
//}
}
else if (!attributeValue.Equals("get"))
{
if (!attributeValue.Equals("set"))
{
throw new Exception("Message-Corrupt: unknown iq type attribute: " + attributeValue);
}
ProtocolTreeNode child = protNode.GetChild("query");
if (child != null)
{
string str8 = child.GetAttribute("xmlns");
if ("jabber:iq:roster" == str8)
{
foreach (ProtocolTreeNode node5 in child.GetAllChildren("item"))
{
node5.GetAttribute("jid");
node5.GetAttribute("subscription");
node5.GetAttribute("ask");
}
}
}
}
else
{
ProtocolTreeNode node3 = protNode.GetChild("ping");
if (node3 != null)
{
//this.EventHandler.OnPing(id);
}
else if ((!ProtocolTreeNode.TagEquals(node3, "query")
|| (str3 == null))
&& (ProtocolTreeNode.TagEquals(node3, "relay")
&& (str3 != null)))
{
int num;
string pin = node3.GetAttribute("pin");
string tmpTimeout = node3.GetAttribute("timeout");
if (
!int.TryParse(tmpTimeout ?? "0", WhatsConstants.WhatsAppNumberStyle, CultureInfo.InvariantCulture,
out num))
{
//throw new CorruptStreamException(
// "relay-iq exception parsing timeout attribute: " + tmpTimeout);
}
if (pin != null)
{
//this.EventHandler.OnRelayRequest(pin, num, id);
}
}
}
}
else
{
//IqResultHandler handler = this.PopIqHandler(id);
//if (handler != null)
//{
// handler.Parse(node, str3);
//}
//else if (id.StartsWith(this.Login.User))
//{
// ProtocolNode node2 = node.GetChild(0);
// ProtocolNode.Require(node2, "account");
// string str4 = node2.GetAttribute("kind");
// if ("paid".Equals(str4))
// {
// this.account_kind = AccountKind.Paid;
// }
// else if ("free".Equals(str4))
// {
// this.account_kind = AccountKind.Free;
// }
// else
// {
// this.account_kind = AccountKind.Unknown;
// }
// string s = node2.GetAttribute("expiration");
// if (s == null)
// {
// throw new IOException("no expiration");
// }
//.........這裏部分代碼省略.........
示例12: PopulateNewMessage
private void PopulateNewMessage(ProtocolTreeNode protocolNode)
{
string mfrom = protocolNode.GetAttribute("from");
string mtype = protocolNode.GetAttribute("type");
string mid = protocolNode.GetAttribute("id");
string mt = protocolNode.GetAttribute("t");
string mdata = "";
string mname = "";
string mdata_binary = "";
string murl = "";
string mfile = "";
string msize = "";
string mmimetype = "";
string mwidth = "";
string mheight = "";
string mduration = "";
string mlatitude = "";
string mlongitude = "";
//Console.WriteLine(protocolNode.NodeString());
if (ProtocolTreeNode.TagEquals(protocolNode, "iq") && protocolNode.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase) && ProtocolTreeNode.TagEquals(protocolNode.children.First(), "query"))
{
/*
<iq from="[email protected]" id="last_0" type="result">
<query xmlns="jabber:iq:last" seconds="3644"></query>
</iq>
*/
string from = mfrom.Substring(0, 11);
if (from == this.phoneNum) return;
double seconds = 0;
Double.TryParse(protocolNode.GetChild("query").GetAttribute("seconds").ToString(), out seconds);
try
{
string LastTime = "";
if (seconds > 0)
{
LastTime = WpfsAppStrings.ult_vez + " ";
DateTime UserLastTime = DateTime.Now.AddSeconds(-seconds);
if (UserLastTime.Date == DateTime.Now.Date)
{
LastTime += WpfsAppStrings.hoy;
}
else
{
LastTime += UserLastTime.ToShortDateString();
}
LastTime += " " + WpfsAppStrings.a_las + " " + UserLastTime.ToShortTimeString();
}
if (!this.userLast.ContainsKey(from))
{
this.userLast.Add(from, LastTime);
}
else if(this.userLast[from].Equals(""))
{
this.userLast[from] = LastTime;
}
}
catch (Exception) { }
return;
}
else if (ProtocolTreeNode.TagEquals(protocolNode, "iq") && protocolNode.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase) && ProtocolTreeNode.TagEquals(protocolNode.children.First(), "picture"))
{
string from = protocolNode.GetAttribute("from").Substring(0, 11);
if (from == this.phoneNum)
{
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = new MemoryStream(protocolNode.children.First().data);
bi.EndInit();
this.imgUser.Source = bi;
this.lblUser.Content = this.phoneNick;
this.imgUser.Visibility = Visibility.Visible;
this.lblUser.Visibility = Visibility.Visible;
}
else if (!this.userImgs.ContainsKey(from))
{
this.userImgs.Add(from, protocolNode.children.First().data);
}
}
else if (ProtocolTreeNode.TagEquals(protocolNode, "presence"))
{
/*
<presence from="[email protected]" type="available"></presence>
<presence from="[email protected]" type="unavailable"></presence>
*/
if (mfrom.Substring(0, 11) == this.phoneNum) return;
if (mfrom != null && mtype != null && !mfrom.Equals("") && !mtype.Equals(""))
//.........這裏部分代碼省略.........