本文整理汇总了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))
//.........这里部分代码省略.........