예제 #1
0
        /// <summary>
        /// Writes a list to the output pipeline.
        /// </summary>
        /// <typeparam name="T">The type of the list that will be output.</typeparam>
        /// <param name="sendToPipeline">The list that will be output to the pipeline.</param>
        /// <param name="settings">How progress should be displayed while the list is being enumerated.</param>
        internal void WriteList <T>(IEnumerable <T> sendToPipeline, ProgressSettings settings)
        {
            ProgressRecord progress = null;

            var recordsProcessed = -1;

            if (settings != null)
            {
                recordsProcessed = 0;

                progress = new ProgressRecord(1, settings.ActivityName, settings.InitialDescription)
                {
                    PercentComplete   = 0,
                    StatusDescription = $"{settings.InitialDescription} {recordsProcessed}/{settings.TotalRecords}"
                };

                WriteProgress(progress);
            }

            foreach (var item in sendToPipeline)
            {
                WriteObject(item);

                if (settings != null)
                {
                    recordsProcessed++;

                    progress.PercentComplete   = (int)(recordsProcessed / Convert.ToDouble(settings.TotalRecords) * 100);
                    progress.StatusDescription = $"{settings.InitialDescription} ({recordsProcessed}/{settings.TotalRecords})";
                    WriteProgress(progress);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Method demos different sample methods for displaying a progress
        /// dialog with progress that cannot be cancelled because:
        ///
        /// - UI shows no Cancel button
        /// - Backend process does not evaluate <seealso cref="CancellationToken"/> parameter
        /// </summary>
        /// <param name="parentWindow"></param>
        /// <param name="progressIsFinite"></param>
        /// <param name="closeDialogOnProgressFinished"></param>
        /// <param name="isCancelable"></param>
        /// <returns></returns>
        internal async Task <int> ShowNoCancelProgressAsync(
            IMetroWindow parentWindow
            , bool progressIsFinite
            , bool closeDialogOnProgressFinished = false
            , bool isCancelable = true
            )
        {
            bool   isVisible    = true;
            string progressText = null;

            var progressColl = new ProgressSettings[1];

            // Configure a progress display with its basic settings
            progressColl[0] = new ProgressSettings(0, 1, 0, progressIsFinite
                                                   , progressText, isCancelable, isVisible
                                                   , closeDialogOnProgressFinished)
            {
                Title      = "Please wait...",
                Message    = "We are baking some cupcakes!",
                ExecAction = GenSampleNonCancelableProocess()
            };

            var viewModel    = new Demos.ViewModels.ProgressDialogViewModel();
            var customDialog = CreateProgressDialog(viewModel);

            var dlg     = GetService <IContentDialogService>();
            var manager = dlg.Manager;

            EventHandler <DialogStateChangedEventArgs> OnViewOpenedEvent = (s, e) =>
            {
                // Start Task in ProgressViewModel and wait for result in Dialog below
                // But do not start before view is visible because task could otherwise
                // finish before view close request can be handled by the view ...
                viewModel.StartProcess(progressColl);
            };

            manager.DialogOpened += OnViewOpenedEvent;

            int result = -1;

            try
            {
                result = await manager.ShowMetroDialogAsync(parentWindow, customDialog);
            }
            finally
            {
                manager.DialogOpened -= OnViewOpenedEvent;
            }

            Console.WriteLine("Process Result: '{0}'", viewModel.Progress.ProcessResult);

            return(result);
        }
예제 #3
0
        internal void ShowDialogOutside(IMetroWindow parentWindow
                                        , bool progressIsFinite
                                        , bool closeDialogOnProgressFinished = false
                                        , bool isCancelable = true
                                        )
        {
            bool   isVisible    = true;
            string progressText = null;

            var progressColl = new ProgressSettings[1];

            // Configure a progress display with its basic settings
            progressColl[0] = new ProgressSettings(0, 1, 0, progressIsFinite
                                                   , progressText, isCancelable, isVisible
                                                   , closeDialogOnProgressFinished)
            {
                Title      = "Progress Outside",
                Message    = "This progress is shown in a seperate window above the main window",
                ExecAction = GenCancelableSampleProcess()
            };

            var viewModel    = new Demos.ViewModels.ProgressDialogViewModel();
            var customDialog = CreateProgressDialog(viewModel);

            var dlg     = GetService <IContentDialogService>();
            var manager = GetService <IContentDialogService>().Manager;

            EventHandler <DialogStateChangedEventArgs> OnViewOpenedEvent = (s, e) =>
            {
                // Start Task in ProgressViewModel and wait for result in Dialog below
                // But do not start before view is visible because task could otherwise
                // finish before view close request can be handled by the view ...
                viewModel.StartProcess(progressColl);
            };

            manager.DialogOpened += OnViewOpenedEvent;

            int result = -1;

            try
            {
                result = dlg.Manager.ShowModalDialogExternal(parentWindow, customDialog
                                                             , dlg.DialogSettings);
            }
            finally
            {
                manager.DialogOpened -= OnViewOpenedEvent;
            }

            Console.WriteLine("Process Result: '{0}'", viewModel.Progress.ProcessResult);
        }
예제 #4
0
        /// <summary>
        /// Shows a sample progress dialog that was invoked via a bound viewmodel.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="progressIsFinite"></param>
        /// <param name="closeDialogOnProgressFinished"></param>
        /// <param name="isCancelable"></param>
        internal async void ShowDialogFromVM(
            object context
            , bool progressIsFinite
            , bool closeDialogOnProgressFinished = false
            , bool isCancelable = true
            )
        {
            bool   isVisible    = true;
            string progressText = null;

            var progressColl = new ProgressSettings[1];

            // Configure a progress display with its basic settings
            progressColl[0] = new ProgressSettings(0, 1, 0, progressIsFinite
                                                   , progressText, isCancelable, isVisible
                                                   , closeDialogOnProgressFinished)
            {
                Title      = "Progress from VM",
                Message    = "Progressing all the things, wait a few seconds",
                ExecAction = GenCancelableSampleProcess()
            };

            var viewModel    = new Demos.ViewModels.ProgressDialogViewModel();
            var customDialog = CreateProgressDialog(viewModel);

            var coord   = GetService <IContentDialogService>().Coordinator;
            var manager = GetService <IContentDialogService>().Manager;

            EventHandler <DialogStateChangedEventArgs> OnViewOpenedEvent = (s, e) =>
            {
                // Start Task in ProgressViewModel and wait for result in Dialog below
                // But do not start before view is visible because task could otherwise
                // finish before view close request can be handled by the view ...
                viewModel.StartProcess(progressColl);
            };

            manager.DialogOpened += OnViewOpenedEvent;

            await coord.ShowMetroDialogAsync(context, customDialog).ContinueWith
            (
                t =>
            {
                manager.DialogOpened -= OnViewOpenedEvent;
                Console.WriteLine(t.Result);
            }
            );
        }
예제 #5
0
        /// <summary>
        /// Performs record-by-record processing functionality for the cmdlet.
        /// </summary>
        protected override void ProcessRecordEx()
        {
            var parameters = CreateParameters();

            IEnumerable <TObject> records;

            ProgressSettings progressSettings = null;

            ProcessIdFilter();
            ProcessNameFilter();
            ProcessTagsFilter();

            if (Filter != null)
            {
                streamResults = false;
            }

            if (Count != null)
            {
                parameters.Count = Count.Value;
                streamResults    = false;
            }

            if (streamResults)
            {
                records = GetResultsWithProgress(out progressSettings);
            }
            else
            {
                if (Filter != null)
                {
                    parameters.SearchFilter = Filter;
                }
                records = GetObjects(parameters);
            }

            records = FilterResponseRecords(records, Name, r => r.Name);
            records = FilterResponseRecordsByTag(records);

            WriteList(records, progressSettings);

            //Clear the filters for the next element on the pipeline, which will simply reuse the existing PrtgTableCmdlet object

            Filter = null;
        }
예제 #6
0
        private IEnumerable <TObject> GetResultsWithProgress(out ProgressSettings progressSettings)
        {
            ProgressRecord progress = null;
            int?           count    = null;

            if (progressThreshold != null)
            {
                progress = new ProgressRecord(1, $"PRTG {content} Search", "Detecting total number of items");
                WriteProgress(progress);
                count = client.GetTotalObjects(content);
            }

            var records = GetRecords();

            progressSettings = CompleteTotalsProgressAndCreateProgressSettings(progress, count);

            return(records);
        }
예제 #7
0
        /// <summary>
        /// Reset all viewmodel states in accordance with the
        /// given <paramref name="settings"/> object. This is
        /// useful when presenting a sequence of different
        /// progress indicators (eg. infinite first and finite later)
        /// in 1 dialog.
        /// </summary>
        /// <param name="settings"></param>
        protected void ResetSettings(ProgressSettings settings)
        {
            if (_Progress == null)
            {
                _Progress = new ProgressViewModel(settings);
            }

            _Progress.ResetSettings(settings);

            IsCancelable = IsCancelButtonVisible = settings.IsCancelable;
            CloseDialogOnProgressFinished = settings.CloseViewOnProgressFinished;

            Title   = settings.Title;
            Message = settings.Message;

            CancelButtonText = settings.CancelButtonText;
            CloseButtonText  = settings.CloseButtonText;

            DefaultResult      = settings.DefaultResult;
            DefaultCloseResult = settings.DefaultCloseResult;
        }
예제 #8
0
        private ProgressSettings CompleteTotalsProgressAndCreateProgressSettings(ProgressRecord progress, int?count)  //TODO - RENAME
        {
            ProgressSettings progressSettings = null;

            if (progress != null)
            {
                progress.RecordType = ProgressRecordType.Completed;
                WriteProgress(progress);

                if (count > progressThreshold)
                {
                    progressSettings = new ProgressSettings()
                    {
                        ActivityName       = $"PRTG {content.ToString().Substring(0, content.ToString().Length - 1)} Search",
                        InitialDescription = $"Retrieving all {content.ToString().ToLower()}",
                        TotalRecords       = count.Value
                    };
                }
            }

            return(progressSettings);
        }
예제 #9
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="settings"></param>
 /// <param name="closeDialogOnProgressFinished"></param>
 public ProgressDialogViewModel(ProgressSettings settings)
     : this()
 {
     ResetSettings(settings);
 }