public static TsvDataSheet Download(AbsoluteUri location) { if (null == location) { throw new ArgumentNullException("location"); } TsvDataSheet tsv = null; var request = WebRequest.Create((Uri)location); using (var response = request.GetResponse()) { using (var stream = response.GetResponseStream()) { if (null != stream) { using (var reader = new StreamReader(stream)) { #if NET20 var file = new FileInfo(StringExtensionMethods.FormatWith("{0}.tsv", AlphaDecimal.Random())); FileInfoExtensionMethods.Create(file, reader.ReadToEnd()); #else var file = new FileInfo("{0}.tsv".FormatWith(AlphaDecimal.Random())); file.Create(reader.ReadToEnd()); #endif tsv = new TsvDataSheet(file); } } } } return(tsv); }
public override IEnumerable <object[]> GetData(MethodInfo methodUnderTest, Type[] parameterTypes) { if (null == methodUnderTest) { throw new ArgumentNullException("methodUnderTest"); } if (null == parameterTypes) { throw new ArgumentNullException("parameterTypes"); } #if NET20 if (Cavity.Collections.IEnumerableExtensionMethods.Count(Locations) != parameterTypes.Length) { throw new InvalidOperationException(StringExtensionMethods.FormatWith(Resources.Attribute_CountsDiffer, Cavity.Collections.IEnumerableExtensionMethods.Count(Locations), parameterTypes.Length)); } #else if (Locations.Count() != parameterTypes.Length) { throw new InvalidOperationException(Resources.Attribute_CountsDiffer.FormatWith(Locations.Count(), parameterTypes.Length)); } #endif var list = new List <object>(); var index = -1; foreach (var location in Locations) { var file = Download(location); #if NET20 var value = FileInfoExtensionMethods.ReadToEnd(file); #else var value = file.ReadToEnd(); #endif index++; if (parameterTypes[index] == typeof(JObject)) { list.Add(JObject.Parse(value)); continue; } list.Add(JsonConvert.DeserializeObject(value, parameterTypes[index])); } yield return(list.ToArray()); }
public static ConfigXml Load <T>(FileInfo file) { Trace.WriteIf(Tracing.Is.TraceVerbose, string.Empty); if (null == file) { throw new ArgumentNullException("file"); } #if !NET20 Trace.WriteIf(Tracing.Is.TraceVerbose, "file.FullName=\"{0}\"".FormatWith(file.FullName)); #endif return(new ConfigXml(file) { #if NET20 Value = file.Exists ? StringExtensionMethods.XmlDeserialize <T>(FileInfoExtensionMethods.ReadToEnd(file)) : default(T) #else Value = file.Exists ? file.ReadToEnd().XmlDeserialize <T>() : default(T) #endif });
public static HtmlDocument Download(AbsoluteUri location) { if (null == location) { throw new ArgumentNullException("location"); } HtmlDocument html = null; var request = WebRequest.Create((Uri)location); using (var response = request.GetResponse()) { using (var stream = response.GetResponseStream()) { if (null != stream) { using (var reader = new StreamReader(stream)) { #if NET20 var file = new FileInfo(StringExtensionMethods.FormatWith("{0}.html", AlphaDecimal.Random())); FileInfoExtensionMethods.Create(file, reader.ReadToEnd()); #else var file = new FileInfo("{0}.html".FormatWith(AlphaDecimal.Random())); file.Create(reader.ReadToEnd()); #endif html = new HtmlDocument(); html.Load(file.FullName); } } } } return(html); }
public override IEnumerable <object[]> GetData(MethodInfo methodUnderTest, Type[] parameterTypes) { if (null == methodUnderTest) { throw new ArgumentNullException("methodUnderTest"); } if (null == parameterTypes) { throw new ArgumentNullException("parameterTypes"); } #if NET20 if (Cavity.Collections.IEnumerableExtensionMethods.Count(Locations) != parameterTypes.Length) { throw new InvalidOperationException(StringExtensionMethods.FormatWith(Resources.Attribute_CountsDiffer, Cavity.Collections.IEnumerableExtensionMethods.Count(Locations), parameterTypes.Length)); } #else if (Locations.Count() != parameterTypes.Length) { throw new InvalidOperationException(Resources.Attribute_CountsDiffer.FormatWith(Locations.Count(), parameterTypes.Length)); } #endif var list = new List <object>(); var index = -1; foreach (var location in Locations) { var file = Download(location); index++; if (parameterTypes[index] == typeof(DataSet)) { var data = new DataSet(); data.ReadXml(file.FullName, XmlReadMode.Auto); list.Add(data); continue; } if (parameterTypes[index] == typeof(XmlDocument) || parameterTypes[index] == typeof(IXPathNavigable)) { var xml = new XmlDocument(); xml.Load(file.FullName); list.Add(xml); continue; } if (parameterTypes[index] == typeof(XPathNavigator)) { var xml = new XmlDocument(); xml.Load(file.FullName); list.Add(xml.CreateNavigator()); continue; } #if !NET20 if (parameterTypes[index] == typeof(XDocument)) { list.Add(XDocument.Load(file.FullName)); continue; } #endif #if NET20 list.Add(StringExtensionMethods.XmlDeserialize(FileInfoExtensionMethods.ReadToEnd(file), parameterTypes[index])); #else list.Add(file.ReadToEnd().XmlDeserialize(parameterTypes[index])); #endif } yield return(list.ToArray()); }