Exemplo n.º 1
0
        private void UpdatePricesThrd()
        {
            int totalRows = MainPricesDT.Rows.Count;

            PriceKeys.Clear();
            for (int row = 0; row < totalRows; row++)
            {
                if (MainPricesDT.Rows[row]["ID"] != null)
                {
                    PriceKeys.Add(MainPricesDT.Rows[row]["ID"].ToString(), row);
                }
            }
            Invoke((MethodInvoker) delegate
            {
                ProgressBarPrice.Maximum = totalRows - 1;
                ProgressBarPrice.Minimum = 0;
                ProgressBarPrice.Value   = 0;
                DGVPrices.DataSource     = null;
                DGVPrices.Hide();
                DGVPrices.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
            });
            string matIDs = "";

            for (int row = 0; row < totalRows; row++)
            {
                if (MainPricesDT.Rows[row]["ID"] != null)
                {
                    matIDs += MainPricesDT.Rows[row]["ID"].ToString() + (((row % PageSize == 0) || (row == totalRows - 1)) ? "" : ",");
                    if (((row % PageSize == 0) || (row == totalRows - 1)) && (matIDs != ""))
                    {
                        string IDs = matIDs;
                        matIDs = "";
                        Thread       nextQ  = new Thread(new ParameterizedThreadStart(UpdateDt));
                        ThreadStrInt StrInt = new ThreadStrInt();
                        StrInt._str = IDs;
                        StrInt._int = row;
                        nextQ.Start(StrInt);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void UpdateDt(object obj)
        {
            while (MaxThreads < 0)
            {
                Thread.Sleep(10);
            }
            ;
            MaxThreads--;
            ThreadStrInt StrInt = (ThreadStrInt)obj;
            string       IDs;
            int          rowsCnt;

            IDs     = StrInt._str;
            rowsCnt = StrInt._int;
            XmlDocument doc1 = new XmlDocument();

            doc1.Load("https://api.evemarketer.com/ec/marketstat?typeid=" + IDs + "&regionlimit=10000002");

            XmlElement  root      = doc1.DocumentElement;
            XmlNodeList TypeNodes = root.SelectNodes("/exec_api/marketstat/type");

            Invoke((MethodInvoker) delegate
            {
                MainPricesDT.BeginLoadData();
                foreach (XmlNode Tnode in TypeNodes)
                {
                    try
                    {
                        int curRow = 0;
                        PriceKeys.TryGetValue(Tnode.Attributes["id"].Value, out curRow);
                        XmlNode Bnodes = Tnode.SelectSingleNode("buy");
                        XmlNode Snodes = Tnode.SelectSingleNode("sell");

                        double Bmin = Convert.ToDouble(Bnodes["min"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);
                        double Bmax = Convert.ToDouble(Bnodes["max"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);
                        double Bavg = Convert.ToDouble(Bnodes["avg"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);
                        double Bmed = Convert.ToDouble(Bnodes["median"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);

                        double Smin = Convert.ToDouble(Snodes["min"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);
                        double Smax = Convert.ToDouble(Snodes["max"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);
                        double Savg = Convert.ToDouble(Snodes["avg"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);
                        double Smed = Convert.ToDouble(Snodes["median"].InnerText, CultureInfo.GetCultureInfo("en-US").NumberFormat);


                        MainPricesDT.Rows[curRow]["Buy(min)"]    = Bmin;
                        MainPricesDT.Rows[curRow]["Buy(max)"]    = Bmax;
                        MainPricesDT.Rows[curRow]["Buy(avg)"]    = Bavg;
                        MainPricesDT.Rows[curRow]["Buy(median)"] = Bmed;
                        MainPricesDT.Rows[curRow]["Buy(self)"]   = MainPricesDT.Rows[curRow]["Buy(self)"].ToString() == "" ? 0 : MainPricesDT.Rows[curRow]["Buy(self)"];

                        MainPricesDT.Rows[curRow]["Sell(min)"]    = Smin;
                        MainPricesDT.Rows[curRow]["Sell(max)"]    = Smax;
                        MainPricesDT.Rows[curRow]["Sell(avg)"]    = Savg;
                        MainPricesDT.Rows[curRow]["Sell(median)"] = Smed;
                        MainPricesDT.Rows[curRow]["Sell(self)"]   = MainPricesDT.Rows[curRow]["Sell(self)"].ToString() == "" ? 0 : MainPricesDT.Rows[curRow]["Sell(self)"];

                        /*Invoke((MethodInvoker)delegate
                         * {*/
                        ProgressBarPrice.Value++;
                        if (ProgressBarPrice.Value == ProgressBarPrice.Maximum)
                        {
                            ProgressBarPrice.Value = 0;
                            ShowPriceDGV();
                        }
                        //});
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                MainPricesDT.EndLoadData();
            });
            MaxThreads++;
        }