Exemplo n.º 1
0
 void CloseProgressPanel(IOverlaySplashScreenHandle handle)
 {
     if (handle != null)
     {
         SplashScreenManager.CloseOverlayForm(handle);
     }
 }
Exemplo n.º 2
0
 public void CloseLoading()
 {
     if (handle != null)
     {
         SplashScreenManager.CloseOverlayForm(handle);
     }
 }
Exemplo n.º 3
0
 public void CloseOverlayForm(IOverlaySplashScreenHandle handle)
 {
     if (handle != null)
     {
         windowCompositePainter = null;
         SplashScreenManager.CloseOverlayForm(handle);
     }
 }
Exemplo n.º 4
0
 private void CloseWaitOverlay()
 {
     if (_overlayHandle != null)
     {
         SplashScreenManager.CloseOverlayForm(_overlayHandle);
         _overlayHandle = null;
     }
 }
Exemplo n.º 5
0
 /// <inheritdoc />
 public void HideIndicator()
 {
     Invoke(new MethodInvoker(delegate()
     {
         if (handle != null)
         {
             SplashScreenManager.CloseOverlayForm(handle);
         }
     }));
 }
Exemplo n.º 6
0
        private void biSimulation_ItemClick(object sender, ItemClickEventArgs e)
        {
            StrategyBase strategy = (StrategyBase)this.gridView1.GetFocusedRow();

            if (strategy == null)
            {
                XtraMessageBox.Show("No strategy selected.");
                return;
            }
            if (!strategy.SupportSimulation)
            {
                XtraMessageBox.Show("This strategy does not support simulation.");
                return;
            }

            StrategiesManager manager = new StrategiesManager();
            StrategyBase      cloned  = strategy.Clone();

            cloned.DemoMode = true;
            manager.Strategies.Add(cloned);

            this.siStatus.Caption = "<b>Loading data from exchanges...</b>";
            IOverlaySplashScreenHandle handle = SplashScreenManager.ShowOverlayForm(this);

            Application.DoEvents();
            manager.Initialize(new SimulationStrategyDataProvider());
            if (!manager.Start())
            {
                XtraMessageBox.Show("Error starting simulation! Please check log messages");
                return;
            }
            this.siStatus.Caption = "<b>Running simulation...</b>";
            Application.DoEvents();

            Stopwatch timer = new Stopwatch();

            timer.Start();
            int elapsedSeconds = 0;

            while (manager.Running)
            {
                if (timer.ElapsedMilliseconds / 1000 > elapsedSeconds)
                {
                    elapsedSeconds        = (int)(timer.ElapsedMilliseconds / 1000);
                    this.siStatus.Caption = string.Format("<b>Running simulation... {0} sec</b>", elapsedSeconds);
                    Application.DoEvents();
                }
            }
            SplashScreenManager.CloseOverlayForm(handle);
            this.siStatus.Caption = "<b>Simulation done.</b>";
            Application.DoEvents();
            StrategyConfigurationManager.Default.ShowData(cloned);
        }
Exemplo n.º 7
0
 public void CloseProgressPanel()
 {
     try
     {
         if (handle != null)
         {
             SplashScreenManager.CloseOverlayForm(handle);
             handle = null;
         }
     }
     catch
     {
     }
 }
