internal async Task GenerateChecksumsAsync(CancellationTokenSource tokenSource)
        {
            try
            {
                Log($"{nameof(TreeChecksumViewModel)}.{nameof(GenerateChecksumsAsync)}: Start");

                IHashAlgorithim algorithim = HashAlgorithimFactory.Get(SelectedAlgorithim);
                Hasher          hasher     = new Hasher(algorithim);

                m_CancellationTokenSource = tokenSource;
                CancellationToken token = tokenSource.Token;
                token.ThrowIfCancellationRequested();

                m_GenerationInProgress = true;

                foreach (DirectoryItem childNode in RootNode.Items)
                {
                    await GenerateChecksumAsync(childNode, hasher, token);
                }
            }
            finally
            {
                Log($"{nameof(TreeChecksumViewModel)}.{nameof(GenerateChecksumsAsync)}: End");

                m_GenerationInProgress = false;

                m_CancellationTokenSource.Dispose();
            }
        }
Example #2
0
        internal async Task ComputeChecksumAsync()
        {
            Log($"{nameof(FileChecksumViewModel)}.{nameof(ComputeChecksumAsync)}: Start");

            IHashAlgorithim algorithim = HashAlgorithimFactory.Get(SelectedAlgorithim);
            Hasher          hasher     = new Hasher(algorithim);

            string checksum = string.Empty;

            bool?result = await Task.Run(() => hasher.TryGetFileChecksum(SelectedItem.FullyQualifiedFilename, out checksum));

            if (result.HasValue &&
                result.Value)
            {
                ComputedChecksum = checksum;
            }
            else
            {
                Log($"    There was no result from the hashing.");
            }

            Log($"{nameof(FileChecksumViewModel)}.{nameof(ComputeChecksumAsync)}: End");
        }
        private async void Application_Startup(object sender, StartupEventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            Log($"Application name: \"{AppDomain.CurrentDomain.FriendlyName}\".");

            if (e.Args.Length > 0)
            {
                // To start off, let's print all given arguments for
                // debugging's sake.
                int count = 0;

                foreach (string arg in e.Args)
                {
                    sb.AppendLine($"  Argument {++count}: \"{arg}\".");
                }

                Log(sb.ToString());

                // If the user just wants to see the help, print and exit.
                if (e.Args[0].Equals(m_Help_1, StringComparison.OrdinalIgnoreCase) ||
                    e.Args[0].Equals(m_Help_2, StringComparison.OrdinalIgnoreCase) ||
                    e.Args[0].Equals(m_Help_3, StringComparison.OrdinalIgnoreCase))
                {
                    ShowUsage();

                    Shutdown(SUCCESS);

                    return;
                }

                // The correct number of arguments were not supplied. Print help
                // and exit.
                if (e.Args.Length != NumberOfRequiredArguments)
                {
                    ShowUsage();

                    Shutdown(FAILURE);

                    return;
                }

                // First agrument should be the source directory.
                string directoryToParse = e.Args[0];

                if (Directory.Exists(directoryToParse) == false)
                {
                    LogError($"The directory \"{directoryToParse}\" does not exist.");

                    ShowUsage();

                    Shutdown(FAILURE);

                    return;
                }

                // Second argument should be the results file.
                string resultsFile = e.Args[1];

                // Third argument should be which algorithim to use for the checksum.
                IHashAlgorithim hashAlgorithim = null;

                try
                {
                    hashAlgorithim = GetAlgorithim(e.Args[2]);
                }
                catch (Exception ex)
                {
                    LogError($"The checksum algorithim could not be determined from the argument \"{e.Args[2]}\"..");
                    LogError(ex.Message);

                    ShowUsage();

                    Shutdown(FAILURE);

                    return;
                }

                // Fourth argument is the export format.
                IFileExport fileExport = null;
                try
                {
                    fileExport = GetExport(e.Args[3]);
                }
                catch (Exception ex)
                {
                    LogError($"The export format could not be determined from the argument \"{e.Args[3]}\"..");
                    LogError(ex.Message);

                    ShowUsage();

                    Shutdown(FAILURE);

                    return;
                }

                ViewModels.DirectoryViewModel vm = new ViewModels.DirectoryViewModel(null)
                {
                    DirectoryToParse = directoryToParse
                };

                await vm.ParseAsync();

                await vm.ExportAsync(resultsFile);

                Shutdown(SUCCESS);

                return;
            }
            else
            {
                ShowUsage();

                Views.MainWindow mainWindow = new Views.MainWindow();

                mainWindow.Show();
            }
        }
        /// <summary>
        /// Shows the previous page with the given transition.
        /// </summary>
        /// <param name="transitionType">
        /// </param>
        internal void ShowPreviousPage(
            PageTransitionType transitionType = PageTransitionType.SlideBackAndFade,
            object additionalData             = null)
        {
            Log($"{nameof(MainWindowViewModel)}.{nameof(ShowPreviousPage)}: Start");

            UserControl newPageControl = null;

            if (m_PageList.Count > 0)
            {
                newPageControl = m_PageList.Pop();

                Log($"  Removed {newPageControl} from stack.");

                if (m_PageList.Count == 1)
                {
                    Log("  There is now 1 item in the stack.");
                }
                else
                {
                    Log($"  There are now {m_PageList.Count} items in the stack.");
                }
            }
            else
            {
                Log($"  The page list stack is empty.");
            }

            if (m_PageList.Count > 0)
            {
                newPageControl = m_PageList.Peek();

                Log($"  New page is {newPageControl}.");
            }

            if (additionalData != null)
            {
                if (newPageControl is DirectoryView)
                {
                    IHashAlgorithim hashAlgorithim = ((ChecksumAlgorithim)additionalData).GetAlgorithimInterface();

                    ((DirectoryView)newPageControl).SetHashAlgorithim(hashAlgorithim);
                }
            }

            // Set back button text.

            if (newPageControl is null)
            {
                newPageControl = new DirectoryView(this);
            }

            CurrentPage = GetPageEnumerationType(newPageControl);

            m_PageTransition.TransitionType = transitionType;
            m_PageTransition.ShowPage(newPageControl);

            ShowStatusMessage(string.Empty, false);

            Log($"{nameof(MainWindowViewModel)}.{nameof(ShowPreviousPage)}: End");
        }
 public Hasher(IHashAlgorithim algorithim)
 {
     m_Algorithim = algorithim;
 }
 public void SetHashAlgorithim(IHashAlgorithim hashAlgorithim)
 {
     m_ViewModel.HashAlgorithim = hashAlgorithim;
 }