Beispiel #1
0
 private void ToolFile_Click(object sender, EventArgs e)
 {
     openFileDialog1.Title            = "请选择文件";
     openFileDialog1.CheckFileExists  = true;
     openFileDialog1.CheckPathExists  = true;
     openFileDialog1.Filter           = "文件|*.*";
     openFileDialog1.Multiselect      = false;
     openFileDialog1.InitialDirectory = Environment.SpecialFolder.MyPictures.ToString();
     openFileDialog1.FileName         = string.Empty;
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         PushHelper.Client.HttpSendFileAsync(PushHelper.Client.Url, openFileDialog1.FileName, url =>
         {
             try
             {
                 var fileUrl  = string.Format("[file={0}]{1}", url, Environment.NewLine);
                 var content  = new GFF.Component.ChatBox.ChatBoxContent();
                 content.Text = fileUrl;
                 SendMsgToServer(SerializeHelper.Serialize(content));
             }
             catch
             {
             }
         });
     }
 }
Beispiel #2
0
 private void OnReceivedMsg(string msg)
 {
     try
     {
         var userName = string.Empty;
         var json     = string.Empty;
         var content  = new GFF.Component.ChatBox.ChatBoxContent();
         if (!string.IsNullOrEmpty(msg) && (msg.IndexOf("|") > -1))
         {
             userName = msg.Substring(0, msg.IndexOf("|"));
             json     = msg.Substring(msg.IndexOf("|") + 1);
             try
             {
                 content = SerializeHelper.Deserialize <GFF.Component.ChatBox.ChatBoxContent>(json);
             }
             catch {
                 return;
             }
             content = SerializeHelper.Deserialize <GFF.Component.ChatBox.ChatBoxContent>(json);
             FriendHelper.Set(userName);
         }
         if (userName != qqUser.DisplayName)
         {
             if (content.Text == "发送了一个抖动提醒。\n")
             {
                 chatBoxSend.Focus();
                 VibrationHelper.Vibration(this);
             }
         }
         if (content.Text.IndexOf("[img=") > -1)
         {
             var fileUrls = content.Text.Split(new[] { @"\r\n" }, StringSplitOptions.None);
             foreach (var item in fileUrls)
             {
                 var imageUrl = item.Substring(item.IndexOf("[img=") + 5);
                 imageUrl = imageUrl.Substring(0, imageUrl.IndexOf("]"));
                 var img = ImageHelper.FromUrl(imageUrl);
                 content.AddForeignImage(0, img);
             }
             content.Text = " ";
         }
         if (content.Text.IndexOf("[file=") > -1)
         {
             var fileUrls = content.Text.Split(new[] { @"\r\n" }, StringSplitOptions.None);
             content.Text = "";
             foreach (var item in fileUrls)
             {
                 var fileUrl = item.Substring(item.IndexOf("[file=") + 6);
                 fileUrl       = fileUrl.Substring(0, fileUrl.IndexOf("]"));
                 content.Text += fileUrl + Environment.NewLine;
             }
         }
         AppendChatBoxContent(userName, null, content, Color.Blue, false);
     }
     catch
     {
     }
 }
Beispiel #3
0
        private void toolZhenDong_Click(object sender, EventArgs e)
        {
            var msg = "发送了一个抖动提醒。\n";

            //this.AppendMessage(this.QQUser.DisplayName, Color.Green, msg);
            chatBoxSend.Focus();
            VibrationHelper.Vibration(this);
            var content = new GFF.Component.ChatBox.ChatBoxContent();

            content.Text = msg;
            SendMsgToServer(SerializeHelper.Serialize(content));
        }
Beispiel #4
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            var content = chatBoxSend.GetContent();

            //发送内容为空时,不做响应
            if (content.IsEmpty())
            {
                return;
            }

            var url = string.Empty;

            if (content.ContainsForeignImage())
            {
                foreach (var item in content.ForeignImageDictionary)
                {
                    try
                    {
                        url += string.Format("[img={0}]{1}", ImageHelper.ToUrl(PushHelper.Client.Url, item.Value),
                                             Environment.NewLine);
                    }
                    catch
                    {
                    }
                }
                content.ForeignImageDictionary.Clear();
                content.Text = url;
            }
            var msgtxt = content.Text;

            //清空发送输入框
            chatBoxSend.Text = string.Empty;
            chatBoxSend.Focus();

            if (string.IsNullOrEmpty(msgtxt) && (content.EmotionDictionary.Count == 0))
            {
                return;
            }

            GFF.Component.ChatBox.ChatBoxContent c = new GFF.Component.ChatBox.ChatBoxContent();
            c.Text = msgtxt;
            c.EmotionDictionary = content.EmotionDictionary;
            c.PicturePositions  = content.PicturePositions;
            c.Font  = content.Font;
            c.Color = content.Color;
            string msg = SerializeHelper.Serialize(c);

            ThreadPool.QueueUserWorkItem(s => SendMsgToServer(msg));
        }
