/// <inheritdoc />
        public void Revoke(DialogDisplayLocation displayLocation, DialogResult dialogResult)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                // Find the matching handler for the display location.
                var dialogHandler = _dialogHandlers.GetDialogHandler(displayLocation);

                // Revoke the currently displayed view.
                dialogHandler.Revoke(dialogResult);
            });
        }
        /// <inheritdoc />
        public void Close(DialogDisplayLocation displayLocation, DialogResult dialogResult)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                // Find the matching handler for the display location.
                var dialogHandler = _dialogHandlers.GetDialogHandler(displayLocation);

                // Close the dialog.
                dialogHandler.Close(dialogResult);
            });
        }
Example #3
0
 /// <summary>
 /// Shows a message dialog.
 /// </summary>
 /// <param name="dialogManager"> The extended <see cref="IDialogManager"/>. </param>
 /// <param name="messageModels"> A collection of <see cref="MessageDialogModel"/>s for the dialog. </param>
 /// <param name="buttons"> The <see cref="DialogButtons"/> to display. Default is <see cref="DialogButtons.Ok"/>. </param>
 /// <param name="displayLocation"> The <see cref="DialogDisplayLocation"/> of the dialog. Default is <see cref="DialogDisplayLocation.Window"/>. </param>
 /// <param name="displayBehavior"> The <see cref="DialogDisplayBehavior"/> of the dialog. Default is <see cref="DialogDisplayBehavior.Show"/>. </param>
 /// <param name="dialogOptions"> The <see cref="DialogOptions"/> of the dialog. Default is <see cref="DialogOptions.None"/>. </param>
 /// <param name="cancellationToken"> An external <see cref="CancellationToken"/> used to cancel the dialog. </param>
 /// <returns> An awaitable <see cref="DialogTask"/>. </returns>
 public static DialogTask ShowMessage
 (
     this IDialogManager dialogManager,
     ICollection <MessageDialogModel> messageModels,
     DialogButtons buttons = DialogButtons.Ok,
     DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
     DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
     DialogOptions dialogOptions           = DialogOptions.None,
     CancellationToken cancellationToken   = default
 )
 => dialogManager.ShowMessage(messageModels, DefaultButtonConfigurations.GetConfiguration(buttons), displayLocation, displayBehavior, dialogOptions, cancellationToken);
Example #4
0
 /// <summary>
 /// Shows a message dialog.
 /// </summary>
 /// <param name="dialogManager"> The extended <see cref="IDialogManager"/>. </param>
 /// <param name="messageModel"> The <see cref="MessageDialogModel"/> of the dialog. </param>
 /// <param name="buttons"> The <see cref="DialogButtons"/> to display. Default is <see cref="DialogButtons.Ok"/>. </param>
 /// <param name="displayLocation"> The <see cref="DialogDisplayLocation"/> of the dialog. Default is <see cref="DialogDisplayLocation.Window"/>. </param>
 /// <param name="displayBehavior"> The <see cref="DialogDisplayBehavior"/> of the dialog. Default is <see cref="DialogDisplayBehavior.Show"/>. </param>
 /// <param name="dialogOptions"> The <see cref="DialogOptions"/> of the dialog. Default is <see cref="DialogOptions.None"/>. </param>
 /// <param name="cancellationToken"> An external <see cref="CancellationToken"/> used to cancel the dialog. </param>
 /// <returns> An awaitable <see cref="DialogTask"/>. </returns>
 public static DialogTask ShowMessage
 (
     this IDialogManager dialogManager,
     MessageDialogModel messageModel,
     DialogButtons buttons = DialogButtons.Ok,
     DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
     DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
     DialogOptions dialogOptions           = DialogOptions.None,
     CancellationToken cancellationToken   = default
 )
 => dialogManager.ShowMessage(new[] { messageModel }, buttons, displayLocation, displayBehavior, dialogOptions, cancellationToken);
Example #5
0
 /// <summary>
 /// Shows an exception dialog.
 /// </summary>
 /// <param name="dialogManager"> The extended <see cref="IDialogManager"/>. </param>
 /// <param name="title"> The title of the dialog. </param>
 /// <param name="message"> The message of the dialog. </param>
 /// <param name="displayLocation"> The <see cref="DialogDisplayLocation"/> of the dialog. Default is <see cref="DialogDisplayLocation.Window"/>. </param>
 /// <param name="displayBehavior"> The <see cref="DialogDisplayBehavior"/> of the dialog. Default is <see cref="DialogDisplayBehavior.Show"/>. </param>
 /// <param name="dialogOptions"> The <see cref="DialogOptions"/> of the dialog. Default is <see cref="DialogOptions.None"/>. </param>
 /// <param name="cancellationToken"> An external <see cref="CancellationToken"/> used to cancel the dialog. </param>
 /// <returns> An awaitable <see cref="DialogTask"/>. </returns>
 public static DialogTask ShowException
 (
     this IDialogManager dialogManager,
     string title   = null,
     string message = null,
     DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
     DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
     DialogOptions dialogOptions           = DialogOptions.None,
     CancellationToken cancellationToken   = default
 )
 => dialogManager.ShowExceptions(new Exception[0], title, message, displayLocation, displayBehavior, dialogOptions, cancellationToken);
