本文整理汇总了C#中WhatsAppApi.Helper.ProtocolTreeNode.GetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# ProtocolTreeNode.GetAttribute方法的具体用法?C# ProtocolTreeNode.GetAttribute怎么用?C# ProtocolTreeNode.GetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WhatsAppApi.Helper.ProtocolTreeNode
的用法示例。
在下文中一共展示了ProtocolTreeNode.GetAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
}
示例3: ParseMessageRecv
/// <summary>
/// Parse recieved message
/// </summary>
/// <param name="messageNode">TreeNode that contains the recieved message</param>
public void ParseMessageRecv(ProtocolTreeNode messageNode)
{
FMessage.Builder builder = new FMessage.Builder();
string tmpAttrbId = messageNode.GetAttribute("id");
string tmpAttrFrom = messageNode.GetAttribute("from");
string tmpAttrFromName = messageNode.GetAttribute("");
string tmpAttrFromJid = messageNode.GetAttribute("author") ?? "";
string tmpAttrType = messageNode.GetAttribute("type");
string tmpTAttribT = messageNode.GetAttribute("t");
long result = 0L;
if (!string.IsNullOrEmpty(tmpTAttribT) && long.TryParse(tmpTAttribT, out result))
{
builder.Timestamp(new DateTime?(WhatsConstants.UnixEpoch.AddSeconds((double)result)));
}
if ("error".Equals(tmpAttrType))
{
TypeError(messageNode, tmpAttrbId, tmpAttrFrom);
}
else if ("subject".Equals(tmpAttrType))
{
TypeSubject(messageNode, tmpAttrFrom, tmpAttrFromJid, tmpAttrbId, tmpTAttribT);
}
else if ("chat".Equals(tmpAttrType))
{
TypeChat(messageNode, tmpAttrFrom, tmpAttrbId, builder, tmpAttrFromJid);
}
else if ("notification".Equals(tmpAttrType))
{
TypeNotification(messageNode, tmpAttrFrom, tmpAttrbId);
}
}
示例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: AddMessage
public void AddMessage(ProtocolTreeNode node)
{
if (this.flowLayoutPanel1.InvokeRequired)
{
AddMessageCallbackNode r = new AddMessageCallbackNode(AddMessage);
this.Invoke(r, new object[] { node });
}
else
{
string author = String.Empty;
WappMessage msg = new WappMessage(node, this.target);
if (this.IsGroup)
{
//extract author
msg.author = node.GetAttribute("author");
}
this.messages.Add(msg);
this.limitMessages();
MessageStore.AddMessage(msg);
this.addChatMessage(msg);
this.ScrollToBottom();
}
}
示例8: 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");
// }
//.........这里部分代码省略.........
示例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: 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":
//TODO
break;
case "contacts":
//TODO
break;
default:
throw new NotImplementedException(node.NodeString());
}
this.SendNotificationAck(node);
}
示例11: 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"));
}
}
示例12: sendMessageReceived
/// <summary>
/// Tell the server we recieved the message
/// </summary>
/// <param name="msg">The ProtocolTreeNode that contains the message</param>
public void sendMessageReceived(ProtocolTreeNode msg, string response = "received")
{
FMessage tmpMessage = new FMessage(new FMessage.FMessageIdentifierKey(msg.GetAttribute("from"), true, msg.GetAttribute("id")));
this.WhatsParser.WhatsSendHandler.SendMessageReceived(tmpMessage, response);
}
示例13: UploadResponse
public UploadResponse(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;
}
}
示例14: sendMessageReceived
/// <summary>
/// Tell the server we recieved the message
/// </summary>
/// <param name="msg">The ProtocolTreeNode that contains the message</param>
protected void sendMessageReceived(ProtocolTreeNode msg)
{
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);
}
示例15: SendNotificationAck
private void SendNotificationAck(ProtocolTreeNode node, string type = null)
{
string from = node.GetAttribute("from");
string to = node.GetAttribute("to");
string participant = node.GetAttribute("participant");
string id = node.GetAttribute("id");
if (type == null)
{
type = node.GetAttribute("type");
}
List<KeyValue> attributes = new List<KeyValue>();
if (!string.IsNullOrEmpty(to))
{
attributes.Add(new KeyValue("from", to));
}
if (!string.IsNullOrEmpty(participant))
{
attributes.Add(new KeyValue("participant", participant));
}
attributes.AddRange(new[] {
new KeyValue("to", from),
new KeyValue("class", node.tag),
new KeyValue("id", id),
new KeyValue("type", type)
});
ProtocolTreeNode sendNode = new ProtocolTreeNode("ack", attributes.ToArray());
this.SendNode(sendNode);
}