Exemplo n.º 8
0
        async void OnRunTaskItemClick(object sender, ItemClickEventArgs e)
        {
            biRunTask.Enabled = false;
            string taskResult;
            IOverlaySplashScreenHandle overlayHandle = SplashScreenManager.ShowOverlayForm(contentPanel, customPainter: new OverlayWindowCompositePainter(overlayLabel, overlayButton));

            try {
                taskResult = await RunTask();
            }
            finally {
                SplashScreenManager.CloseOverlayForm(overlayHandle);
                biRunTask.Enabled = true;
            }
            XtraMessageBox.Show(this, taskResult, "Task Result");
        }
 private void btnSaveAsCMTX_ItemClick(object sender, ItemClickEventArgs e)
 {
     using (var dlg = new SaveFileDialog()
     {
         Filter = "e-Sword Commentary file (*.cmtx)|*.cmtx"
     }) {
         if (dlg.ShowDialog() == DialogResult.OK)
         {
             IOverlaySplashScreenHandle handle = null;
             try {
                 handle = SplashScreenManager.ShowOverlayForm(this);
                 new eSwordExportHelper().ExportCmtx(Commentary, dlg.FileName);
             }
             finally {
                 SplashScreenManager.CloseOverlayForm(handle);
             }
         }
     }
 }
 private void biOpen_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     if (this.xtraOpenFileDialog1.ShowDialog() == DialogResult.OK)
     {
         WebTickers = TickerExchangeWebListInfo.FromFile(this.xtraOpenFileDialog1.FileName);
         if (WebTickers == null)
         {
             WebTickers = new TickerExchangeWebListInfo();
         }
         else
         {
             var handle = SplashScreenManager.ShowOverlayForm(this);
             try {
                 foreach (var ticker in WebTickers.Tickers)
                 {
                     ticker.Update();
                 }
             }
             finally {
                 SplashScreenManager.CloseOverlayForm(handle);
             }
         }
     }
 }