Example #6
0
 /// <summary>
 /// Shows a warning dialog.
 /// </summary>
 /// <param name="dialogManager"> The extended <see cref="IDialogManager"/>. </param>
 /// <param name="messageModels"> A collection of <see cref="MessageDialogModel"/>s for the dialog. </param>
 /// <param name="buttonConfigurations"> A collection of custom <see cref="ButtonConfiguration"/> used to display buttons. </param>
 /// <param name="displayLocation"> The <see cref="DialogDisplayLocation"/> of the dialog. Default is <see cref="DialogDisplayLocation.Window"/>. </param>
 /// <param name="displayBehavior"> The <see cref="DialogDisplayBehavior"/> of the dialog. Default is <see cref="DialogDisplayBehavior.Show"/>. </param>
 /// <param name="dialogOptions"> The <see cref="DialogOptions"/> of the dialog. Default is <see cref="DialogOptions.None"/>. </param>
 /// <param name="cancellationToken"> An external <see cref="CancellationToken"/> used to cancel the dialog. </param>
 /// <returns> An awaitable <see cref="DialogTask"/>. </returns>
 public static DialogTask ShowWarning
 (
     this IDialogManager dialogManager,
     ICollection <MessageDialogModel> messageModels,
     IEnumerable <ButtonConfiguration> buttonConfigurations,
     DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
     DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
     DialogOptions dialogOptions           = DialogOptions.None,
     CancellationToken cancellationToken   = default
 )
 => dialogManager.ShowMessage(new WarningDialogViewModel(messageModels), buttonConfigurations, displayLocation, displayBehavior, dialogOptions, cancellationToken);
 /// <inheritdoc />
 public DialogTask ShowContent
 (
     object viewModel,
     IEnumerable <ButtonConfiguration> buttonConfigurations,
     DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
     DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
     DialogOptions dialogOptions           = DialogOptions.HideTransparencyToggle,
     CancellationToken cancellationToken   = default
 )
 {
     return(this.Show(viewModel, _wrappingViewProvider, buttonConfigurations, displayLocation, displayBehavior, dialogOptions, cancellationToken));
 }
Example #8
0
 /// <summary>
 /// Shows an exception dialog.
 /// </summary>
 /// <param name="dialogManager"> The extended <see cref="IDialogManager"/>. </param>
 /// <param name="exception"> The <see cref="Exception"/> of the dialog. If this is an <see cref="AggregateException"/>, then the <see cref="AggregateException.InnerExceptions"/> collection will be used. </param>
 /// <param name="title"> The title of the dialog. </param>
 /// <param name="message"> The message of the dialog. </param>
 /// <param name="displayLocation"> The <see cref="DialogDisplayLocation"/> of the dialog. Default is <see cref="DialogDisplayLocation.Window"/>. </param>
 /// <param name="displayBehavior"> The <see cref="DialogDisplayBehavior"/> of the dialog. Default is <see cref="DialogDisplayBehavior.Show"/>. </param>
 /// <param name="dialogOptions"> The <see cref="DialogOptions"/> of the dialog. Default is <see cref="DialogOptions.None"/>. </param>
 /// <param name="cancellationToken"> An external <see cref="CancellationToken"/> used to cancel the dialog. </param>
 /// <returns> An awaitable <see cref="DialogTask"/>. </returns>
 public static DialogTask ShowException
 (
     this IDialogManager dialogManager,
     Exception exception,
     string title   = null,
     string message = null,
     DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
     DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
     DialogOptions dialogOptions           = DialogOptions.None,
     CancellationToken cancellationToken   = default
 )
 => dialogManager.ShowExceptions(exception is AggregateException aggregateException ? aggregateException.InnerExceptions.ToArray() : new[] { exception }, title, message, displayLocation, displayBehavior, dialogOptions, cancellationToken);
Example #9
0
 /// <summary>
 /// Shows a message dialog.
 /// </summary>
 /// <param name="dialogManager"> The extended <see cref="IDialogManager"/>. </param>
 /// <param name="title"> The title of the dialog. </param>
 /// <param name="message"> The message of the dialog. </param>
 /// <param name="contentViewModel"> The inner content (view model) of the dialog. </param>
 /// <param name="buttons"> The <see cref="DialogButtons"/> to display. Default is <see cref="DialogButtons.Ok"/>. </param>
 /// <param name="displayLocation"> The <see cref="DialogDisplayLocation"/> of the dialog. Default is <see cref="DialogDisplayLocation.Window"/>. </param>
 /// <param name="displayBehavior"> The <see cref="DialogDisplayBehavior"/> of the dialog. Default is <see cref="DialogDisplayBehavior.Show"/>. </param>
 /// <param name="dialogOptions"> The <see cref="DialogOptions"/> of the dialog. Default is <see cref="DialogOptions.None"/>. </param>
 /// <param name="cancellationToken"> An external <see cref="CancellationToken"/> used to cancel the dialog. </param>
 /// <returns> An awaitable <see cref="DialogTask"/>. </returns>
 public static DialogTask ShowMessage
 (
     this IDialogManager dialogManager,
     string title            = null,
     string message          = null,
     object contentViewModel = null,
     DialogButtons buttons   = DialogButtons.Ok,
     DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
     DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
     DialogOptions dialogOptions           = DialogOptions.None,
     CancellationToken cancellationToken   = default
 )
 => dialogManager.ShowMessage(new MessageDialogModel(identifier: null, title: title, message: message, contentViewModel: contentViewModel), buttons, displayLocation, displayBehavior, dialogOptions, cancellationToken);
