Exemple #1
0
        public static async Task <TaskResult> Run <T>(string title, string message, Func <T, IProgress <WaitDialogProgressData>, CancellationToken, Task> task,
                                                      T param, TimeSpan?delayToShowDialog = null)
        {
            var data = new WaitDialogProgressData(message);

            return(await Run(title, data, task, param, true, delayToShowDialog ?? TimeSpan.FromSeconds(2)));
        }
Exemple #2
0
        public static async Task <TaskResult> Run(string title, string message, Func <Task> task,
                                                  TimeSpan?delayToShowDialog = null)
        {
            var data = new WaitDialogProgressData(message);

            return(await Run(title, data, (progress, cancellation) => task(), false, delayToShowDialog ?? TimeSpan.FromSeconds(2)));
        }
Exemple #3
0
        public static Session StartWaitDialog(this IWaitDialogFactory factory, string waitCatption,
                                              WaitDialogProgressData initialProgress = null, TimeSpan delayToShow = default)
        {
            var instance           = factory.CreateInstance();
            var cancellationSource = new CancellationTokenSource();
            var progress           = new ProgressAdapter(instance, cancellationSource);
            var callback           = new CancellationCallback(cancellationSource);

            instance.StartWaitDialogWithCallback(waitCatption, initialProgress?.WaitMessage,
                                                 initialProgress?.ProgressText, initialProgress?.StatusBarText,
                                                 initialProgress != null && initialProgress.IsCancelable, (int)delayToShow.TotalSeconds, true, initialProgress?.TotalSteps ?? 0,
                                                 initialProgress?.CurrentStep ?? 0, callback);
            return(new Session(instance, progress, cancellationSource.Token, callback));
        }
Exemple #4
0
        /// <summary>
        /// Starts the wait dialog and executes the task.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="asyncFunc">The asynchronous function.</param>
        /// <param name="waitCaption">The caption of the dialog.</param>
        /// <param name="initialProgress">The initial progress.</param>
        /// <param name="delayToShowDialog">The delay to show the dialog.</param>
        public static void StartWaitDialog(this IWaitDialogFactory factory,
                                           Func <IProgress <WaitDialogProgressData>, Task> asyncFunc, string waitCaption,
                                           WaitDialogProgressData initialProgress = null, TimeSpan delayToShowDialog = default(TimeSpan))
        {
            var instance = factory.CreateInstance();
            var session  = CreateSession(instance);

            instance.SetFunction(() => asyncFunc(session.Progress));
            instance.StartWaitDialogWithCallback(
                waitCaption,
                initialProgress?.WaitMessage,
                initialProgress?.ProgressText,
                initialProgress?.StatusBarText,
                initialProgress != null && initialProgress.IsCancelable,
                (int)delayToShowDialog.TotalSeconds,
                true, initialProgress?.TotalSteps ?? 0,
                initialProgress?.CurrentStep ?? 0,
                session.Callback);
        }
Exemple #5
0
        internal static async Task <TaskResult> Run(string title, WaitDialogProgressData progressData, Func <IProgress <WaitDialogProgressData>, CancellationToken, Task> task,
                                                    bool cancelable, TimeSpan delayToShowDialog = default)
        {
            var f = IoC.Get <IWaitDialogFactory>();

            f.CreateInstance(out var window);

            var waitSeconds = (int)delayToShowDialog.TotalSeconds;

            var session = WaitDialogHelper.CreateSession(window);

            window.StartWaitDialogWithCallback(title, progressData.WaitMessage, progressData.ProgressText,
                                               progressData.StatusBarText, cancelable, waitSeconds, true, 0, 0,
                                               session.Callback);

            await Task.Run(async() => await task(session.Progress, session.UserCancellationToken));

            window.EndWaitDialog(out var canceled);
            return(canceled ? TaskResult.Canceled : TaskResult.Completed);
        }