Example #1
0
        /// <summary>
        /// Generate the list of files to include in the package.
        /// </summary>
        /// <param name="result">The build result.</param>
        /// <param name="fileSystem">The file system.</param>
        /// <returns>A list of all the files to be included.</returns>
        /// <remarks>
        /// This method uses custom logic for handling "**"
        /// </remarks>
        private List <string> GenerateFileList(IIntegrationResult result, IFileSystem fileSystem)
        {
            var fileList        = new List <string>();
            var allDirsWildcard = Path.DirectorySeparatorChar + "**" + Path.DirectorySeparatorChar;

            // Handle any wildcard characters
            if (this.SourceFile.Contains("*") || this.SourceFile.Contains("?"))
            {
                var possibilities = new List <string>();
                var actualPath    = Path.IsPathRooted(this.SourceFile) ? this.SourceFile : result.BaseFromWorkingDirectory(this.SourceFile);

                // Check for **, if it exists, then split the search pattern and use the second half to find all
                // matching files
                if (actualPath.Contains(allDirsWildcard))
                {
                    var position = actualPath.IndexOf(allDirsWildcard);
                    var path     = actualPath.Substring(0, position);
                    var pattern  = actualPath.Substring(position + 4);
                    possibilities.AddRange(fileSystem.GetFilesInDirectory(path, pattern, SearchOption.AllDirectories));
                }
                else
                {
                    // Otherwise, just use the plain ordinary search pattern
                    var position = actualPath.IndexOfAny(new char[] { '*', '?' });
                    position = actualPath.LastIndexOf(Path.DirectorySeparatorChar, position);
                    var path    = actualPath.Substring(0, position);
                    var pattern = actualPath.Substring(position + 1);
                    possibilities.AddRange(fileSystem.GetFilesInDirectory(path, pattern, SearchOption.TopDirectoryOnly));
                }

                // The current list of files is just a set of possibilities, now need to check that they completely
                // match the search criteria and they have not already been added.
                foreach (var possibility in possibilities)
                {
                    if (!fileList.Contains(possibility))
                    {
                        if (PathUtils.MatchPath(actualPath, possibility, false))
                        {
                            fileList.Add(possibility);
                        }
                    }
                }
            }
            else
            {
                // Make sure the file is rooted
                string actualPath = Path.IsPathRooted(this.SourceFile) ? this.SourceFile : result.BaseFromWorkingDirectory(this.SourceFile);

                // Only add it to the list if it doesn't already exist
                if (!fileList.Contains(actualPath))
                {
                    fileList.Add(actualPath);
                }
            }

            return(fileList);
        }
 private void CopyRootFiles(string solutionDirRoot, string dir)
 {
     foreach (string file in _fileSystem.GetFilesInDirectory(solutionDirRoot, "*.*"))
     {
         string targetDir = Path.Combine(dir, _fileSystem.GetFileNameWithExtension(file));
         _fileSystem.Copy(file, targetDir);
         if (FileShouldHaveTokensReplaced(targetDir))
         {
             _fileTokenReplacer.Replace(targetDir);
         }
     }
 }
Example #3
0
        private void AddFilesFromDirectory(string dir, string filter)
        {
            if (_fileSystem.DirectoryExists(dir))
            {
                foreach (string file in _fileSystem.GetFilesInDirectory(dir, filter))
                {
                    AddFileToList(file);
                }

                if (_recurse)
                {
                    try
                    {
                        foreach (string subdir in _fileSystem.GetDirectoriesInDirectory(dir))
                        {
                            AddFilesFromDirectory(subdir, filter);
                        }
                    }
                    catch (UnauthorizedAccessException)
                    {
                        Console.Error.WriteLineAsync("Unauthorized access exception for directory: " + dir);
                    }
                }
            }
        }
