Example #1
0
 public async Task <bool> FileExistsAndOverwriteNotCheckedAsync()
 {
     if (!await FileInfo.CheckIfFileExistsInOutput(WindowInputs.OutputDirectory) ||
         WindowInputs.OverwriteCheckBox == true)
     {
         return(true);
     }
     Logger.Log("File already exists - Overwrite not checked - Skipping file");
     WindowInputs.IncrementProgressBar();
     return(false);
 }
Example #2
0
 public async Task <bool> FileExistsAndCopyEnabledAndDirectoryDefaultAsync()
 {
     if (!await FileInfo.CheckIfFileExistsInOutput(WindowInputs.OutputDirectory) ||
         WindowInputs.OverwriteCheckBox != true ||
         WindowInputs.CopyCheckBox != true || WindowInputs.OutputDirectory != OriginalDirectory)
     {
         return(true);
     }
     Logger.Log("File already exists - Can't overwrite a file already in use - Skipping file");
     WindowInputs.IncrementProgressBar();
     return(false);
 }
Example #3
0
        private async void StartOperation(object sender, RoutedEventArgs e)
        {
            try
            {
                WindowInputs = new WindowInputs(_window);
                WindowInputs.SetStartButtonContent("Stop !!!");
                WindowInputs.SetProgressBarPercentage(false);
                WindowInputs.SetProgressBarValue(0);
                Logger.Clear();
                if (FilePaths == null)
                {
                    Logger.Log("No files selected");
                    return;
                }

                WindowInputs.SetProgressBarPercentage(true);
                Logger.Log("Starting operation - Please wait");
                _window.StartButton.Click += ShowStopWindow;
                WindowInputs.SetProgressBarMaxmimum(FilePaths.Length);
                foreach (var file in FilePaths)
                {
                    var inMemoryRepository = new InMemoryRepository();
                    var fileService        = new FileService(file, inMemoryRepository);
                    await fileService.CreateFileRepository();

                    var fileModel = await inMemoryRepository.Read();

                    fileModel.OutputDirectory = WindowInputs.OutputDirectory;
                    var errorChecking = new ErrorChecking(fileService, WindowInputs, Path.GetDirectoryName(file), Logger);
                    //Under kan endres hva som skjer med navnet
                    if (WindowInputs.SpecificStringThis != "")
                    {
                        await fileService.ReplaceSpecificString(WindowInputs.SpecificStringThis,
                                                                WindowInputs.SpecificStringWith);
                    }
                    if (WindowInputs.FromIndex != "")
                    {
                        await fileService.SubstringThis(WindowInputs.FromIndex, WindowInputs.ToIndex);
                    }
                    if (WindowInputs.TrimCheckBox == true)
                    {
                        await fileService.Trim();
                    }
                    await fileService.UpperCase(WindowInputs.UppercaseCheckBox);

                    Logger.Log(fileModel.LogStartProcessing);
                    //Forskjellig error checking
                    if (await errorChecking.DirectoryExistsOrNotAsync() == false)
                    {
                        break;
                    }
                    if (await errorChecking.FileExistsAndCopyEnabledAndDirectoryDefaultAsync() == false)
                    {
                        continue;
                    }
                    if (await errorChecking.FileExistsAndOverwriteNotCheckedAsync() == false)
                    {
                        continue;
                    }
                    await errorChecking.FileExistsAndOverwriteCheckedAsync();

                    //Output ting her nede
                    await CopyOrMoveFilesAsync(WindowInputs.OutputDirectory, WindowInputs.CopyCheckBox,
                                               (bool)WindowInputs.OverwriteCheckBox, fileModel);

                    WindowInputs.IncrementProgressBar();
                    Logger.Log(fileModel.LogFinishedProcessing);
                }

                Logger.Log("Operation finished");
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
            finally
            {
                _window.StartButton.Click -= ShowStopWindow;
                WindowInputs.SetStartButtonContent("Start");
                FilePaths = null;
                WindowInputs.SetSelectedFilesText("");
                _window.InformationList.ScrollIntoView(_window.InformationList.Items[^ 1]);