Exemplo n.º 11
0
 public static void HideLoader(this Control handledControl, IOverlaySplashScreenHandle overlayHandle)
 => handledControl.Invoke((MethodInvoker) delegate { SplashScreenManager.CloseOverlayForm(overlayHandle); });
        private void biSimulation_ItemClick(object sender, ItemClickEventArgs e)
        {
            Stopped = false;
            StrategyBase strategy = (StrategyBase)this.gridView1.GetFocusedRow();

            if (strategy == null)
            {
                XtraMessageBox.Show("No strategy selected.");
                return;
            }
            if (!strategy.SupportSimulation)
            {
                XtraMessageBox.Show("This strategy does not support simulation.");
                return;
            }

            StrategiesManager manager = new StrategiesManager();

            manager.FileName = "SimulationStrategiesManager.xml";
            StrategyBase cloned = strategy.Clone();

            cloned.DemoMode = true;
            manager.Strategies.Add(cloned);

            this.siStatus.Caption = "<b>Loading data from exchanges...</b>";
            IOverlaySplashScreenHandle handle = SplashScreenManager.ShowOverlayForm(gridControl1);

            Application.DoEvents();
            SimulationStrategyDataProvider dataProvider = new SimulationStrategyDataProvider();

            dataProvider.DownloadProgressChanged += OnSimulationProviderDownloadProgressChanged;

            this.beSimulationProgress.EditValue  = 0;
            this.beSimulationProgress.Visibility = BarItemVisibility.Always;

            manager.Initialize(dataProvider);
            dataProvider.DownloadProgressChanged -= OnSimulationProviderDownloadProgressChanged;
            if (!manager.Start())
            {
                XtraMessageBox.Show("Error starting simulation! Please check log messages");
                return;
            }
            this.beSimulationProgress.EditValue  = 0;
            this.beSimulationProgress.Visibility = BarItemVisibility.Always;
            this.siStatus.Caption = "<b>Running simulation...</b>";
            Application.DoEvents();

            Stopwatch timer = new Stopwatch();

            timer.Start();
            int    elapsedSeconds = 0;
            double progress       = 0;

            while (manager.Running)
            {
                this.beSimulationProgress.EditValue = (int)(dataProvider.SimulationProgress * this.repositoryItemProgressBar1.Maximum);
                if (timer.ElapsedMilliseconds / 1000 > elapsedSeconds)
                {
                    elapsedSeconds        = (int)(timer.ElapsedMilliseconds / 1000);
                    this.siStatus.Caption = string.Format("<b>Running simulation... {0} sec</b>", elapsedSeconds);
                    Application.DoEvents();
                }
                if ((dataProvider.SimulationProgress - progress) >= 0.05)
                {
                    progress = dataProvider.SimulationProgress;
                    Application.DoEvents();
                }
            }
            this.beSimulationProgress.Visibility = BarItemVisibility.Never;
            SplashScreenManager.CloseOverlayForm(handle);
            manager.Save();
            this.siStatus.Caption = "<b>Simulation done.</b>";
            Application.DoEvents();
            //this.toastNotificationsManager1.ShowNotification("404ef86f-183c-4fea-960b-86f54e52ea76");
            StrategyConfigurationManager.Default.ShowData(cloned);
        }
        private void DownloadData()
        {
            BinanceExchange.Default.Connect();
            PoloniexExchange.Default.Connect();

            Stop = false;
            List <WalletInvestorDataItem> list = new List <WalletInvestorDataItem>();

            this.walletInvestorDataItemBindingSource.DataSource = list;
            var    handle  = SplashScreenManager.ShowOverlayForm(this.gridControl);
            double percent = Convert.ToDouble(this.barEditItem1.EditValue);

            for (int i = 1; i < 1000; i++)
            {
                if (Stop)
                {
                    break;
                }
                this.siStatus.Caption = "<b>Downloading page " + i + "</b>";
                Application.DoEvents();
                WebClient wc   = new WebClient();
                byte[]    data = wc.DownloadData(string.Format("https://walletinvestor.com/?sort=-percent_change_24h&page={0}&per-page=100", i));
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.Load(new MemoryStream(data));

                HtmlNode node = doc.DocumentNode.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "currency-desktop-table kv-grid-table table table-hover table-bordered table-striped table-condensed kv-table-wrap");
                if (node == null)
                {
                    return;
                }
                HtmlNode        body = node.Element("tbody");
                List <HtmlNode> rows = body.Descendants().Where(n => n.GetAttributeValue("data-key", "") != "").ToList();
                if (rows.Count == 0)
                {
                    break;
                }
                bool finished = false;
                foreach (HtmlNode row in rows)
                {
                    HtmlNode name      = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "2");
                    HtmlNode prices    = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "3");
                    HtmlNode change24  = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "4");
                    HtmlNode volume24  = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "5");
                    HtmlNode marketCap = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "7");

                    try {
                        WalletInvestorDataItem item = new WalletInvestorDataItem();
                        item.Name      = name.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "detail").InnerText.Trim();
                        item.LastPrice = Convert.ToDouble(CorrectString(prices.Element("a").InnerText));
                        item.Rise      = change24.Element("a").GetAttributeValue("class", "") != "red";
                        string change = CorrectString(change24.InnerText);
                        item.Change24 = Convert.ToDouble(change);
                        if (item.Change24 < percent)
                        {
                            finished = true;
                            break;
                        }
                        item.Volume           = volume24.InnerText.Trim();
                        item.MarketCap        = marketCap.Element("a").InnerText.Trim();
                        item.ListedOnBinance  = BinanceExchange.Default.Tickers.FirstOrDefault(t => t.MarketCurrency == item.Name) != null;
                        item.ListedOnPoloniex = PoloniexExchange.Default.Tickers.FirstOrDefault(t => t.MarketCurrency == item.Name) != null;
                        list.Add(item);
                    }
                    catch (Exception) {
                        continue;
                    }
                }
                Items = list;
                this.gridView1.RefreshData();
                Application.DoEvents();
                if (finished)
                {
                    break;
                }
            }
            SplashScreenManager.CloseOverlayForm(handle);
        }
        private void ImportWordFile(string filePath)
        {
            IOverlaySplashScreenHandle handle = null;

            try {
                handle = SplashScreenManager.ShowOverlayForm(this);
                using (var editor = new RichEditControl()) {
                    editor.LoadDocument(filePath);
                    var fileName = Path.GetFileNameWithoutExtension(filePath);
                    var book     = new XPQuery <Book>(uow).Where(x => x.Abbreviation == fileName).FirstOrDefault();
                    if (book == null)
                    {
                        XtraMessageBox.Show("File name not match!");
                        return;
                    }

                    var rangeStartIndex = -1;
                    var rangeEndIndex   = -1;

                    var chapter  = 0;
                    var chapter2 = 0;

                    var verseRanges = new List <VerseRange>();
                    for (int i = 0; i < 5; i++)
                    {
                        verseRanges.Add(new VerseRange()
                        {
                            VerseBegin = -1,
                            VerseEnd   = -1
                        });
                    }

                    Commentary.Items.Where(x => x.Book == book.NumberOfBook).ToList().ForEach(x => { x.Delete(); });
                    uow.CommitChanges();

                    foreach (var par in editor.Document.Paragraphs)
                    {
                        var text = editor.Document.GetText(par.Range).Trim();
                        if (par.Style != null)
                        {
                            if (!String.IsNullOrEmpty(text) && par.Style.Name == "heading 1")
                            {
                                if (text.ToLower().StartsWith("wstęp "))
                                {
                                    rangeStartIndex = par.Range.Start.ToInt();
                                }
                                else if (rangeStartIndex != -1 && (text.ToLower().StartsWith("list ") || text.ToLower().StartsWith("ewangelia ") || text.ToLower().StartsWith("dzieje ")))
                                {
                                    rangeEndIndex = par.Range.Start.ToInt() - 1;
                                    Commentary.Items.Add(new CommentaryItem(uow)
                                    {
                                        Book         = book.NumberOfBook,
                                        ChapterBegin = 0,
                                        ChapterEnd   = 0,
                                        VerseBegin   = 0,
                                        VerseEnd     = 0,
                                        Comments     = editor.Document.GetRtfText(editor.Document.CreateRange(rangeStartIndex, rangeEndIndex - rangeStartIndex))
                                    });
                                    rangeStartIndex = -1;
                                    rangeEndIndex   = -1;
                                }
                            }
                            else if (!String.IsNullOrEmpty(text) && par.Style.Name == "heading 2")
                            {
                                if (rangeStartIndex == -1)
                                {
                                    par.Range.Start.ToInt();
                                }
                            }
                            else if (!String.IsNullOrEmpty(text) && par.Style.Name == "heading 3")
                            {
                                var patternBase  = @"\((?<chapter>[0-9]+)(\,)?";
                                var patternRange = @"((?<verseBegin{0}>[0-9]+)([a-z])?(\-(?<verseEnd{0}>[0-9]+)([a-z])?)?(\.)?)";

                                var pattern = patternBase;
                                for (int i = 0; i < 5; i++)
                                {
                                    pattern += String.Format(patternRange, i);
                                    pattern += "?";
                                }
                                pattern += @"\)";

                                if (text.Contains(";"))
                                {
                                    pattern = @"\((?<chapter1>[0-9]+)\,(?<verse1>[0-9]+)\;(?<chapter2>[0-9]+)\,(?<verse2>[0-9]+)\)";
                                    if (Regex.IsMatch(text, pattern))
                                    {
                                        var m = Regex.Match(text, pattern);
                                        chapter  = Convert.ToInt32(m.Groups["chapter1"].Value);
                                        chapter2 = Convert.ToInt32(m.Groups["chapter2"].Value);
                                        verseRanges[0].VerseBegin = Convert.ToInt32(m.Groups["verse1"].Value);
                                        verseRanges[0].VerseEnd   = Convert.ToInt32(m.Groups["verse2"].Value);
                                        for (int i = 1; i < 5; i++)
                                        {
                                            verseRanges[i].VerseBegin = -1;
                                            verseRanges[i].VerseEnd   = -1;
                                        }
                                        continue;
                                    }
                                }

                                if (Regex.IsMatch(text, pattern))
                                {
                                    rangeEndIndex = SavePrevious(editor, book, rangeStartIndex, rangeEndIndex, chapter, chapter2, ref verseRanges, par);

                                    var m = Regex.Match(text, pattern);
                                    chapter  = Convert.ToInt32(m.Groups["chapter"].Value);
                                    chapter2 = Convert.ToInt32(m.Groups["chapter"].Value);

                                    for (int i = 0; i < 5; i++)
                                    {
                                        if (m.Groups[$"verseEnd{i}"] != null && m.Groups[$"verseEnd{i}"].Success)
                                        {
                                            verseRanges[i].VerseBegin = Convert.ToInt32(m.Groups[$"verseBegin{i}"].Value);
                                            verseRanges[i].VerseEnd   = Convert.ToInt32(m.Groups[$"verseEnd{i}"].Value);
                                        }
                                        else if (m.Groups[$"verseBegin{i}"] != null && m.Groups[$"verseBegin{i}"].Success)
                                        {
                                            verseRanges[i].VerseBegin = Convert.ToInt32(m.Groups[$"verseBegin{i}"].Value);
                                            verseRanges[i].VerseEnd   = Convert.ToInt32(m.Groups[$"verseBegin{i}"].Value);
                                        }
                                        else if (chapter != 0 && i == 0)
                                        {
                                            verseRanges[i].VerseBegin = 0;
                                            verseRanges[i].VerseEnd   = 0;
                                        }
                                        else
                                        {
                                            verseRanges[i].VerseBegin = -1;
                                            verseRanges[i].VerseEnd   = -1;
                                        }
                                    }

                                    rangeStartIndex = par.Range.Start.ToInt();
                                    rangeEndIndex   = -1;
                                }
                                else
                                {
                                    if (rangeStartIndex == -1)
                                    {
                                        par.Range.Start.ToInt();
                                    }
                                }
                            }
                        }

                        if (par == editor.Document.Paragraphs.Last())
                        {
                            rangeEndIndex = SavePrevious(editor, book, rangeStartIndex, rangeEndIndex, chapter, chapter2, ref verseRanges, par);
                        }
                    }

                    uow.CommitChanges();
                    Commentary = new XPQuery <Commentary>(uow).Where(x => x.Oid == Commentary.Oid).FirstOrDefault();
                    LoadBooks();
                }
            }
            finally {
                SplashScreenManager.CloseOverlayForm(handle);
            }
        }
