Example #1
0
        private void GetNewMessage()
        {
            if (!this.ExitApplication)
            {
                if (this.FormLoaded && (!this.Busyness))
                {
                    if (this.tvOrganize.InvokeRequired)
                    {
                        if (!this.ExitApplication)
                        {
                            SetGetNewMessage getNewMessage = new SetGetNewMessage(this.GetNewMessage);
                            if (getNewMessage != null)
                            {
                                this.Invoke(getNewMessage);
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            // 获取最新即时通讯消息
                            DotNetService dotNetService = new DotNetService();
                            //  这里获取用户的登录凭证,看与本地的是否一致?
                            string openId = string.Empty;
                            DataTable dataTable = dotNetService.MessageService.GetDataTableNew(this.UserInfo, out openId);
                            if ((dataTable != null) && (dataTable.Rows.Count > 0))
                            {
                                BaseMessageEntity messageEntity = new BaseMessageEntity();
                                for (int i = 0; i < dataTable.Rows.Count; i++)
                                {
                                    messageEntity.GetFrom(dataTable.Rows[i]);
                                    if (messageEntity.FunctionCode.Equals("Message"))
                                    {
                                        this.ShowMessage(messageEntity);
                                    }
                                    else
                                    {
                                        this.ShowRemind(messageEntity);
                                    }
                                    // 将信息标记为已阅读
                                    dotNetService.MessageService.Read(UserInfo, messageEntity.Id);
                                }
                                if (dotNetService.MessageService is ICommunicationObject)
                                {
                                    ((ICommunicationObject)dotNetService.MessageService).Close();
                                }
                            }
                            // 若检查在线状态,根本就无法登录了,所以加上这样的判断
                            if (BaseSystemInfo.CheckOnLine && !UserInfo.OpenId.Equals(openId))
                            {
                                //if (Program.frmMessage != null)
                                //{
                                //    Program.frmMessage.ExitApplication = true;
                                //    Program.frmMessage.AbortThread();
                                //    Program.frmMessage.Close();
                                //    Program.frmMessage.Dispose();
                                //}
                                throw  new InvalidOperationException();

                                // 修改当前用户的登录状态
                                BaseSystemInfo.UserIsLogOn = false;
                                if (MessageBox.Show(AppMessage.MSG0300, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Stop) == System.Windows.Forms.DialogResult.OK)
                                {
                                    Application.Exit();
                                }
                            }
                        }
                        catch (System.Exception ex)
                        {
                            // 在本地记录异常
                            FileUtil.WriteException(UserInfo, ex);
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// 得到新消息
        /// </summary>
        private void GetNewMessage()
        {
            if (this.ExitApplication)
            {
                return;
            }
            if (!this.FormLoaded || (this.Busyness))
            {
                return;
            }

            if (this.tvOrganize.InvokeRequired)
            {
                if (this.ExitApplication)
                {
                    return;
                }
                SetGetNewMessage getNewMessage = this.GetNewMessage;
                this.Invoke(getNewMessage);
            }
            else
            {
                try
                {
                    // 获取最新即时通讯消息
                    var serviceInstance = new RDIFrameworkService();
                    //  这里获取用户的登录凭证,看与本地的是否一致?
                    var openId    = string.Empty;
                    var dataTable = serviceInstance.MessageService.GetDTNew(this.UserInfo, out openId);
                    if ((dataTable != null) && (dataTable.Rows.Count > 0))
                    {
                        var messageEntity = new CiMessageEntity();
                        for (var i = 0; i < dataTable.Rows.Count; i++)
                        {
                            messageEntity.GetFrom(dataTable.Rows[i]);
                            if (messageEntity.FunctionCode.Equals("UserMessage"))
                            {
                                this.ShowMessage(messageEntity);
                            }
                            else
                            {
                                this.ShowRemind(messageEntity);
                            }
                            //TODO:系统推送的...

                            // 将信息标记为已阅读
                            serviceInstance.MessageService.Read(UserInfo, messageEntity.Id);
                        }
                        if (serviceInstance.MessageService is ICommunicationObject)
                        {
                            ((ICommunicationObject)serviceInstance.MessageService).Close();
                        }
                    }
                    // 若检查在线状态,根本就无法登录了,所以加上这样的判断
                    if (SystemInfo.CheckOnLine && !UserInfo.OpenId.Equals(openId))
                    {
                        if (AppStart.frmMsg != null)
                        {
                            AppStart.frmMsg.ExitApplication = true;
                            AppStart.frmMsg.AbortThread();
                            AppStart.frmMsg.Close();
                            AppStart.frmMsg.Dispose();
                        }
                        // 修改当前用户的登录状态
                        SystemInfo.LogOned = false;
                        if (MessageBox.Show(RDIFrameworkMessage.MSG0300, RDIFrameworkMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Stop) == System.Windows.Forms.DialogResult.OK)
                        {
                            Application.Exit();
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    // 在本地记录异常
                    FileHelper.WriteException(UserInfo, ex);
                }
            }
        }