Example #4
0
        public static void UseWgrib2ToFindStartAndEndDatesOnWGribFiles(
            WrfConfiguration config, out DateTime startDate, out DateTime endDate,
            IProcessLauncher processLauncher, IFileSystem fileSystem)
        {
            string dataDirectory = config.DataDirectory;

            string[] files = fileSystem.GetFilesInDirectory(dataDirectory);

            // go past the period and the 'f'. ex: .f003.
            string[] orderedFiles = files.OrderByDescending(n =>
                                                            int.Parse(n.Substring(n.LastIndexOf('.') + 2))).ToArray();

            string lastFile  = orderedFiles[0];
            string firstFile = orderedFiles[orderedFiles.Length - 1];

            lastFile  = Path.Combine(dataDirectory, lastFile);
            firstFile = Path.Combine(dataDirectory, firstFile);

            string wgrib2Path = config.WGRIB2FilePath;

            //352:18979996:start_ft=2016071706
            string stdOut =
                processLauncher.LaunchProcessAndCaptureSTDOUT(wgrib2Path, $"-start_ft {firstFile}");

            startDate = GetDateTimeForStdOut(stdOut);

            stdOut =
                processLauncher.LaunchProcessAndCaptureSTDOUT(wgrib2Path, $"-start_ft {lastFile}");

            endDate = GetDateTimeForStdOut(stdOut);
        }
Example #5
0
        public static List <string> RemoveTempFilesInWRFDirectory(WrfConfiguration config,
                                                                  IFileSystem fileSystem, ILogger iLogger)
        {
            List <string> ret = new List <string>();

            string[] files = fileSystem.GetFilesInDirectory(config.WRFDirectory);
            foreach (string file in files)
            {
                foreach (string prefix in PrefixesOfFilesToDeleteFromWRFDirectory)
                {
                    if (PlatformIndependentGetFilename(file).StartsWith(prefix))
                    {
                        ret.Add(file);
                        fileSystem.DeleteFile(file);
                        //iLogger.LogLine($"\t...deleted file {file}");
                    }
                }
                foreach (string suffix in SufixesOfFilesToDeleteFromWRFDirectory)
                {
                    if (PlatformIndependentGetFilename(file).EndsWith(suffix))
                    {
                        ret.Add(file);
                        fileSystem.DeleteFile(file);
                        //iLogger.LogLine($"\t...deleted file {file}");
                    }
                }
            }
            return(ret);
        }
Example #6
0
        public List <string> FindDotFntFileNamePartialMatchesFromFileResource(string providedAssetPathNameWithoutAssemblyOrExtension)
        {
            var files = _fileSystem.GetFilesInDirectory(_startUpProperties.FontFolder, "*.*", SearchOption.AllDirectories);

            var matches = files.Where(x => x.Contains(providedAssetPathNameWithoutAssemblyOrExtension)).Where(x => x.Contains(".fnt")).ToList();

            return(matches);
        }
Example #7
0
        private bool IsOutputDirectoryDirty(IEnumerable <CodegenJob> jobs, string outputDir)
        {
            var outputFolderFiles = fileSystem.GetFilesInDirectory(outputDir)
                                    .Select(file => Path.GetFullPath(file.CompletePath)).ToList();

            var expectedFiles = jobs.SelectMany(job => job.ExpectedOutputFiles);

            return(outputFolderFiles.Intersect(expectedFiles).Count() != outputFolderFiles.Count);
        }
Example #8
0
        public static string[] RetrieveNclScriptsToRun(WrfConfiguration config, IFileSystem iFileSystem)
        {
            string nclScriptsDirectory = config.ScriptsDirectory;

            List <string> ret = new List <string>();

            foreach (string file in iFileSystem.GetFilesInDirectory(nclScriptsDirectory))
            {
                ret.Add(file);
            }

            return(ret.ToArray());
        }
Example #9
0
        public static void CreateMetEmSymlinksInRealDirectory(WrfConfiguration config, IFileSystem fileSystem)
        {
            IEnumerable <string> files = fileSystem.GetFilesInDirectory(
                config.WPSDirectory).Where(m => PlatformIndependentGetFilename(m).StartsWith("met_em"));

            foreach (string file in files)
            {
                // replace windows slashes with linux slashes
                string link = Path.Combine(config.WRFDirectory, PlatformIndependentGetFilename(file)).Replace("\\", "/");
                //Console.WriteLine($"Creating symbolic link from {file} to {link}");
                fileSystem.CreateSymLink(file, link);
            }
        }
