private bool _SetSseHeader(CoCNotifyHost host, string head) { try { host.Response.ContentEncoding = Encoding.UTF8; host.Response.AddHeader("Cache-Control", "no-cache"); host.Response.AddHeader("Access-Control-Allow-Origin", "*"); host.Response.AddHeader("X-Accel-Buffering", "no"); host.Response.KeepAlive = true; host.Response.ContentType = head; host.Response.StatusCode = (int)HttpStatusCode.OK; return(true); } #if DEBUG catch (Exception e) { if (this._parent.isLogEnable) { this._parent._ilog.LogError( string.Format( Properties.Resources.CoCNotifyProcessError, Properties.Resources.CoCNotifySetHeader, host.IpAddress, e.Message ) ); } #else catch (Exception) { #endif return(false); } }
private bool _SendPartSse(CoCNotifyHost host, string msg) { try { if (host.Response.OutputStream == null) { throw new ArgumentException(); } byte [] bmsg = Encoding.UTF8.GetBytes(msg); host.Response.OutputStream.Write(bmsg, 0, bmsg.Length); host.Response.OutputStream.Flush(); return(true); } #if DEBUG catch (Exception e) { if (this._parent.isLogEnable) { this._parent._ilog.LogError( string.Format( Properties.Resources.CoCNotifyProcessError, Properties.Resources.CoCNotifySendPart, host.IpAddress, e.Message ) ); } #else catch (Exception) { #endif return(false); } }
public bool SendSseStreamComplette(CoCNotifyHost host, string evname, string evdata) { if (!this._SetSseHeader(host, HttpUtil.GetMimeType("", HttpUtil.MimeType.MimeSse))) { return(false); } return(this._SendPartSse(host, this._EventSseToString(evname, evdata, this.getEventId))); }
public bool SendRssCompletteStatic(CoCNotifyHost host) { if (!this._SetSseHeader(host, HttpUtil.GetMimeType("", HttpUtil.MimeType.MimeXml))) { return(false); } return(this._SendPartSse(host, this._rssString)); }
public bool SendJsonComplette(CoCNotifyHost host, bool isfull) { if (!this._SetSseHeader(host, HttpUtil.GetMimeType("", HttpUtil.MimeType.MimeJson))) { return(false); } return(this._SendPartSse(host, this._data.ToJson(isfull, false, (this._parent.UpdateNextMilliseconds + 35000)))); }
private string _EventRssToString(CoCNotifyHost host) { int count = 0; stRSS.RSSWriter rssRoot = null; CultureInfo ci = stNet.stWebServerUtil.HttpUtil.GetHttpClientLanguage(host.Language, this._parent._ci); try { if ((rssRoot = this._RssRootAdd(ci)) == null) { throw new ArgumentNullException(); } foreach (DataRow row in this._data.Rows) { RSSFeedItem itm = this._RssItemAdd(row, (count++), ci); if (itm != null) { rssRoot.Add(itm); } } return(rssRoot.WriteString(this._parent._ilog)); } #if DEBUG catch (Exception e) { if (this._parent.isLogEnable) { this._parent._ilog.LogError( string.Format( Properties.Resources.CoCNotifyProcessError, Properties.Resources.CoCNotifyDataRss, Properties.Resources.CoCNotifyDataOtherError, e.Message ) ); } #else catch (Exception) { #endif } return(this._rssString); }
private bool _DataSseSend(CoCNotifyHost host) { if (this._data.Rows.Count == 0) { if (!this.SendSseStreamAlive(host)) { return(false); } return(true); } try { foreach (DataRow row in this._data.Rows) { if (!this._SendPartSse(host, this._EventSseToString((string)row["id"], row.ToJson()))) { return(false); } } } #if DEBUG catch (Exception e) { if (this._parent.isLogEnable) { this._parent._ilog.LogError( string.Format( Properties.Resources.CoCNotifyProcessError, Properties.Resources.CoCNotifyDataSseSend, host.IpAddress, e.Message ) ); } #else catch (Exception) { #endif } return(true); }
public bool SendRssComplette(CoCNotifyHost host) { if (!this._SetSseHeader(host, HttpUtil.GetMimeType("", HttpUtil.MimeType.MimeXml))) { return(false); } if (string.IsNullOrEmpty(host.Language)) { return(this._SendPartSse(host, this._rssString)); } else { string rssString = this._EventRssToString(host); return(this._SendPartSse( host, ((string.IsNullOrWhiteSpace(rssString)) ? CoCEnum.EventNotify.ServerError.ToString() : rssString ) )); } }
public void AddSseHost(CoCNotifyHost host) { if (host == null) { return; } if ( (!this._SetSseHeader(host, HttpUtil.GetMimeType("", HttpUtil.MimeType.MimeSse))) || (!this._SetupSseSend(host)) ) { try { host.Response.Abort(); } catch (Exception) { } return; } Task.Factory.StartNew(() => { lock (this._lockClient) { if (this._notifySseClient.Find(o => (o.Response.Equals(host.Response))) == null) { try { this._notifySseClient.Add(host); } #if DEBUG catch (Exception e) { if (this._parent.isLogEnable) { this._parent._ilog.LogError( string.Format( Properties.Resources.CoCNotifyProcessError, Properties.Resources.CoCNotifyAddClient, host.IpAddress, e.Message ) ); } #else catch (Exception) { #endif return; } } } // end lock client #if DEBUG if (this._parent.isLogEnable) { this._parent._ilog.LogInfo( string.Format( Properties.Resources.CoCNotifyProcessDebug, host.IpAddress, Properties.Resources.CoCNotifyHostDataCount, this._notifySseClient.Count + "/" + this._data.Rows.Count ) ); } #endif if (this._data.Rows.Count > 0) { lock (this._lockData) { if (!this._DataSseSend(host)) { lock (_lockClient) { this._notifySseClient.Remove(host); } } } // end lock data } }); }
public bool SendSseStreamAlive(CoCNotifyHost host) { return(this._SendPartSse(host, this._EventSseToString(CoCEnum.EventNotify.TestAlive.ToString(), DateTime.Now.ToString(), this.getEventId))); }
public bool SendSseStreamPart(CoCNotifyHost host, string evname, string evdata) { return(this._SendPartSse(host, this._EventSseToString(evname, evdata, this.getEventId))); }
private bool _SetupSseSend(CoCNotifyHost host) { return(this._SendPartSse(host, this._EventSseToString(CoCEnum.EventNotify.EventSetup.ToString(), this._sseSetup, this.getEventId))); }
public bool NotifySendRssComplette(CoCNotifyHost host) { return(this._cocNotifier.SendRssComplette(host)); }
public bool NotifySendJsonComplette(CoCNotifyHost host, bool isfull = true) { return(this._cocNotifier.SendJsonComplette(host, isfull)); }
public bool NotifySendSseStreamComplette(CoCNotifyHost host, string evname, string evdata) { return(this._cocNotifier.SendSseStreamComplette(host, evname, evdata)); }
public void NotifySseAdd(CoCNotifyHost host) { this._cocNotifier.AddSseHost(host); }