示例#1
0
        private bool CopyFile(FolderMap baseFolder, string aFile)
        {
            // Just an input check
            if (aFile == null || aFile == "")
            {
                return(false);
            }

            if (_commandHandler.IgnoreFile(baseFolder, aFile))
            {
                return(false);
            }
            string aTarget = aFile.Replace(baseFolder.Source, baseFolder.Target);

            bool doCopy = _commandHandler.NeedToCopy(baseFolder, aFile, aTarget);

            if (doCopy)
            {
                ProcessInfoEvent?.Invoke(this, new ProcessInfoEventArgs("Copy File: " + aFile + " to " + aTarget));
                if (_commandHandler.CanReadFile(aFile))
                {
                    // Try if we can copy the file.
                    _commandHandler.CopyFile(aFile, aTarget);
                }
            }
            return(doCopy);
        }
示例#2
0
        private void ThisDirectory(FolderMap baseFolder, string aFolder)
        {
            if (!FolderExists(aFolder))
            {
                return;
            }

            if (System.Text.RegularExpressions.Regex.IsMatch(aFolder, "(Temporary Internet Files)$"))
            {
                return;
            }

            ProcessInfoEvent?.Invoke(this, new ProcessInfoEventArgs("Process directory: " + aFolder));

            if (!CreateTargetDirectory(baseFolder, aFolder))
            {
                return;
            }

            string[] theFiles;
            int      nrOfCopiedFiles = 0;

            // Now copy files
            try
            {
                theFiles = _fileSystem.Directory.GetFiles(aFolder);
                foreach (string aFile in theFiles)
                {
                    if (CopyFile(baseFolder, aFile))
                    {
                        nrOfCopiedFiles += 1;
                    }
                }
                Logger.Info($"Copied {nrOfCopiedFiles} of {theFiles.Length} in folder {aFolder}");
            }
            catch (UnauthorizedAccessException ex)
            {
                _commandHandler.HandleException("Could not read directories of folder: " + aFolder + "(" + ex.Message + ")", ex);
            }

            ProcessSubfolders(baseFolder, aFolder);
        }
示例#3
0
        public bool CreateDirectory(string theTarget)
        {
            if (_fileSystem.Directory.Exists(theTarget))
            {
                return(true);
            }

            bool result = false;

            // Target folder does not exist Create it
            ProcessInfoEvent?.Invoke(this, new ProcessInfoEventArgs("Create directory: " + theTarget));
            try
            {
                _fileSystem.Directory.Create(theTarget);
                result = true;
            }
            catch (DirectoryNotFoundException ex)
            {
                _exceptionHandler.HandleException("Failed to create directory " + theTarget + "(" + ex.Message + ")", ex);
                result = false;
            }
            return(result);
        }
示例#4
0
 public void LogEvent(string message)
 {
     ProcessInfoEvent?.Invoke(this, new ProcessInfoEventArgs(message));
 }