static List <DataFixModel> WalkDirectoryTree(System.IO.DirectoryInfo root, List <DataFixModel> foundInFolderDataFixModels)
        {
            System.IO.FileInfo[]      files   = null;
            System.IO.DirectoryInfo[] subDirs = null;

            // First, process all the files directly under this folder

            files = root.GetFiles("*.*");



            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    // In this example, we only access the existing FileInfo object. If we
                    // want to open, delete or modify the file, then
                    // a try-catch block is required here to handle the case
                    // where the file has been deleted since the call to TraverseTree().
                    DataFixModel dm = new DataFixModel();
                    dm = TextParser.FindVersionInfo(fi);
                    if (dm == null)
                    {
                        throw new DataMisalignedException("No version info in one of the files in the folder.");
                    }
                    foundInFolderDataFixModels.Add(dm);
                }

                // Now find all the subdirectories under this directory.
                subDirs = root.GetDirectories();

                List <DirectoryInfo> acceptableDirs = new List <DirectoryInfo>();

                foreach (var s in subDirs)
                {
                    if (!GlobalConfig.FoldersToIgnore.Contains(s.Name))
                    {
                        acceptableDirs.Add(s);
                    }
                }

                foreach (System.IO.DirectoryInfo dirInfo in acceptableDirs)
                {
                    // Resursive call for each subdirectory.
                    WalkDirectoryTree(dirInfo, foundInFolderDataFixModels);
                }
            }

            return(foundInFolderDataFixModels);
        }
Example #2
0
        public static DataFixModel FindVersionInfo(FileInfo file)
        {
            DataFixModel dm    = new DataFixModel();
            Regex        regex = new Regex(@"execute\s*dbo\.InsertVersion\s*'DataFix'\s*,\s*[0-9]{4}\s*,\s*[0-9]{1,}\s*,\s*[0-9]{1,}\s*,\s*[0-9]{1,}", RegexOptions.IgnoreCase);

            // "\s/Content/"         : space and then Content directory
            // "([a-zA-Z0-9\-]+?)    : group of alphanumeric characters and hyphen
            // ?                     : don't be greedy, match lazily
            // \.aspx                : file extension required for match
            using (StreamReader reader = new StreamReader(file.FullName))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    // Try to match each line against the Regex.
                    Match match = regex.Match(line);
                    if (match.Success)
                    {
                        // Write original line and the value.
                        string v            = match.Groups[0].Value;
                        Regex  numbersRegex = new Regex(@"[0-9]{4}\s*,\s*[0-9]{1,}\s*,\s*[0-9]{1,}\s*,\s*[0-9]{1,}");
                        Match  numbersMatch = numbersRegex.Match(v);
                        if (numbersMatch.Success)
                        {
                            string   numbersV      = numbersMatch.Groups[0].Value;
                            string[] numbersVSplit = numbersV.Split(',');
                            dm.MajorVersion = Convert.ToInt32(numbersVSplit[0]);
                            dm.MinorVersion = Convert.ToInt32(numbersVSplit[1]);
                            dm.BuildVersion = Convert.ToInt32(numbersVSplit[2]);
                            dm.RevnVersion  = Convert.ToInt32(numbersVSplit[3]);
                        }
                    }
                }
            }
            return(dm);
        }