Example #10
0
 void ReadSchemas(string directory, string searchPattern, bool readOnly)
 {
     if (fileSystem.DirectoryExists(directory))
     {
         foreach (string fileName in fileSystem.GetFilesInDirectory(directory, searchPattern))
         {
             XmlSchemaCompletion schema = ReadSchema(fileName, readOnly);
             if (schema != null)
             {
                 AddSchema(schema);
             }
         }
     }
 }
Example #11
0
        private IEnumerable <string> GetFilesInDirectory(string path, string searchPattern, SearchOption searchOption)
        {
            try
            {
                return(fileSystem.GetFilesInDirectory(path, searchPattern, searchOption));
            }
            catch (UnauthorizedAccessException e)
            {
                logger.Log(LogSeverity.Error, "Unable to access the AutoCAD plugin directory.", e);
            }
            catch (IOException e)
            {
                logger.Log(LogSeverity.Error, "Error occurred while searching the AutoCAD plugin directory.", e);
            }

            return(EmptyArray <string> .Instance);
        }
Example #12
0
        public static string RetrievePathToWrfOutFile(WrfConfiguration config, IFileSystem fileSystem)
        {
            string wrfDirectory = config.WRFDirectory;

            Console.WriteLine("Looking at " + wrfDirectory);

            string supposedWrfOutFile = fileSystem.GetFilesInDirectory(wrfDirectory).Where(
                m => PlatformIndependentGetFilename(m.ToLower()).StartsWith("wrfout_")).FirstOrDefault();

            if (supposedWrfOutFile != null)
            {
                return(supposedWrfOutFile);
            }
            else
            {
                throw new MissingWrfOutFileException();
            }
        }
Example #13
0
        public void Clean()
        {
            foreach (var entry in OutputFiles)
            {
                var path     = Path.Combine(OutputDirectory, entry);
                var fileInfo = fileSystem.GetFileInfo(path);

                if (fileInfo.Exists())
                {
                    fileInfo.Delete();
                }

                var remainingFilesInFolder = fileSystem.GetFilesInDirectory(fileInfo.DirectoryPath);
                if (remainingFilesInFolder.Count == 0)
                {
                    fileSystem.DeleteDirectory(fileInfo.DirectoryPath);
                }
            }
        }
Example #14
0
        public override IEnumerable GetChildren(TreePath treePath)
        {
            if (treePath.IsEmpty())
            {
                yield return(projectRoot);
            }
            else if (treePath.LastNode == projectRoot)
            {
                foreach (var n in projectRoot.Nodes)
                {
                    yield return(n);
                }
            }
            else if (treePath.LastNode is FilesNode)
            {
                foreach (var file in testProject.TestPackage.Files)
                {
                    yield return(new FileNode(file.FullName));
                }
            }
            else if (treePath.LastNode is ReportsNode && !string.IsNullOrEmpty(fileName))
            {
                var reportDirectory = Path.Combine(Path.GetDirectoryName(fileName), "Reports");

                if (!fileSystem.DirectoryExists(reportDirectory))
                {
                    yield break;
                }

                var regex         = new Regex("{.}");
                var searchPattern = regex.Replace(testProject.ReportNameFormat, "*") + "*.xml";
                foreach (var file in fileSystem.GetFilesInDirectory(reportDirectory, searchPattern,
                                                                    SearchOption.TopDirectoryOnly))
                {
                    yield return(new ReportNode(file));
                }
            }
        }
