6
6
using System . IO ;
7
7
using System . Security . Cryptography ;
8
8
using System . Text ;
9
+ using System . Linq ;
9
10
10
11
public class GitVersionCacheKeyFactory
11
12
{
@@ -33,20 +34,20 @@ private static string GetGitSystemHash(GitPreparer gitPreparer, IFileSystem file
33
34
// lifted from https://msdn.microsoft.com/en-us/library/bb513869.aspx
34
35
public static List < string > TraverseTree ( string root )
35
36
{
36
- var result = new List < string > ( ) ;
37
- result . Add ( root ) ;
37
+ var result = new List < string > { root } ;
38
+
38
39
// Data structure to hold names of subfolders to be
39
40
// examined for files.
40
- Stack < string > dirs = new Stack < string > ( 20 ) ;
41
+ var dirs = new Stack < string > ( 20 ) ;
41
42
42
- if ( ! System . IO . Directory . Exists ( root ) )
43
+ if ( ! Directory . Exists ( root ) )
43
44
{
44
45
throw new ArgumentException ( ) ;
45
46
}
46
47
47
48
dirs . Push ( root ) ;
48
49
49
- while ( dirs . Count > 0 )
50
+ while ( dirs . Any ( ) )
50
51
{
51
52
string currentDir = dirs . Pop ( ) ;
52
53
@@ -56,7 +57,7 @@ public static List<string> TraverseTree(string root)
56
57
string [ ] subDirs ;
57
58
try
58
59
{
59
- subDirs = System . IO . Directory . GetDirectories ( currentDir ) ;
60
+ subDirs = Directory . GetDirectories ( currentDir ) ;
60
61
}
61
62
// An UnauthorizedAccessException exception will be thrown if we do not have
62
63
// discovery permission on a folder or file. It may or may not be acceptable
@@ -72,7 +73,7 @@ public static List<string> TraverseTree(string root)
72
73
Logger . WriteError ( e . Message ) ;
73
74
continue ;
74
75
}
75
- catch ( System . IO . DirectoryNotFoundException e )
76
+ catch ( DirectoryNotFoundException e )
76
77
{
77
78
Logger . WriteError ( e . Message ) ;
78
79
continue ;
@@ -81,7 +82,7 @@ public static List<string> TraverseTree(string root)
81
82
string [ ] files = null ;
82
83
try
83
84
{
84
- files = System . IO . Directory . GetFiles ( currentDir ) ;
85
+ files = Directory . GetFiles ( currentDir ) ;
85
86
}
86
87
87
88
catch ( UnauthorizedAccessException e )
@@ -90,19 +91,17 @@ public static List<string> TraverseTree(string root)
90
91
continue ;
91
92
}
92
93
93
- catch ( System . IO . DirectoryNotFoundException e )
94
+ catch ( DirectoryNotFoundException e )
94
95
{
95
96
Logger . WriteError ( e . Message ) ;
96
97
continue ;
97
98
}
98
- // Perform the required action on each file here.
99
- // Modify this block to perform your required task.
99
+
100
100
foreach ( string file in files )
101
101
{
102
102
try
103
103
{
104
- // Perform whatever action is required in your scenario.
105
- System . IO . FileInfo fi = new System . IO . FileInfo ( file ) ;
104
+ var fi = new FileInfo ( file ) ;
106
105
result . Add ( fi . Name ) ;
107
106
result . Add ( File . ReadAllText ( file ) ) ;
108
107
//Logger.WriteInfo(string.Format("{0}: {1}, {2}", fi.Name, fi.Length, fi.CreationTime));
0 commit comments