当前位置: 首页>>代码示例>>C#>>正文


C# MessageInfo.Update方法代码示例

本文整理汇总了C#中MessageInfo.Update方法的典型用法代码示例。如果您正苦于以下问题:C# MessageInfo.Update方法的具体用法?C# MessageInfo.Update怎么用?C# MessageInfo.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MessageInfo的用法示例。


在下文中一共展示了MessageInfo.Update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnClientMessage

        void OnClientMessage(WebSocketConnection sender, DataReceivedEventArgs e)
        {
            OnlineUser user = Users.Single(a => a.Connection == sender);
            int index = e.Data.IndexOf(">>");
            string[] action = e.Data.Substring(0, index).Split(':');
            string[] args = action[1].Split(',');
            string data = e.Data.Remove(0, index + 2);
            Dictionary<string, string[]> actions = GetAllArgs(args);
            Func<string> combine = delegate()
            {
                List<string> newargs = new List<string>();
                foreach(KeyValuePair<string, string[]> a in actions)
                    newargs.Add(string.Format("{0}({1})", a.Key, String.Join("|", a.Value)));
                return string.Format("{0}:{1}>>{2}", action[0], string.Join(",", newargs.ToArray()), data);
            };
            switch(action[0])
            {
                case "REGISTER":
                    //auth here
                    int newuserid = int.Parse(args[0]);
                    if (Users.Exists(c => c.UserID == newuserid))
                        Users.Single(c => c.UserID == newuserid).Connection.Dispose();

                    user.UserID = newuserid;
                    user.Contacts = new List<int>();
                    ContactInfo.GetContacts(user.UserID).ForEach(delegate(ContactInfo i) { user.Contacts.Add(i.ContactID); });
                    user.Contacts.ForEach(delegate(int cid){
                        if (Users.Exists(c => c.UserID == cid))
                        {
                            SendToContact(cid, String.Format("ONLINE:{0}>>", user.UserID));
                            SendToContact(user.UserID, String.Format("ONLINE:{0}>>", cid));
                        }
                    });
                    foreach (MessageInfo undmessage in MessageInfo.GetAllUndelivered(user.UserID))
                    {
                        SendToContact(user.UserID, undmessage.MessageText);
                        UndeliveredMessageInfo.Create(undmessage.MessageID, user.UserID).Remove();
                    }
                    break;
                case "MESSAGE":
                    MessageInfo message = new MessageInfo();
                    message.UserID = user.UserID;
                    message.MessageText = e.Data;
                    message.CreatedDate = DateTime.Now;
                    if (actions["TYPE"][0] == "chat") message.MessageType = MessageTypes.Chat;
                    else if (actions["TYPE"][0] == "topic") message.MessageType = MessageTypes.Comment;
                    message.Update();
                    if (message.MessageID > 0 && actions["TYPE"][0] == "topic")
                    {
                        int tid = int.Parse(actions["ID"][0]);
                        MessageInTopicInfo.Create(message.MessageID, tid).Add();
                    }

                    int iid;
                    foreach (string id in actions["TO"])
                    {
                        if (int.TryParse(id, out iid) && user.Contacts.Contains(iid))
                        {
                            bool isOnline = Users.Exists(c => c.UserID == iid);
                            //save as undelivered
                            if (message.MessageID > 0 && !isOnline)
                                UndeliveredMessageInfo.Create(message.MessageID, iid).Add();
                            //dispatch message
                            if (isOnline)
                            {
                                OnlineUser contact = Users.Single(c => c.UserID == iid);
                                contact.Connection.Send(e.Data);
                            }
                        }
                    }
                    break;
                case "TOPICGET":
                    TopicInfo topicinfo = TopicInfo.Get(int.Parse(actions["ID"][0]));
                    List<UserInTopicInfo> usersintopic = UserInTopicInfo.GetByTopic(topicinfo.TopicID);
                    List<string> ids = new List<string>(),
                        mentors = new List<string>();
                    usersintopic.ForEach(delegate(UserInTopicInfo uit) { ids.Add(uit.UserID.ToString()); if (uit.UserTopicRole == UserTopicRoles.Mentor) mentors.Add(uit.UserID.ToString()); });
                    user.Connection.Send(string.Format("TOPIC:TO({0}),MENTORS({1}),TOPICID({2})>>{3}", string.Join("|", ids.ToArray()), string.Join("|", mentors.ToArray()), topicinfo.TopicID, topicinfo.TopicText));
                    foreach(MessageInfo topicmessageinfo in MessageInfo.GetByTopic(topicinfo.TopicID))
                    {
                        user.Connection.Send(topicmessageinfo.MessageText);
                    }
                    break;
                case "TOPIC":
                    TopicInfo info = new TopicInfo();
                    info.TopicText = data;
                    info.Update();
                    for (int i = 0; i < actions["TO"].Length; i++)
                    {
                        UserInTopicInfo usertopic = new UserInTopicInfo();
                        usertopic.UserID = int.Parse(actions["TO"][i]);
                        usertopic.TopicID = info.TopicID;
                        usertopic.UserTopicRole = (actions["MENTORS"].Contains(actions["TO"][i]) ? UserTopicRoles.Mentor : UserTopicRoles.User);
                        usertopic.Add();
                    }
                    actions.Add("TOPICID", new string[] { info.TopicID.ToString() });
                    string newdata = combine();
                    foreach (string id in actions["TO"])
                    {
                        if (int.TryParse(id, out iid) && iid != user.UserID && Users.Exists(c => c.UserID == iid))
//.........这里部分代码省略.........
开发者ID:rosenkolev,项目名称:Communication-System,代码行数:101,代码来源:ChatServer.cs


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