예제 #1
0
        public void Initialise()
        {
            testSourcePath            = @"C:\Users\Dj Music\Documents\visual studio 2015\Projects\MusicMoverApp\TestFiles\Source";
            testTargetPath            = @"C:\Users\Dj Music\Documents\visual studio 2015\Projects\MusicMoverApp\TestFiles\Target";
            testFileMover             = new FileMover();
            testCopyFileName          = "01. DJ Jay Rock - Intro.mp3";
            testCopyDestinationFile   = Path.Combine(testTargetPath, testCopyFileName);
            testDeleteFileName        = "Porky Pig - That's All Folks.mp3";
            testDeleteSourceFile      = Path.Combine(testSourcePath, testDeleteFileName);
            testDeleteDestinationFile = Path.Combine(testTargetPath, testDeleteFileName);

            // create target directory if it doesnt exist
            if (!Directory.Exists(testTargetPath))
            {
                Directory.CreateDirectory(testTargetPath);
            }

            // clean up previously copied file
            if (File.Exists(testCopyDestinationFile))
            {
                File.Delete(testCopyDestinationFile);
            }

            // copy file to be deleted
            if (!File.Exists(testDeleteDestinationFile))
            {
                File.Copy(testDeleteSourceFile, testDeleteDestinationFile);
            }
        }