Example #15
0
        /// <summary>
        /// Generate the list of files to include in the package.
        /// </summary>
        /// <param name="result">The build result.</param>
        /// <param name="fileSystem">The file system.</param>
        /// <returns>A list of all the files to be included.</returns>
        /// <remarks>
        /// This method uses custom logic for handling "**"
        /// </remarks>
        private List<string> GenerateFileList(IIntegrationResult result, IFileSystem fileSystem)
        {
            var fileList = new List<string>();
            var allDirsWildcard = Path.DirectorySeparatorChar + "**" + Path.DirectorySeparatorChar;

                // Handle any wildcard characters
            if (this.SourceFile.Contains("*") || this.SourceFile.Contains("?"))
            {
                var possibilities = new List<string>();
                var actualPath = Path.IsPathRooted(this.SourceFile) ? this.SourceFile : result.BaseFromWorkingDirectory(this.SourceFile);

                // Check for **, if it exists, then split the search pattern and use the second half to find all
                // matching files
                if (actualPath.Contains(allDirsWildcard))
                {
                    var position = actualPath.IndexOf(allDirsWildcard);
                    var path = actualPath.Substring(0, position);
                    var pattern = actualPath.Substring(position + 4);
                    possibilities.AddRange(fileSystem.GetFilesInDirectory(path, pattern, SearchOption.AllDirectories));
                }
                else
                {
                    // Otherwise, just use the plain ordinary search pattern
                    var position = actualPath.IndexOfAny(new char[] { '*', '?' });
                    position = actualPath.LastIndexOf(Path.DirectorySeparatorChar, position);
                    var path = actualPath.Substring(0, position);
                    var pattern = actualPath.Substring(position + 1);
                    possibilities.AddRange(fileSystem.GetFilesInDirectory(path, pattern, SearchOption.TopDirectoryOnly));
                }

                // The current list of files is just a set of possibilities, now need to check that they completely
                // match the search criteria and they have not already been added.
                foreach (var possibility in possibilities)
                {
                    if (!fileList.Contains(possibility))
                    {
                        if (PathUtils.MatchPath(actualPath, possibility, false))
                        {
                            fileList.Add(possibility);
                        }
                    }
                }
            }
            else
            {
                // Make sure the file is rooted
                string actualPath = Path.IsPathRooted(this.SourceFile) ? this.SourceFile : result.BaseFromWorkingDirectory(this.SourceFile);

                // Only add it to the list if it doesn't already exist
                if (!fileList.Contains(actualPath))
                {
                    fileList.Add(actualPath);
                }
            }

            return fileList;
        }
        private void CopyFromIndex(
            string indexFile, 
            string targetFolder, 
            IFileSystem fileSystem, 
            ILogger logger, 
            IIntegrationResult result)
        {
            var basePath = Path.GetDirectoryName(indexFile);
            using (var reader = fileSystem.Load(indexFile))
            {
                XDocument document = null;
                try
                {
                    document = XDocument.Load(reader);
                }
                catch (Exception error)
                {
                    throw new CruiseControlException(
                        "Unable to load index file - " + error.Message ?? string.Empty,
                        error);
                }

                var rootEl = document.Element("ReportResources");
                if (rootEl == null)
                {
                    throw new CruiseControlException("Unable to load contents manifest - unable to find root node");
                }

                var files = new List<string>();
                foreach (var fileEl in rootEl.Elements("File"))
                {
                    var fullPath = fileEl.Value;
                    if (!Path.IsPathRooted(fullPath))
                    {
                        fullPath = Path.Combine(basePath, fileEl.Value);
                    }

                    files.Add(fullPath);
                }

                foreach (var folder in rootEl.Elements("Directory"))
                {
                    var fullPath = folder.Value;
                    if (!Path.IsPathRooted(fullPath))
                    {
                        fullPath = Path.Combine(basePath, fullPath);
                    }

                    files.AddRange(fileSystem.GetFilesInDirectory(fullPath, true));
                }

                var baseLength = basePath.Length;
                foreach (var file in files)
                {
                    logger.Info("Copying file '{0}' to '{1}'", file, targetFolder);
                    var targetFile = file.StartsWith(basePath) ?
                        file.Substring(baseLength) :
                        Path.GetFileName(file);
                    result.BuildProgressInformation.AddTaskInformation(
                        string.Format(CultureInfo.CurrentCulture, "Copying file '{0}' to '{1}'", targetFile, targetFolder));
                    fileSystem.Copy(file, Path.Combine(targetFolder, targetFile));
                }
            }

        }
        private void CopyFromIndex(
            string indexFile,
            string targetFolder,
            IFileSystem fileSystem,
            ILogger logger,
            IIntegrationResult result)
        {
            var basePath = Path.GetDirectoryName(indexFile);

            using (var reader = fileSystem.Load(indexFile))
            {
                XDocument document = null;
                try
                {
                    document = XDocument.Load(reader);
                }
                catch (Exception error)
                {
                    throw new CruiseControlException(
                              "Unable to load index file - " + error.Message ?? string.Empty,
                              error);
                }

                var rootEl = document.Element("ReportResources");
                if (rootEl == null)
                {
                    throw new CruiseControlException("Unable to load contents manifest - unable to find root node");
                }

                var files = new List <string>();
                foreach (var fileEl in rootEl.Elements("File"))
                {
                    var fullPath = fileEl.Value;
                    if (!Path.IsPathRooted(fullPath))
                    {
                        fullPath = Path.Combine(basePath, fileEl.Value);
                    }

                    files.Add(fullPath);
                }

                foreach (var folder in rootEl.Elements("Directory"))
                {
                    var fullPath = folder.Value;
                    if (!Path.IsPathRooted(fullPath))
                    {
                        fullPath = Path.Combine(basePath, fullPath);
                    }

                    files.AddRange(fileSystem.GetFilesInDirectory(fullPath, true));
                }

                var baseLength = basePath.Length;
                foreach (var file in files)
                {
                    logger.Info("Copying file '{0}' to '{1}'", file, targetFolder);
                    var targetFile = file.StartsWith(basePath) ?
                                     file.Substring(baseLength) :
                                     Path.GetFileName(file);
                    result.BuildProgressInformation.AddTaskInformation(
                        string.Format(CultureInfo.CurrentCulture, "Copying file '{0}' to '{1}'", targetFile, targetFolder));
                    fileSystem.Copy(file, Path.Combine(targetFolder, targetFile));
                }
            }
        }
