示例#1
0
        private async void bAddSteamProfile_Click(object sender, RoutedEventArgs e)
        {
            if (!auth)
            {
                return;
            }
            string link = tbLink.Text;

            if (link.StartsWith("http"))
            {
                link = $"{tbLink.Text.Replace("https://", "http://")}";
            }
            else
            {
                link = $"http://{tbLink.Text}";
            }
            string accountNick = CheckNick(link);

            if (!String.IsNullOrEmpty(accountNick))
            {
                try
                {
                    link = $"{link}/inventory/json/730/2";
                    ResultCheckItem res = await SteamProfileItem.CheckLastItem(link);

                    //SteamProfileItem.CheckLastItem(out itemId, out picUrl, out itemName, out error, link);
                    if (String.IsNullOrEmpty(res.error))
                    {
                        if (!String.IsNullOrEmpty(res.itemId) && !String.IsNullOrEmpty(res.picUrl) && !String.IsNullOrEmpty(res.itemName))
                        {
                            SteamProfileItem item = new SteamProfileItem(link, accountNick, res.picUrl, res.itemName, res.itemId, tbLogSteam);
                            item.bDelete.Click += DelAccount;
                            profilesItems.Add(item);
                            spContent.Children.Add(item);
                        }
                        else
                        {
                            tbLogSteam.AppendText(DateTime.Now + ": " + "Ссылка на аккаунт верна, но не могу загрузить инвентарь. Возможно он недоступен." + Environment.NewLine);
                        }
                    }
                    else
                    {
                        tbLogSteam.AppendText($"{DateTime.Now}: {res.error}{Environment.NewLine}");
                    }
                }
                catch (Exception ex)
                {
                    tbLogSteam.AppendText(DateTime.Now + ": " + ex.Message + Environment.NewLine);
                }
            }
            else
            {
                tbLogSteam.AppendText(DateTime.Now + ": " + "Ссылка на аккаунт не верна." + Environment.NewLine);
            }
            tbLink.Text = "";
        }
        async void CheckInventory()
        {
            try
            {
                ResultCheckItem res = await CheckLastItem(linkToJSON);

                if (res.error == "")
                {
                    if (res.itemId != "" && res.itemId != itemId)
                    {
                        itemId = res.itemId;
                        await Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
                                                         () =>
                        {
                            ChangeItem(res.picUrl, res.itemName);
                        }));
                    }
                    else
                    {
                        await Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
                                                         () =>
                        {
                            tbNick.Text = $"Account nick {accountNick} / Last updated {DateTime.Now}";
                        }));
                    }
                }
                else
                {
                    await Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
                                                     () =>
                    {
                        tbLog.AppendText($"{DateTime.Now}: {res.error}{Environment.NewLine}");
                    }));
                }
            }
            catch (Exception ex)
            {
                await Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
                                                 () =>
                {
                    tbLog.AppendText($"{DateTime.Now}: {ex.Message}{Environment.NewLine}");
                }));
            }
            t.Enabled = true;
        }