Ejemplo n.º 1
0
    void LiveItemDisplay(int startIndex)//表示items从直播列表的哪一个索引值开始显示
    {
        Debug.Log("startIndext:" + startIndex);
        for (int i = 0; i < liveItems.Count; i++)
        {
            if (i < JsonDataManager.liveTotalCount)
            {
                liveTitles[i].text = JsonDataManager.liveItems[startIndex + i].title;
                liveItems[i].name  = JsonDataManager.liveItems[startIndex + i].liveId;
                LiveItemData Items = new LiveItemData();
                Items.contentId  = JsonDataManager.liveItems[startIndex + i].liveId;
                Items.title      = JsonDataManager.liveItems[startIndex + i].title;
                Items.clickType  = JsonDataManager.liveItems[startIndex + i].clickType;
                Items.clickParam = JsonDataManager.liveItems[startIndex + i].clickParam;

                if (!JsonDataManager.liceItemDic.ContainsKey(Items.contentId))
                {
                    // Debug.Log("Items.contentId:" + Items.contentId);
                    JsonDataManager.liceItemDic.Add(Items.contentId, Items);//加载图片完成后,加入字典。根据id添加
                }
                JsonDataManager.instance.SetImage(JsonDataManager.liveItems[startIndex + i].cover, Items, liveRawImages[i]);
            }
            else
            {
                liveTitles[i].text = "";
                liveItems[i].gameObject.SetActive(false);
            }
        }

        livePageShowText.text = currentPage + "/" + totalPages;
    }
Ejemplo n.º 2
0
        private async Task PollItemDataAsync()
        {
            while (!_cts.IsCancellationRequested)
            {
                var httpTimeout = CancellationTokenSource.CreateLinkedTokenSource(_cts.Token, new CancellationTokenSource(TimeSpan.FromSeconds(5)).Token);
                OverviewResponseViewModel itemData;
                try
                {
                    itemData = await _nexusHubClient.GetItemOverview($"{Server}-{Faction}", httpTimeout.Token);
                }
                catch (TaskCanceledException)
                {
                    await Task.Delay(TimeSpan.FromMinutes(1));

                    continue;
                }
                if (itemData != null)
                {
                    await using var context = new BuzzBotDbContext(_configuration);
                    var server = context.Servers.Include(s => s.Factions).ThenInclude(f => f.ItemData)
                                 .FirstOrDefault(s => s.Id == Server);
                    if (server == null)
                    {
                        server = new Server()
                        {
                            Id = Server, Factions = new List <Faction>()
                        };
                        context.Servers.Add(server);

                        await context.SaveChangesAsync(_cts.Token);
                    }

                    var faction = server.Factions.FirstOrDefault(f => f.Id == $"{Server}-{Faction}");
                    if (faction == null)
                    {
                        faction = new Faction {
                            Id = $"{Server}-{Faction}", ServerId = server.Id, ItemData = new List <LiveItemData>()
                        };
                        server.Factions.Add(faction);
                        context.Factions.Add(faction);
                        await context.SaveChangesAsync(_cts.Token);
                    }
                    foreach (var item in itemData.Data)
                    {
                        if (context.Items.Find(item.ItemId) == null)
                        {
                            continue;
                        }
                        var existingItem = faction.ItemData.FirstOrDefault(f => f.ItemId == item.ItemId);
                        if (existingItem == null)
                        {
                            existingItem = new LiveItemData {
                                FactionId = faction.Id, ItemId = item.ItemId
                            };
                            faction.ItemData.Add(existingItem);
                            context.LiveItemData.Add(existingItem);
                        }

                        existingItem.HistoricalValue  = item.HistoricalValue ?? 0;
                        existingItem.MarketValue      = item.MarketValue ?? 0;
                        existingItem.MinimumBuyout    = item.MinimumBuyout ?? 0;
                        existingItem.NumberOfAuctions = item.NumberAuctions ?? 0;
                        existingItem.Quantity         = item.Quantity ?? 0;
                    }
                    await context.SaveChangesAsync(_cts.Token);
                }

                await Task.Delay(TimeSpan.FromHours(1), _cts.Token);
            }
        }