示例#1
0
        public ActionResult Index(string article)
        {
            var httpEvent = new HttpEvent { Data = article };
            this.CurrentContext
                .EventSession
                .ToList()
                .ForEach(item => item.SendEvent(httpEvent));

            return Json("你的文章已推荐给所有人");
        }
示例#2
0
        /// <summary>
        /// 发送事件到客户端
        /// </summary>
        /// <param name="httpEvent">http事件</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <returns></returns>
        public bool SendEvent(HttpEvent httpEvent)
        {
            if (httpEvent == null)
            {
                throw new ArgumentNullException();
            }

            try
            {
                var bytes = Encoding.UTF8.GetBytes(httpEvent.ToString());
                this.session.Send(bytes);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#3
0
        /// <summary>
        /// 发送事件到客户端
        /// </summary>
        /// <param name="httpEvent">http事件</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <returns></returns>
        public bool SendEvent(HttpEvent httpEvent)
        {
            if (httpEvent == null)
            {
                throw new ArgumentNullException();
            }

            try
            {
                var bytes = Encoding.UTF8.GetBytes(httpEvent.ToString());
                this.session.Send(new ByteRange(bytes));
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
 /// <summary>
 /// 服务器发送事件结果
 /// </summary>
 /// <param name="httpEvent">事件</param>
 public EventResult(HttpEvent httpEvent)
 {
     this.httpEvent = httpEvent;
 }
示例#5
0
 /// <summary>
 /// 服务器发送事件结果
 /// </summary>
 /// <param name="httpEvent">事件</param>
 public EventResult(HttpEvent httpEvent)
 {
     this.httpEvent = httpEvent;
 }