コード例 #1
0
        public RenameAndMoveOperation(FileInfo originalFile, DirectoryInfo targetDirectory, DateTime documentDate,
            string documentTitle)
        {
            OriginalFile = originalFile;
            TargetDirectory = targetDirectory;
            DocumentDate = documentDate;
            DocumentTitle = documentTitle;
            DocumentExtension = Path.GetExtension(OriginalFile.Name);

            NewFilename = string.Format(Settings.RenamePattern, DocumentDate, DocumentTitle, DocumentExtension);

            _operation = new MoveOperation(OriginalFile,
                new FileInfo(Path.Combine(TargetDirectory.FullName, NewFilename)));
        }
コード例 #2
0
        public void Can_Do_Move_Operation()
        {
            // arrange
            var file = Path.GetTempFileName();
            var newFilename = Path.GetTempPath() + Guid.NewGuid() + ".tmp";
            var operation = new MoveOperation(
                new FileInfo(file), new FileInfo(newFilename));

            // assume
            File.Exists(file).ShouldBe(true);
            File.Exists(newFilename).ShouldBe(false);

            // act
            operation.Do();

            // assert
            File.Exists(file).ShouldBe(false);
            File.Exists(newFilename).ShouldBe(true);
        }
コード例 #3
0
        public void MoveDocument()
        {
            try
            {
                var filename = Path.Combine(SelectedTargetDirectory.FullName, SelectedSourceFile.Name);
                var newFile = new FileInfo(filename);
                var operation = new MoveOperation(SelectedSourceFile, newFile);
                OperationsStack.DoOperation(operation);

                AfterAction();
            }
            catch (Exception ex)
            {
                Log.Error("Error moving document.", ex);
                MessageBox.Show("Error:" + ex.Message);
            }
        }