• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Parser.FMessage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中WhatsAppApi.Parser.FMessage的典型用法代码示例。如果您正苦于以下问题:C# FMessage类的具体用法?C# FMessage怎么用?C# FMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FMessage类属于WhatsAppApi.Parser命名空间,在下文中一共展示了FMessage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: WhatsEventHandlerOnMessageRecievedEvent

        private void WhatsEventHandlerOnMessageRecievedEvent(FMessage mess)
        {
            if (mess == null || mess.key.remote_jid == null || mess.key.remote_jid.Length == 0)
                return;

            if(!this.messageHistory.ContainsKey(mess.key.remote_jid))
                this.messageHistory.Add(mess.key.remote_jid, new List<FMessage>());

            this.messageHistory[mess.key.remote_jid].Add(mess);
            this.CheckIfUserRegisteredAndCreate(mess);
        }
开发者ID:rquiroz,项目名称:WhatsAPINet,代码行数:11,代码来源:WhatsMessageHandler.cs


示例2: CheckIfUserRegisteredAndCreate

        private void CheckIfUserRegisteredAndCreate(FMessage mess)
        {
            if (this.messageHistory.ContainsKey(mess.key.remote_jid))
                return;

            var jidSplit = mess.key.remote_jid.Split('@');
            WhatsUser tmpWhatsUser = new WhatsUser(jidSplit[0], jidSplit[1], mess.key.serverNickname);
            User tmpUser = new User(jidSplit[0], jidSplit[1]);
            tmpUser.SetUser(tmpWhatsUser);

            this.messageHistory.Add(mess.key.remote_jid, new List<FMessage>());
            this.messageHistory[mess.key.remote_jid].Add(mess);
        }
开发者ID:rquiroz,项目名称:WhatsAPINet,代码行数:13,代码来源:WhatsMessageHandler.cs


示例3: OnMessageRecievedEventHandler

        /*
         * No need to add documentation here
         * User will only handle the delagates and events
         * */

        internal static void OnMessageRecievedEventHandler(FMessage mess)
        {
            var h = MessageRecievedEvent;
            if (h == null)
                return;
            foreach (var tmpSingleCast in h.GetInvocationList())
            {
                var tmpSyncInvoke = tmpSingleCast.Target as ISynchronizeInvoke;
                if (tmpSyncInvoke != null && tmpSyncInvoke.InvokeRequired)
                {
                    tmpSyncInvoke.BeginInvoke(tmpSingleCast, new object[] {mess});
                    continue;
                }
                h.BeginInvoke(mess, null, null);
            }
        }
开发者ID:Chandu-cuddle,项目名称:Chat-API-NET,代码行数:21,代码来源:WhatsEventHandler.cs


示例4: SendMessageWithBody

 protected void SendMessageWithBody(FMessage message, bool hidden = false)
 {
     var child = new ProtocolTreeNode("body", null, null, WhatsApp.SYSEncoding.GetBytes(message.data));
     this.SendNode(GetMessageNode(message, child, hidden));
 }
开发者ID:RCOliveira,项目名称:WhatsAPINet,代码行数:5,代码来源:WhatsApp.cs


示例5: getFmessageImage

        protected FMessage getFmessageImage(string to, byte[] ImageData, ImageType imgtype)
        {
            string type = string.Empty;
            string extension = string.Empty;
            switch (imgtype)
            {
                case ImageType.PNG:
                    type = "image/png";
                    extension = "png";
                    break;
                case ImageType.GIF:
                    type = "image/gif";
                    extension = "gif";
                    break;
                default:
                    type = "image/jpeg";
                    extension = "jpg";
                    break;
            }

            //create hash
            string filehash = string.Empty;
            using(HashAlgorithm sha = HashAlgorithm.Create("sha256"))
            {
                byte[] raw = sha.ComputeHash(ImageData);
                filehash = Convert.ToBase64String(raw);
            }

            //request upload
            WaUploadResponse response = this.UploadFile(filehash, "image", ImageData.Length, ImageData, to, type, extension);

            if (response != null && !String.IsNullOrEmpty(response.url))
            {
                //send message
                FMessage msg = new FMessage(to, true)
                {
                    media_wa_type = FMessage.Type.Image,
                    media_mime_type = response.mimetype,
                    media_name = response.url.Split('/').Last(),
                    media_size = response.size,
                    media_url = response.url,
                    binary_data = this.CreateThumbnail(ImageData)
                };
                return msg;
            }
            return null;
        }
