Пример #1
0
        /// <summary>
        /// Evaluates the specified result and shows a dialog depending on the status.
        /// </summary>
        /// <param name="result">The result to be evaluated.</param>
        /// <returns>True on successful evaluation, false otherwise.</returns>
        internal MessageDialog CreateResultDialog(Result result)
        {
            MessageDialog dialog;

            switch (result.StatusCode)
            {
            case Result.Status.Success:
            {
                var durationText = BuildDurationText(result.ElapsedTime);
                dialog = DialogFactory.CreateInformationDialog(
                    I18N.Resources.GetString("Success/Text"), durationText);
                break;
            }

            case Result.Status.Fail:
            {
                var message = !string.IsNullOrEmpty(result.Message)
                            ? result.Message : I18N.Resources.GetString("SomethingWentWrong/Text");
                dialog = DialogFactory.CreateErrorDialog(message);
                break;
            }

            case Result.Status.Interrupt:
            {
                dialog = DialogFactory.CreateInformationDialog(
                    I18N.Resources.GetString("Interrupted/Text"),
                    I18N.Resources.GetString("OperationCancelled/Text"));
                break;
            }

            case Result.Status.PartialFail:
            {
                dialog = DialogFactory.CreateErrorDialog(
                    I18N.Resources.GetString("NotAllExtracted/Text"));
                break;
            }

            default: throw new ArgumentOutOfRangeException(nameof(result.StatusCode));
            }
            return(dialog);
        }
        /// <summary>
        /// Reads the specified archive and returns its root node.
        /// </summary>
        /// <param name="archive">The archive to be read.</param>
        /// <returns>The root node of the archive.</returns>
        internal async Task <Node> ReadArchive(StorageFile archive)
        {
            if (_archiveFile != null && _archiveFile.IsEqual(archive))
            {
                return(_rootNode);
            }

            _archiveFile = archive;
            using (var reader = new ArchiveReader())
            {
                Node rootNode = null;
                try
                {
                    rootNode = await reader.Read(archive);
                }
                catch (IOException)
                {
                    var dialog = DialogFactory.CreateErrorDialog(
                        I18N.Resources.GetString("ErrorReadingArchive/Text"));
                    dialog.ShowAsync().AsTask().Forget();
                }
                return(_rootNode = rootNode);
            }
        }