Beispiel #5
0
 /// <summary>
 ///     发送信息文本到内容框
 /// </summary>
 /// <param name="userName">名字</param>
 /// <param name="originTime">时间</param>
 /// <param name="content">发送内容</param>
 /// <param name="color">字体颜色</param>
 /// <param name="followingWords">是否有用户名</param>
 /// <param name="offlineMessage">是否在线消息</param>
 private void AppendChatBoxContent(string userName, DateTime?originTime, GFF.Component.ChatBox.ChatBoxContent content, Color color,
                                   bool followingWords, bool offlineMessage)
 {
     if (InvokeRequired)
     {
         BeginInvoke(
             new Action(
                 () =>
         {
             AppendChatBoxContent(userName, originTime, content, color, followingWords, offlineMessage);
         }));
     }
     else
     {
         if (!followingWords)
         {
             var showTime = DateTime.Now.ToLongTimeString();
             if (!offlineMessage && (originTime != null))
             {
                 showTime = originTime.Value.ToString();
             }
             if (userName == QQUser.DisplayName)
             {
                 color = Color.YellowGreen;
             }
             chatBox_history.AppendRichText(string.Format("{0}  {1}\n", userName, showTime),
                                            new Font(messageFont, FontStyle.Regular), color);
             if ((originTime != null) && offlineMessage)
             {
                 chatBox_history.AppendText(string.Format("    [{0} 离线消息] ", originTime.Value));
             }
             else
             {
                 chatBox_history.AppendText("    ");
             }
         }
         else
         {
             chatBox_history.AppendText("   .");
         }
         chatBox_history.AppendChatBoxContent(content);
         chatBox_history.AppendText("  \n");
         chatBox_history.Focus();
         chatBox_history.Select(chatBox_history.Text.Length, 0);
         chatBox_history.ScrollToCaret();
         chatBoxSend.Focus();
     }
 }
Beispiel #6
0
        /// <summary>
        /// 获取Box中的所有内容。
        /// </summary>
        /// <param name="containsForeignObject">内容中是否包含不是由IImagePathGetter管理的图片对象</param>
        /// <returns>key为位置,val为图片的ID</returns>
        public ChatBoxContent GetContent()
        {
            ChatBoxContent  content = new ChatBoxContent(this.Text, this.Font, this.ForeColor);
            List <REOBJECT> list    = this.RichEditOle.GetAllREOBJECT();

            for (int i = 0; i < list.Count; i++)
            {
                uint pos = (uint)list[i].posistion;
                content.PicturePositions.Add(pos);
                if (list[i].dwUser != 10000)
                {
                    content.AddEmotion(pos, list[i].dwUser);
                }
                else
                {
                    GifBox box = (GifBox)Marshal.GetObjectForIUnknown(list[i].poleobj);
                    content.AddForeignImage(pos, box.Image);
                }
            }

            return(content);
        }
Beispiel #7
0
 /// <summary>
 ///     发送信息文本到内容框
 /// </summary>
 /// <param name="userName">名字</param>
 /// <param name="originTime">时间</param>
 /// <param name="content">发送内容</param>
 /// <param name="color">字体颜色</param>
 /// <param name="followingWords">是否有用户名</param>
 private void AppendChatBoxContent(string userName, DateTime?originTime, GFF.Component.ChatBox.ChatBoxContent content, Color color,
                                   bool followingWords)
 {
     AppendChatBoxContent(userName, originTime, content, color, followingWords, originTime != null);
 }
Beispiel #8
0
 private void OnReceivedMsg(GFF.Component.ChatBox.ChatBoxContent content, DateTime?originTime)
 {
     AppendChatBoxContent(lblChatName.Tag == null ? "斯" : lblChatName.Tag.ToString(), originTime, content,
                          Color.Blue, false);
 }
Beispiel #9
0
        public void AppendChatBoxContent(ChatBoxContent content)
        {
            try
            {
                if (content == null || content.Text == null)
                {
                    return;
                }

                int count = this.Text.Length;
                if (content.EmotionDictionary != null)
                {
                    string pureText = content.Text;
                    //去掉表情和图片的占位符
                    List <uint> emotionPosList = new List <uint>(content.EmotionDictionary.Keys);
                    List <uint> tempList       = new List <uint>();
                    tempList.AddRange(emotionPosList);
                    foreach (uint key in content.ForeignImageDictionary.Keys)
                    {
                        tempList.Add(key);
                    }
                    tempList.Sort();

                    for (int i = tempList.Count - 1; i >= 0; i--)
                    {
                        pureText = pureText.Remove((int)tempList[i], 1);
                    }
                    this.AppendText(pureText);
                    //插入表情
                    for (int i = 0; i < tempList.Count; i++)
                    {
                        uint position = tempList[i];
                        if (emotionPosList.Contains(position))
                        {
                            this.InsertDefaultEmotion(content.EmotionDictionary[position], (int)(count + position));
                        }
                        else
                        {
                            this.InsertImage(content.ForeignImageDictionary[position], (int)(count + position));
                        }
                    }
                }
                else
                {
                    this.AppendText(content.Text);
                }

                this.Select(count, content.Text.Length);
                if (content.Color != null)
                {
                    this.SelectionColor = content.Color;
                }
                if (content.Font != null)
                {
                    this.SelectionFont = content.Font;
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }