zoukankan      html  css  js  c++  java
  • 1

        /// <summary>
        /// 聊天室实体
        /// </summary>
        public class ChatDTO
        {
            /// <summary>
            /// 聊天室ID
            /// </summary>
            public Guid ChatID { get; set; }
            /// <summary>
            /// 访客
            /// </summary>
            public Visitor Visitor { get; set; }
            /// <summary>
            /// 客服
            /// </summary>
            public List<Agent> Agents { get; set; }
            public DateTime CreateTime { get; set; }
        }
    
        /// <summary>
        /// visitor
        /// </summary>
        public class Visitor
        {
            public int ID { get; set; }
            public string Name { get; set; }
        }
    
        /// <summary>
        /// agent
        /// </summary>
        public class Agent
        {
            public int ID { get; set; }
            public string Name { get; set; }
        }
    
        /// <summary>
        /// 消息实体
        /// </summary>
        public class Messages
        {
            //主键
            public Guid MID { get; set; }
            //聊天室ID
            public Guid ChatID { get; set; }
            //发送者的ID
            public int ID { get; set; }
            //发送者角色,客服or访客
            public int Role { get; set; }
            //消息内容
            public string Content { get; set; }
            //发送时间
            public DateTime SendTime { get; set; }
        }
    
        public interface IChatService
        {
            /// <summary>
            /// 创建聊天室
            /// </summary>
            /// <returns></returns>
            Guid CreateChat(Visitor visitor);
    
            /// <summary>
            /// 关闭聊天室
            /// </summary>
            /// <param name="chatid"></param>
            /// <returns></returns>
            bool CloseChat(Guid chatid);
    
            /// <summary>
            /// 添加客服
            /// </summary>
            /// <param name="agent"></param>
            /// <returns></returns>
            bool AddAgent(Agent agent);
    
            /// <summary>
            /// 客服离开
            /// </summary>
            /// <param name="id">客服ID</param>
            /// <returns></returns>
            bool RemoveAgent(int id);
    
            /// <summary>
            /// 发送消息
            /// </summary>
            /// <param name="chatid">聊天室ID</param>
            /// <param name="id">发送者的ID</param>
            /// <param name="role">发送者角色,客服or访客</param>
            /// <param name="content">消息内容</param>
            void SendMsg(Guid chatid, int id, int role, string content);
        }
    
        public class ChatService : IChatService
        {
            //当前存在的聊天室
            List<ChatDTO> chatDTOs = new List<ChatDTO>();
            //已发送的消息
            List<Messages> messages = new List<Messages>();
    
            public bool AddAgent(Agent agent)
            {
                throw new NotImplementedException();
            }
    
            public bool CloseChat(Guid chatid)
            {
                throw new NotImplementedException();
            }
    
            public Guid CreateChat(Visitor visitor)
            {
                var curChat = chatDTOs.Where(c => c.Visitor == visitor).FirstOrDefault();
                if (curChat != null)
                {
                    return curChat.ChatID;
                }
                else
                {
                    ChatDTO chat = new ChatDTO()
                    {
                        ChatID = Guid.NewGuid(),
                        Visitor = visitor,
                        CreateTime = DateTime.Now
                    };
                    chatDTOs.Add(chat);
                    return chat.ChatID;
                }
            }
    
            public bool RemoveAgent(int id)
            {
                throw new NotImplementedException();
            }
    
            public void SendMsg(Guid chatid, int id, int role, string content)
            {
                throw new NotImplementedException();
            }
        }
  • 相关阅读:
    写代码如坐禅:你是哪一类程序员
    开发企业应用系统需要掌握的知识技能(转)
    (转)谈谈多线程的思维方式
    深入理解JavaScript定时机制
    (转)javascritp对fckeditor编辑器操作
    JavaScript异步编程的Promise模式
    (转)jquery调WCF
    (转)《代码大全》学习笔记:第10,11,12,13章 关于变量的使用,命名等
    编程:是一门艺术(转)
    禅修程序员十诫(转)
  • 原文地址:https://www.cnblogs.com/2333hh/p/13357120.html
Copyright © 2011-2022 走看看