/// <summary> /// Scans for prices. /// </summary> /// <returns></returns> private static IEnumerable <MineralPrice> GetPrices(IMineralParser parser) { string content = String.Empty; try { content = HttpWebClientService.DownloadString(parser.URL).Result; } catch (HttpWebClientServiceException ex) { ExceptionHandler.LogException(ex, false); } // Scan for prices MatchCollection mc = parser.Tokenizer.Matches(content); return(mc.Cast <Match>().Select(match => { int typeID; string name = Int32.TryParse(match.Groups["name"].Value, out typeID) ? StaticItems.GetItemByID(typeID).Name : match.Groups["name"].Value; return new MineralPrice { Name = name, Price = Decimal.Parse(match.Groups["price"].Value, NumberStyles.Currency, CultureInfo.InvariantCulture) }; })); }
/// <summary> /// Gets the courtesy text. /// </summary> /// <param name="source">The source.</param> /// <returns>The courtesy text.</returns> public static string GetCourtesyText(string source) { if (!s_parsers.ContainsKey(source)) { throw new ArgumentException("that is not a registered mineraldatasource", "source"); } IMineralParser p = s_parsers[source]; return(p.CourtesyText); }
/// <summary> /// Gets the prices. /// </summary> /// <param name="source">The source.</param> /// <returns>An enumerable collection of Minerals and Prices.</returns> public static IEnumerable <Pair <string, Decimal> > GetPrices(string source) { if (!s_parsers.ContainsKey(source)) { throw new ArgumentException("that is not a registered mineraldatasource", "source"); } IMineralParser p = s_parsers[source]; return(p.GetPrices()); }
/// <summary> /// Gets the courtesy URL. /// </summary> /// <param name="source">The source.</param> /// <returns>The courtesy URL.</returns> public static Uri GetCourtesyUrl(string source) { if (!s_parsers.ContainsKey(source)) { throw new ArgumentException(@"That is not a registered mineral datasource.", nameof(source)); } IMineralParser p = s_parsers[source]; return(p.CourtesyUrl); }
/// <summary> /// The prices of mineral from the given source. /// </summary> /// <param name="source">The source.</param> /// <returns>An enumerable collection of Minerals and Prices.</returns> public static IEnumerable <MineralPrice> Prices(string source) { if (!s_parsers.ContainsKey(source)) { throw new ArgumentException(@"That is not a registered mineral datasource.", nameof(source)); } IMineralParser parser = s_parsers[source]; return(GetPrices(parser)); }
/// <summary> /// Initializes the <see cref="MineralDataRequest"/> class. /// </summary> static MineralDataRequest() { Assembly asm = Assembly.GetExecutingAssembly(); foreach (Type tt in asm.GetTypes()) { foreach ( DefaultMineralParserAttribute dmpa in tt.GetCustomAttributes(typeof(DefaultMineralParserAttribute), false)) { IMineralParser mp = Activator.CreateInstance(tt) as IMineralParser; if (mp != null) { RegisterDataSource(dmpa.Name, mp); } } } }
/// <summary> /// Registers the data source. /// </summary> /// <param name="name">The name.</param> /// <param name="parser">The parser.</param> public static void RegisterDataSource(string name, IMineralParser parser) { s_parsers.Add(name, parser); }
/// <summary> /// Scans for prices. /// </summary> /// <returns></returns> private static IEnumerable<MineralPrice> GetPrices(IMineralParser parser) { string content = String.Empty; try { content = HttpWebClientService.DownloadString(parser.URL).Result; } catch (HttpWebClientServiceException ex) { ExceptionHandler.LogException(ex, false); } // Scan for prices MatchCollection mc = parser.Tokenizer.Matches(content); return mc.Cast<Match>().Select(match => { int typeID; string name = Int32.TryParse(match.Groups["name"].Value, out typeID) ? StaticItems.GetItemByID(typeID).Name : match.Groups["name"].Value; return new MineralPrice { Name = name, Price = Decimal.Parse(match.Groups["price"].Value, NumberStyles.Currency, CultureInfo.InvariantCulture) }; }); }