Example #18
0
 IEnumerable <FileInfo> ISolutionPageModel.GetFilesInDirectory(string directory, string pattern)
 {
     return(_fileSystem.GetFilesInDirectory(directory, pattern));
 }
        /// <summary>
        /// Generate a list of differences in files.
        /// </summary>
        /// <param name="originalList"></param>
        ///<param name="outputDirectory"></param>
        /// <returns></returns>
        private string[] ListFileDifferences(Dictionary <string, DateTime> originalList, string outputDirectory)
        {
            var contentsFile = Path.Combine(outputDirectory, "ReportResources.xml");

            if (fileSystem.FileExists(contentsFile))
            {
                using (var reader = fileSystem.Load(contentsFile))
                {
                    XDocument document = null;
                    try
                    {
                        document = XDocument.Load(reader);
                    }
                    catch (Exception error)
                    {
                        throw new CruiseControlException(
                                  "Unable to load contents manifest - " + error.Message ?? string.Empty,
                                  error);
                    }

                    var rootEl = document.Element("ReportResources");
                    if (rootEl == null)
                    {
                        throw new CruiseControlException("Unable to load contents manifest - unable to find root node");
                    }

                    var files = new List <string>();
                    foreach (var fileEl in rootEl.Elements("File"))
                    {
                        files.Add(Path.Combine(outputDirectory, fileEl.Value));
                    }

                    foreach (var folder in rootEl.Elements("Directory"))
                    {
                        var fullPath = Path.Combine(outputDirectory, folder.Value);
                        files.AddRange(fileSystem.GetFilesInDirectory(fullPath, true));
                    }

                    return(files.ToArray());
                }
            }
            else
            {
                string[] newList = { };
                if (fileSystem.DirectoryExists(outputDirectory))
                {
                    newList = fileSystem.GetFilesInDirectory(outputDirectory);
                }

                var differenceList = new List <string>();

                // For each new file, see if it is in the old file list
                foreach (var newFile in newList)
                {
                    if (originalList.ContainsKey(newFile))
                    {
                        // Check if the times are different
                        if (originalList[newFile] != fileSystem.GetLastWriteTime(newFile))
                        {
                            differenceList.Add(newFile);
                        }
                    }
                    else
                    {
                        // Not in the old file, therefore it's new
                        differenceList.Add(newFile);
                    }
                }

                return(differenceList.ToArray());
            }
        }