Exemplo n.º 15
0
        protected void GetForecasts()
        {
            Stop = false;
            var    handle  = SplashScreenManager.ShowOverlayForm(this.gridControl);
            double percent = Settings.Min24HourChange;

            for (int i = 1; i < 1000; i++)
            {
                if (Stop)
                {
                    break;
                }
                this.siStatus.Caption = "<b>Downloading page " + i + "</b>";
                Application.DoEvents();
                WebClient wc     = new WebClient();
                string    adress = string.Format("https://walletinvestor.com/forecast?sort=-forecast_percent_change_14d&page={0}&per-page=100", i);
                byte[]    data   = wc.DownloadData(adress);
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.Load(new MemoryStream(data));

                HtmlNode node = doc.DocumentNode.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "currency-desktop-table kv-grid-table table table-hover table-bordered table-striped table-condensed");
                if (node == null)
                {
                    return;
                }
                HtmlNode        body = node.Element("tbody");
                List <HtmlNode> rows = body.Descendants().Where(n => n.GetAttributeValue("data-key", "") != "").ToList();
                if (rows.Count == 0)
                {
                    break;
                }
                bool finished = false;
                for (int ri = 0; ri < rows.Count; ri++)
                {
                    HtmlNode row          = rows[ri];
                    HtmlNode day14Change  = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "1");
                    string   changeString = CorrectString(day14Change.InnerText);
                    double   change       = Convert.ToDouble(CorrectString(changeString));
                    HtmlNode name         = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "0");
                    try {
                        HtmlNode nameDetail         = name.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "detail");
                        string   nameString         = nameDetail.InnerText.Trim();
                        WalletInvestorDataItem item = WiItems.FirstOrDefault(it => it.Name == nameString);
                        if (item == null)
                        {
                            continue;
                        }
                        item.Forecast14Day = change;
                        HtmlNode month3Change = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "2");
                        item.Forecast3Month = Convert.ToDouble(CorrectString(month3Change.Element("a").InnerText));
                        if (change < Settings.Min14DayChange)
                        {
                            finished = true;
                            break;
                        }
                    }
                    catch (Exception) {
                        continue;
                    }
                }
                if (Stop)
                {
                    this.siStatus.Caption = "<b>Interrupted<b>";
                }
                else
                {
                    this.siStatus.Caption = "<b>Done<b>";
                }
                this.gridView1.RefreshData();
                Application.DoEvents();
                if (finished)
                {
                    break;
                }
            }
            SplashScreenManager.CloseOverlayForm(handle);
        }