Example #10
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="displayLocation"> The <see cref="DialogDisplayLocation"/> of this <see cref="DialogHandler"/>. </param>
        /// <param name="dialogViewProvider"> <see cref="DialogAssemblyViewProvider"/> used to obtain the proper view for an <see cref="IDialogContainerViewModel"/>. </param>
        public DialogHandler
        (
            DialogDisplayLocation displayLocation,
            DialogAssemblyViewProvider dialogViewProvider
        )
        {
            // Save parameters.
            this.DisplayLocation = displayLocation;
            _containerViewModel  = new DialogContainerViewModel();

            // Initialize fields.
            _containerView     = dialogViewProvider.GetViewInstance(_containerViewModel);
            _dialogs           = new ConcurrentStack <Dialog>();
            this.IsInitialized = false;
        }
        /// <inheritdoc />
        public DialogTask ShowExceptions
        (
            ICollection <Exception> exceptions,
            string title   = null,
            string message = null,
            DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
            DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
            DialogOptions dialogOptions           = DialogOptions.None,
            CancellationToken cancellationToken   = default
        )
        {
            var viewModel            = new ExceptionDialogViewModel(title, message, exceptions);
            var buttonConfigurations = new[] { DefaultButtonConfigurations.OkButtonConfiguration };

            return(this.Show(viewModel, _dialogAssemblyViewProvider, buttonConfigurations, displayLocation, displayBehavior, dialogOptions, cancellationToken));
        }
        /// <inheritdoc />
        public DialogTask ShowMessage
        (
            MessageDialogViewModel viewModel,
            IEnumerable <ButtonConfiguration> buttonConfigurations,
            DialogDisplayLocation displayLocation,
            DialogDisplayBehavior displayBehavior,
            DialogOptions dialogOptions,
            CancellationToken cancellationToken = default
        )
        {
            // Try to resolve the content views of all message models if necessary.
            foreach (var messageDialogModel in viewModel.MessageModels.Where(model => model.ContentViewModel != null))
            {
                messageDialogModel.ContentView = _wrappingViewProvider.GetViewInstance(messageDialogModel.ContentViewModel);
            }

            return(this.Show(viewModel, _dialogAssemblyViewProvider, buttonConfigurations, displayLocation, displayBehavior, dialogOptions, cancellationToken));
        }
        private DialogTask Show
        (
            object viewModel,
            IViewProvider viewProvider,
            IEnumerable <ButtonConfiguration> buttonConfigurations,
            DialogDisplayLocation displayLocation,
            DialogDisplayBehavior displayBehavior,
            DialogOptions dialogOptions,
            CancellationToken cancellationToken
        )
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(DialogTask.Killed);
            }

            DialogTask dialogTask = null;

            Application.Current.Dispatcher.Invoke(() =>
            {
                var view = viewProvider.GetViewInstance(viewModel);

                // Find the matching handler for the display location.
                var dialogHandler = _dialogHandlers.GetDialogHandler(displayLocation);

                // Tell it to show the content.
                dialogTask = dialogHandler.ShowView(view, buttonConfigurations, displayBehavior, dialogOptions, cancellationToken);
            });

            if (dialogTask is null)
            {
                return(null);
            }

            if (cancellationToken.IsCancellationRequested)
            {
                return(DialogTask.Killed);
            }

            dialogTask.Start();
            return(dialogTask);
        }
 public DialogHandler GetDialogHandler(DialogDisplayLocation displayLocation)
 {
     return(this.FirstOrDefault(dialogRegistration => dialogRegistration.DisplayLocation == displayLocation));
 }
 /// <summary>
 /// Creates a new instance of a <see cref="DialogHandler"/> based on <paramref name="displayLocation"/>.
 /// </summary>
 /// <param name="displayLocation"> The <see cref="DialogDisplayLocation"/> used later on to identify the <see cref="DialogHandler"/>. </param>
 /// <param name="dialogAssemblyViewProvider"> An instance of a <see cref="DialogAssemblyViewProvider"/> used to resolve views for the direct dialog view models. </param>
 /// <returns> A new <see cref="DialogHandler"/> instance. </returns>
 private static DialogHandler CreateDialogHandler(DialogDisplayLocation displayLocation, DialogAssemblyViewProvider dialogAssemblyViewProvider)
 {
     return(new DialogHandler(displayLocation, dialogAssemblyViewProvider));
 }