开发者ID:RCOliveira,项目名称:WhatsAPINet,代码行数:47,代码来源:WhatsApp.cs


示例6: GetMessageNode

 protected static ProtocolTreeNode GetMessageNode(FMessage message, ProtocolTreeNode pNode, bool hidden = false)
 {
     return new ProtocolTreeNode("message", new[] {
         new KeyValue("to", message.identifier_key.remote_jid),
         new KeyValue("type", message.media_wa_type == FMessage.Type.Undefined?"text":"media"),
         new KeyValue("id", message.identifier_key.id)
     },
     new ProtocolTreeNode[] {
         new ProtocolTreeNode("x", new KeyValue[] { new KeyValue("xmlns", "jabber:x:event") }, new ProtocolTreeNode("server", null)),
         pNode,
         new ProtocolTreeNode("offline", null)
     });
 }
开发者ID:RCOliveira,项目名称:WhatsAPINet,代码行数:13,代码来源:WhatsApp.cs


示例7: SendMessageVcard

 public void SendMessageVcard(string to, string name, string vcard_data)
 {
     var tmpMessage = new FMessage(GetJID(to), true) { data = vcard_data, media_wa_type = FMessage.Type.Contact, media_name = name };
     this.SendMessage(tmpMessage, this.hidden);
 }
开发者ID:RCOliveira,项目名称:WhatsAPINet,代码行数:5,代码来源:WhatsApp.cs


示例8: SendMessage

 public void SendMessage(FMessage message, bool hidden = false)
 {
     if (message.media_wa_type != FMessage.Type.Undefined)
     {
         this.SendMessageWithMedia(message);
     }
     else
     {
         this.SendMessageWithBody(message, hidden);
     }
 }
开发者ID:RCOliveira,项目名称:WhatsAPINet,代码行数:11,代码来源:WhatsApp.cs


示例9: SendMessageReceived

        protected void SendMessageReceived(FMessage message, string response)
        {
            ProtocolTreeNode node = new ProtocolTreeNode("receipt", new[] {
                new KeyValue("to", message.identifier_key.remote_jid),
                new KeyValue("id", message.identifier_key.id)
            });

            this.SendNode(node);
        }
开发者ID:badr19,项目名称:WhatsAPINet,代码行数:9,代码来源:WhatsSendBase.cs


示例10: WhatsEventHandlerOnMessageRecievedEvent

 private void WhatsEventHandlerOnMessageRecievedEvent(FMessage mess)
 {
     var tmpMes = mess.data;
     this.AddNewText(this.user.UserName, tmpMes);
 }
开发者ID:richchen1010,项目名称:WhatsAPINet,代码行数:5,代码来源:frmUserChat.cs


示例11: GetMessageNode

 /// <summary>
 /// Get the message node
 /// </summary>
 /// <param name="message">the message</param>
 /// <param name="pNode">The protocol tree node</param>
 /// <returns>An instance of the ProtocolTreeNode class.</returns>
 internal static ProtocolTreeNode GetMessageNode(FMessage message, ProtocolTreeNode pNode, bool hidden = false)
 {
     return new ProtocolTreeNode("message", new[] {
         new KeyValue("to", message.identifier_key.remote_jid),
         new KeyValue("type", "chat"),
         new KeyValue("id", message.identifier_key.id)
     },
     new ProtocolTreeNode[] {
         new ProtocolTreeNode("x", new KeyValue[] { new KeyValue("xmlns", "jabber:x:event") }, new ProtocolTreeNode("server", null)),
         pNode,
         new ProtocolTreeNode("offline", null)
     });
 }
开发者ID:GruppoPotente,项目名称:WhatsAPINet,代码行数:19,代码来源:WhatsSendHandler.cs


示例12: SendMessageReceived

 /// <summary>
 /// Tell the server the message has been recieved.
 /// </summary>
 /// <param name="message">An instance of the FMessage class.</param>
 public void SendMessageReceived(FMessage message, string response)
 {
     var child = new ProtocolTreeNode(response, new[] { new KeyValue("xmlns", "urn:xmpp:receipts") });
     var node = new ProtocolTreeNode("message", new[] { new KeyValue("to", message.identifier_key.remote_jid), new KeyValue("type", "chat"), new KeyValue("id", message.identifier_key.id) }, child);
     this.whatsNetwork.SendData(this._binWriter.Write(node));
 }
