public void Notify(Actions action, Types type) { if (RequestHandled == null) { return; } var evargs = new RequestHandledEventArgs(); evargs.Action = Actions.Remove; RequestHandled(this, evargs); }
private static void Controller_RequestHandled(object sender, RequestHandledEventArgs e) { // Update log _apiLog.Add(e); // Print response to console only if new foreach (var responsePair in e.ResponseBlock.ParsedMessages) { switch (responsePair.Key) { case RequestType.GetMapObjects: ParseMapObject((GetMapObjectsResponse)responsePair.Value); continue; case RequestType.DownloadSettings: case RequestType.GetAssetDigest: case RequestType.DownloadRemoteConfigVersion: continue; } var output = _outputMessages.SingleOrDefault(tuple => tuple.Item1 == responsePair.Key); var outputMessage = ParseResponseMessage(responsePair); if (output == null) { _outputMessages.Add(new Tuple <RequestType, string>(responsePair.Key, outputMessage)); Console.WriteLine($"[+] New {responsePair.Key} response"); Console.WriteLine(outputMessage); } else { if (output.Item2 == outputMessage) { continue; } Console.WriteLine($"[+] Updated {responsePair.Key} response"); Console.WriteLine(outputMessage); } } }
public void Start() { using (var wc = new WebClient()) { wc.DownloadStringCompleted += (wc_sender, wc_e) => { using (var bgw = new BackgroundWorker()) { bgw.WorkerReportsProgress = true; bgw.WorkerSupportsCancellation = true; bgw.DoWork += (bgw_doWorkSender, bgw_e) => { var response = new XmlDocument(); response.LoadXml((string)bgw_e.Argument); var totalStreams = int.Parse(response.DocumentElement.SelectSingleNode("STREAMSTATS/TOTALSTREAMS").InnerText); if (totalStreams != 0 && totalStreams < byte.MaxValue) { var streamXML = new XmlDocument(); using (var scStream = new ShoutcastStream()) for (var i = 0; i < totalStreams; i++) { streamXML.LoadXml(response.DocumentElement.SelectNodes("STREAMSTATS/STREAM")[i].OuterXml .Replace(string.Format("<STREAM id=\"{0}\">", (i + 1)), "<SHOUTCASTSERVER>") .Replace("</STREAM>", "</SHOUTCASTSERVER>")); streamXML.CreateXmlDeclaration("1.0", "UTF-8", "yes"); scStream.Listeners = int.Parse(streamXML.DocumentElement.SelectSingleNode("CURRENTLISTENERS").InnerText); scStream.Active = (int.Parse(streamXML.DocumentElement.SelectSingleNode("STREAMSTATUS").InnerText) != 0); scStream.Title = streamXML.DocumentElement.SelectSingleNode("SONGTITLE").InnerText; scStream.Name = streamXML.DocumentElement.SelectSingleNode("SERVERTITLE").InnerText; scStream.ID = Convert.ToString((i + 1)); scStream.XML = streamXML; bgw.ReportProgress((i + 1), scStream); } } }; bgw.ProgressChanged += (bgw_progChanged_sender, progress) => { var stream = (ShoutcastStream)progress.UserState; if (string.IsNullOrEmpty(stream.ID)) { lock (streams) { if (streams.ContainsKey(stream.ID)) { streams.Add(stream.ID, stream); } else { streams[stream.ID].Listeners = stream.Listeners; streams[stream.ID].Name = stream.Name; streams[stream.ID].Title = stream.Title; streams[stream.ID].XML = stream.XML; } } } }; bgw.RunWorkerCompleted += (bgw_done_sender, done_e) => { if (RequestHandled == null) { return; } var evargs = new RequestHandledEventArgs(); evargs.Action = Actions.Add; evargs.Type = Types.Content; RequestHandled.Invoke(this, evargs); }; } }; wc.DownloadStringAsync(sc_url); } }