Exemplo n.º 16
0
        protected virtual void DownloadCoinPredictorForecast()
        {
            this.siStatus.Caption = "<b>Connecting Binance</b>";
            Application.DoEvents();
            BinanceExchange.Default.Connect();

            Stop = false;
            var    handle  = SplashScreenManager.ShowOverlayForm(this.gridControl);
            double percent = Settings.Min24HourChange;
            string adress  = "https://coinpredictor.io/ranks?t=price&from=0&to=3000&sort=day&d=desc&type=number";

            this.siStatus.Caption = "<b>Downloading data from coinpredictor.io</b>";
            Application.DoEvents();
            WebClient wc = new WebClient();

            string text = wc.DownloadString(adress);

            if (string.IsNullOrEmpty(text))
            {
                SplashScreenManager.CloseOverlayForm(handle);
                XtraMessageBox.Show("Error downloading data from coinpredictor.io. Please contact developer");
                this.siStatus.Caption = "<b>Error downloading data from coinpredictor.io</b>";
                SplashScreenManager.CloseOverlayForm(handle);
                return;
            }

            JObject obj = (JObject)JsonConvert.DeserializeObject(text);

            if (obj == null)
            {
                SplashScreenManager.CloseOverlayForm(handle);
                XtraMessageBox.Show("Error deserializing data from coinpredictor.io. Please contact developer");
                this.siStatus.Caption = "<b>Error deserializing data from coinpredictor.io</b>";
                SplashScreenManager.CloseOverlayForm(handle);
                return;
            }

            JArray list = obj.Value <JArray>("list");

            if (list == null)
            {
                SplashScreenManager.CloseOverlayForm(handle);
                XtraMessageBox.Show("Error deserializing data from coinpredictor.io. Please contact developer");
                this.siStatus.Caption = "<b>Error deserializing data from coinpredictor.io</b>";
                SplashScreenManager.CloseOverlayForm(handle);
                return;
            }
            this.siStatus.Caption = string.Format("<b>Parsing data (total {0})</b>", list.Count);
            Application.DoEvents();

            this.beProgress.EditValue  = 0;
            this.beProgress.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
            int index = 0;
            List <CoinPredictorDataItem> cplist = new List <CoinPredictorDataItem>();

            CpItems = cplist;
            for (int i = 0; i < list.Count; i++)
            {
                JObject item = (JObject)list[i];
                if (Stop)
                {
                    break;
                }
                string name   = item.Value <string>("ticker");
                Ticker ticker = BinanceExchange.Default.Tickers.FirstOrDefault(t => t.MarketCurrency == name && t.BaseCurrency == "BTC");
                if (ticker == null)
                {
                    continue;
                }
                string slug        = item.Value <string>("slug");
                string description = item.Value <string>("name");

                CoinPredictorDataItem cp = new CoinPredictorDataItem();
                cp.Name         = name;
                cp.Description  = description;
                cp.BinanceLink  = ticker.WebPageAddress;
                cp.ForecastLink = string.Format("https://coinpredictor.io/{0}#price", slug.ToLower());
                double day7  = GetDoubleProperty(item, "dayFormatted", 0);
                double day1  = GetDoubleProperty(item, "dayFormattedFirst", 0);
                double week4 = GetDoubleProperty(item, "weekFormatted", 0);
                double month = GetDoubleProperty(item, "monthFormatted", 0);
                double price = GetDoubleProperty(item, "priceFormatted", 0);
                cp.LastPrice       = price;
                cp.Forecast1Day    = day1;
                cp.Forecast7Day    = day7;
                cp.Forecast4Week   = week4;
                cp.Forecast3Month  = month;
                cp.ListedOnBinance = BinanceExchange.Default.GetTicker(cp.Name) != null;
                cp.Match           = cp.Forecast1Day >= Settings.MinCp24HourChange && cp.Forecast7Day >= Settings.MinCp7DayChange && cp.Forecast4Week >= Settings.MinCp4WeekChange &&
                                     cp.Forecast3Month >= Settings.MinCp3MonthChange;
                cplist.Add(cp);
                int progress = index * 100 / list.Count;
                if (((int)this.beProgress.EditValue) != progress)
                {
                    this.beProgress.EditValue = progress;
                    this.gridView2.RefreshData();
                    Application.DoEvents();
                }
                index++;
            }
            this.beProgress.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            this.siStatus.Caption      = Stop? "<b>Interrupted</b>": "<b>Done</b>";
            this.gridView2.RefreshData();
            SplashScreenManager.CloseOverlayForm(handle);
            UpdateCombined();
            XtraMessageBox.Show(string.Format("Found {0} items matched criteria", CpItems.Count(i => i.Match)));
        }