开发者ID:GruppoPotente,项目名称:WhatsAPINet,代码行数:10,代码来源:WhatsSendHandler.cs


示例13: SendMessageReceived

        protected void SendMessageReceived(FMessage message, string type = "read")
        {
            KeyValue toAttrib = new KeyValue("to", message.identifier_key.remote_jid);
            KeyValue idAttrib = new KeyValue("id", message.identifier_key.id);

            var attribs = new List<KeyValue>();
            attribs.Add(toAttrib);
            attribs.Add(idAttrib);
            if (type.Equals("read"))
            {
                KeyValue typeAttrib = new KeyValue("type", type);
                attribs.Add(typeAttrib);
            }

            ProtocolTreeNode node = new ProtocolTreeNode("receipt", attribs.ToArray());

            this.SendNode(node);
        }
开发者ID:jwerba,项目名称:WhatsAPINet,代码行数:18,代码来源:WhatsSendBase.cs


示例14: MessageImage

        /// <summary>
        /// Send an image to a person
        /// </summary>
        /// <param name="msgid">The id of the message</param>
        /// <param name="to">the reciepient</param>
        /// <param name="url">The url to the image</param>
        /// <param name="file">Filename</param>
        /// <param name="size">The size of the image in string format</param>
        /// <param name="icon">Icon</param>
        public void MessageImage(string to, string filepath)
        {
            to = this.GetJID(to);
            FileInfo finfo = new FileInfo(filepath);
            string type = string.Empty;
            switch (finfo.Extension)
            {
                case ".png":
                    type = "image/png";
                    break;
                case ".gif":
                    type = "image/gif";
                    break;
                default:
                    type = "image/jpeg";
                    break;
            }

            //create hash
            string filehash = string.Empty;
            using(FileStream fs = File.OpenRead(filepath))
            {
                using(BufferedStream bs = new BufferedStream(fs))
                {
                    using(HashAlgorithm sha = HashAlgorithm.Create("sha256"))
                    {
                        byte[] raw = sha.ComputeHash(bs);
                        filehash = Convert.ToBase64String(raw);
                    }
                }
            }

            //request upload
            UploadResponse response = this.UploadFile(filehash, "image", finfo.Length, filepath, to, type);

            if (response != null && !String.IsNullOrEmpty(response.url))
            {
                //send message
                FMessage msg = new FMessage(to, true) { identifier_key = { id = TicketManager.GenerateId() }, media_wa_type = FMessage.Type.Image, media_mime_type = response.mimetype, media_name = response.url.Split('/').Last(), media_size = response.size, media_url = response.url, binary_data = this.CreateThumbnail(filepath) };
                this.WhatsSendHandler.SendMessage(msg);
            }
        }
开发者ID:jergasmx,项目名称:WhatsAPINet,代码行数:51,代码来源:WhatsApp.cs


示例15: Message

 /// <summary>
 /// Send a message to a person
 /// </summary>
 /// <param name="to">The phone number to send</param>
 /// <param name="txt">The text that needs to be send</param>
 public void Message(string to, string txt)
 {
     var tmpMessage = new FMessage(this.GetJID(to), true) { identifier_key = { id = TicketManager.GenerateId() }, data = txt };
     this.WhatsParser.WhatsSendHandler.SendMessage(tmpMessage);
 }
开发者ID:jergasmx,项目名称:WhatsAPINet,代码行数:10,代码来源:WhatsApp.cs


