예제 #1
0
 private static string GetStringContents(Constants.GrabSource grabSource, string url)
 {
     string contents = null;
     switch (grabSource) {
         case Constants.GrabSource.Url:
             using (WebClient client = new WebClient())
             using (Stream responseStream = client.OpenRead(url))
             using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8)) {
                 contents = reader.ReadToEnd();
             }
             break;
         case Constants.GrabSource.File:
             contents = File.ReadAllText(url);
             break;
     }
     return contents;
 }
예제 #2
0
 /// <summary>
 /// Gets the binary contents.
 /// </summary>
 /// <param name="grabSource">The grab source.</param>
 /// <param name="url">The URL.</param>
 /// <returns></returns>
 private static byte[] GetBinaryContents(Constants.GrabSource grabSource, string url)
 {
     var contents = new byte[0];
     switch (grabSource) {
         case Constants.GrabSource.Url:
             byte[] buffer = new byte[1024];
             int read;
             using (WebClient client = new WebClient())
             using (Stream responseStream = client.OpenRead(url))
             using (BinaryReader reader = new BinaryReader(responseStream, Encoding.UTF8))
             using (MemoryStream ms = new MemoryStream()) {
                 while ((read = reader.Read(buffer, 0, buffer.Length)) > 0) {
                     ms.Write(buffer, 0, read);
                 }
                 contents = ms.ToArray();
             }
             break;
         case Constants.GrabSource.File:
             contents = File.ReadAllBytes(url);
             break;
     }
     return contents;
 }