示例#1
0
        /// <summary>
        /// Загрузить данные по акциям
        /// </summary>
        /// <param name="lst">Список акций</param>
        /// <param name="lbl">Лейбл с формы</param>
        /// <param name="bar">Прогресс-бар</param>
        /// <returns></returns>
        public static async Task LoadStocksData(List <Stock> lst, IReportText lbl, IReportProgress bar)
        {
            int count = lst.Count, doneEvents = 0;
            var report = new StringBuilder();

            Task[] tasks = new Task[count];

            Stopwatch stwatch = Stopwatch.StartNew();

            for (int i = 0; i < lst.Count; i++)
            {
                var i1 = i;
                tasks[i] = Task.Run(async() =>
                {
                    try
                    {
                        await GetStockData(lst[i1]);
                    }
                    catch (Exception er)
                    {
                        Logger.Log.Error(
                            $"Не удалось получить инфу по {lst[i1].Name}: {er.Message}\r\n{er.StackTrace}");
                        report.Append($"{lst[i1].Name};");
                    }

                    Interlocked.Increment(ref doneEvents);
                    if (i1 % 10 != 0)
                    {
                        return;
                    }

                    if (lbl != null)
                    {
                        double mins = stwatch.Elapsed.TotalSeconds * (1.0 / ((double)doneEvents / count) - 1) / 60.0;
                        mins        = Math.Floor(mins) + (mins - Math.Floor(mins)) * 0.6;
                        lbl.Text    = $@"Обработано {doneEvents} / {count}. Расчетное время: {
								(mins >= 1 ? Math.Floor(mins) + " мин " : "")
							}{Math.Floor((mins - Math.Floor(mins)) * 100)} с"                            ;
                    }
                    if (bar != null)
                    {
                        bar.Value = doneEvents * 100 / count;
                    }
                });
            }
            await Task.WhenAll(tasks);

            stwatch.Stop();
            if (bar != null)
            {
                bar.Value = 100;
            }
            if (lbl != null)
            {
                lbl.Text = @"Готово.";
            }
            MakeReportAndSaveToFile(lst, report.ToString());
        }
示例#2
0
        /// <summary>
        /// Загрузить список всех акций
        /// </summary>
        public static async Task GetStocksList(IReportText lbl, IReportProgress bar, bool loadAllStocksAgain = true)
        {
            Stocks.Clear();
            try
            {
                if (loadAllStocksAgain)
                {
                    var getRus = Task.Run(GetRussianStocks);
                    var getUsa = Task.Run((Action)GetUsaStocks);

                    await Task.WhenAll(getRus, getUsa);

                    CheckForRepeatsAndSort();
                }

                int count = Stocks.Count;
                s_doneEventsCount = 0;

                Stopwatch stwatch      = Stopwatch.StartNew();
                var       tinkoffCheck = Task.Run(async() => await CheckAllForTinkoff(count));

                while (true)
                {
                    double mins = stwatch.Elapsed.TotalSeconds * (1.0 / ((double)s_doneEventsCount / count) - 1) / 60.0;
                    mins = Math.Floor(mins) + (mins - Math.Floor(mins)) * 0.6;

                    if (lbl != null)
                    {
                        lbl.Text =
                            $@"Обработано {s_doneEventsCount} / {count}. Расчетное время: {
									(mins >= 1 ? Math.Floor(mins) + " мин " : "")
								}{Math.Floor((mins - Math.Floor(mins)) * 100)} с"                                ;
                    }
                    if (bar != null)
                    {
                        bar.Value = s_doneEventsCount * 100 / count;
                    }
                    if (tinkoffCheck.IsCompleted)
                    {
                        break;
                    }

                    await Task.Delay(5 * 1000);

                    if (tinkoffCheck.IsCanceled || tinkoffCheck.IsFaulted)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex);
                throw;
            }
        }
示例#3
0
        protected override void OnClosed(EventArgs e)
        {
            instance = null;
            if (reportProgress != null)
            {
                reportProgress.Progress -= OnProgressReport;
                reportProgress           = null;
            }

            base.OnClosed(e);
        }
        /// <summary>
        /// Adds the given <paramref name="task"/> to the list of currently loading tasks.
        /// </summary>
        /// <param name="task"><see cref="IReportProgress"/> to add to the loading list.</param>
        public virtual void ShowLoading(IReportProgress task)
        {
            task.Completed       += OnLoadingTaskCompleted;
            task.ProgressChanged += OnLoadingTaskProgressed;

            IsCompleted = false;

            lock (_loadingReportablesLock)
            {
                RunningProgressReportables.Add(task);
            }

            UpdateLoadingStatus();
        }