示例16: TypeChat

        /// <summary>
        /// Notify typing chat
        /// </summary>
        /// <param name="messageNode"></param>
        /// <param name="tmpAttrFrom"></param>
        /// <param name="tmpAttrbId"></param>
        /// <param name="builder"></param>
        /// <param name="tmpAttrFromJid"></param>
        private void TypeChat(ProtocolTreeNode messageNode, string tmpAttrFrom, string tmpAttrbId, FMessage.Builder builder, string tmpAttrFromJid)
        {
            foreach (ProtocolTreeNode itemNode in (messageNode.GetAllChildren() ?? new ProtocolTreeNode[0]))
            {
                if (ProtocolTreeNode.TagEquals(itemNode, "composing"))
                {
                    WhatsEventHandler.OnIsTypingEventHandler(tmpAttrFrom, true);
                }
                else if (ProtocolTreeNode.TagEquals(itemNode, "paused"))
                {
                    WhatsEventHandler.OnIsTypingEventHandler(tmpAttrFrom, false);
                }
                else if (ProtocolTreeNode.TagEquals(itemNode, "body") && (tmpAttrbId != null))
                {
                    string dataString = WhatsApp.SYSEncoding.GetString(itemNode.GetData());
                    var tmpMessKey = new FMessage.Key(tmpAttrFrom, false, tmpAttrbId);
                    builder.Key(tmpMessKey).Remote_resource(tmpAttrFromJid).NewIncomingInstance().Data(dataString);
                }
                else if (ProtocolTreeNode.TagEquals(itemNode, "media") && (tmpAttrbId != null))
                {
                    long tmpMediaSize;
                    int tmpMediaDuration;

                    builder.Media_wa_type(FMessage.GetMessage_WA_Type(itemNode.GetAttribute("type"))).Media_url(
                        itemNode.GetAttribute("url")).Media_name(itemNode.GetAttribute("file"));

                    if (long.TryParse(itemNode.GetAttribute("size"), WhatsConstants.WhatsAppNumberStyle,
                                      CultureInfo.InvariantCulture, out tmpMediaSize))
                    {
                        builder.Media_size(tmpMediaSize);
                    }
                    string tmpAttrSeconds = itemNode.GetAttribute("seconds");
                    if ((tmpAttrSeconds != null) &&
                        int.TryParse(tmpAttrSeconds, WhatsConstants.WhatsAppNumberStyle, CultureInfo.InvariantCulture, out tmpMediaDuration))
                    {
                        builder.Media_duration_seconds(tmpMediaDuration);
                    }

                    if (builder.Media_wa_type().HasValue && (builder.Media_wa_type().Value == FMessage.Type.Location))
                    {
                        double tmpLatitude = 0;
                        double tmpLongitude = 0;
                        string tmpAttrLatitude = itemNode.GetAttribute("latitude");
                        string tmpAttrLongitude = itemNode.GetAttribute("longitude");
                        if ((tmpAttrLatitude == null) || (tmpAttrLongitude == null))
                        {
                            tmpAttrLatitude = "0";
                            tmpAttrLongitude = "0";
                        }
                        else if (!double.TryParse(tmpAttrLatitude, WhatsConstants.WhatsAppNumberStyle, CultureInfo.InvariantCulture, out tmpLatitude) ||
                            !double.TryParse(tmpAttrLongitude, WhatsConstants.WhatsAppNumberStyle, CultureInfo.InvariantCulture, out tmpLongitude))
                        {
                            throw new CorruptStreamException("location message exception parsing lat or long attribute: " + tmpAttrLatitude + " " + tmpAttrLongitude);
                        }

                        builder.Latitude(tmpLatitude).Longitude(tmpLongitude);

                        string tmpAttrName = itemNode.GetAttribute("name");
                        string tmpAttrUrl = itemNode.GetAttribute("url");
                        if (tmpAttrName != null)
                        {
                            builder.Location_details(tmpAttrName);
                        }
                        if (tmpAttrUrl != null)
                        {
                            builder.Location_url(tmpAttrUrl);
                        }
                    }

                    if (builder.Media_wa_type().HasValue && (builder.Media_wa_type().Value) == FMessage.Type.Contact)
                    {
                        ProtocolTreeNode tmpChildMedia = itemNode.GetChild("media");
                        if (tmpChildMedia != null)
                        {
                            builder.Media_name(tmpChildMedia.GetAttribute("name")).Data(WhatsApp.SYSEncoding.GetString(tmpChildMedia.GetData()));
                        }
                    }
                    else
                    {
                        string tmpAttrEncoding = itemNode.GetAttribute("encoding") ?? "text";
                        if (tmpAttrEncoding == "text")
                        {
                            builder.Data(WhatsApp.SYSEncoding.GetString(itemNode.GetData()));
                        }
                    }
                    var tmpMessageKey = new FMessage.Key(tmpAttrFrom, false, tmpAttrbId);
                    builder.Key(tmpMessageKey).Remote_resource(tmpAttrFromJid).NewIncomingInstance();
                }
                else if (ProtocolTreeNode.TagEquals(itemNode, "request"))
                {
                    builder.Wants_receipt(true);
                }
//.........这里部分代码省略.........
开发者ID:netoCastillo,项目名称:WhatsAPINet,代码行数:101,代码来源:MessageRecvResponse.cs


示例17: sendMessageReceived

 protected void sendMessageReceived(ProtocolTreeNode msg, string response = "received")
 {
     FMessage tmpMessage = new FMessage(new FMessage.FMessageIdentifierKey(msg.GetAttribute("from"), true, msg.GetAttribute("id")));
     this.SendMessageReceived(tmpMessage, response);
 }
开发者ID:badr19,项目名称:WhatsAPINet,代码行数:5,代码来源:WhatsSendBase.cs


示例18: Message

        public string Message(string to, string txt)
        {
            //var bodyNode = new ProtocolTreeNode("body", null, txt);

            //var tmpMessage = new FMessage(to, true) { key = { id = TicketCounter.MakeId("mSend_") }, data = txt };
            var tmpMessage = new FMessage(to, true) { key = { id = TicketManager.GenerateId() }, data = txt };
            this.WhatsParser.WhatsSendHandler.SendMessage(tmpMessage);
            return tmpMessage.key.id;
        }
开发者ID:MrSiir,项目名称:WhatsAPINet,代码行数:9,代码来源:WhatsApp.cs


示例19: MessageImage

        public string MessageImage(string to, string url, long size, string mime_type, string binary_data, string mid)
        {
            //var mediaAttribs = new KeyValue[]
            //                       {
            //                           new KeyValue("xmlns", "urn:xmpp:whatsapp:mms"),
            //                           new KeyValue("type", "image"),
            //                           new KeyValue("url", url),
            //                           new KeyValue("file", file),
            //                           new KeyValue("size", size)
            //                       };

            //var mediaNode = new ProtocolTreeNode("media", mediaAttribs, icon);
            //this.SendMessageNode(msgid, to, mediaNode);

            if (string.IsNullOrEmpty(mid))
            {
                mid = TicketManager.GenerateId();
            }

            var tmpMessage = new FMessage(to, true) { key = { id = mid } };

            tmpMessage.binary_data = Convert.FromBase64String(binary_data);
            tmpMessage.data = "";
            tmpMessage.media_mime_type = mime_type;
            tmpMessage.media_name = "";
            tmpMessage.media_size = size;
            tmpMessage.media_url = url;
            tmpMessage.media_wa_type = FMessage.Type.Image;

            this.WhatsParser.WhatsSendHandler.SendMessageWithMedia(tmpMessage);
            return tmpMessage.key.id;
        }
开发者ID:MrSiir,项目名称:WhatsAPINet,代码行数:32,代码来源:WhatsApp.cs


示例20: SendMessageBroadcast

        public void SendMessageBroadcast(string[] to, FMessage message)
        {
            if (to != null && to.Length > 0 && message != null && !string.IsNullOrEmpty(message.data))
            {
                ProtocolTreeNode child;
                if (message.media_wa_type == FMessage.Type.Undefined)
                {
                    //text broadcast
                    child = new ProtocolTreeNode("body", null, null, WhatsApp.SYSEncoding.GetBytes(message.data));
                }
                else
                {
                    throw new NotImplementedException();
                }

                //compose broadcast envelope
                ProtocolTreeNode xnode = new ProtocolTreeNode("x", new KeyValue[] {
                    new KeyValue("xmlns", "jabber:x:event")
                }, new ProtocolTreeNode("server", null));
                List<ProtocolTreeNode> toNodes = new List<ProtocolTreeNode>();
                foreach (string target in to)
                {
                    toNodes.Add(new ProtocolTreeNode("to", new KeyValue[] { new KeyValue("jid", WhatsAppApi.WhatsApp.GetJID(target)) }));
                }

                ProtocolTreeNode broadcastNode = new ProtocolTreeNode("broadcast", null, toNodes);
                ProtocolTreeNode messageNode = new ProtocolTreeNode("message", new KeyValue[] {
                    new KeyValue("to", "broadcast"),
                    new KeyValue("type", message.media_wa_type == FMessage.Type.Undefined?"text":"media"),
                    new KeyValue("id", message.identifier_key.id)
                }, new ProtocolTreeNode[] {
                    broadcastNode,
                    xnode,
                    child
                });
                this.SendNode(messageNode);
            }
        }
开发者ID:RCOliveira,项目名称:WhatsAPINet,代码行数:38,代码来源:WhatsApp.cs



注:本文中的WhatsAppApi.Parser.FMessage类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Core.ActionInput类代码示例发布时间:2022-05-26
下一篇:
C# Helper.ProtocolTreeNode类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap