Ejemplo n.º 1
0
        public static SearchResult ParseSearchResult(IEnumerable<Item> items)
        {
            var result = new SearchResult();
            result.JsonResultType = JsonResultType.Search;

            result.Items.Clear();
            var hotItems = new List<HotItem>();
            foreach (var itemDetail in items)
            {
                var item = HotItemController.FromDataId(itemDetail.Id);
                if (item != null)
                {
                    hotItems.Add(item);
                }
            }
            HotItemController.UpdatePricesMultiple(hotItems);
            result.Items = hotItems;
            return result;
        }
        void transactionScraper_Finished(object sender, ScrapeFinishedEventArgs e)
        {
            var result = new SearchResult(e.Value, e.Arg.ToString(), e.Uri, JsonResultType.Transactions, e.TransactionType);

            for (int i = 0; i < Items.Count; i++)
            {
                for (int j = 0; j < result.Items.Count; j++)
                {
                    if (Items[i].DataId == result.Items[j].DataId)
                    {
                        result.Items[j].Notify = Items[i].Notify;
                    }
                }
            }
            MainWindowViewModel.Dispatcher.BeginInvoke(new Action(() =>
                {
                    for (int i = 0; i < result.Items.Count; i++)
                    {
                        result.Items[i].IsExpanded = false;
                        var item = Items.FirstOrDefault(x => x.DataId == result.Items[i].DataId);
                        if (item == null)
                        {
                            Items.Add(result.Items[i]);
                        }
                        else
                        {
                            for (int j = 0; j < result.Items[i].Items.Count; j++)
                            {
                                var innerItem = item.Items.FirstOrDefault(x => x.ListingId == result.Items[i].Items[j].ListingId);
                                if (innerItem == null)
                                {
                                    var child = result.Items[i].Items[j];
                                    item.Items.Add(child);
                                    item.GroupItem(child, item.Items);
                                }
                            }
                        }
                    }
                    for (int i = 0; i < Items.Count; i++)
                    {
                        HotItem item = Items[i];
                        var rs = result.Items.FirstOrDefault(x => x.ListingId == item.ListingId);
                        if (rs == null)
                        {
                            item.Notify = false;
                            Items.Remove(item);
                            i--;
                        }
                    }
                }));

            //Items = new ObservableCollection<HotItem>(result.Items);

            if (HotItemController.Config.IsTransactionNotificationEnabled)
            {
                FindBoughtAndSoldItems(TransactionType, Items.ToList());
            }
        }
Ejemplo n.º 3
0
        public void Search(int page, SearchFilters filter)
        {
            if (SearchFinished != null)
            {
                IsSearchInProgress = true;
                Filter = filter;
                Filter.Offset = page * filter.ItemsPerPage;
                if (filter.SearchType == SearchType.Items)
                {
                    SearchResult = SearchItems(Filter);
                }
                else
                {
                    SearchResult = SearchRecipes(Filter);
                }

                IsSearchInProgress = false;

                if (SearchFinished != null)
                {
                    SearchFinished(this, new EventArgs<SearchResult>(this.SearchResult));
                }
            }
        }
Ejemplo n.º 4
0
 public SearchResult ParseSearch(SearchResult sr, JObject json)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 5
0
 public SearchResult ParseTransaction(SearchResult sr, JObject json, TransactionType type)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 6
0
        public SearchResult ParseTransaction(SearchResult sr, JObject json, TransactionType type)
        {
            if (sr == null)
                sr = new SearchResult();
            return sr; // Not supported yet
            //try
            //{
            //    sr.Total = json["total"].ToObject<int>();
            //    if (sr.Total > 0)
            //    {
            //        sr.Offset = json["args"]["offset"].ToObject<int>();
            //        sr.Count = json["args"]["count"].ToObject<int>();

            //        JToken token = json["listings"];
            //        for (int i = 0; i < token.Count(); i++)
            //        {
            //            int dataId = token[i]["data_id"].ToObject<int>();

            //            HotItem item = new HotItem(dataId)
            //            {
            //                Name = token[i]["name"].ToObject<String>(),
            //                UnitPrice = token[i]["unit_price"].ToObject<int>(),
            //                ImgUri = token[i]["img"].ToObject<String>(),
            //                Quantity = token[i]["quantity"].ToObject<int>(),
            //                SaleVolume = token[i]["sale_availability"].ToObject<int>(),
            //                BuyVolume = token[i]["offer_availability"].ToObject<int>(),
            //                DateTimeStamp = token[i]["created"].ToObject<String>()
            //            };
            //            //if (TransactionType == Notifier.TransactionType.Buying || TransactionType == Notifier.TransactionType.Selling)
            //            //{
            //            //    item.Crawl(); // we crawl buy and sell listing
            //            //}
            //            sr.Items.Add(item);
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    Debug.WriteLine(ex);
            //}
            //return sr;
            //GroupItems();
        }
Ejemplo n.º 7
0
        public SearchResult ParseSearch(SearchResult sr, JObject json)
        {
            if (sr == null)
                sr = new SearchResult();

            try
            {
                sr.Count = json["count"].ToObject<int>();

                int page = json["page"].ToObject<int>();
                if (page == 0)
                    page++;
                page--;// Yeah that makes sense \o/

                sr.Offset = page * ItemsPerPage + 1;
                sr.Total = json["total"].ToObject<int>();
                JToken token = json["results"];
                for (int i = 0; i < token.Count(); i++)
                {
                    int dataId = token[i]["data_id"].ToObject<int>();
                    string name = token[i]["name"].ToObject<String>();
                    string imgUri = token[i]["img"].ToObject<String>();
                    HotItem item = new HotItem(dataId)
                    {
                        Name = name,
                        SellPrice = token[i]["min_sale_unit_price"].ToObject<int>(),
                        BuyPrice = token[i]["max_offer_unit_price"].ToObject<int>(),
                        BuyVolume = token[i]["offer_availability"].ToObject<long>(),
                        SaleVolume = token[i]["sale_availability"].ToObject<long>(),
                        DateTimeStamp = token[i]["price_last_changed"].ToObject<String>(),
                        Rarity = token[i]["rarity"].ToObject<int>(),
                        ImgUri = imgUri,
                        Quantity = token[i]["sale_availability"].ToObject<int>(),
                        Level = token[i]["restriction_level"].ToObject<int>()
                    };

                    sr.Items.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            return sr;
        }