public ParsingException( ValueParsingException innerException, ParsingTarget target, string name) : base($"{target.Map()} parsing error. Name: {name}, value: {innerException.Value}.", innerException) { Target = target; Name = name; Value = innerException.Value; }
/// <summary> /// Loads an image from a specified source. /// </summary> /// <param name="node">An ansector node to the one that contains the link to the image.</param> /// <param name="toParse">Specifies the type of a node to load an image from.</param> /// <returns>A System.Drawing.Image.</returns> private static Image GetImage(HtmlNode node, ParsingTarget toParse) { string imgClass; switch (toParse) { case ParsingTarget.Flag: imgClass = "thumbborder"; break; case ParsingTarget.WeaponImage: imgClass = "thumbimage"; break; default: throw new UnexpectedInputException("Unexpected parsing target."); } HtmlNode imgNode = node.SelectSingleNode(@"//img[@class='" + imgClass + "']"); if (imgNode == null) { if (node.HasChildNodes) { imgNode = node.SelectSingleNode(@"//a/img"); } else { return((Image)Image.FromFile(Constants.imgNotFound).Clone()); } } string src = (imgNode.Attributes["src"] != null) ? imgNode.Attributes["src"].Value : string.Empty; if (src == string.Empty) { return(null); } try { using (var wc = new WebClient()) { using (var imgStream = new MemoryStream(wc.DownloadData("https:" + src))) { using (var image = Image.FromStream(imgStream)) { return(new Bitmap(image)); } } } } catch (IOException) { return(null); } }
public static string Map(this ParsingTarget target) { switch (target) { case ParsingTarget.Argument: return("argument"); case ParsingTarget.Option: return("option"); default: throw new InvalidOperationException( $"{nameof(ParsingTarget)} to string conversion error. Unknown value: {target}."); } }
public void TestWcSettingsConstructorConstraint() { // Arrange ParsingTarget p = new ParsingTarget(); p.fLines = true; p.fVolume = false; p.fWords = true; List <String> expectedFlags = new List <string>() { "l", "w" }; string[] paths = new[] { "firstpath.txt", "secpath.txt" }; //Act _settings = new wcSettings(p, paths); // Assert Assert.AreEqual(expectedFlags, _settings.Flags); Assert.AreEqual(paths, _settings.Paths); }