Exemple #1
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 fileInfo = new FileInputs(file)
                    {
                        Copy = WindowInputs.CopyCheckBox, OutputDirectory = WindowInputs.OutputDirectory
                    };
                    var fileNameEditor = new FileNameEditor(fileInfo);
                    var errorChecking  = new ErrorChecking(fileInfo, WindowInputs, Logger);
                    //Under kan endres hva som skjer med navnet

                    if (WindowInputs.SpecificStringThis != "")
                    {
                        fileNameEditor.ReplaceSpecificString(WindowInputs.SpecificStringThis,
                                                             WindowInputs.SpecificStringWith);
                    }
                    if (WindowInputs.FromIndex != "")
                    {
                        fileNameEditor.SubstringThis(WindowInputs.FromIndex, WindowInputs.ToIndex);
                    }
                    if (WindowInputs.TrimCheckBox == true)
                    {
                        fileNameEditor.Trim();
                    }
                    fileNameEditor.UpperCase(WindowInputs.UppercaseCheckBox);
                    Logger.Log(fileInfo.LogStartProcessing);
                    //Forskjellig error checking

                    if (errorChecking.DirectoryExistsOrNot() == false)
                    {
                        break;
                    }
                    if (errorChecking.FileExistsAndCopyEnabledAndDirectoryDefault() == false)
                    {
                        continue;
                    }
                    if (errorChecking.FileExistsAndOverwriteNotChecked() == false)
                    {
                        continue;
                    }
                    errorChecking.FileExistsAndOverwriteChecked();
                    //Output ting her nede

                    await CopyOrMoveFilesAsync(fileInfo.OutputDirectory, fileInfo, WindowInputs.CopyCheckBox,
                                               (bool)WindowInputs.OverwriteCheckBox);

                    WindowInputs.IncrementProgressBar();
                    Logger.Log(fileInfo.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]);
Exemple #2
0
 public FileNameEditor(FileInputs file)
 {
     FileInfo = file;
 }