Esempio n. 1
0
        private void ControllerOnPluginProgressUpdated(IPlugin plugin, ProgressProvider progressProvider)
        {
            SetLastControllerEventTimeStamp();

            if (_isRunning || progressProvider.State != ProgressProviderState.Running)
            {
                _state = progressProvider.State;
            }

            if (!_isRunning && _state == ProgressProviderState.Running)
            {
                _logger.Warn("State mismatch: _isRunning == false but _state == Running");
            }

            var percentCompleteStr = (progressProvider.PercentComplete / 100.0).ToString("P");
            var line = string.Format("{0} is {1} - {2} complete - {3} - {4} elapsed, {5} remaining",
                                     plugin.Name, progressProvider.State, percentCompleteStr,
                                     progressProvider.LongStatus,
                                     progressProvider.RunTime.ToStringShort(),
                                     progressProvider.TimeRemaining.ToStringShort());

            if (_isRunning)
            {
                AppendStatus(line);
            }

            _lastProgressPercentComplete    = progressProvider.PercentComplete;
            _lastProgressPercentCompleteStr = percentCompleteStr;

            UpdateProgressBars();
        }
Esempio n. 2
0
        private async void Login()
        {
            RaiseCanExecuteChanged();

            SimpleUser user;

            try
            {
                using (ProgressProvider.StartProgress())
                {
                    user = await _signalHelperFacade.LoginSignalHelper.Login(Username, Password).ConfigureAwait(true);
                }
            }
            catch (LoginFailedException e)
            {
                LoginFailed?.Invoke(new LoginFailedEventArgs(e.Message));
                return;
            }
            finally
            {
                RaiseCanExecuteChanged();
            }

            LoggedIn = true;
            LoginSucceeded?.Invoke(new LoginSucceededEventArgs(user));

            Application.Current.Dispatcher.Invoke(RaiseCanExecuteChanged);
        }
Esempio n. 3
0
        private void ProgressProviderOnUpdated(ProgressProvider progressProvider)
        {
            if (PluginProgressUpdated != null)
            {
                // Marshal event back to UI thread
                Task.Factory.StartNew(delegate
                {
                    var guid     = progressProvider.Plugin.AssemblyInfo.Guid;
                    var hashCode = progressProvider.GetHashCode();

                    var containsKey  = _progressMap.ContainsKey(guid);
                    var prevHashCode = containsKey ? _progressMap[guid] : -1;

                    Logger.DebugFormat(
                        "ProgressProviderOnUpdated() - Plugin \"{0}\": prev progress hashCode = {1}, cur progress hashCode = {2}",
                        progressProvider.Plugin.Name, prevHashCode, hashCode
                        );

                    // Progress hasn't changed since last update
                    if (containsKey && prevHashCode == hashCode)
                    {
                        return;
                    }

                    _progressMap[guid] = hashCode;

                    Logger.Debug("ProgressProviderOnUpdated() - Calling PluginProgressUpdated event handlers");

                    PluginProgressUpdated(progressProvider.Plugin, progressProvider);
                }, CancellationToken.None, TaskCreationOptions.None, _callbackScheduler);
            }
        }