Exemplo n.º 17
0
        private void DownloadWalletInvestorForecast()
        {
            var handle = SplashScreenManager.ShowOverlayForm(this.gridControl);

            this.siStatus.Caption = "<b>Connect Binance</b>";
            Application.DoEvents();
            if (!BinanceExchange.Default.Connect())
            {
                XtraMessageBox.Show("Failed connect Binance");
                this.siStatus.Caption = "<b>Failed connect Binance</b>";
                SplashScreenManager.CloseOverlayForm(handle);
            }
            Stop = false;

            this.siStatus.Caption = "<b>Autorizing on walletinvestor.com</b>";
            Application.DoEvents();

            WalletInvestorPortalHelper helper = new WalletInvestorPortalHelper();

            helper.Enter(InvictusSettings.Default.Login, InvictusSettings.Default.Password);
            if (!Registered && !helper.WaitUntil(Settings.AutorizationOperationWaitTimeInSeconds * 1000, () => helper.State == PortalState.AutorizationDone))
            {
                XtraMessageBox.Show("Error autorizing on walletinvestor.com");
                this.siStatus.Caption = "<b>Error autorizing on walletinvestor.com</b>";
                SplashScreenManager.CloseOverlayForm(handle);
                helper.Dispose();
                return;
            }

            Registered = true;

            List <WalletInvestorDataItem> list = new List <WalletInvestorDataItem>();

            WiItems = list;

            //List<Ticker>

            double percent = Settings.Min24HourChange;

            for (int i = 1; i < 1000; i++)
            {
                if (Stop)
                {
                    break;
                }
                this.siStatus.Caption = "<b>Downloading page " + i + "</b>";
                Application.DoEvents();
                WebClient wc   = new WebClient();
                byte[]    data = wc.DownloadData(string.Format("https://walletinvestor.com/forecast?sort=-forecast_percent_change_14d&page={0}&per-page=100", i));
                if (data == null || data.Length == 0)
                {
                    XtraMessageBox.Show("Error downloading page from walletinvestor.com");
                    this.siStatus.Caption = "<b>Error downloading page from walletinvestor.com</b>";
                    SplashScreenManager.CloseOverlayForm(handle);
                    helper.Dispose();
                    return;
                }

                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.Load(new MemoryStream(data));

                HtmlNode node = doc.DocumentNode.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "currency-desktop-table kv-grid-table table table-hover table-bordered table-striped table-condensed");
                if (node == null)
                {
                    XtraMessageBox.Show("It seems that walletinvestor forecast page layout is changed. Please contact developer");
                    SplashScreenManager.CloseOverlayForm(handle);
                    helper.Dispose();
                    this.siStatus.Caption = "<b>Error!</b>";
                    return;
                }

                HtmlNode        body     = node.Element("tbody");
                List <HtmlNode> rows     = body.Descendants().Where(n => n.GetAttributeValue("data-key", "") != "").ToList();
                bool            finished = false;
                for (int ri = 0; ri < rows.Count; ri++)
                {
                    HtmlNode row  = rows[ri];
                    HtmlNode name = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "0");
                    try {
                        string nameText             = name.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "detail").InnerText.Trim();
                        WalletInvestorDataItem item = new WalletInvestorDataItem();

                        string description = name.InnerText.Remove(name.InnerText.Length - nameText.Length);

                        item.Name        = nameText;
                        item.Description = description;
                        Ticker   ticker     = BinanceExchange.Default.Tickers.FirstOrDefault(t => t.MarketCurrency == item.Name && t.BaseCurrency == "BTC");
                        HtmlNode forecast14 = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "1");
                        item.Forecast14Day = Convert.ToDouble(CorrectString(forecast14.Element("a").InnerText));
                        if (item.Forecast14Day < Settings.Min14DayChange)
                        {
                            finished = true;
                            break;
                        }
                        if (ticker == null)
                        {
                            continue;
                        }
                        item.BinanceLink = ticker.WebPageAddress;
                        HtmlNode forecast3Month = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "2");
                        item.Forecast3Month = Convert.ToDouble(CorrectString(forecast3Month.Element("a").InnerText));
                        item.ForecastLink   = name.Element("a").GetAttributeValue("href", "");
                        item.ForecastLink2  = string.Format("https://walletinvestor.com/forecast?currency={0}", item.Name);
                        name.Element("a").GetAttributeValue("href", "");
                        list.Add(item);
                    }
                    catch (Exception) {
                        XtraMessageBox.Show("An error was detected when parsing page. Please contact developer");
                        SplashScreenManager.CloseOverlayForm(handle);
                        this.siStatus.Caption = "<b>Error!</b>";
                        continue;
                    }
                }
                this.gridView1.RefreshData();
                Application.DoEvents();
                if (finished)
                {
                    break;
                }
            }

            this.siStatus.Caption      = "<b>Downloading 7-day forecast</b>";
            this.beProgress.EditValue  = 0;
            this.beProgress.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
            Application.DoEvents();
            int itemIndex = 0;

            foreach (WalletInvestorDataItem item in WiItems)
            {
                if (!Get7DayForecastFor(item, item.ForecastLink, helper))
                {
                    XtraMessageBox.Show("Error parsing 7-day forecast page. Please contact developer");
                    this.siStatus.Caption = "<b>Error!</b>";
                    helper.Dispose();
                    this.gridView1.RefreshData();
                    SplashScreenManager.CloseOverlayForm(handle);
                    return;
                }

                item.Match = item.Forecast7Day >= Settings.Min7DaysChange &&
                             item.Forecast14Day >= Settings.Min14DayChange &&
                             item.Forecast3Month >= Settings.Min3MonthChange;
                this.beProgress.EditValue = (int)((double)itemIndex / WiItems.Count * 100);
                itemIndex++;
                Application.DoEvents();
                if (Stop)
                {
                    break;
                }
            }
            this.beProgress.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;

            this.siStatus.Caption = Stop? "<b>Interrupted<b>": "<b>Done<b>";
            this.gridView1.RefreshData();
            helper.Dispose();
            SplashScreenManager.CloseOverlayForm(handle);
            UpdateCombined();
            XtraMessageBox.Show(string.Format("Found {0} items matched criteria", WiItems.Count(i => i.Match)));
        }