當前位置: 首頁>>代碼示例>>C#>>正文


C# Helper.ProtocolTreeNode類代碼示例

本文整理匯總了C#中WhatsAppApi.Helper.ProtocolTreeNode的典型用法代碼示例。如果您正苦於以下問題:C# ProtocolTreeNode類的具體用法?C# ProtocolTreeNode怎麽用?C# ProtocolTreeNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ProtocolTreeNode類屬於WhatsAppApi.Helper命名空間,在下文中一共展示了ProtocolTreeNode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: UploadFile

        protected WaUploadResponse UploadFile(string b64hash, string type, long size, byte[] fileData, string to, string contenttype, string extension)
        {
            ProtocolTreeNode media = new ProtocolTreeNode("media", new KeyValue[] {
                new KeyValue("hash", b64hash),
                new KeyValue("type", type),
                new KeyValue("size", size.ToString())
            });
            string id = TicketManager.GenerateId();
            ProtocolTreeNode node = new ProtocolTreeNode("iq", new KeyValue[] {
                new KeyValue("id", id),
                new KeyValue("to", WhatsConstants.WhatsAppServer),
                new KeyValue("type", "set"),
                new KeyValue("xmlns", "w:m")
            }, media);
            this.uploadResponse = null;
            this.SendNode(node);
            int i = 0;
            while (this.uploadResponse == null && i <= 10)
            {
                i++;
                this.pollMessage();
            }
            if (this.uploadResponse != null && this.uploadResponse.GetChild("duplicate") != null)
            {
                WaUploadResponse res = new WaUploadResponse(this.uploadResponse);
                this.uploadResponse = null;
                return res;
            }
            else
            {
                try
                {
                    string uploadUrl = this.uploadResponse.GetChild("media").GetAttribute("url");
                    this.uploadResponse = null;

                    Uri uri = new Uri(uploadUrl);

                    string hashname = string.Empty;
                    byte[] buff = MD5.Create().ComputeHash(System.Text.Encoding.Default.GetBytes(b64hash));
                    StringBuilder sb = new StringBuilder();
                    foreach (byte b in buff)
                    {
                        sb.Append(b.ToString("X2"));
                    }
                    hashname = String.Format("{0}.{1}", sb.ToString(), extension);

                    string boundary = "zzXXzzYYzzXXzzQQ";

                    sb = new StringBuilder();

                    sb.AppendFormat("--{0}\r\n", boundary);
                    sb.Append("Content-Disposition: form-data; name=\"to\"\r\n\r\n");
                    sb.AppendFormat("{0}\r\n", to);
                    sb.AppendFormat("--{0}\r\n", boundary);
                    sb.Append("Content-Disposition: form-data; name=\"from\"\r\n\r\n");
                    sb.AppendFormat("{0}\r\n", this.phoneNumber);
                    sb.AppendFormat("--{0}\r\n", boundary);
                    sb.AppendFormat("Content-Disposition: form-data; name=\"file\"; filename=\"{0}\"\r\n", hashname);
                    sb.AppendFormat("Content-Type: {0}\r\n\r\n", contenttype);
                    string header = sb.ToString();

                    sb = new StringBuilder();
                    sb.AppendFormat("\r\n--{0}--\r\n", boundary);
                    string footer = sb.ToString();

                    long clength = size + header.Length + footer.Length;

                    sb = new StringBuilder();
                    sb.AppendFormat("POST {0}\r\n", uploadUrl);
                    sb.AppendFormat("Content-Type: multipart/form-data; boundary={0}\r\n", boundary);
                    sb.AppendFormat("Host: {0}\r\n", uri.Host);
                    sb.AppendFormat("User-Agent: {0}\r\n", WhatsConstants.UserAgent);
                    sb.AppendFormat("Content-Length: {0}\r\n\r\n", clength);
                    string post = sb.ToString();

                    TcpClient tc = new TcpClient(uri.Host, 443);
                    SslStream ssl = new SslStream(tc.GetStream());
                    try
                    {
                        ssl.AuthenticateAsClient(uri.Host);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }

                    List<byte> buf = new List<byte>();
                    buf.AddRange(Encoding.UTF8.GetBytes(post));
                    buf.AddRange(Encoding.UTF8.GetBytes(header));
                    buf.AddRange(fileData);
                    buf.AddRange(Encoding.UTF8.GetBytes(footer));

                    ssl.Write(buf.ToArray(), 0, buf.ToArray().Length);

                    //moment of truth...
                    buff = new byte[1024];
                    ssl.Read(buff, 0, 1024);

                    string result = Encoding.UTF8.GetString(buff);
                    foreach (string line in result.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries))
//.........這裏部分代碼省略.........
開發者ID:RCOliveira,項目名稱:WhatsAPINet,代碼行數:101,代碼來源:WhatsApp.cs

示例2: SendClientConfig

 public void SendClientConfig(string platform, string lg, string lc, Uri pushUri, bool preview, bool defaultSetting, bool groupsSetting, IEnumerable<GroupSetting> groups, Action onCompleted, Action<int> onError)
 {
     string id = TicketCounter.MakeId("config_");
     var node = new ProtocolTreeNode("iq",
                                 new[]
                                 {
                                     new KeyValue("id", id), new KeyValue("type", "set"),
                                     new KeyValue("to", "") //this.Login.Domain)
                                 },
                                 new ProtocolTreeNode[]
                                 {
                                     new ProtocolTreeNode("config",
                                     new[]
                                         {
                                             new KeyValue("xmlns","urn:xmpp:whatsapp:push"),
                                             new KeyValue("platform", platform),
                                             new KeyValue("lg", lg),
                                             new KeyValue("lc", lc),
                                             new KeyValue("clear", "0"),
                                             new KeyValue("id", pushUri.ToString()),
                                             new KeyValue("preview",preview ? "1" : "0"),
                                             new KeyValue("default",defaultSetting ? "1" : "0"),
                                             new KeyValue("groups",groupsSetting ? "1" : "0")
                                         },
                                     this.ProcessGroupSettings(groups))
                                 });
     this.SendNode(node);
 }
開發者ID:RCOliveira,項目名稱:WhatsAPINet,代碼行數:28,代碼來源:WhatsApp.cs

示例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);
            }
        }
