List <Show> Grab(GrabParametersBase p, ILogger logger) { var pp = (CyfraPlus.GrabParameters)p; var shows = new List <Show>(); var wr = WebRequest.Create(string.Format(urlFormat, pp.Date.ToString(DateFormat))); logger.WriteEntry(string.Format("Grabbing Cyfra+ date {0} ...", pp.Date.ToString(DateFormat)), LogType.Info); var res = (HttpWebResponse)wr.GetResponse(); const int ChannelDepth = 2; using (var sr = new StreamReader(res.GetResponseStream())) { var startDownloadTime = DateTime.Now; var data = new StringBuilder(); int blockSize = 16384; while (!sr.EndOfStream) { var buf = new char[blockSize]; var totalRead = sr.ReadBlock(buf, 0, blockSize); data.Append(buf); if (DateTime.Now - startDownloadTime > TimeSpan.FromSeconds(1)) { startDownloadTime = DateTime.Now; logger.WriteEntry(string.Format("Downloaded {0:#,##0} bytes so far", data.Length), LogType.Info); } } var r = new Newtonsoft.Json.JsonTextReader(new StringReader(data.ToString())); while (r.Read()) { r.Read(); var channelNumber = r.ReadAsInt32(); var channelName = r.ReadAsString(); r.Read(); r.Read(); while (r.Depth > ChannelDepth) { var show = new Show(); show.Channel = channelName.Trim(); var programId = r.ReadAsInt32(); show.Title = Tools.CleanupText(r.ReadAsString()); show.StartTime = new DateTime(1970, 1, 1).Add(TimeSpan.FromSeconds(r.ReadAsInt32().Value)); show.EndTime = show.StartTime.Add(TimeSpan.FromSeconds(Convert.ToDouble(r.ReadAsInt32()))); var num = r.ReadAsInt32(); shows.Add(show); var depth = r.Depth; while (r.Depth == depth) { r.Read(); } r.Read(); } } } return(shows); }
public static RaiserInfo GetValueFromJson(TextReader jsonStream, string language) { RaiserInfo result = null; using (Newtonsoft.Json.JsonTextReader jtr = new Newtonsoft.Json.JsonTextReader(jsonStream)) { bool? enable = true; int? count = 0; string md5 = string.Empty, url = string.Empty, tmp; while (jtr.Read()) { if (jtr.TokenType == Newtonsoft.Json.JsonToken.PropertyName) { if (((string)jtr.Value).ToLower() == language.ToLower()) { while (jtr.Read()) { if (jtr.TokenType == Newtonsoft.Json.JsonToken.PropertyName) { tmp = ((string)jtr.Value).ToLower(); if (tmp == "enabled") { enable = jtr.ReadAsBoolean(); } else if (tmp == "filecount") { count = jtr.ReadAsInt32(); } else if (tmp == "patchmd5") { md5 = jtr.ReadAsString(); } else if (tmp == "patchurl") { url = jtr.ReadAsString(); } else { jtr.Skip(); } } } } else { jtr.Skip(); } } } if (enable.HasValue && !enable.Value) { result = new RaiserInfo(false, count.HasValue ? count.Value : 0, md5, url); } else { result = new RaiserInfo(true, count.HasValue ? count.Value : 0, md5, url); } } return(result); }
List<Show> Grab(GrabParametersBase p,ILogger logger) { var pp = (CyfraPlus.GrabParameters)p; var shows = new List<Show>(); var wr = WebRequest.Create(string.Format(urlFormat, pp.Date.ToString(DateFormat))); logger.WriteEntry(string.Format("Grabbing Cyfra+ date {0} ...", pp.Date.ToString(DateFormat)), LogType.Info); var res = (HttpWebResponse)wr.GetResponse(); const int ChannelDepth = 2; using (var sr = new StreamReader(res.GetResponseStream())) { var startDownloadTime = DateTime.Now; var data = new StringBuilder(); int blockSize = 16384; while (!sr.EndOfStream) { var buf = new char[blockSize]; var totalRead = sr.ReadBlock(buf, 0, blockSize); data.Append(buf); if (DateTime.Now - startDownloadTime > TimeSpan.FromSeconds(1)) { startDownloadTime = DateTime.Now; logger.WriteEntry(string.Format("Downloaded {0:#,##0} bytes so far", data.Length), LogType.Info); } } var r = new Newtonsoft.Json.JsonTextReader(new StringReader(data.ToString())); while (r.Read()) { r.Read(); var channelNumber = r.ReadAsInt32(); var channelName = r.ReadAsString(); r.Read(); r.Read(); while (r.Depth > ChannelDepth) { var show = new Show(); show.Channel = channelName.Trim(); var programId = r.ReadAsInt32(); show.Title = Tools.CleanupText(r.ReadAsString()); show.StartTime = new DateTime(1970, 1, 1).Add(TimeSpan.FromSeconds(r.ReadAsInt32().Value)); show.EndTime = show.StartTime.Add(TimeSpan.FromSeconds(Convert.ToDouble(r.ReadAsInt32()))); var num = r.ReadAsInt32(); shows.Add(show); var depth = r.Depth; while (r.Depth == depth) r.Read(); r.Read(); } } } return shows; }
private void recv(string msg) { if (State == WebSockState.Connecting) { if (ci.cii == null) { ci.cii = new Dictionary<string, string>(); ci.cii.Add("nick", ci.nick); ci.cii.Add("room", ci.room); } Send(make_msg("join", ci.cii)); State = WebSockState.Connected; } else if (msg == "2::") { Send("2::"); } else { msg = msg.Substring(4); Newtonsoft.Json.JsonTextReader JTR = new Newtonsoft.Json.JsonTextReader(new System.IO.StringReader(msg)); char name_type = '\0'; Dictionary<string, string> args = new Dictionary<string, string>(5); while (JTR.Read()) { switch (JTR.ValueType == typeof(string) ? (string)JTR.Value : "") { case "name": name_type = JTR.ReadAsString()[0]; break; case "args": switch (name_type) { case 'u': JTR.Read(); JTR.Read(); JTR.Read(); switch (JTR.ReadAsString()) { case "l": Dictionary<string, user_info> ui = new Dictionary<string,user_info>(8); JTR.Read(); JTR.Read(); while (JTR.Read()) { string nick = (string)JTR.Value; user_info lui = new user_info(); JTR.Read(); while (JTR.Read() && JTR.Value != null && JTR.ValueType.ToString() != "EndObject") { switch ((string)JTR.Value) { case "a": lui.admin = JTR.ReadAsInt32() == 0 ? false : true; break; case "t": lui.conn = (DateTime)JTR.ReadAsDateTime(); break; case "m": lui.mb_id = JTR.ReadAsString(); break; case "l": lui.login = JTR.ReadAsInt32() == 1 ? false : true; break; default: JTR.Read(); break; } } if(nick != null) ui.Add(nick, lui); } break; default: break; } break; case 'c': JTR.Skip(); JTR.Skip(); while (JTR.Read()) { args.Add((string)JTR.Value, JTR.ReadAsString()); } break; default: break; } break; default: break; } } } }
private void recv(string msg) { if (State == WebSockState.Connecting) { if (ci.cii == null) { ci.cii = new Dictionary <string, string>(); ci.cii.Add("nick", ci.nick); ci.cii.Add("room", ci.room); } Send(make_msg("join", ci.cii)); State = WebSockState.Connected; } else if (msg == "2::") { Send("2::"); } else { msg = msg.Substring(4); Newtonsoft.Json.JsonTextReader JTR = new Newtonsoft.Json.JsonTextReader(new System.IO.StringReader(msg)); char name_type = '\0'; Dictionary <string, string> args = new Dictionary <string, string>(5); while (JTR.Read()) { switch (JTR.ValueType == typeof(string) ? (string)JTR.Value : "") { case "name": name_type = JTR.ReadAsString()[0]; break; case "args": switch (name_type) { case 'u': JTR.Read(); JTR.Read(); JTR.Read(); switch (JTR.ReadAsString()) { case "l": Dictionary <string, user_info> ui = new Dictionary <string, user_info>(8); JTR.Read(); JTR.Read(); while (JTR.Read()) { string nick = (string)JTR.Value; user_info lui = new user_info(); JTR.Read(); while (JTR.Read() && JTR.Value != null && JTR.ValueType.ToString() != "EndObject") { switch ((string)JTR.Value) { case "a": lui.admin = JTR.ReadAsInt32() == 0 ? false : true; break; case "t": lui.conn = (DateTime)JTR.ReadAsDateTime(); break; case "m": lui.mb_id = JTR.ReadAsString(); break; case "l": lui.login = JTR.ReadAsInt32() == 1 ? false : true; break; default: JTR.Read(); break; } } if (nick != null) { ui.Add(nick, lui); } } break; default: break; } break; case 'c': JTR.Skip(); JTR.Skip(); while (JTR.Read()) { args.Add((string)JTR.Value, JTR.ReadAsString()); } break; default: break; } break; default: break; } } } }