public List <IPlugin> LoadPlugins(string path) { this.path = path; DirectoryInfo dir = new DirectoryInfo(path); if (!dir.Exists) { return(plugins); } Type pluginType = typeof(IPlugin); foreach (FileInfo fileInfo in dir.GetFiles("*.dll")) { try { Assembly assembly = Assembly.LoadFrom(fileInfo.FullName); foreach (var type in assembly.GetTypes()) { if (!type.IsInterface && !type.IsAbstract && pluginType.IsAssignableFrom(type)) { IPlugin plugin = (IPlugin)Activator.CreateInstance(type); plugins.Add(plugin); } } } catch (Exception ex) { Radio.Log(ex.Message, this); } } return(plugins); }
void GetHttpStream() { do { try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); request.Headers.Add("icy-metadata", "1"); request.ReadWriteTimeout = 10 * 1000; request.Timeout = 10 * 1000; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { //get the position of metadata int metaInt = 0; if (!string.IsNullOrEmpty(response.GetResponseHeader("icy-metaint"))) { metaInt = Convert.ToInt32(response.GetResponseHeader("icy-metaint")); } using (Stream socketStream = response.GetResponseStream()) { byte[] buffer = new byte[16384]; int metadataLength = 0; int streamPosition = 0; int bufferPosition = 0; int readBytes = 0; StringBuilder metadataSb = new StringBuilder(); while (Running) { if (bufferPosition >= readBytes) { readBytes = socketStream.Read(buffer, 0, buffer.Length); bufferPosition = 0; } if (readBytes <= 0) { Radio.Log("Stream over", this); break; } if (metadataLength == 0) { if (metaInt == 0 || streamPosition + readBytes - bufferPosition <= metaInt) { streamPosition += readBytes - bufferPosition; ProcessStreamData(buffer, ref bufferPosition, readBytes - bufferPosition); continue; } ProcessStreamData(buffer, ref bufferPosition, metaInt - streamPosition); metadataLength = Convert.ToInt32(buffer[bufferPosition++]) * 16; //check if there's any metadata, otherwise skip to next block if (metadataLength == 0) { streamPosition = Math.Min(readBytes - bufferPosition, metaInt); ProcessStreamData(buffer, ref bufferPosition, streamPosition); continue; } } //get the metadata and reset the position while (bufferPosition < readBytes) { metadataSb.Append(Convert.ToChar(buffer[bufferPosition++])); metadataLength--; if (metadataLength == 0) { Metadata = metadataSb.ToString(); metadataSb.Clear(); streamPosition = Math.Min(readBytes - bufferPosition, metaInt); ProcessStreamData(buffer, ref bufferPosition, streamPosition); break; } } } } } } catch (IOException ex) { Radio.Log(string.Format("Handled IOException, reconnecting. Details:\n{0}\n{1}", ex.Message, ex.StackTrace), this); OnStreamOver?.Invoke(this, new StreamOverEventArgs()); } catch (SocketException ex) { Radio.Log(string.Format("Handled SocketException, reconnecting. Details:\n{0}\n{1}", ex.Message, ex.StackTrace), this); OnStreamOver?.Invoke(this, new StreamOverEventArgs()); } catch (WebException ex) { Radio.Log(string.Format("Handled WebException, reconnecting. Details:\n{0}\n{1}", ex.Message, ex.StackTrace), this); OnStreamOver?.Invoke(this, new StreamOverEventArgs()); } } while (Running); }