Example #1
0
        /// <summary>
        /// Confirm if the user wants to start scanning despite low disk space.
        /// </summary>
        /// <param name="requiredSpace">The disk space required for storing images, in bytes</param>
        /// <param name="availableSpace">The disk space available on the selected logical drive, in bytes</param>
        /// <param name="timeout">Removes the dialogue if it is still running after this amount of milliseconds</param>
        /// <param name="cancellationToken">Removes the dialogue if it is still running</param>
        /// <returns><see langword="true"/> if the user confirms to start scanning</returns>
        public async Task <bool> DiskSpaceDialog(long requiredSpace, long availableSpace, int timeout = 10000, CancellationToken cancellationToken = default)
        {
            _log.LogDebug($"{nameof(DiskSpaceDialog)} initiated.");

            IDialogSettings dialogSettings = new DialogSettings
            {
                AffirmativeButtonText = "Start scanning",
                NegativeButtonText    = "Cancel",
                CancellationToken     = cancellationToken
            };

            var dialogResult = await _dialogManager.ShowMessageWithTimeoutAsync(
                _context,
                "Disk space low",
                $"The images generated from scanning will require approximately {StringFormat.ByteSize(requiredSpace)} of disk space." +
                $"Only {StringFormat.ByteSize(availableSpace)} is available, are you sure you want to continue?",
                DialogStyle.AffirmativeAndNegative,
                dialogSettings,
                timeout);

            if (dialogResult == DialogResult.Canceled)
            {
                _log.LogDebug($"{nameof(DiskSpaceDialog)} closed by CancellationToken before user input recieved");
            }

            _log.LogDebug($"User input return from {nameof(DiskSpaceDialog)}: {dialogResult}");

            return(dialogResult == DialogResult.Affirmative);
        }