Пример #1
0
        private void GetSalesResponse(IAsyncResult result)
        {
            HttpWebRequest request = result.AsyncState as HttpWebRequest;

            if (request != null)
            {
                WebResponse response = request.EndGetResponse(result);
                Stream outStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(outStream);
                string xmlResult = reader.ReadToEnd();

                var wikiRevisionObject = JsonConvert.DeserializeObject<WikiSales>(xmlResult);

                WikiSales wikiSale = wikiRevisionObject as WikiSales;

                revisions[] revisionArray = wikiSale.query.pages.pageDetails.revisions;

                string revisionText = revisionArray[0].parsetree;

                SalesList salesList = new SalesList();

                XDocument xdoc = XDocument.Parse(revisionText);

                XElement rootNode = xdoc.Element("root");

                IEnumerable<XElement> templates = rootNode.Elements("template");

                foreach (XElement template in templates)
                {
                    unSortedSales.Clear();
                    IEnumerable<XElement> partsNodes = template.Elements("part");
                    foreach (XElement part in partsNodes)
                    {
                        if (part.HasElements)
                        {
                            XElement name = part.Element("name");
                            string nameValue = name.Value.Trim();
                            StorePart(salesList, part, nameValue);
                        }
                    }
                }

                salesList.Import(unSortedSales);
                (Application.Current as App).saleList = salesList;
                DataBindView(salesList);
            }
        }
Пример #2
0
 private void DataBindView(SalesList sales)
 {
     Dispatcher.BeginInvoke(() =>
     {
         DurationTimeText.Text = sales.startdate + " to " + sales.enddate;
         championSaleListBox.ItemsSource = sales.championsOnSale;
         skinSaleListBox.ItemsSource = sales.skinsOnSale;
     });
 }
Пример #3
0
 private void StorePart(SalesList salesList, XElement part, string nameValue)
 {
     switch (nameValue)
     {
         case "enddate":
             salesList.enddate = part.Element("value").Value.Trim();
             break;
         case "startdate":
             salesList.startdate = part.Element("value").Value.Trim();
             break;
         default:
             if (nameValue.Contains("champ"))
             {
                 int champId = int.Parse(nameValue.Replace("champ", String.Empty).Trim());
                 if (MemoryContainSaleItem(champId))
                 {
                     SaleItem si = GetSaleItem(champId);
                     si.champName = part.Element("value").Value.Trim();
                 }
                 else
                 {
                     SaleItem newSales = new SaleItem()
                     {
                         champId = champId,
                         champName = part.Element("value").Value.Trim()
                     };
                     unSortedSales.Add(newSales);
                 }
             }
             else if (nameValue.Contains("ip"))
             {
                 int champId = int.Parse(nameValue.Replace("ip", String.Empty).Trim());
                 if (MemoryContainSaleItem(champId))
                 {
                     SaleItem si = GetSaleItem(champId);
                     si.ipPrice = part.Element("value").Value.Trim();
                 }
                 else
                 {
                     SaleItem newSales = new SaleItem()
                     {
                         champId = champId,
                         ipPrice = part.Element("value").Value.Trim()
                     };
                     unSortedSales.Add(newSales);
                 }
             }
             else if (nameValue.Contains("price"))
             {
                 int champId = int.Parse(nameValue.Replace("price", String.Empty).Trim());
                 if (MemoryContainSaleItem(champId))
                 {
                     SaleItem si = GetSaleItem(champId);
                     si.rpPrice = part.Element("value").Value.Trim();
                 }
                 else
                 {
                     SaleItem newSales = new SaleItem()
                     {
                         champId = champId,
                         rpPrice = part.Element("value").Value.Trim()
                     };
                     unSortedSales.Add(newSales);
                 }
             }
             else if (nameValue.Contains("skin"))
             {
                 int champId = int.Parse(nameValue.Replace("skin", String.Empty).Trim());
                 if (MemoryContainSaleItem(champId))
                 {
                     SaleItem si = GetSaleItem(champId);
                     si.skinName = part.Element("value").Value.Trim();
                     si.skinSale = true;
                 }
                 else
                 {
                     SaleItem newSales = new SaleItem()
                     {
                         champId = champId,
                         skinName = part.Element("value").Value.Trim(),
                         skinSale = true
                     };
                     unSortedSales.Add(newSales);
                 }
             }
             break;
     }
 }