Exemplo n.º 1
0
        public List <Top100Entry> Query(Top100Category category)
        {
            lock (Cache)
            {
                var key   = "top100/" + Context.ShardId + "/" + category.ToString();
                var value = Cache.GetCacheItem(key);

                if (value != null)
                {
                    return((List <Top100Entry>)value.Value);
                }

                using (var db = DAFactory.Get())
                {
                    List <Top100Entry> results = null;

                    if (category.IsLotCategory())
                    {
                        results = db.LotTop100.GetByCategory(Context.ShardId, category.ToLotCategory()).Select(x => new Top100Entry()
                        {
                            Rank = x.rank,
                            //Data service uses lot location as the ID
                            TargetId   = (uint?)x.lot_location,
                            TargetName = x.lot_name
                        }).ToList();
                    }
                    else
                    {
                        //TODO:
                        results = new List <Top100Entry>();
                        for (var i = 0; i < 100; i++)
                        {
                            results.Add(new Top100Entry {
                                Rank = (byte)(i + 1)
                            });
                        }
                    }

                    Cache.Add(key, results, new CacheItemPolicy()
                    {
                        AbsoluteExpiration = DateTime.Now.Add(TimeSpan.FromMinutes(5))
                    });
                    return(results);
                }
            }
        }
Exemplo n.º 2
0
 public static bool IsAvatarCategory(this Top100Category category)
 {
     return(!category.IsLotCategory());
 }
        public void SetCategory(Top100Category category)
        {
            Category = category;

            if (category.IsLotCategory())
            {
                LastLotCategory = category;
            }
            else
            {
                LastAvatarCategory = category;
            }

            View.SelectCategory(category);
            DatabaseService.GetTop100(new GetTop100Request()
            {
                Category = category
            })
            .ContinueWith(x => {
                //Category has been switched
                if (Category != category)
                {
                    return;
                }


                List <Top100ListItem> enriched = null;

                if (category.IsLotCategory())
                {
                    enriched = DataService.EnrichList <Top100ListItem, Top100Entry, Lot>(x.Result.Items, y => y.TargetId, (top100Entry, lot) =>
                    {
                        return(new Top100ListItem()
                        {
                            Top100Entry = top100Entry,
                            Lot = lot
                        });
                    });
                }
                else
                {
                    enriched = DataService.EnrichList <Top100ListItem, Top100Entry, Avatar>(x.Result.Items, z => z.TargetId, (top100Entry, avatar) =>
                    {
                        return(new Top100ListItem()
                        {
                            Top100Entry = top100Entry,
                            Avatar = avatar
                        });
                    });
                }

                //Fill in any gaps
                while (enriched.Count < 100)
                {
                    enriched.Add(new Top100ListItem {
                        Top100Entry = new Top100Entry()
                        {
                            Rank = (byte)(enriched.Count + 1)
                        }
                    });
                }

                enriched = enriched.OrderBy(i => i.Top100Entry.Rank).ToList();
                View.DisplayResults(enriched);
            });
        }