示例#5
0
        private StatusDialog(Window owner, string title, BackgroundRequest request, HResult hr, string message, string errorPreamble, Action postAction)
        {
            instance = this;

            this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            this.Owner                = owner;
            this.Title                = title;
            this.ErrorStatus          = new ErrorStatus();
            this.ErrorStatus.Preamble = message;
            this.ErrorStatus.SetStatus(ErrorSeverity.Info, null, null);

            this.request         = request;
            this.reportProgress  = request as IReportProgress;
            this.DataContext     = this;
            this.originalMessage = message;

            this.currentMessage = new MessageNode
            {
                Preamble   = errorPreamble ?? StringResources.UnknownErrorOccurred,
                PostAction = postAction
            };

            InitializeComponent();

            if (request != null)
            {
                request.Dispatched += OnRequestDispatched;

                if (reportProgress != null)
                {
                    reportProgress.Progress += OnProgressReport;
                }

                if (request.IsDispatchComplete)
                {
                    // We were asked to wait on a request that has already been dispatched.  Simulate notification
                    // of the dispatch.  Can't call it directly because Close() right now is bad news.
                    this.Dispatcher.BeginInvoke((Action)(() => { this.OnRequestDispatched(request, EventArgs.Empty); }), DispatcherPriority.Background);
                }
            }
            else
            {
                SwitchToError(hr, false);
            }

            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, OnCopyExecuted));
        }
        private StatusDialog(Window owner, string title, BackgroundRequest request, HResult hr, string message, string errorPreamble, Action postAction)
        {
            instance = this;

            this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            this.Owner = owner;
            this.Title = title;
            this.ErrorStatus = new ErrorStatus();
            this.ErrorStatus.Preamble = message;
            this.ErrorStatus.SetStatus(ErrorSeverity.Info, null, null);

            this.request = request;
            this.reportProgress = request as IReportProgress;
            this.DataContext = this;
            this.originalMessage = message;

            this.currentMessage = new MessageNode
            {
                Preamble = errorPreamble ?? StringResources.UnknownErrorOccurred,
                PostAction = postAction
            };

            InitializeComponent();

            if (request != null)
            {
                request.Dispatched += OnRequestDispatched;

                if (reportProgress != null)
                {
                    reportProgress.Progress += OnProgressReport;
                }

                if (request.IsDispatchComplete)
                {
                    // We were asked to wait on a request that has already been dispatched.  Simulate notification
                    // of the dispatch.  Can't call it directly because Close() right now is bad news.
                    this.Dispatcher.BeginInvoke((Action)(() => { this.OnRequestDispatched(request, EventArgs.Empty); }), DispatcherPriority.Background);
                }
            }
            else
            {
                SwitchToError(hr, false);
            }

            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, OnCopyExecuted));
        }
        public XF_AsyncResult(IReportProgress manager)
        {
            InitializeComponent();

            if (manager == null)
                throw new ArgumentNullException("manager");

            this.Manager = manager;
            this.DataItem = new BindingSource();
            this.DataItem.DataSource = new List<ProgressItem>();
            this.gridControlReport.DataSource = this.DataItem;
            this.gridViewReport.CustomDrawCell += gridViewReport_CustomDrawCell;

            this.Manager.OnProgressChanged += Manager_OnProgressChanged;
            this.Manager.OnComplete += Manager_OnComplete;
            this.FormClosing += XF_AsyncResult_FormClosing;

            this.btnClose.Enabled = false;
        }
示例#8
0
        public XF_AsyncResult(IReportProgress manager)
        {
            InitializeComponent();

            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }

            this.Manager                        = manager;
            this.DataItem                       = new BindingSource();
            this.DataItem.DataSource            = new List <ProgressItem>();
            this.gridControlReport.DataSource   = this.DataItem;
            this.gridViewReport.CustomDrawCell += gridViewReport_CustomDrawCell;

            this.Manager.OnProgressChanged += Manager_OnProgressChanged;
            this.Manager.OnComplete        += Manager_OnComplete;
            this.FormClosing += XF_AsyncResult_FormClosing;

            this.btnClose.Enabled = false;
        }
 // Token: 0x0600139A RID: 5018 RVA: 0x0004521C File Offset: 0x0004341C
 public static CmdletBasedRunspaceConfiguration Create(MonadConnectionInfo connectionInfo, string identityName, IReportProgress reportProgress)
 {
     CmdletBasedRunspaceConfiguration.reportProgress = reportProgress;
     CmdletBasedRunspaceConfiguration.connectionInfo = connectionInfo;
     return(new CmdletBasedRunspaceConfiguration(identityName));
 }
 public SearchOperation(string root, int maxDepth, IReportProgress progressSink)
 {
     this.root         = root;
     this.progressSink = progressSink;
     this.maxDepth     = maxDepth;
 }
 public SearchOperation(string root, int maxDepth, IReportProgress progressSink)
 {
     this.root         = root;
     this.progressSink = progressSink;
     this.maxDepth     = maxDepth;
 }
示例#12
0
 public JobsController(IReportProgress <ActionReport> progress, IMessageProducer producer)
 {
     _progress = progress;
     _producer = producer;
 }
示例#13
0
 public BackgroundJobConsumer(IReportProgress <BackgroundJobReport> progress, ILogger <BackgroundJobConsumer> logger)
 {
     _progress = progress;
     _logger   = logger;
 }
        protected override void OnClosed(EventArgs e)
        {
            instance = null;
            if (reportProgress != null)
            {
                reportProgress.Progress -= OnProgressReport;
                reportProgress = null;
            }

            base.OnClosed(e);
        }
 public static DialogResult ShowWindow(IReportProgress manager)
 {
     using (XF_AsyncResult form = new XF_AsyncResult(manager))
         return form.ShowDialog();
 }
示例#16
0
 public static DialogResult ShowWindow(IReportProgress manager)
 {
     using (XF_AsyncResult form = new XF_AsyncResult(manager))
         return(form.ShowDialog());
 }