@@ -9,7 +9,36 @@ public class FacesReader : DynReader {
99 public FacesReader ( DirectoryInfo myDir ) : base ( myDir ) { }
1010
1111 public override void ExecuteSqliteCommands ( SqliteTransaction transaction ) {
12-
12+ string myDirPath = myDir . FullName ;
13+
14+ Dictionary < int , string > faceTypes = new Dictionary < int , string > ( ) ;
15+ faceTypes . Add ( 0 , "8x8" ) ;
16+ faceTypes . Add ( 1 , "16x16" ) ;
17+ faceTypes . Add ( 2 , "32x32" ) ;
18+ faceTypes . Add ( 3 , "body" ) ;
19+
20+ foreach ( int faceType in faceTypes . Keys ) {
21+ string faceTypeStr = faceTypes [ faceType ] ;
22+ DirectoryInfo faceDir = new DirectoryInfo ( Path . Combine ( myDirPath , faceTypeStr ) ) ;
23+
24+ if ( faceDir . Exists ) {
25+ foreach ( FileInfo image in faceDir . EnumerateFiles ( ) . Where ( file => file . Name . EndsWith ( ".png" ) ) ) {
26+ SqliteCommand cmd = new SqliteCommand ( ) ;
27+ cmd . CommandText = "INSERT INTO Faces VALUES (@Name, @Type, @ImageBytes);" ;
28+
29+ string name = image . Name . Substring ( 0 , image . Name . Length - 4 ) ;
30+ cmd . Parameters . AddWithValue ( "@Name" , name ) ;
31+ cmd . Parameters . AddWithValue ( "@Type" , faceType ) ;
32+ cmd . Parameters . AddWithValue ( "@ImageBytes" , File . ReadAllBytes ( image . FullName ) ) ;
33+
34+ cmd . Transaction = transaction ;
35+ cmd . Connection = transaction . Connection ;
36+ cmd . ExecuteNonQuery ( ) ;
37+
38+ Console . WriteLine ( "Command executed for " + name + " " + faceTypeStr ) ;
39+ }
40+ }
41+ }
1342 }
1443 }
1544}
0 commit comments