コード例 #1
0
 /// <summary>
 /// Maps a file type enumeration into actual search pattern that can be used in Directory.GetFiles() call.
 /// </summary>
 /// <param name="fileType">File type to get a corresponding file pattern.</param>
 private static string GetFileExtensionFromType(LcxType fileType)
 {
     switch (fileType)
     {
     case LcxType.Lcl:
         return("*.lcl");
     }
     throw new EnlistmentException(string.Format("Unsupported {0} file type", fileType));
 }
コード例 #2
0
        /// <summary>
        /// Builds a flat list of files under the specified path (under enlistment location) that match the specified filter.
        /// These can be the files that can be processed by OSLEBot engine.
        /// </summary>
        /// <param name="relativePath">Path under enlistment location to look for files.</param>
        /// <param name="fileType">One of the file types supported by enlistment.</param>
        public IEnumerable <ConfigItem> GetFiles(string relativePath, LcxType fileType)
        {
            var retVal = new List <ConfigItem>();

            if (!IsDetected)
            {
                throw new EnlistmentException("Cannot get files because enlistment location is unknown.");
            }

            var searchPath    = Path.Combine(Location, relativePath);
            var searchPattern = GetFileExtensionFromType(fileType);
            var rawProjects   = Directory.GetFiles(searchPath, "*.snt", SearchOption.AllDirectories);

            LoggerSAP.Trace("{0} projects identified under {1}.", rawProjects.Length, searchPath);
            foreach (var project in rawProjects)
            {
                var projectSentinelFile = new FileInfo(project);
                var projectName         = projectSentinelFile.Directory.Name;
                var projectDirectory    = projectSentinelFile.DirectoryName;

                var rawLanguages = Directory.GetFiles(projectDirectory, ".language", SearchOption.AllDirectories);
                foreach (var language in rawLanguages)
                {
                    var languageSentinelFile = new FileInfo(language);
                    var languageName         = languageSentinelFile.Directory.Name;
                    var languageDirectory    = languageSentinelFile.DirectoryName;

                    var rawLocGroups = Directory.GetFiles(languageDirectory, ".locgroup", SearchOption.AllDirectories);
                    foreach (var locGroup in rawLocGroups)
                    {
                        var locGroupSentinelFile = new FileInfo(locGroup);
                        var locGroupName         = locGroupSentinelFile.Directory.Name;
                        var locGroupDirectory    = locGroupSentinelFile.DirectoryName;

                        var rawInput = Directory.GetFiles(locGroupDirectory, searchPattern, SearchOption.AllDirectories);

                        foreach (var inputFile in rawInput) //These are possible input files for OSLEBot (*.lcl files).
                        {
                            var fileObject = new FileInfo(inputFile);

                            var inputConfig = new ConfigItem
                            {
                                Project      = projectName,
                                Language     = languageName,
                                LocGroup     = locGroupName,
                                File         = fileObject.Name,
                                PhysicalPath = fileObject.FullName,
                            };
                            retVal.Add(inputConfig);
                        }
                    }
                }
            }
            return(retVal);
        }