private async Task FetchPlatPriceTask(DisplayPrime displayPrime) { var minSell = await PlatinumPrices.GetPrimePlatSellOrders(displayPrime.Prime.Name); if (minSell.HasValue) { displayPrime.PlatinumPrice = minSell.ToString(); } else { displayPrime.PlatinumPrice = "?"; } }
public void OnDraw(object sender, DrawingContext context) { double height = 0; double width = 0; List <KeyValuePair <int, FormattedText> > _text = new List <KeyValuePair <int, FormattedText> >(); for (int i = 0; i < displayPrimes.Count; i++) { DisplayPrime p = displayPrimes[i]; StringBuilder text = new StringBuilder(p.Prime.Name); text.Append(p.Prime.Name.Length < 20 ? "\t\t" : "\t"); text.Append(p.DucatValue + " Ducats"); if (p.PlatinumPrice != "?") { text.Append("\t" + p.PlatinumPrice + " Plat"); } if (!string.IsNullOrWhiteSpace(p.Data.Notes)) { text.Append("\t" + p.Data.Notes); } SolidColorBrush color = p.Data.NumberOwned >= 1 ? Brushes.CadetBlue : Brushes.OrangeRed; // Draw a formatted text string into the DrawingContext. FormattedText Ftext = new FormattedText(text.ToString(), CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, Typeface, 13, color, MainWindow.pixelsPerDip); height = Ftext.Height; if (width < Ftext.Width) { width = Ftext.Width; } _text.Add(new KeyValuePair <int, FormattedText>(i, Ftext)); } //Draw a rectangle bellow the text for easier reading context?.DrawRectangle(brush, pen, new Rect(drawStartX - 10, drawStartY - 10, width + 20, ((height + 5) * displayPrimes.Count) + displayPrimes.Count * 7)); foreach (KeyValuePair <int, FormattedText> keyValuePair in _text) { context.DrawText(keyValuePair.Value, new Point(drawStartX, (drawStartY + 25 * keyValuePair.Key))); } }
private async Task FetchDucatPriceTask(DisplayPrime displayPrime) { if (string.IsNullOrWhiteSpace(displayPrime.DucatValue) || displayPrime.DucatValue == "0" || displayPrime.DucatValue == "?" || displayPrime.DucatValue == "...") { string name = displayPrime.Prime.Name; int? ducat = await DucatPrices.GetPrimePartDucats(name); if (ducat.HasValue) { displayPrime.DucatValue = ((int)ducat).ToString(); } else { displayPrime.DucatValue = "?"; } } }
private async Task FetchPlatTask(DisplayPrime displayPrime) { if (FetchPlatinum) { string name = displayPrime.Prime.Name; long?minSell = await PlatinumPrices.GetPrimePlatSellOrders(name).ConfigureAwait(false); if (minSell.HasValue) { displayPrime.PlatinumPrice = minSell.Value.ToString(); } else { displayPrime.PlatinumPrice = "?"; } } }
public void OnDraw(object sender, DrawingContext context) { double height = 0; double width = 0; List <KeyValuePair <int, FormattedText> > _text = new List <KeyValuePair <int, FormattedText> >(); for (int i = 0; i < displayPrimes.Count; i++) { DisplayPrime p = displayPrimes[i]; StringBuilder text = new StringBuilder(p.Prime.Name); text.Append(p.Prime.Name.Length < 20 ? "\t\t" : "\t"); text.Append(p.Prime.Ducats + " Ducats"); if (p.PlatinumPrice != "?") { text.Append("\t" + p.PlatinumPrice + " Plat"); } // Draw a formatted text string into the DrawingContext. FormattedText Ftext = new FormattedText(text.ToString(), CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface(TypefaceName), 13, Brushes.OrangeRed); height = Ftext.Height; if (width < Ftext.Width) { width = Ftext.Width; } _text.Add(new KeyValuePair <int, FormattedText>(i, Ftext)); } //Draw a rectangle bellow the text for easier reading context.DrawRectangle(brush, pen, new Rect(drawStartX - 10, drawStartY - 10, width + 20, ((height + 5) * displayPrimes.Count) + displayPrimes.Count * 7)); foreach (KeyValuePair <int, FormattedText> keyValuePair in _text) { context.DrawText(keyValuePair.Value, new Point(drawStartX, (drawStartY + 25 * keyValuePair.Key))); } }
public static async Task <int> GetDucatPriceValue(DisplayPrime displayPrime) { if (displayPrime.Ducats == "?") { return(0); } if (displayPrime.Prime.Ducats != 0) { return(displayPrime.Prime.Ducats); } var partName = displayPrime.Prime.Name.ToLower().Replace(' ', '_'); string jsonData; using (var client = new WebClient()) { var uri = new Uri(string.Format(_baseUrl, Uri.EscapeDataString(partName))); try { jsonData = await client.DownloadStringTaskAsync(uri); dynamic result = JsonConvert.DeserializeObject(jsonData); IEnumerable <dynamic> itemSets = result.payload.item.items_in_set; int ducats = itemSets .Where(itemSet => itemSet.url_name == partName) .Min(itemSet => itemSet.ducats); return(ducats); } catch { return(0); } } }
private async Task FetchDucatValueTask(DisplayPrime displayPrime) { var ducats = await DucatValues.GetDucatPriceValue(displayPrime); if (ducats != 0) { displayPrime.Prime.Ducats = ducats; displayPrime.Ducats = ducats.ToString(); if (displayPrime.PlatinumPrice != "?") { int plat = 0; if (int.TryParse(displayPrime.PlatinumPrice, out plat)) { float ratio = (float)ducats / (float)plat; displayPrime.DucatRatio = ratio.ToString("n2"); } } } else { displayPrime.Ducats = "?"; } }