Beispiel #1
0
        public void Init()
        {
            this.TitleLabel.Content = this.To;

            if (SignalRProxy == null)
            {
                SignalRProxy = new SignalRProxy();
            }
            SignalRProxy.ConnectAsync();


            //注册SignalR客户端方法
            if (SignalRProxy.ReceviceFialureMessage == null)
            {
                SignalRProxy.ReceviceFialureMessage = (message) =>
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        MessageBox.Show(message);
                    });
                };
            }

            if (SignalRProxy.ReceviceMessage == null)
            {
                SignalRProxy.ReceviceMessage = (username, message) =>
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        LeftMessageBoxUControl leftMessageBoxUControl = new LeftMessageBoxUControl();
                        leftMessageBoxUControl.Init(username, message);
                        this.MessageStackPanel.Children.Add(leftMessageBoxUControl);
                    });
                };
            }

            if (SignalRProxy.ReceviceRecord == null)
            {
                SignalRProxy.ReceviceRecord = (username, record) =>
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        if (username.Equals(To))
                        {
                            LeftMessageBoxUControl leftMessageBoxUControl = new LeftMessageBoxUControl();
                            leftMessageBoxUControl.Init(To, record);
                            this.MessageStackPanel.Children.Add(leftMessageBoxUControl);
                        }
                        else
                        {
                            RightMessageBoxUControl rightMessageBoxUControl = new RightMessageBoxUControl();
                            rightMessageBoxUControl.Init(Self, record);
                            this.MessageStackPanel.Children.Add(rightMessageBoxUControl);
                        }
                    });
                };
            }
        }
Beispiel #2
0
        void PublicDialog()
        {
            PublicDialog pd = new PublicDialog();
            SignalRProxy s  = new SignalRProxy();

            pd.Init("邵工", "市场部", s);

            Thread.Sleep(10000);

            s.Login("邵工", "邵工");
            s.GetContactRecord("市场部");
            pd.Show();
        }
Beispiel #3
0
        void InputBtn_Click(object sender, RoutedEventArgs e)
        {
            String message = this.InputTBox.Text.Trim();

            try
            {
                SignalRProxy.PrivateSend(this.To, message, SignalCore.MessageType.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("发生未知错误!");
            }
        }
Beispiel #4
0
        public void Init(String userName, String group, SignalRProxy signalrProxy)
        {
            if (signalrProxy != null)
            {
                this.SignalRProxy = signalrProxy;
            }
            this.Group    = group;
            this.UserName = userName;

            if (SignalRProxy.ReceviceNotice == null)
            {
                SignalRProxy.ReceviceNotice = (username, notice) => {
                    this.Dispatcher.Invoke(() => {
                        //bool isExistence = false;
                        //foreach (var node in NoticeStackPanel.Children)
                        //{
                        //    if ((node as PLeftMessageBoxUControl).Id == notice.Id)
                        //    {
                        //        var item = node as PLeftMessageBoxUControl;
                        //        item.UpdateListBox(notice.Comments);
                        //        isExistence = true;
                        //        break;
                        //    }
                        //}

                        //if (!isExistence)
                        //{
                        //    if (notice.KeyWord == Expander_Range.Header.ToString())
                        //    {
                        //        PLeftMessageBoxUControl pLeftMessage = new PLeftMessageBoxUControl();
                        //        pLeftMessage.Init(notice.Belongs, notice.Comments, notice.DateTime,
                        //            notice.From, notice.Id, notice.Message);
                        //        pLeftMessage.Comment = (id) =>
                        //        {
                        //            this.CommentId = id;
                        //            this.input.ToolTip = "评论";
                        //            this.InputNoticeTBox.Text = userName + ":";
                        //        };
                        //        NoticeStackPanel.Children.Add(pLeftMessage);
                        //    }
                        //}
                        SaveMessage(notice, userName);
                    });
                };
            }

            SignalRProxy.ConnectAsync();
        }
Beispiel #5
0
        void InputNoticeBtn_Click(object sender, RoutedEventArgs e)
        {
            if (input.Content.Equals("+"))      //防止点击"+"直接发送消息了
            {
                return;
            }

            String keyword = Expander_Range.Header.ToString();

            if (input.ToolTip.Equals("发送"))
            {
                SignalRProxy.PublicSend(Group, false, String.Empty, System.Guid.Empty, keyword, this.InputNoticeTBox.Text.Trim(), SignalCore.MessageType.Text);
            }
            else
            {
                SignalRProxy.PublicSend(Group, true, String.Empty, CommentId, keyword, this.InputNoticeTBox.Text.Trim(), SignalCore.MessageType.Text);
            }
        }
Beispiel #6
0
        public void Init(String userName, String group, SignalRProxy signalrProxy)
        {
            if (signalrProxy != null)
            {
                this.SignalRProxy = signalrProxy;
            }
            this.Group    = group;
            this.UserName = userName;

            if (SignalRProxy.ReceviceNotice == null)
            {
                SignalRProxy.ReceviceNotice = (username, notice) => {
                    this.Dispatcher.Invoke(() => {
                        bool isExistence = false;
                        foreach (var node in NoticeStackPanel.Children)
                        {
                            if ((node as PLeftMessageBoxUControl).Id == notice.Id)
                            {
                                var item = node as PLeftMessageBoxUControl;
                                item.UpdateListBox(notice.Comments);
                                isExistence = true;
                                break;
                            }
                        }

                        if (!isExistence)
                        {
                            PLeftMessageBoxUControl pLeftMessage = new PLeftMessageBoxUControl();
                            pLeftMessage.Init(notice.Belongs, notice.Comments, notice.DateTime,
                                              notice.From, notice.Id, notice.Message);
                            pLeftMessage.Comment = (id) =>
                            {
                                this.CommentId            = id;
                                this.input.ToolTip        = "评论";
                                this.InputNoticeTBox.Text = userName + ":";
                            };
                            NoticeStackPanel.Children.Add(pLeftMessage);
                        }
                    });
                };
            }

            SignalRProxy.ConnectAsync();
        }