예제 #2
0
        /// <summary>
        /// create new output file stream and don't write the ID3v2 block to it
        /// </summary>
        /// <remarks>
        /// makes a backup as it's re-writing the audio
        /// Always need to re-initialise the mp3 file wrapper if you use it after this runs
        /// </remarks>
        /// <param name="bakFileInfo">location of backup file - must be on same drive</param>
        private void RewriteFileNoV2tag(FileInfo bakFileInfo)
        {
            // generate a temp filename in the target's directory
            string   tempName     = Path.ChangeExtension(_sourceFileInfo.FullName, "$$$");
            FileInfo tempFileInfo = new FileInfo(tempName);

            using (FileStream writeStream = tempFileInfo.Open(FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
            {
                CopyAudioStream(writeStream);

                // if the stream copies without error, update the start of the audio
                _audioStart = 0;

                // now overwrite or append the ID3v1 tag to new file
                WriteID3v1(writeStream);
            }

            // replace the original file, delete new file if fail
            try
            {
                FileMover.FileMove(tempFileInfo, _sourceFileInfo, bakFileInfo);
            }
            catch
            {
                tempFileInfo.Delete();
                throw;
            }
        }
예제 #3
0
        public FileSorting(int priority,
                           FileFinder[] fileFinder,
                           FileFilter[] fileFilter,
                           FileInformationExtractor[] fileInformationExtractor,
                           FileInformationMapper[] fileInformationMapper,
                           FileInformationFilter[] fileInformationFilter,
                           FilePathCreator filePathCreator,
                           FilePathCreator backupFilePathCreator,
                           FileMover fileMover,
                           FileContentChanger[] fileContentChanger,
                           FileIndexer[] fileIndexer)
        {
            Priority   = priority;
            FileFinder = fileFinder ?? throw new ArgumentNullException("fileFinder");
            FileFilter = fileFilter ?? throw new ArgumentNullException("fileFilter");
            FileInformationExtractor = fileInformationExtractor ?? throw new ArgumentNullException("fileInformationExtractor");
            FileInformationMapper    = fileInformationMapper ?? throw new ArgumentNullException(nameof(fileInformationMapper));
            FileInformationFilter    = fileInformationFilter ?? throw new ArgumentNullException("fileInformationFilter");
            FilePathCreator          = filePathCreator ?? throw new ArgumentNullException("filePathCreator");
            BackupFilePathCreator    = backupFilePathCreator;
            FileMover          = fileMover ?? throw new ArgumentNullException("fileMover");
            FileContentChanger = fileContentChanger ?? throw new ArgumentNullException("fileConentChanger");
            FileIndexer        = fileIndexer ?? throw new ArgumentNullException("indexer");

            if (fileFinder.Length == 0)
            {
                throw new ArgumentException("Minimal one fileFinder must be availible");
            }
            if (fileInformationExtractor.Length == 0)
            {
                throw new ArgumentException("Minimal one FileInformationExtractor must be availible");
            }
        }
        public void TestMethodMoveArchive()
        {
            string srcFullFileName  = Path.Combine(SourceFolderTest, SourceFileName);
            string arcFullFileName  = FileCompressor.GetArchiveFileName(srcFullFileName);
            string arcFileName      = Path.GetFileName(arcFullFileName);
            string destFullFileName = Path.Combine(TargetFolderTest, arcFileName);

            string[] sourceFiles;
            string[] sourceZipFiles;
            string[] targetFiles;
            sourceFiles    = Directory.GetFiles(SourceFolderTest, SourceFileName);
            sourceZipFiles = Directory.GetFiles(SourceFolderTest, arcFileName);
            targetFiles    = Directory.GetFiles(TargetFolderTest, arcFileName);
            Assert.AreEqual(1, sourceFiles.Length, "Source file must be present");
            Assert.AreEqual(0, sourceZipFiles.Length, "Source compressed file must be absent");
            Assert.AreEqual(0, targetFiles.Length, "Target compreesd file must be absent");

            FileCompressor.Compress(srcFullFileName);
            sourceZipFiles = Directory.GetFiles(SourceFolderTest, arcFileName);
            Assert.AreEqual(1, sourceZipFiles.Length, "Source compressed file must be present");

            FileMover.Move(arcFullFileName, destFullFileName);
            sourceZipFiles = Directory.GetFiles(SourceFolderTest, arcFileName);
            targetFiles    = Directory.GetFiles(TargetFolderTest, arcFileName);

            Assert.AreEqual(0, sourceZipFiles.Length, "Source compressed file must be absent");
            Assert.AreEqual(1, targetFiles.Length, "Target compreesd file must be present");
        }
예제 #5
0
        //Define the event handlers.
        private static void OnChanged(object source, FileSystemEventArgs e)
        {
            var logger        = new PatchLogger(SERVICE_NAME);
            var deploymentSet = new DeploymentSet(Directory.GetFiles(Constants.POLL_DIRECTORY));

            if (deploymentSet.IsValid())
            {
                //Move files from POLL to PROCESSING directory
                FileMover.MoveFiles(Constants.POLL_DIRECTORY, Constants.INPROCESS_DIRECTORY);

                //Create FilesToProcess.txt
                FileWriter.WriteFilesToProcess(deploymentSet.AllFiles);

                //Run PatchBuilder.NET to create package
                RunPatchBuilder(@"C:\PRODUCTION\", "ServiceDeployment");

                //Move files from PROCESSING directory to patchfile
                FileMover.MoveFiles(Constants.INPROCESS_DIRECTORY, Constants.PATCH_FILES_DIRECTORY);

                //Execute DeployPatch.bat
                if (System.IO.File.Exists(Constants.BATCH_FILE_NAME))
                {
                    RunBatchFile(@"C:\PRODUCTION\");
                }
            }
            else
            {
                logger.EventLog.WriteEntry("Deployment set is invalid. Nothing deployed.", EventLogEntryType.Error);
            }
        }
예제 #6
0
        private static void RenameInteriorFiles()
        {
            // @"H:\GoogleFinanceData\equity\usa\minute\"
            string basepath = @"I:\Dropbox\JJ\data\equity\usa\minute";

            FileMover.RenameInteriorFiles(new DirectoryInfo(basepath));
        }
예제 #7
0
        public void TestJjNames()
        {
            FileInfo jjlistpath = new FileInfo(@"I:\Dropbox\JJ\symbols.txt");
            var      ret        = FileMover.CheckJJList(jjlistpath);

            Assert.IsTrue(ret);
        }
예제 #8
0
        public void MovesMinuteFiles()
        {
            bool ret = true;

            FileMover.CopyMinuteFiles(new DirectoryInfo(@"L:\GoogleFinanceData\equity\usa\minute\"));
            Assert.IsTrue(ret);
        }
예제 #9
0
        public void FileMoveTestLockedTarget()
        {
            FileInfo sourceLocation = new FileInfo(TestContext.TestName + ".new");
            FileInfo targetLocation = new FileInfo(TestContext.TestName + ".txt");
            FileInfo backupLocation = new FileInfo(TestContext.TestName + ".bak");

            File.WriteAllText(sourceLocation.FullName, "source");
            File.WriteAllText(targetLocation.FullName, "target");
            File.WriteAllText(backupLocation.FullName, "backup");

            try
            {
                using (FileStream locker = targetLocation.OpenRead())
                {
                    FileMover.FileMove(sourceLocation, targetLocation, backupLocation);
                }
                Assert.Fail("should have thrown an exception");
            }
            catch
            {}

            // check the original files are still there
            Assert.AreEqual(File.ReadAllText(sourceLocation.FullName), "source");
            Assert.AreEqual(File.ReadAllText(targetLocation.FullName), "target");
            Assert.AreEqual(File.ReadAllText(backupLocation.FullName), "backup");

            sourceLocation.Delete();
            targetLocation.Delete();
            backupLocation.Delete();
        }
예제 #10
0
        static void Main(string[] args)
        {
            FileMover   fileMover   = new FileMover();
            FileRenamer fileRenamer = new FileRenamer();

            fileMover.FlattenFolder();
            fileRenamer.CompressFileNumbers();
        }
예제 #11
0
        public void appendNumsToDupFileName()
        {
            var mover   = new FileMover();
            var newName = mover.Move("temp.jpg", @"dev\a.jpg");

            Assert.AreEqual(@"dev\a.2.jpg", newName);

            Assert.IsTrue(File.Exists(@"dev\a.1.jpg"));
        }
예제 #12
0
        /// <summary>
        ///  Moves the minute data symbol folder up one folder to correct a bug
        /// </summary>
        /// <param name="sender">the button being clicked</param>
        /// <param name="e">No event args</param>
        private void buttonMoveData_Click(object sender, EventArgs e)
        {
            string directory = GetSaveDirectory();

            if (directory.Length > 0)
            {
                DirectoryInfo info = new DirectoryInfo(directory);
                FileMover.CopyDailyFiles(info);
            }
        }
        private void ProcessFileMover(ConfigurationStepModel csm)
        {
            if (csm.ParametersArray.Length == 2)
            {
                string fileFromMove = csm.ParametersArray[0];
                string fileToMove   = csm.ParametersArray[1];

                FileMover fm = new FileMover(fileFromMove, fileToMove);
                workers.Add(fm);
            }
        }
예제 #14
0
        public MainWindow()
        {
            InitializeComponent();


            folderWatcher      = new FolderWatcher(Log, Dispatcher);
            printerMultiplexer = new PrinterMultiplexer(Log, Dispatcher);
            fileMover          = new FileMover(Log, Dispatcher);
            // TODO Add completion detection (in the multiplexer module)

            folderWatcher.Outputs.SetOutput(FolderWatcher.NextModule, printerMultiplexer);
            printerMultiplexer.Outputs.SetOutput(PrinterMultiplexer.NextModule, fileMover);

            // Initializes some things to use in PrintButton testing.
            ticket = new PrintTicket();
        }
예제 #15
0
        public MainWindow()
        {
            InitializeComponent();

            // Initialize modules, with our logging method.
            folderWatcher = new FolderWatcher(Log, Dispatcher);
            imageReviewer = new ImageReviewer(Log, Dispatcher);
            acceptMover   = new FileMover(Log, Dispatcher);
            rejectMover   = new FileMover(Log, Dispatcher);

            // Connect the modules in their intended orders.
            folderWatcher.Outputs.SetOutput(FolderWatcher.NextModule, imageReviewer);
            imageReviewer.Outputs.SetOutput(ImageReviewer.AcceptOutput, acceptMover);
            imageReviewer.Outputs.SetOutput(ImageReviewer.RejectOutput, rejectMover);

            // Load the first image whenever it's ready.
            nextImage();
        }
        public void TestMethodMove()
        {
            string srcFullFileName  = Path.Combine(SourceFolderTest, SourceFileName);
            string destFullFileName = Path.Combine(TargetFolderTest, SourceFileName);

            string[] sourceFiles;
            string[] targetFiles;
            sourceFiles = Directory.GetFiles(SourceFolderTest, SourceFileName);
            targetFiles = Directory.GetFiles(TargetFolderTest, SourceFileName);
            Assert.AreEqual(1, sourceFiles.Length, "Source file must be present");
            Assert.AreEqual(0, targetFiles.Length, "Target file must be absent");

            FileMover.Move(srcFullFileName, destFullFileName);
            sourceFiles = Directory.GetFiles(SourceFolderTest, SourceFileName);
            targetFiles = Directory.GetFiles(TargetFolderTest, SourceFileName);

            Assert.AreEqual(0, sourceFiles.Length);
            Assert.AreEqual(1, targetFiles.Length);
        }
예제 #17
0
        /// <summary>
        /// create new output file stream and write the ID3v2 block to it
        /// </summary>
        /// <remarks>
        /// makes a backup as it's modifying the tags and re-writing the audio
        /// </remarks>
        /// <param name="bakFileInfo">location of backup file - must be on same drive</param>
        private void RewriteFile(FileInfo bakFileInfo)
        {
            // generate a temp filename in the target's directory
            string   tempName     = Path.ChangeExtension(_sourceFileInfo.Name, "$$$");
            FileInfo tempFileInfo = new FileInfo(tempName);

            using (FileStream writeStream = tempFileInfo.Open(FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
            {
                // write an ID3v2 tag to new file
                FrameManager.Serialize(TagModel, writeStream);

                uint newAudioStart = (uint)writeStream.Position;

                CopyAudioStream(writeStream);

                // if the stream copies without error, update the start of the audio
                _audioStart = newAudioStart;

                // now overwrite or append the ID3v1 tag to new file
                WriteID3v1(writeStream);
            }

            // replace the original file, delete new file if fail
            try
            {
                FileMover.FileMove(tempFileInfo, _sourceFileInfo, bakFileInfo);
            }
            catch
            {
                tempFileInfo.Delete();
                throw;
            }

            // re-initialise the mp3 file wrapper
            // this is a bit expensive, as having just updated the file on disk,
            // the user will probably just throw away the mp3file anyway.
            // however, it's logically necessary given the mp3file model
            // (i.e. that the mp3file is an image of the current mp3 file on disk).
            // TODO: lazy-initialise the mp3file so it only gets done if needed again.
            Initialise();
        }
예제 #18
0
        static void Main(string[] args)
        {
            var copyTargets = new List <CopyTarget>()
            {
                new CopyTarget("C:\\Temp\\Input\\Motus"),
                new ArchiveTarget("C:\\Temp\\Archive\\Motus")
            };

            using (IFileObserver observer = new TimerFileObserver(5, 1, 300))
            {
                IFileMover mover = new FileMover(observer, copyTargets);

                var lockObject = new object();

                observer.AddFile("C:\\Temp\\Motus\\required1.txt", true);
                observer.AddFile("C:\\Temp\\Motus\\required2.txt", true);
                observer.AddFile("C:\\Temp\\Motus\\optional1.txt", false);
                observer.AddFile("C:\\Temp\\Motus\\optional2.txt", false);

                observer.CheckingForFirstFile += (sender, e) => Console.WriteLine("Checking for first file...");
                observer.WatchingForAllFiles  += (sender, e) => Console.WriteLine("First file observed. Watching for remaining files.");
                observer.StoppedObserving     += (sender, e) => Console.WriteLine("Stopped observing files.");
                observer.AllFilesObserved     += (sender, e) => Console.WriteLine("All expected files observed.");

                mover.OneFileCopied   += (sender, e) => Console.WriteLine($"Source: {e.File.FileName} | Target: {e.Target}");
                mover.OneFileDeleted  += (sender, e) => Console.WriteLine($"Source: {e.File.FileName}");
                mover.AllFilesCopied  += (sender, e) => Console.WriteLine($"All files copied.");
                mover.AllFilesDeleted += (sender, e) => Console.WriteLine($"All files deleted.");
                mover.AllFilesMoved   += (sender, e) => Console.WriteLine($"All files moved.");

                observer.AllFilesObserved += (sender, e) =>
                {
                    mover.Move();
                    observer.StartObserving();
                };

                observer.StartObserving();

                Console.ReadLine();
            }
        }
예제 #19
0
        static void Main(string[] args)
        {
            IUserInterface userInterface = new UserInterface();


            if (args.Length < 2)
            {
                userInterface.WriteError("Merci de fournir : le dossier de lecture des images, et le dossier de rangement des images");
                return;
            }
            var sourceFolder = args[0];
            var targetFolder = args[1];

            IPhotoSource source = new PhotoSource(sourceFolder);
            IFileMover   mover  = new FileMover(targetFolder);


            var engine = new PhotoSorterEngine(mover, source, userInterface);

            engine.Run();
        }
예제 #20
0
        public void FileMoveTest()
        {
            FileInfo sourceLocation = new FileInfo(TestContext.TestName + ".new");
            FileInfo targetLocation = new FileInfo(TestContext.TestName + ".txt");
            FileInfo backupLocation = new FileInfo(TestContext.TestName + ".bak");

            File.WriteAllText(sourceLocation.FullName, "source");
            File.WriteAllText(targetLocation.FullName, "target");
            File.WriteAllText(backupLocation.FullName, "backup");

            FileMover.FileMove(sourceLocation, targetLocation, backupLocation);

            Assert.AreEqual(File.ReadAllText(targetLocation.FullName), "source");
            Assert.AreEqual(File.ReadAllText(backupLocation.FullName), "target");
            bool exists = sourceLocation.Exists;

            Assert.IsFalse(exists);

            targetLocation.Delete();
            backupLocation.Delete();
        }
예제 #21
0
 public void AddNewItem1(FileSystemEventArgs e, DataItems items, IDataSerializer dataSerializer, string targetFolder)
 {
     try
     {
         string sourceFilePath = e.FullPath;
         //string archiveName = FileCompressor.GetArchiveFileName(e.FullPath);
         string fileName     = Path.GetFileName(sourceFilePath);
         string destFilePath = targetFolder;
         Task.Run(
             () =>
         {
             if (FileMover.Move(sourceFilePath, destFilePath))
             {
                 FileCompressor.Compress(destFilePath);
                 dataSerializer.Store(items);
             }
         }
             );
     }
     catch (Exception ex)
     {
         _log.Error(ex);
     }
 }
예제 #22
0
        static void Main(string[] args)
        {
            bool      bShowHelp      = false;
            string    strDestination = "";
            string    strSource      = "";
            string    strError       = "";
            FileMover _Mover         = new FileMover();

            try
            {
                foreach (string arg in args)
                {
                    if (arg.ToLower() == "/help" ||
                        arg.ToLower() == "-?" ||
                        arg.ToLower() == "/?")
                    {
                        bShowHelp = true;
                    }

                    else if (arg.ToLower().Substring(0, 1) == "/")
                    {
                        if (arg.ToLower().Substring(1, 1) == "o")
                        {
                            try {
                                if (arg.ToLower().Substring(2, 1) == "h")
                                {
                                    _Mover.m_OlderThanHours = Convert.ToDouble(arg.Substring(3));
                                }
                                else
                                {
                                    _Mover.m_OlderThanDays = Convert.ToDouble(arg.Substring(2));
                                    //_Mover.m_OlderThanDays = Convert.ToInt32(arg.Substring(2));
                                }
                            }
                            catch (FormatException ex)
                            {
                                strError += "not a number: " + arg + "\r\n";
                            }
                        }
                        else if (arg.ToLower().Substring(1, 1) == "c")
                        {
                            _Mover.m_DeleteOnly = true;
                        }
                        else if (arg.ToLower().Substring(1, 1) == "f")
                        {
                            _Mover.m_DeleteSubDir = true;
                        }
                        else if (arg.ToLower().Substring(1, 1) == "d")
                        {
                            try
                            {
                                _Mover.m_DebugLevel = Convert.ToInt32(arg.Substring(2));
                            }
                            catch (FormatException ex)
                            {
                                strError += "not a number: " + arg + "\r\n";
                            }
                        }
                        else
                        {
                            strError += "unknown argument: " + arg + "\r\n";
                        }
                    }
                    else
                    {
                        if (strSource == "")
                        {
                            strSource = arg;
                        }
                        else
                        {
                            strDestination = arg;
                        }
                    }
                }
                if (bShowHelp)
                {
                    PrintHelp();
                }
                else
                {
                    if (strSource == "")
                    {
                        strError += "no source specified \r\n";
                    }
                    if (strDestination == "" && !_Mover.m_DeleteOnly)
                    {
                        strError += "no destination specified \r\n";
                    }
                    if (strDestination != "" && _Mover.m_DeleteOnly)
                    {
                        strError += "destination specified but Delete-Flag set\r\n";
                    }
                    if (strError != "")
                    {
                        strError += "use /? for help \r\n";
                        throw new ArgumentException(strError);
                    }
                    else
                    {
                        _Mover.m_Destination = strDestination;
                        _Mover.m_Source      = strSource;
                        _Mover.Run();
                    }
                }
            }


            catch (ArgumentException ex)
            {
                Console.Write(ex.Message);
            }
            finally
            {
            }
        }
예제 #23
0
        static void Main(string[] args)
        {
            FileMover fileMover = new FileMover();

            fileMover.FlattenFolder();
        }
예제 #24
0
 public void RenamesInteriorFileInZipFile()
 {
     FileMover.RenameInteriorFiles(new DirectoryInfo(@"H:\GoogleFinanceData\equity\usa\minute\"));
     Assert.IsTrue(true);
 }
예제 #25
0
 public void MovesFiles()
 {
     FileMover.CopyDailyFiles(new DirectoryInfo(@"H:\GoogleFinanceData\NYSE\"));
     Assert.IsTrue(File.Exists(@"H:\GoogleFinanceData\equity\usa\minute\ATT\20150519_trade.zip"));
 }
예제 #26
0
 public void SetUp()
 {
     _sut = new FileMover();
     Directory.CreateDirectory(SourceDirectory);
     Directory.CreateDirectory(DestinationDirectory);
 }
예제 #27
0
 public virtual void MoveFile(string archiveName, string destFilePath)
 {
     FileMover.Move(archiveName, destFilePath);
 }
예제 #28
0
 private void interiorFileNameToolStripMenuItem_Click(object sender, EventArgs e)
 {
     FileMover.RenameInteriorFiles(new DirectoryInfo(@"H:\GoogleFinanceData\equity\usa\minute\"));
 }