開發者ID:netoCastillo,項目名稱:WhatsAPINet,代碼行數:37,代碼來源:MessageRecvResponse.cs

示例4: SendSync

 public void SendSync(string[] numbers, SyncMode mode = SyncMode.Delta, SyncContext context = SyncContext.Background, int index = 0, bool last = true)
 {
     List<ProtocolTreeNode> users = new List<ProtocolTreeNode>();
     foreach (string number in numbers)
     {
         string _number = number;
         if (!_number.StartsWith("+", StringComparison.InvariantCulture))
             _number = string.Format("+{0}", number);
         users.Add(new ProtocolTreeNode("user", null, System.Text.Encoding.UTF8.GetBytes(_number)));
     }
     ProtocolTreeNode node = new ProtocolTreeNode("iq", new KeyValue[]
     {
         new KeyValue("to", GetJID(this.phoneNumber)),
         new KeyValue("type", "get"),
         new KeyValue("id", TicketCounter.MakeId("sendsync_")),
         new KeyValue("xmlns", "urn:xmpp:whatsapp:sync")
     }, new ProtocolTreeNode("sync", new KeyValue[]
         {
             new KeyValue("mode", mode.ToString().ToLowerInvariant()),
             new KeyValue("context", context.ToString().ToLowerInvariant()),
             new KeyValue("sid", DateTime.Now.ToFileTimeUtc().ToString()),
             new KeyValue("index", index.ToString()),
             new KeyValue("last", last.ToString())
         },
         users.ToArray()
         )
     );
     this.SendNode(node);
 }
開發者ID:bastidererste,項目名稱:WhatsAPINet,代碼行數:29,代碼來源:WhatsApp.cs

示例5: 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;
     }
 }
開發者ID:JeremyManz,項目名稱:WinApp.NET,代碼行數:33,代碼來源:Message.cs

示例6: ProtocolTreeNode

 public ProtocolTreeNode(string tag, IEnumerable<KeyValue> attributeHash, ProtocolTreeNode children = null)
 {
     this.tag = tag ?? "";
     this.attributeHash = attributeHash ?? new KeyValue[0];
     this.children = children != null ? new ProtocolTreeNode[] { children } : new ProtocolTreeNode[0];
     this.data = new byte[0];
 }
開發者ID:krish-kapadia,項目名稱:WhatsAPINet,代碼行數:7,代碼來源:ProtocolTreeNode.cs

示例7: AddMessage

 public void AddMessage(ProtocolTreeNode node)
 {
     lock (messageLock)
     {
         this.messageQueue.Add(node);
     }
 }
開發者ID:RCOliveira,項目名稱:WhatsAPINet,代碼行數:7,代碼來源:WhatsAppBase.cs

