예제 #1
0
        public static string GetMessage(MessageID code, CultureInfo culture)
        {
            string message = ResourceManager.GetString(code.ToString(), culture);

            Debug.Assert(!string.IsNullOrEmpty(message), code.ToString());
            return(message);
        }
예제 #2
0
 /// <remarks>Don't call this during a parse--it loads resources</remarks>
 public static string GetMessage(MessageID code)
 {
     return(code.ToString());
     //string message = ResourceManager.GetString(code.ToString());
     //Debug.Assert(!string.IsNullOrEmpty(message), code.ToString());
     //return message;
 }
예제 #3
0
        public override void OnMessage(USocket us, ByteBuf bb)
        {
            if (onMessage != null)
            {
                onMessage();
            }
            int len = bb.ReadShort();

            if (bb.ReadableBytes() != len)
            {
                Log.Error("数据长度不对!");
                return;
            }
            MessageID msgId = (MessageID)bb.ReadShort();

            byte[]   data    = bb.ReadBytes(len - 2);
            IMessage msgData = MessageMap.GetMessageData(msgId, data);

            if (msgData == null)
            {
                return;
            }
            //Messenger.BroadcastAsync<IMessage>(msgId.ToString(), msgData);
            Messenger.BroadcastAsync(msgId.ToString(), (object)msgData);
        }
예제 #4
0
 public Message(agsXMPP.protocol.client.Message msg, DirectionTypes directionType, DateTime receivedTime)
 {
     this.InternalMessage  = msg;
     this.DateTimeReceived = receivedTime;
     this.DirectionType    = directionType;
     this.Unread           = (directionType == DirectionTypes.Incoming);
     this.MessageID        = Guid.NewGuid();
     this.InternalMessage  = msg;
     this.Replied          = false;
     base.Path             = MessageID.ToString();
     UpdateItemInfo();
 }
예제 #5
0
 public override string ToString()
 {
     return(String.Join("\t",
                        new[]
     {
         MessageID.ToString(CultureInfo.InvariantCulture),
         Position.ToString(CultureInfo.InvariantCulture),
         ReplyTo.ToString(),
         TopicID.ToString(CultureInfo.InvariantCulture),
         UserID.ToString(CultureInfo.InvariantCulture),
         Message
     }) + (IsQuestion == IsQuestion.Unknown ? "" : "\t" + (int)IsQuestion));
 }
예제 #6
0
 public void SetPropertyDisplay()
 {
     StrIsEnabled = CurrentApp.GetLanguageInfo(IsEnabled ? "2501001" : "2501000",
                                               IsEnabled ? "Enabled" : "Disabled");
     StrType = Type.ToString();
     if (ListBasicDataInfos != null)
     {
         var info =
             ListBasicDataInfos.FirstOrDefault(
                 b => b.InfoID == S2501Consts.BID_ALARM_TYPE && b.Value == Type.ToString());
         if (info != null)
         {
             StrType =
                 CurrentApp.GetLanguageInfo(string.Format("BID{0}{1}", S2501Consts.BID_ALARM_TYPE, info.SortID.ToString("000")),
                                            info.Icon);
         }
     }
     StrLevel = Level.ToString();
     if (Level == -1)
     {
         StrLevel = CurrentApp.GetLanguageInfo("2501002", "Source Level");
     }
     if (ListBasicDataInfos != null)
     {
         var info =
             ListBasicDataInfos.FirstOrDefault(
                 b => b.InfoID == S2501Consts.BID_ALARM_LEVEL && b.Value == Level.ToString());
         if (info != null)
         {
             StrLevel =
                 CurrentApp.GetLanguageInfo(string.Format("BID{0}{1}", S2501Consts.BID_ALARM_LEVEL, info.SortID.ToString("000")),
                                            info.Icon);
         }
     }
     StrMessage = MessageID.ToString();
     if (Message != null)
     {
         StrMessage = CurrentApp.GetLanguageInfo(string.Format("2501MSG{0}", Message.SerialID), Message.Description);
         //全部状态
         if (Message.StatusID == 0)
         {
             StrMessage = string.Format("{0}[{1}]", StrMessage, CurrentApp.GetLanguageInfo("2501004", "All Status"));
         }
     }
     StrCreateTime = CreateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
 }
예제 #7
0
        public override void OnMessage(USocket us, ByteBuf bb)
        {
            if (onMessage != null)
            {
                onMessage();
            }
            int len = bb.ReadShort();

            if (bb.ReadableBytes() != len)
            {
                Log.Error("数据长度不对!");
                return;
            }
            MessageID msgId = (MessageID)bb.ReadShort();

            byte[]   data    = bb.ReadBytes(len - 2);
            IMessage msgData = null;

            switch (msgId)
            {
            case MessageID.ReqUserLogin:
            case MessageID.ReqUserRegister:
                Log.Error("收到请求消息非法!");
                return;

            case MessageID.ResUserLogin:
                ResUserLoginMessage userLogin = ResUserLoginMessage.Parser.ParseFrom(data);
                msgData = userLogin;
                break;

            case MessageID.ResUserRegister:
                break;

            default:
                break;
            }
            if (msgData == null)
            {
                return;
            }
            Messenger.BroadcastAsync <IMessage>(msgId.ToString(), msgData);
        }
예제 #8
0
 public static string GetMessage(MessageID id)
 {
     return(id.ToString());
 }
예제 #9
0
 /// <remarks>Don't call this during a parse--it loads resources</remarks>
 public static string GetMessage(MessageID code, CultureInfo culture)
 {
     string message = ResourceManager.GetString(code.ToString(), culture);
     Debug.Assert(!string.IsNullOrEmpty(message));
     return message;
 }
 /// <summary>
 /// Generate a client JavaScript for displaying modal window for message editing.
 /// </summary>
 private void ProcessData()
 {
     lnkEdit.OnClientClick = "EditBoardMessage('" + ResolveUrl("~/CMSModules/MessageBoards/CMSPages/Message_Edit.aspx") + "?messageid=" + MessageID.ToString() + "&messageboardid=" + MessageBoardID.ToString() + "');return false;";
 }
예제 #11
0
        public static DialogResult ShowMsg(MessageID messageId, MessageType msgType, params string[] args)
        {
            XmlHelper.XmlFilePath = AppDomain.CurrentDomain.BaseDirectory + @"Message.xml";
            string msg = XmlHelper.GetProValueByValue("Messagers", "message", "code", messageId.ToString());

            msg = String.Format(msg, args);

            if (msgType == MessageType.Alert)
            {
                return(MessageBox.Show(msg, "提示消息"));
            }
            else
            {
                return(MessageBox.Show(msg, "确认消息", MessageBoxButtons.OKCancel));
            }
        }
예제 #12
0
파일: ErrorFacts.cs 프로젝트: omajid/corefx
        public static string GetMessage(MessageID id)
        {
            string idStr = id.ToString();

            return(SR.GetResourceString(idStr, idStr));
        }
예제 #13
0
파일: ExecMsg.cs 프로젝트: Khrove/LowPay
 /// <summary>
 /// Gets a HashCode for this ExecMsg.  The Severity, MessageID, and
 /// Message text are all taken into account.
 /// </summary>
 /// <returns></returns>
 public override int GetHashCode()
 {
     return((Severity.ToString() + "\0" + MessageID.ToString() + "\0" + Message).GetHashCode());
 }
예제 #14
0
        /// <summary>
        /// 接收来自服务器的消息
        /// </summary>
        private void ReceiveMessage()
        {
            while (true)
            {
                #region 接收消息
                byte[] MessageBuffer        = new byte[] { };
                int    MessageBufferSize    = 0;
                string ServerMessagePackage = "";

                try
                {
                    MessageBuffer        = new byte[UnitySocket.ReceiveBufferSize - 1];
                    MessageBufferSize    = UnitySocket.Receive(MessageBuffer);
                    ServerMessagePackage = Encoding.UTF8.GetString(MessageBuffer, 0, MessageBufferSize);
                }
                catch (ThreadAbortException) { return; }
                catch (Exception ex)
                {
                    UnityModule.DebugPrint("接收消息时遇到错误:{0}", ex.Message);
                    HideMe(HideTo.JusetClose);
                    this.loginForm.Show();
                    this.loginForm.ShowTips("与服务器连接中断,请检查网络连接。" + Convert.ToString(ex.HResult, 16));
                    return;
                }

                UnityModule.DebugPrint("ServerMessagePackage : {0}", ServerMessagePackage);
                #endregion

                /*
                 * 遇到严重的TCP粘包问题,服务端分多次发送的GETFRIENDSLIST协议,被一次发送给了客户端
                 * 导致客户端只能提取到第一条协议,因为每条协议以'\n'结尾,所以每次收到数据包后对其按'\n'分割
                 * 分割后判断不为空的段后加'\n'再按正常的协议包处理,为空不处理
                 * 以上,解决粘包问题
                 */
                string[] ServerMessages = ServerMessagePackage.Split('\n');
                foreach (string TempServerMessage in ServerMessages)
                {
                    try
                    {
                        if (string.IsNullOrEmpty(TempServerMessage))
                        {
                            continue;
                        }

                        #region 读取消息协议类型
                        string ServerMessage = TempServerMessage + '\n';
                        UnityModule.DebugPrint("ServerMessage : {0}", ServerMessage);
                        string MessagePattern     = ProtocolFormatter.GetCMDTypePattern();
                        Regex  MessageRegex       = new Regex(MessagePattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        Match  MessageMatchResult = MessageRegex.Match(ServerMessage);
                        string cmdType            = MessageMatchResult.Groups["CMDTYPE"].Value.ToUpper();
                        UnityModule.DebugPrint("收到 CMDTYPE : {0}", cmdType);
                        #endregion

                        switch (cmdType)
                        {
                        case "CHATMESSAGE":
                        {
                            #region 聊天消息
                            string   FromID = null, Message = null;
                            int      MessageID;
                            DateTime ChatTime;
                            MessagePattern     = ProtocolFormatter.GetProtocolPattern(ProtocolFormatter.CMDType.ChatMessage);
                            MessageRegex       = new Regex(MessagePattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
                            MessageMatchResult = MessageRegex.Match(ServerMessage);
                            FromID             = MessageMatchResult.Groups["FROMID"].Value;
                            ChatTime           = DateTime.TryParse(MessageMatchResult.Groups["CHATTIME"].Value.ToString(), out ChatTime) ? ChatTime.ToLocalTime() : DateTime.Now;
                            MessageID          = int.Parse(MessageMatchResult.Groups["MESSAGEID"].Value);
                            Message            = Encoding.UTF8.GetString(Convert.FromBase64String(MessageMatchResult.Groups["MESSAGE"].Value));

                            this.Invoke(new Action(() =>
                                {
                                    FriendItem MessageFrom = FriendItem.GetFriendItemByFriendID(FromID);
                                    if (MessageFrom != null)
                                    {
                                        FriendsFlowPanel.Controls.SetChildIndex(MessageFrom, 0);

                                        if (FriendItem.ActiveFriend != MessageFrom)
                                        {
                                            MessageFrom.MessageNRTCount += 1;
                                        }

                                        MessageFrom.ChatBubblesPanel.Controls.Add(
                                            new ChatBubble
                                            (
                                                MessageID.ToString(),
                                                ChatTime.ToString(),
                                                FromID,
                                                Message,
                                                BubbleMaxWidth,
                                                false
                                            )
                                            );
                                    }
                                }));
                            break;
                            #endregion
                        }

                        case "GETCHATHISTORY":
                        {
                            #region 获取历史聊天记录
                            //todo:显示历史聊天记录
                            string FromID    = "";
                            int    MessageID = 0;
                            //更新本地第一条聊天记录MessageID
                            if (FriendsFirstMessageID.ContainsKey(FromID))
                            {
                                //如果遇到更小的MessageID,只有
                                if (MessageID < FriendsFirstMessageID[FromID])
                                {
                                    FriendsFirstMessageID[FromID] = MessageID;
                                }
                            }
                            else
                            {
                                //估计运行不到这里
                                FriendsFirstMessageID.Add(FromID, MessageID);
                            }
                            break;
                            #endregion
                        }

                        case "GETFRIENDSLIST":
                        {
                            #region 获取好友列表
                            string FriendID = null, NickName = null, Signature = null; bool OnLine = false;
                            MessagePattern     = ProtocolFormatter.GetProtocolPattern(ProtocolFormatter.CMDType.GetFriendsList);
                            MessageRegex       = new Regex(MessagePattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
                            MessageMatchResult = MessageRegex.Match(ServerMessage);
                            FriendID           = MessageMatchResult.Groups["FRIENDID"].Value.ToString();
                            NickName           = Encoding.UTF8.GetString(Convert.FromBase64String(MessageMatchResult.Groups["NICKNAME"].Value.ToString()));
                            Signature          = Encoding.UTF8.GetString(Convert.FromBase64String(MessageMatchResult.Groups["SIGNATURE"].Value.ToString()));
                            OnLine             = Convert.ToBoolean(MessageMatchResult.Groups["ONLINE"].Value.ToString());

                            this.Invoke(new Action(() =>
                                {
                                    UnityModule.DebugPrint("收到好友信息:{1} ({0}):{2}", FriendID, NickName, Signature);

                                    if (FriendItem.FriendExisted(FriendID))
                                    {
                                        //TODO:如果 FriendID已经存在,且FriendItem不为null,仅更新FriendID的信息,此特性可以在服务端用于有用户更新了资料时,立即向好友客户端更新资料
                                        FriendItem.GetFriendItemByFriendID(FriendID)?.SetNickNameSignatureAndOnLine(NickName, Signature, OnLine);
                                    }
                                    else
                                    {
                                        //默认好友聊天历史记录最早一条MessageID=0
                                        if (!FriendsFirstMessageID.ContainsKey(FriendID))
                                        {
                                            FriendsFirstMessageID.Add(FriendID, 0);
                                        }
                                        //新添加 FriendItem
                                        FriendItem NewFriendItem = new FriendItem(FriendID, NickName, Signature, OnLine)
                                        {
                                            RightToLeft = RightToLeft.No
                                        };
                                        NewFriendItem.FriendItemClick += new EventHandler(FriendItemClick);

                                        //创建好友聊天记录控件
                                        MyTableLayoutPanel NewChatBubblePanel = new MyTableLayoutPanel()
                                        {
                                            AutoScroll = true,
                                            Dock       = DockStyle.Fill,
                                            BackColor  = Color.White,
                                            Visible    = false,
                                        };

                                        //绑定自动滚动到底部事件
                                        NewChatBubblePanel.ControlAdded += new ControlEventHandler(ChatBubblesPanel_ControlAdded);

                                        MainPanel.Controls.Add(NewChatBubblePanel);

                                        NewFriendItem.ChatBubblesPanel = NewChatBubblePanel;
                                        FriendsFlowPanel.Controls.Add(NewFriendItem);
                                    }
                                }));
                            break;
                            #endregion
                        }

                        case "FRIENDSIGNIN":
                        {
                            #region 好友登录
                            string FriendID = null;
                            MessagePattern     = ProtocolFormatter.GetProtocolPattern(ProtocolFormatter.CMDType.FriendSignIn);
                            MessageRegex       = new Regex(MessagePattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
                            MessageMatchResult = MessageRegex.Match(ServerMessage);
                            FriendID           = MessageMatchResult.Groups["FRIENDID"].Value.ToString();

                            this.Invoke(new Action(() =>
                                {
                                    UnityModule.DebugPrint("收到好友登录消息:{0}", FriendID);
                                    if (FriendItem.FriendExisted(FriendID))
                                    {
                                        FriendItem JustSignIn = FriendItem.GetFriendItemByFriendID(FriendID);
                                        if (JustSignIn != null)
                                        {
                                            FriendsFlowPanel.Controls.SetChildIndex(JustSignIn, FriendItem.OnLineCount);
                                            JustSignIn.OnLine = true;
                                        }
                                    }
                                }));

                            break;
                            #endregion
                        }

                        case "FRIENDSIGNOUT":
                        {
                            #region 好友注销登录
                            string FriendID = null;
                            MessagePattern     = ProtocolFormatter.GetProtocolPattern(ProtocolFormatter.CMDType.FriendSignOut);
                            MessageRegex       = new Regex(MessagePattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
                            MessageMatchResult = MessageRegex.Match(ServerMessage);
                            FriendID           = MessageMatchResult.Groups["FRIENDID"].Value.ToString();

                            this.Invoke(new Action(() =>
                                {
                                    UnityModule.DebugPrint("收到好友注销消息:{0}", FriendID);
                                    if (FriendItem.FriendExisted(FriendID))
                                    {
                                        FriendItem JustSignIn = FriendItem.GetFriendItemByFriendID(FriendID);
                                        if (JustSignIn != null)
                                        {
                                            JustSignIn.OnLine = false;
                                            FriendsFlowPanel.Controls.SetChildIndex(JustSignIn, FriendItem.OnLineCount);
                                        }
                                    }
                                }));
                            break;
                            #endregion
                        }

                        case "FRIENDSLISTCOMPLETE":
                        {
                            #region 好友列表获取完毕
                            UnitySocket.Send(Encoding.UTF8.GetBytes(ProtocolFormatter.FormatProtocol(ProtocolFormatter.CMDType.GetMessageNotSendYet, Application.ProductVersion, UnityModule.USERID)));
                            break;
                            #endregion
                        }

                        case "MESSAGENSYCOMPLETE":
                        {
                            #region 未读消息获取完毕
                            //准备完毕,测试用
                            UnitySocket.Send(Encoding.UTF8.GetBytes(ProtocolFormatter.FormatProtocol(ProtocolFormatter.CMDType.GetChatHistory, Application.ProductVersion, "66666", "0")));
                            break;
                            #endregion
                        }

                        case "ANOTHORSIGNIN":
                        {
                            #region 异地登录
                            this.Invoke(new Action(() =>
                                {
                                    HideMe(HideTo.JusetClose);
                                    this.loginForm.Show();
                                    this.loginForm.ShowTips("您的账号异地登陆,请注意密码安全!");
                                    UnitySocket.Close();
                                    ReceiveThread.Abort();
                                }));
                            //这里需要 return; 否则会进入 catch(){} 被当做异常处理
                            return;

                            #endregion
                        }

                        case "SERVERSHUTDOWN":
                        {
                            #region 远程服务端关闭
                            this.Invoke(new Action(() => {
                                    HideMe(HideTo.JusetClose);
                                    this.loginForm.Show();
                                    this.loginForm.ShowTips("远程服务器主动关闭,可能Leon关机去上课了...");
                                    UnitySocket.Close();
                                    ReceiveThread.Abort();
                                }));
                            return;

                            #endregion
                        }

                        default:
                        {
                            #region 未知的消息协议
                            this.Invoke(new Action(() =>
                                {
                                    new MyMessageBox("遇到未知的 CMDTYPE : " + cmdType, MyMessageBox.IconType.Info).Show(this);
                                }));
                            break;
                            #endregion
                        }
                        }
                    }
                    catch (ThreadAbortException) { return; }
                    catch (Exception ex)
                    {
                        UnityModule.DebugPrint("处理消息时遇到错误:{0}", ex.Message);
                    }
                }
            }
        }
예제 #15
0
 public static string GetMessage(MessageID id)
 {
     return id.ToString();
 }
예제 #16
0
            //
            //
            #region postMessage
            //
            public void Post(MessageID _message, Component sender, object param = null)
            {
                //get action list from dictionary
                List <Action <Component, object> > waitList = new List <Action <Component, object> >();

                //

                waitList.Clear();
                if (listener.TryGetValue(_message, out waitList))
                {
                    for (int i = 0, amount = waitList.Count; i < amount; i++)
                    {
                        try
                        {
                            waitList[i](sender, param);
                        }
                        catch (Exception e)
                        {
                            //remove listeer at i - that cause the exception
                            //if no listener remain then declete this key
                            Common.LogWarning(this, "Error whenn PostEvent : {0}, message : {2}", _message, e.Message);
                            waitList.RemoveAt(i);
                            if (0 == waitList.Count)
                            {
                                listener.Remove(_message);
                            }
                            amount--;
                            i--;
                        }
                    }
                }
                else
                {
                    Common.LogWarning(this, "PostEvent, event : {0}, no listener for this event", _message.ToString());
                }
            }