1+ using static System . Console ;
2+ using System . Linq ;
3+ using Microsoft . CodeAnalysis ;
4+ using Microsoft . CodeAnalysis . CSharp ;
5+ using Microsoft . EntityFrameworkCore ;
6+ using System ;
7+ using System . IO ;
8+ using System . Collections ;
9+ using System . Collections . Generic ;
10+ using System . Threading . Tasks ;
11+ using CSharpParser . model ;
12+
13+ namespace CSharpParser
14+ {
15+ class ProgramHelper
16+ {
17+ public static IEnumerable < string > GetSourceFilesFromDir ( string root , string extension )
18+ {
19+ IEnumerable < string > allFiles = new string [ ] { } ;
20+ // Data structure to hold names of subfolders.
21+ ArrayList dirs = new ArrayList ( ) ;
22+
23+ if ( ! System . IO . Directory . Exists ( root ) )
24+ {
25+ throw new ArgumentException ( ) ;
26+ }
27+ dirs . Add ( root ) ;
28+
29+ while ( dirs . Count > 0 )
30+ {
31+ string currentDir = dirs [ 0 ] . ToString ( ) ;
32+ dirs . RemoveAt ( 0 ) ;
33+ string [ ] subDirs ;
34+ try
35+ {
36+ subDirs = System . IO . Directory . GetDirectories ( currentDir ) ;
37+ }
38+ catch ( UnauthorizedAccessException e )
39+ {
40+ WriteLine ( e . Message ) ;
41+ continue ;
42+ }
43+ catch ( System . IO . DirectoryNotFoundException e )
44+ {
45+ WriteLine ( e . Message ) ;
46+ continue ;
47+ }
48+
49+ // Add the subdirectories for traversal.
50+ dirs . AddRange ( subDirs ) ;
51+
52+ string [ ] files = null ;
53+ try
54+ {
55+ files = System . IO . Directory . GetFiles ( currentDir ) ;
56+ }
57+ catch ( UnauthorizedAccessException e )
58+ {
59+ Console . WriteLine ( e . Message ) ;
60+ continue ;
61+ }
62+ catch ( System . IO . DirectoryNotFoundException e )
63+ {
64+ Console . WriteLine ( e . Message ) ;
65+ continue ;
66+ }
67+
68+ foreach ( string file in files )
69+ {
70+ try
71+ {
72+ System . IO . FileInfo fi = new System . IO . FileInfo ( file ) ;
73+ if ( fi . Extension == extension ) {
74+ allFiles = allFiles . Append ( file ) ;
75+ }
76+ }
77+ catch ( System . IO . FileNotFoundException e )
78+ {
79+ // If file was deleted by a separate application
80+ Console . WriteLine ( e . Message ) ;
81+ }
82+ }
83+ }
84+
85+ return allFiles ;
86+ }
87+
88+ public static string transformConnectionString ( string _connectionString )
89+ {
90+ _connectionString = _connectionString . Substring ( _connectionString . IndexOf ( ':' ) + 1 ) ;
91+ _connectionString = _connectionString . Replace ( "user" , "username" ) ;
92+ string [ ] properties = _connectionString . Split ( ';' ) ;
93+ string csharpConnectionString = "" ;
94+ for ( int i = 0 ; i < properties . Length ; ++ i )
95+ {
96+ csharpConnectionString += properties [ i ] . Substring ( 0 , 1 ) . ToUpper ( )
97+ + properties [ i ] . Substring ( 1 ) ;
98+ if ( i < properties . Length - 1 )
99+ {
100+ csharpConnectionString += ";" ;
101+ }
102+ }
103+
104+ return csharpConnectionString ;
105+ }
106+ }
107+ }
0 commit comments