示例8: fireOnGetMessageAudio

 protected void fireOnGetMessageAudio(ProtocolTreeNode mediaNode, string from, string id, string fileName, int fileSize, string url, byte[] preview, string name)
 {
     if (this.OnGetMessageAudio != null)
     {
         this.OnGetMessageAudio(mediaNode, from, id, fileName, fileSize, url, preview, name);
     }
 }
開發者ID:kunalsmehtajobs,項目名稱:Chat-API-NET,代碼行數:7,代碼來源:WhatsEventBase.cs

示例9: fireOnGetMessage

 protected void fireOnGetMessage(ProtocolTreeNode messageNode, string from, string id, string name, string message, bool receipt_sent)
 {
     if (this.OnGetMessage != null)
     {
         this.OnGetMessage(messageNode, from, id, name, message, receipt_sent);
     }
 }
開發者ID:kunalsmehtajobs,項目名稱:Chat-API-NET,代碼行數:7,代碼來源:WhatsEventBase.cs

示例10: 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;
     }
 }
開發者ID:4nh51rk,項目名稱:WhatsAPINet,代碼行數:26,代碼來源:WaUploadResponse.cs

示例11: addFeatures

        protected ProtocolTreeNode addFeatures()
        {
			ProtocolTreeNode readReceipts = new ProtocolTreeNode ("readreceipts", null,null, null);
			ProtocolTreeNode groups_v2 = new ProtocolTreeNode ("groups_v2", null,null, null);
			ProtocolTreeNode privacy = new ProtocolTreeNode ("privacy", null,null, null);
			ProtocolTreeNode presencev2 = new ProtocolTreeNode ("presence", null,null, null);
			return new ProtocolTreeNode("stream:features", null, new ProtocolTreeNode[] {readReceipts, groups_v2, privacy, presencev2}, null);
        }
開發者ID:kunalsmehtajobs,項目名稱:Chat-API-NET,代碼行數:8,代碼來源:WhatsSendBase.cs

示例12: Write

 public string Write(ProtocolTreeNode node)
 {
     if (node == null)
     {
         this.output += "\x00";
     }
     else
     {
         this.writeInternal(node);
     }
     return this.flushBuffer();
 }
開發者ID:rquiroz,項目名稱:WhatsAPINet,代碼行數:12,代碼來源:BinTreeNodeWriter.cs

示例13: Write

 public byte[] Write(ProtocolTreeNode node, bool encrypt = true)
 {
     if (node == null)
     {
         this.buffer.Add(0);
     }
     else
     {
         this.DebugPrint(node.NodeString("SENT: "));
         this.writeInternal(node);
     }
     return this.flushBuffer(encrypt);
 }
開發者ID:hermanho,項目名稱:WhatsAPINet,代碼行數:13,代碼來源:BinTreeNodeWriter.cs

示例14: SendClearDirty

 public void SendClearDirty(IEnumerable<string> categoryNames)
 {
     string id = TicketCounter.MakeId("clean_dirty_");
     //this.AddIqHandler(id, new FunXMPP.IqResultHandler(null));
     IEnumerable<ProtocolTreeNode> source = from category in categoryNames select new ProtocolTreeNode("category", new[] { new KeyValue("name", category) });
     var child = new ProtocolTreeNode("clean", new[] { new KeyValue("xmlns", "urn:xmpp:whatsapp:dirty") }, source);
     var node = new ProtocolTreeNode("iq",
                                     new[]
                                         {
                                             new KeyValue("id", id), new KeyValue("type", "set"),
                                             new KeyValue("to", "s.whatsapp.net")
                                         }, child);
     this.whatsNetwork.SendNode(node);
 }
開發者ID:rquiroz,項目名稱:WhatsAPINet,代碼行數:14,代碼來源:WhatsSendHandler.cs

示例15: Write

 public byte[] Write(ProtocolTreeNode node, bool encrypt = true)
 {
     if (node == null)
     {
         this.buffer.Add(0);
     }
     else
     {
         if (WhatsApp.DEBUG && WhatsApp.DEBUGOutBound)
             this.DebugPrint(node.NodeString("tx "));
         this.writeInternal(node);
     }
     return this.flushBuffer(encrypt);
 }
開發者ID:elloko75,項目名稱:Chat-API-NET,代碼行數:14,代碼來源:BinTreeNodeWriter.cs


注:本文中的WhatsAppApi.Helper.ProtocolTreeNode類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。