Inheritance: LibraryBase.Wpf.ViewModel.BindableBase
Exemple #1
0
        public static List <HotItem> GroupItems(List <HotItem> items)
        {
            List <HotItem> uniqueItems = new List <HotItem>();

            try
            {
                foreach (HotItem item in items)
                {
                    try
                    {
                        if (!uniqueItems.Exists(x => x.DataId == item.DataId))
                        {
                            HotItem groupItem = HotItem.CreateGroupItem(item, items);

                            uniqueItems.Add(groupItem);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }
            return(uniqueItems);
        }
Exemple #2
0
 public void Import(string filePath)
 {
     try
     {
         string[]   columns;
         string[][] rows;
         CsvHelper.ReadCsv(filePath, out columns, out rows, ",");
         int dataIdColumn = -1;
         for (int i = 0; i < columns.Length; i++)
         {
             if (columns[i] == "data_id")
             {
                 dataIdColumn = i;
             }
         }
         if (dataIdColumn >= 0)
         {
             for (int i = 0; i < rows.Length; i++)
             {
                 int dataId = int.Parse(rows[i][dataIdColumn]);
                 var item   = new HotItem(dataId);
                 UpdateItemDetails(item);
                 Add(item);
             }
         }
     }
     catch
     {
     }
 }
        public void GroupItem(HotItem item, IList <HotItem> result)
        {
            int    quantity = result.Sum(x => x.Quantity);
            double avg      = result.Average(x => x.UnitPrice);

            this.UnitPrice = (int)Math.Round(avg);
            this.Quantity  = quantity;

            this.DisplayName     = String.Format("Transactions {0}", result.Count());
            this.DateTimeStamp   = item.DateTimeStamp;
            this.TransactionTime = result.OrderByDescending(t => t.TransactionTime).First().TransactionTime;

            if (TransactionTime == DateTime.MinValue)
            {
                var tempDateTime = ParseTimeStamp(DateTimeStamp);
                if (tempDateTime.HasValue)
                {
                    this.TransactionTime = tempDateTime.Value;
                }
            }

            this.Name          = item.Name;
            this.ItemBuildDone = item.ItemBuildDone;
            this.Image         = item.Image;
            this.ListingId     = item.ListingId;
            this.DataId        = item.DataId;
            this.BuyPrice      = item.BuyPrice;
            this.SellPrice     = item.SellPrice;
        }
        public static HotItem CreateGroupItem(HotItem item, IList <HotItem> items)
        {
            HotItem groupItem = new HotItem(item.DataId);

            item.Parent       = groupItem;
            groupItem.IsGroup = true;

            var result = items.Where(x => x.DataId == item.DataId).ToList();

            //foreach (var i in result)
            //{
            //    groupItem.Items.Add(i);
            //}

            var list = result.GroupBy(x => x.ListingId);

            foreach (var group in list)
            {
                //groupItem.Items.Add();
                var g = new HotItem(item.DataId);
                g.GroupItem(group.First(), group.ToList());
                groupItem.Items.Add(g);
            }

            groupItem.GroupItem(item, result);
            return(groupItem);
        }
 public NotifierRule(HotItem item, RuleType type, int value, ContextType contextType, INotificationHost host)
 {
     this.Host = host;
     this.Money = new Money(0, 0, value) { Name = "Rule" };
     this.Item = item;
     this.SelectedRuleType = type;
     this.ContextType = contextType;
 }
Exemple #6
0
 public void ApplyItemValues(HotItem item)
 {
     if (item != null)
     {
         Name      = item.Name;
         Quantitiy = item.Quantity;
         Image     = item.Image;
     }
 }
Exemple #7
0
        public static void UpdatePrice(AggregateListing listing, HotItem hotItem)
        {
            hotItem.BuyVolume = listing.BuyOffers.Quantity;
            hotItem.BuyPrice  = listing.BuyOffers.UnitPrice;

            hotItem.SaleVolume = listing.SellOffers.Quantity;
            hotItem.SellPrice  = listing.SellOffers.UnitPrice;

            hotItem.UpdatePriceChanged();
        }
Exemple #8
0
 public NotifierRule(HotItem item, RuleType type, int value, ContextType contextType, INotificationHost host)
 {
     this.Host  = host;
     this.Money = new Money(0, 0, value)
     {
         Name = "Rule"
     };
     this.Item             = item;
     this.SelectedRuleType = type;
     this.ContextType      = contextType;
 }
Exemple #9
0
        public static void UpdateItemDetails(HotItem hotItem)
        {
            var item = TradingPostApiOfficial.ItemTradingPostDB.Values.FirstOrDefault(x => x.Id == hotItem.DataId);

            if (item != null)
            {
                hotItem.Name       = item.Name;
                hotItem.ImgUri     = item.Icon;
                hotItem.RarityWord = item.Rarity;
                hotItem.Level      = item.Level;
            }
        }
Exemple #10
0
        void newItem_Crawled(object sender, EventArgs e)
        {
            HotItem item = (HotItem)sender;

            if (item != null)
            {
                for (int i = 0; i < item.Items.Count; i++)
                {
                    HotItem itemInner = item.Items[i];
                    itemInner.Update();
                }
            }
        }
Exemple #11
0
        void newItem_Built(object sender, EventArgs e)
        {
            HotItem item = (HotItem)sender;

            if (item != null)
            {
                for (int i = 0; i < item.Items.Count; i++)
                {
                    HotItem itemInner = item.Items[i];
                    itemInner.MarketItem = item;
                }
            }
        }
Exemple #12
0
        public void RegisterRecipeItem(HotItem item)
        {
            int dataId = item.DataId;

            if (!RecipeItemPool.ContainsKey(dataId))
            {
                var newItem = new HotItem(dataId);
                newItem.ItemCreated  += newItem_Built;
                newItem.PriceChanged += newItem_Crawled;
                RecipeItemPool.Add(dataId, newItem);
            }

            RecipeItemPool[dataId].Items.Add(item);
        }
Exemple #13
0
 private void UpdateItem(HotItem item1, HotItem item2)
 {
     item1.Name       = item2.Name;
     item1.SellPrice  = item2.SellPrice;
     item1.BuyPrice   = item2.BuyPrice;
     item1.Rarity     = item2.Rarity;
     item1.RarityWord = item2.RarityWord;
     //item1.BuyContext = item2.BuyContext;
     //item1.SellContext = item2.SellContext;
     item1.SaleVolume = item2.SaleVolume;
     item1.BuyVolume  = item2.BuyVolume;
     item1.Image      = item2.Image;
     item1.ImgUri     = item2.ImgUri;
 }
        public NotificationModel(HotItem item, NotifierRule rule, String message, DateTime timeStamp, NotificationType notificationType)
        {
            this.DataId = item.DataId;
            this.NotificationType = notificationType;
            this.TimeStamp = timeStamp;
            this.Message = message;
            this.Item = item;
            if (this.Item != null)
            {
                this.BuyMoney = item.BuyMoney;
                this.SellMoney = item.SellMoney;
            }

            this.Rule = rule;
        }
Exemple #15
0
        public static HotItem FromDataId(int dataId)
        {
            var item = TradingPostApiOfficial.ItemTradingPostDB.Values.FirstOrDefault(x => x.Id == dataId);

            if (item != null)
            {
                var hotItem = new HotItem(dataId)
                {
                    Name       = item.Name,
                    ImgUri     = item.Icon,
                    RarityWord = item.Rarity,
                    Level      = item.Level
                };
                return(hotItem);
            }
            return(null);
        }
        public NotificationModel(HotItem item, NotifierRule rule, String message, DateTime timeStamp, NotificationType notificationType)
        {
            this.DataId = item.DataId;
            this.NotificationType = notificationType;
            this.TimeStamp = timeStamp;
            this.Message = message;
            this.Item = item;
            if (this.Item != null)
            {
                this.BuyMoney = item.BuyMoney;
                this.SellMoney = item.SellMoney;
            }
            this.Rule = rule;

            ApplyItemValues(item);
            // TODO: Refactoring, someday NotifierRule and NotificationModel must be merged together
        }
Exemple #17
0
        public void Export(string filePath)
        {
            try
            {
                String[] columns = new string[] {
                    "data_id", "name", "rarity", "restriction_level", "img", "type_id", "sub_type_id", "price_last_changed", "max_offer_unit_price", "min_sale_unit_price", "offer_availability",
                    "sale_availability", "gw2db_external_id", "sale_price_change_last_hour", "offer_price_change_last_hour"
                };

                Object[][] rows = new object[Queue.Count][];

                for (int i = 0; i < rows.Length; i++)
                {
                    rows[i] = new object[columns.Length];

                    HotItem item = Queue[i];

                    rows[i][0]  = item.DataId;
                    rows[i][1]  = item.Name;
                    rows[i][2]  = "";
                    rows[i][3]  = "";
                    rows[i][4]  = "";
                    rows[i][5]  = "";
                    rows[i][6]  = "";
                    rows[i][7]  = "";
                    rows[i][8]  = item.BuyPrice;
                    rows[i][9]  = item.SellPrice;
                    rows[i][10] = item.BuyVolume;
                    rows[i][11] = item.SaleVolume;
                    rows[i][12] = "";
                    rows[i][13] = "";
                    rows[i][14] = "";
                }

                CsvHelper.WriteCsv(filePath, columns, rows, ",");
            }
            catch
            {
            }
        }
 public void ApplyItemValues(HotItem item)
 {
     if (item != null)
     {
         Name = item.Name;
         Quantitiy = item.Quantity;
         Image = item.Image;
     }
 }
Exemple #19
0
 public void Remove(HotItem item)
 {
     item.BuyPriceChanged  -= new EventHandler <PriceChangedEventArgs>(item_BuyPriceChanged);
     item.SellPriceChanged -= new EventHandler <PriceChangedEventArgs>(item_SellPriceChanged);
     Queue.Remove(item);
 }
 public void Add(HotItem item)
 {
     //item.BuyNotification += new EventHandler<NotificationEventArgs>(item_BuyNotification);
     //item.SellNotification += new EventHandler<NotificationEventArgs>(item_SellNotification);
     item.BuyPriceChanged += new EventHandler<PriceChangedEventArgs>(item_BuyPriceChanged);
     item.SellPriceChanged += new EventHandler<PriceChangedEventArgs>(item_SellPriceChanged);
     Queue.Add(item);
 }
 public void Remove(HotItem item)
 {
     //item.BuyNotification -= new EventHandler<NotificationEventArgs>(item_BuyNotification);
     //item.SellNotification -= new EventHandler<NotificationEventArgs>(item_SellNotification);
     item.BuyPriceChanged -= new EventHandler<PriceChangedEventArgs>(item_BuyPriceChanged);
     item.SellPriceChanged -= new EventHandler<PriceChangedEventArgs>(item_SellPriceChanged);
     Queue.Remove(item);
 }
 public void AddNotificationMessage(HotItem item, String message)
 {
     NotificationModel m = new NotificationModel(item, null, message, item.TransactionTimeLocal, NotificationType.Undefined);
     m.AsTransaction();
     AddBuyNotification(m);
 }
        public static HotItem CreateGroupItem(HotItem item, IList<HotItem> items)
        {
            HotItem groupItem = new HotItem(item.DataId);
            item.Parent = groupItem;
            groupItem.IsGroup = true;

            var result = items.Where(x => x.DataId == item.DataId).ToList();

            //foreach (var i in result)
            //{
            //    groupItem.Items.Add(i);
            //}

            var list = result.GroupBy(x => x.TransactionTime.Day);

            foreach (var group in list)
            {
                //groupItem.Items.Add();
                var g = new HotItem(item.DataId);
                g.GroupItem(group.First(), group.ToList());
                groupItem.Items.Add(g);
            }

            groupItem.GroupItem(item, result);
            return groupItem;
        }
        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;
        }
 private void AddItemInternal(HotItem item)
 {
     HotItemController.Add(item);
 }
        public IList<HotItem> ParseTrendSell(JToken json)
        {
            var items = new List<HotItem>();
            foreach (var token in json)
            {
                var item = new HotItem(token["data_id"].ToObject<int>())
                    {
                        SellPriceMoveCurrent = token["sell_price"].ToObject<float>(),
                        BuyPriceMoveCurrent = token["buy_price"].ToObject<float>(),
                        SellCountMove = token["sell_count"].ToObject<double>(),
                        BuyCountMove = token["buy_count"].ToObject<double>(),

                        DateTimeTrend = token["datetime"].ToObject<DateTime>(),

                        SellPriceMove = token["sell_price_move"].ToObject<float>(),
                        BuyPriceMove = token["buy_price_move"].ToObject<float>(),
                        SellCountMovePercent = token["sell_count_move"].ToObject<float>(),
                        BuyCountMovePercent = token["buy_count_move"].ToObject<float>(),
                    };
                items.Add(item);
            }
            return items;
        }
 public static void UpdateItemDetails(HotItem hotItem)
 {
     var item = TradingPostApiOfficial.ItemTradingPostDB.Values.FirstOrDefault(x => x.Id == hotItem.DataId);
     if (item != null)
     {
         hotItem.Name = item.Name;
         hotItem.ImgUri = item.Icon;
         hotItem.RarityWord = item.Rarity;
         hotItem.Level = item.Level;
     }
 }
 public HotItem ParseItemListing(HotItem item, JObject json)
 {
     throw new NotImplementedException();
 }
Exemple #29
0
        private void ThreadRun()
        {
            GuildWars2Status = Notifier.GuildWars2Status.Loading;

            LoadItems();
            LoadRecipes();

            TradingPostApiOfficial.Initialize();

            GuildWars2Status = Notifier.GuildWars2Status.FinishedLoading;
            //LoadRavenDB();

            //String uriTrendSell = CurrendTrendApi.UriTrendSell();
            //ScrapeHelper.Get(uriTrendSell, "", null, "", TrendActionSell, "");

            //String uriTrendBuy = CurrendTrendApi.UriTrendBuy();
            //ScrapeHelper.Get(uriTrendBuy, "", null, "", TrendActionBuy, "");

            try
            {
                while (IsRunning)
                {
                    //while (IsSearchInProgress)
                    //{
                    //    Thread.Sleep(10);
                    //}
                    for (int i = 0; i < Queue.Count; i++)
                    {
                        HotItem item = Queue[i];

                        Task.Factory.StartNew(() =>
                        {
                            item.BuildItem(ForceItemBuild); // It checks that the item gets build only once
                            item.UpdatePrices();
                            item.CompareToRules();
                        });

                        //ItemStore.Store(Queue);
                        Thread.Sleep(100);
                    }

                    try
                    {
                        var items = new List <HotItem>(RecipeItemPool.Values);
                        foreach (var item in RecipeItemPool)
                        {
                            UpdateItemDetails(item.Value);
                            item.Value.BuildItem(false);
                        }
                        UpdatePricesMultiple(items);
                    }
                    catch
                    {
                        // Changed the collection
                    }

                    try
                    {
                        Gem.Update();
                    }
                    catch
                    {
                    }

                    ForceItemBuild = false;
                    Thread.Sleep(5000);
                }
            }
            catch (ThreadInterruptedException)
            {
                IsRunning = false;
            }
        }
Exemple #30
0
 public void Add(HotItem item)
 {
     item.BuyPriceChanged  += new EventHandler <PriceChangedEventArgs>(item_BuyPriceChanged);
     item.SellPriceChanged += new EventHandler <PriceChangedEventArgs>(item_SellPriceChanged);
     Queue.Add(item);
 }
        public void Register(HotItem item, ObservableDataSource<ItemProxy> items)
        {
            items.SetYMapping(y => y.SellPrice);
            items.SetXMapping(x => HorizontalAxis.ConvertToDouble(x.DateTime));

            ChartPlotter.AddLineGraph(items, 2.0, item.Name + " S");

            chartItems.Add(item.DataId, items);
            item.PropertyChanged += item_PropertyChanged;
        }
        public HotItem ParseItemListing(HotItem item, JObject json)
        {
            if (item == null)
                item = new HotItem();
            try
            {
                try
                {
                    item.BuyPrice = json["result"]["max_offer_unit_price"].ToObject<int>();
                }
                catch
                {

                }
                try
                {
                    item.SellPrice = json["result"]["min_sale_unit_price"].ToObject<int>();
                }
                catch
                {

                }

                item.BuyVolume = json["result"]["offer_availability"].ToObject<int>();
                item.SaleVolume = json["result"]["sale_availability"].ToObject<int>();
            }
            catch
            {

            }
            return item;
        }
 public ItemContext(ContextType contextType, HotItem item)
 {
     this.ContextType = contextType;
     this.Item = item;
 }
        public HotItem ParseItem(HotItem item, JObject json)
        {
            if (item == null)
                item = new HotItem();
            try
            {
                try
                {
                    item.Name = json["result"]["name"].ToObject<String>();
                }
                catch
                {

                }

                try
                {
                    item.ImgUri = json["result"]["img"].ToObject<String>();
                }
                catch
                {

                }
            }
            catch
            {

            }
            return item;
        }
 private void RemoveInternal(HotItem item)
 {
     HotItemController.Remove(item);
 }
 public void Remove(HotItem item)
 {
     item.BuyPriceChanged -= new EventHandler<PriceChangedEventArgs>(item_BuyPriceChanged);
     item.SellPriceChanged -= new EventHandler<PriceChangedEventArgs>(item_SellPriceChanged);
     Queue.Remove(item);
 }
        public void GroupItem(HotItem item, IList<HotItem> result)
        {
            int quantity = result.Sum(x => x.Quantity);
            double avg = result.Average(x => x.UnitPrice);
            this.UnitPrice = (int)Math.Round(avg);
            this.Quantity = quantity;

            this.DisplayName = String.Format("Transactions {0}", result.Count());
            this.DateTimeStamp = item.DateTimeStamp;
            this.TransactionTime = result.OrderByDescending(t => t.TransactionTime).First().TransactionTime;

            if (TransactionTime == DateTime.MinValue)
            {
                var tempDateTime = ParseTimeStamp(DateTimeStamp);
                if (tempDateTime.HasValue)
                {
                    this.TransactionTime = tempDateTime.Value;
                }
            }

            this.Name = item.Name;
            this.ItemBuildDone = item.ItemBuildDone;
            this.Image = item.Image;
            this.ListingId = item.ListingId;
            this.DataId = item.DataId;
            this.BuyPrice = item.BuyPrice;
            this.SellPrice = item.SellPrice;
        }
 public void ViewRecipe(HotItem item)
 {
     Task.Factory.StartNew(() =>
     {
         int itemId = HotItemController.DataIdToRecipeId(item.DataId);
         if (itemId > 0)
         {
             Recipe recipe = HotItemController.RecipeDB.Find(x => x.CreatedItemId == itemId);
             Add(recipe);
         }
     });
 }
 //private void LoadRavenDB()
 //{
 //    //MongoClient = new MongoClient("mongodb://localhost");
 //    //MongoServer = MongoClient.GetServer();
 //    //var db = MongoServer.GetDatabase("ztpn");
 //    var path = Path.Combine(ZicoresUtils.Zicore.Configuration.ConfigHelper.GetConfigFolder(), "RavenDB");
 //    DocumentStore = new EmbeddableDocumentStore { DataDirectory = path };
 //    DocumentStore.Initialize();
 //    ItemStore = new ItemStore(DocumentStore);
 //}
 private void UpdateItem(HotItem item1, HotItem item2)
 {
     item1.Name = item2.Name;
     item1.SellPrice = item2.SellPrice;
     item1.BuyPrice = item2.BuyPrice;
     item1.Rarity = item2.Rarity;
     item1.RarityWord = item2.RarityWord;
     //item1.BuyContext = item2.BuyContext;
     //item1.SellContext = item2.SellContext;
     item1.SaleVolume = item2.SaleVolume;
     item1.BuyVolume = item2.BuyVolume;
     item1.Image = item2.Image;
     item1.ImgUri = item2.ImgUri;
 }
        public void Import(string filePath)
        {
            try
            {
                string[] columns;
                string[][] rows;
                CsvHelper.ReadCsv(filePath, out columns, out rows, ",");
                int dataIdColumn = -1;
                for (int i = 0; i < columns.Length; i++)
                {
                    if (columns[i] == "data_id")
                    {
                        dataIdColumn = i;
                    }
                }
                if (dataIdColumn >= 0)
                {
                    for (int i = 0; i < rows.Length; i++)
                    {
                        int dataId = int.Parse(rows[i][dataIdColumn]);
                        var item = new HotItem(dataId);
                        UpdateItemDetails(item);
                        Add(item);
                    }
                }
            }
            catch
            {

            }
        }
        public void RegisterRecipeItem(HotItem item)
        {
            int dataId = item.DataId;
            if (!RecipeItemPool.ContainsKey(dataId))
            {
                var newItem = new HotItem(dataId);
                newItem.Built += newItem_Built;
                newItem.Crawled += newItem_Crawled;
                RecipeItemPool.Add(dataId, newItem);
            }

            RecipeItemPool[dataId].Items.Add(item);
        }
 public void Add(HotItem item)
 {
     item.BuyPriceChanged += new EventHandler<PriceChangedEventArgs>(item_BuyPriceChanged);
     item.SellPriceChanged += new EventHandler<PriceChangedEventArgs>(item_SellPriceChanged);
     Queue.Add(item);
 }
 public void UnregisterRecipeItem(HotItem item)
 {
     UnregisterRecipeItem(item.DataId);
 }
        public static void UpdatePrice(AggregateListing listing, HotItem hotItem)
        {
            hotItem.BuyVolume = listing.BuyOffers.Quantity;
            hotItem.BuyPrice = listing.BuyOffers.UnitPrice;

            hotItem.SaleVolume = listing.SellOffers.Quantity;
            hotItem.SellPrice = listing.SellOffers.UnitPrice;

            hotItem.UpdatePriceChanged();
        }
 public static HotItem FromDataId(int dataId)
 {
     var item = TradingPostApiOfficial.ItemTradingPostDB.Values.FirstOrDefault(x => x.Id == dataId);
     if (item != null)
     {
         var hotItem = new HotItem(dataId)
             {
                 Name = item.Name,
                 ImgUri = item.Icon,
                 RarityWord = item.Rarity,
                 Level = item.Level
             };
         return hotItem;
     }
     return null;
 }
Exemple #46
0
 public void UnregisterRecipeItem(HotItem item)
 {
     UnregisterRecipeItem(item.DataId);
 }