Esempio n. 4
0
        private void ProgressProviderOnUpdatedSync(ProgressProvider progressProvider)
        {
            var guid     = progressProvider.Plugin.AssemblyInfo.Guid;
            var hashCode = progressProvider.GetHashCode();

            var containsKey  = _progressMap.ContainsKey(guid);
            var prevHashCode = containsKey ? _progressMap[guid] : -1;

#if DEBUG_CONCURRENCY
            Logger.DebugFormat("ProgressProviderOnUpdated() - Plugin \"{0}\": prev progress hashCode = {1}, cur progress hashCode = {2}",
                               progressProvider.Plugin.Name, prevHashCode, hashCode
                               );
#endif

            // Progress hasn't changed since last update
            if (containsKey && prevHashCode == hashCode)
            {
                return;
            }

            _progressMap[guid] = hashCode;

#if DEBUG_CONCURRENCY
            Logger.Debug("ProgressProviderOnUpdated() - Calling PluginProgressUpdated event handlers");
#endif

            if (PluginProgressUpdated != null)
            {
                PluginProgressUpdated(progressProvider.Plugin, progressProvider);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Restarts the HelpWorkflow
        /// </summary>
        public void Start(bool force = false)
        {
            if (RootStage == null)
            {
                throw new Exception("No RootStage exists for Help, you will need to create one");
            }

            if (!force && !ProgressProvider.ShouldShowUserWorkflow(this))
            {
                return;
            }

            _cancellationTokenSource = new CancellationTokenSource();

            _help = new TransparentHelpForm(HostControl);
            _help.ShowWithoutActivate();
            _helpClosed       = false;
            _help.FormClosed += (sender, args) =>
            {
                _helpClosed = true;
                _cancellationTokenSource.Cancel();
            };

            ShowStage(RootStage);
        }
Esempio n. 6
0
        private static void ControllerOnPluginProgressUpdated(IPlugin plugin, ProgressProvider progressProvider)
        {
            var line = string.Format("{0} - {1}{2}: {3} ({4} / {5})",
                                     (progressProvider.PercentComplete / 100.0).ToString("P"),
                                     plugin.Name,
                                     progressProvider.State != ProgressProviderState.Running ? string.Format(" ({0})", progressProvider.State) : "",
                                     progressProvider.ShortStatus,
                                     progressProvider.RunTime.ToStringMicro(),
                                     progressProvider.TimeRemaining.ToStringMicro());

            if (line == _lastLine)
            {
                return;
            }

            // Erase previous characters by padding current line with spaces
            var paddingCount = Console.WindowWidth - line.Length - 1;

            if (paddingCount > 0)
            {
                line += new string(' ', paddingCount);
            }

            Console.Write("\r{0}", line);

            // Move cursor back to the end of the new line text
            if (paddingCount > 0)
            {
                Console.Write(new string('\b', paddingCount));
            }

            _lastLine = line;
        }
Esempio n. 7
0
 private void ProgressProviderOnUpdated(ProgressProvider progressProvider)
 {
     if (PluginProgressUpdated != null)
     {
         _uiInvoker.InvokeAsync(() => ProgressProviderOnUpdatedSync(progressProvider));
     }
 }
        public void RunReport()
        {
            GenerateReportIntro();

            GenerateReport();
            if (ProgressProvider.CancelRequested)
            {
                return;
            }
            ProgressProvider.UpdateProgress("Writing the report");
            WriteReportToFile();
        }
Esempio n. 9
0
        /// <summary>
        /// Ends the current help session (cannot be reversed)
        /// </summary>
        public void Abandon()
        {
            if (_help == null)
            {
                return;
            }

            if (HostControl.InvokeRequired)
            {
                HostControl.Invoke(new MethodInvoker(Abandon));
                return;
            }
            ProgressProvider.Completed(this);
            _help.Close();
            _help = null;
        }
Esempio n. 10
0
        private static void ControllerOnPluginProgressUpdated(IPlugin plugin, ProgressProvider progressProvider)
        {
            var line = string.Format("{0} is {1} - {2} complete - {3} - {4} elapsed, {5} remaining",
                                     plugin.Name, progressProvider.State, (progressProvider.PercentComplete / 100.0).ToString("P"),
                                     progressProvider.Status,
                                     progressProvider.RunTime.ToStringShort(),
                                     progressProvider.TimeRemaining.ToStringShort());

            if (progressProvider.State == ProgressProviderState.Running)
            {
                Console.WriteLine("\r{0}", line);
            }
            else
            {
                Console.WriteLine(line);
            }
        }
        /// <summary>
        /// Looks for all the nodes with the same action line, but different board cards.
        /// </summary>
        public List <IServerNode> FindSimilarNodesOnOtherBoards(IServerNode node)
        {
            Stack <IServerNode> fullPath = new Stack <IServerNode>();

            for (IServerNode temp = node; temp.Parent != null; temp = temp.Parent)
            {
                fullPath.Push(temp);
            }

            List <IServerNode> allSimilar = new List <IServerNode>();

            allSimilar.Add(fullPath.Pop());
            List <IServerNode> tempList = new List <IServerNode>();

            int progressReportingPathIndex = 0;
            int progressReportingPathTotal = fullPath.Count;

            while (fullPath.Count > 0)
            {
                var pattern = fullPath.Pop();

                int progressReportingNodeIndex = 1;
                progressReportingPathIndex++;

                foreach (var item in allSimilar)
                {
                    ProgressProvider.UpdateProgress("listing nodes. Path (" + progressReportingPathIndex + "/" + progressReportingPathTotal + ") " + progressReportingNodeIndex++ + " nodes");
                    if (ProgressProvider.CancelRequested)
                    {
                        return(new List <IServerNode>());
                    }

                    var itemChildren = Context.ServerWrapper.ShowChildren(item);
                    foreach (var child in itemChildren)
                    {
                        if (child.NodeText == pattern.NodeText || item.NodeType == "SPLIT_NODE")
                        {
                            tempList.Add(child);
                        }
                    }
                }
                allSimilar = tempList;
                tempList   = new List <IServerNode>();
            }
            return(allSimilar);
        }
Esempio n. 12
0
        private void ControllerOnPluginProgressUpdated(IPlugin plugin, ProgressProvider progressProvider)
        {
            if (!_isRunning)
            {
                return;
            }

            _state = progressProvider.State;

            var percentCompleteStr = (progressProvider.PercentComplete / 100.0).ToString("P");
            var line = string.Format("{0} is {1} - {2} complete - {3} - {4} elapsed, {5} remaining",
                                     plugin.Name, progressProvider.State, percentCompleteStr,
                                     progressProvider.Status,
                                     progressProvider.RunTime.ToStringShort(),
                                     progressProvider.TimeRemaining.ToStringShort());

            AppendStatus(line);

            progressBar.ValuePercent = progressProvider.PercentComplete;
            _progressBarToolTip.SetToolTip(progressBar, string.Format("{0}: {1}", progressProvider.State, percentCompleteStr));
            _taskbarItem.Progress = progressProvider.PercentComplete;

            switch (progressProvider.State)
            {
            case ProgressProviderState.Error:
                progressBar.SetError();
                _taskbarItem.Error();
                break;

            case ProgressProviderState.Paused:
                progressBar.SetPaused();
                _taskbarItem.Pause();
                break;

            case ProgressProviderState.Canceled:
                progressBar.SetMuted();
                _taskbarItem.NoProgress();
                break;

            default:
                progressBar.SetSuccess();
                _taskbarItem.Normal();
                break;
            }
        }
        private void RenderButton_Click(object sender, EventArgs e)
        {
            this.Configuration.Scale = (double)this.ScaleNumeric.Value;

            foreach (Control c in this.Controls.OfType <Control>().Where(c => !(c is ProgressBar)))
            {
                c.Enabled = false;
            }

            ProgressProvider progress     = new ProgressProvider((s, a) => this.Invoke((Action)(() => this.MainProgressBar.Value = (int)(100 * (s as ProgressProvider).Progress))));
            Thread           renderThread = new Thread((ThreadStart)(() =>
            {
                Bitmap rendered = MultislitRenderer.RenderHighRes(this.Configuration, new Size((int)this.WidthNumeric.Value, (int)this.HeightNumeric.Value), progress);
                this.Invoke((Action)(() =>
                {
                    ImageSavingHelper.Save(rendered);
                    this.Close();
                }));
            }));

            renderThread.Start();
        }
Esempio n. 14
0
        protected override async void SendMessage(string message)
        {
            using (ProgressProvider.StartProgress())
            {
                var simpleMessage = new OwnSimpleMessage(User, message)
                {
                    MessageSentDateTime = DateTime.Now
                };

                if (File.Exists(MessageImagePath))
                {
                    using (var fileStream = File.OpenRead(MessageImagePath))
                    {
                        var imageName    = Guid.NewGuid().ToString();
                        var memoryStream = new MemoryStream();
                        fileStream.CopyTo(memoryStream);

                        simpleMessage.ImageStream       = memoryStream;
                        simpleMessage.Base64ImageString = Convert.ToBase64String(memoryStream.ToArray());
                        simpleMessage.ImageName         = imageName;

                        _imageHelper.AddImageStream(memoryStream, imageName);
                    }
                }

                MessageImagePath = string.Empty;

                simpleMessage.IsLocalMessage = true;
                Messages.Add(simpleMessage);

                simpleMessage.ImageUploading = true;
                await SignalHelperFacade.ChatSignalHelper.SendMessage(simpleMessage).ConfigureAwait(true);

                simpleMessage.ImageUploading = false;
            }
        }
Esempio n. 15
0
        public static Bitmap RenderHighRes(MultislitConfiguration configuration, Size size, ProgressProvider progress)
        {
            double[] yBrightnessFactors = MultislitRenderer.CalculateYBrightnessDistribution(configuration, size.Height);

            using (FastBitmap target = new FastBitmap(size, Color.FromArgb(10, 10, 10)))
            {
                int    chunkSize      = 10;
                int    finishedChunks = 0;
                double chunkFactor    = ((double)chunkSize / size.Width);
                if (configuration.LightSources.Any())
                {
                    Parallel.For(0, (int)Math.Ceiling(size.Width / (double)chunkSize), i =>
                    {
                        for (int ix = i * chunkSize; ix < Math.Min(i * chunkSize + chunkSize, size.Width); ix++)
                        {
                            double x        = (ix - size.Width * 0.5) / configuration.Scale;
                            RgbColor xColor = configuration.Brightness * MultislitRenderer.CalculateColorAt(configuration, x, 1, 250);

                            for (int iy = 0; iy < size.Height; iy++)
                            {
                                if (target == null || target.IsDisposed)
                                {
                                    return;
                                }

                                if (configuration.DisplayDistribution)
                                {
                                    target[ix, iy] = xColor;
                                }
                                else
                                {
                                    target[ix, iy] = yBrightnessFactors[iy] * xColor;
                                }
                            }
                        }

                        finishedChunks++;
                        progress.Progress = chunkFactor * finishedChunks;
                    });
                }

                return((Bitmap)target.InternalBitmap.Clone());
            }
        }
        /// <summary>
        /// Generate the full report
        /// </summary>
        private void GenerateReport()
        {
            ReportBuilder.AppendLine("");

            ProgressProvider.UpdateProgress("list nodes");


            if (CFRFilePaths == null)
            {
                CFRFilePaths = new List <string>();
                CFRFilePaths.Add(null);
            }

            int loop  = 0;
            int loops = CFRFilePaths.Count;

            foreach (var path in CFRFilePaths)
            {
                loop++;

                if (path != null)
                {
                    ProgressProvider.UpdateProgress("Load file " + loop + " out of " + loops);
                    Context.ServerWrapper.LoadTree(path);
                    Node = Context.ServerWrapper.RefreshNode(Node);
                }

                var similarNodes      = FindSimilarNodesOnOtherBoards(Node);
                int total             = similarNodes.Count;
                int progressNodeCount = 0;

                var root         = Context.ServerWrapper.ShowRootNode();
                var rootMatchups = Context.ServerWrapper.CalcEquityInNode(Context.ServerUtils.IP, root).TotalMatchups();

                var results = new List <ReportLine>();

                foreach (var singleNode in similarNodes)
                {
                    progressNodeCount++;
                    if (ProgressProvider.CancelRequested)
                    {
                        return;
                    }
                    if (loops > 1)
                    {
                        ProgressProvider.UpdateProgress("file " + loop + " out of " + loops + ". Analyse " + string.Join("", singleNode.Board.ToList()) + " " + progressNodeCount + " out of " + total);
                    }
                    else
                    {
                        ProgressProvider.UpdateProgress("Analyze " + string.Join("", singleNode.Board.ToList()) + " " + progressNodeCount + " out of " + total);
                    }
                    results.Add(ReportLine.CreateReportLineForNode(singleNode, this.Context));
                }
                var summaryResult = ReportLine.ToSummaryCSVLine(results);

                if (loop == 1)
                {
                    ReportBuilder.AppendLine(string.Join(",", GenerateHeaderNames(summaryResult.ActionNames)));
                }

                if (results.Count > 1)
                {
                    ReportBuilder.AppendLine(string.Join(",", summaryResult.ToCSVLine(rootMatchups)));
                }

                foreach (var resultLine in results)
                {
                    ReportBuilder.AppendLine(string.Join(",", resultLine.ToCSVLine(rootMatchups)));
                }
            }
        }