2323using SourcePro . Csharp . Lab . ComponentModel . Trace ;
2424using System . ComponentModel ;
2525using SourcePro . Csharp . Lab . Commons ;
26+ using System . IO ;
27+ using SourcePro . Csharp . Lab . Commons . Entity ;
28+ using System . Threading ;
29+ using System . Linq ;
2630
2731namespace SourcePro . Csharp . Lab . Forms
2832{
@@ -54,6 +58,7 @@ private void InitializeVariables()
5458 protected override void InitializeControls ( )
5559 {
5660 base . InitializeControls ( ) ;
61+ this . SetProgressImageVisible ( true ) ;
5762 this . InitializeVariables ( ) ;
5863 this . StartBackgroundJob ( ) ;
5964 }
@@ -62,21 +67,93 @@ protected override void InitializeControls()
6267 #region RegisterControlsEventHandlers
6368 protected override void RegisterControlsEventHandlers ( )
6469 {
65- this . CtrlBackgroundWorker_BuildJob . DoWork += new DoWorkEventHandler ( CaptureBackgroundProgress ) ;
70+ this . CtrlButton_Cancel . Click += new EventHandler ( RequestCancelBackgroundJob ) ;
71+ }
72+ #endregion
73+
74+ #region RequestCancelBackgroundJob
75+ private void RequestCancelBackgroundJob ( object sender , EventArgs e )
76+ {
77+ this . Trace . Output ( new TraceViewerInvokerArgs ( ) { Status = JobProgress . Cancel , Message = "Try cancel !" } ) ;
78+ try
79+ {
80+ this . BackgroundJob . Abort ( ) ;
81+ this . CtrlButton_Cancel . Enabled = false ;
82+ this . CtrlButton_Close . Enabled = true ;
83+ this . Trace . Output ( new TraceViewerInvokerArgs ( ) { Status = JobProgress . Abort , Message = "The background job was abort !" } ) ;
84+ }
85+ catch ( Exception )
86+ {
87+ this . Trace . Output ( new TraceViewerInvokerArgs ( ) { Status = JobProgress . Failed , Message = "Unabled to cancel background job !" } ) ;
88+ }
6689 }
6790 #endregion
6891
6992 #region CaptureBackgroundProgress
70- private void CaptureBackgroundProgress ( object sender , DoWorkEventArgs e )
93+ private void CaptureBackgroundProgress ( )
7194 {
7295 this . Trace . Output ( new TraceViewerInvokerArgs ( ) { Status = JobProgress . Start , Message = "AIEDITOR search operation is starting!" } ) ;
96+ if ( this . AssemblyInformation . IncludeFolders . Count > 0 )
97+ {
98+ foreach ( FolderProperty item in this . AssemblyInformation . IncludeFolders )
99+ {
100+ this . SearchIncludedFolder ( new DirectoryInfo ( item . SelectedPath ) , item . IncludeSubDirectories ) ;
101+ }
102+ }
103+ else this . Trace . Output ( new TraceViewerInvokerArgs ( ) { Status = JobProgress . Skip , Message = "You do not set the folder you want to search!" } ) ;
73104 }
74105 #endregion
75106
76107 #region StartBackgroundJob
77108 private void StartBackgroundJob ( )
78109 {
79- this . CtrlBackgroundWorker_BuildJob . RunWorkerAsync ( ) ;
110+ this . BackgroundJob = new Thread ( new ThreadStart ( this . CaptureBackgroundProgress ) ) ;
111+ this . BackgroundJob . Start ( ) ;
112+ }
113+ #endregion
114+
115+ #region SetProgressImageVisible
116+ private void SetProgressImageVisible ( bool visible )
117+ {
118+ this . CtrlPictureBox_Progress . Visible = visible ;
119+ }
120+ #endregion
121+
122+ #region SearchIncludedFolder
123+ private void SearchIncludedFolder ( DirectoryInfo folder , bool includeSubs )
124+ {
125+ this . Trace . Output ( new TraceViewerInvokerArgs ( ) { Status = JobProgress . Searching , Message = string . Format ( "Now searching the folder [{0}]" , folder . FullName ) } ) ;
126+ if ( ! this . IsExcludedFolder ( folder . FullName ) )
127+ {
128+ DirectoryInfo [ ] subs = folder . GetDirectories ( ) ;
129+ if ( includeSubs && subs . Length > 0 )
130+ {
131+ foreach ( DirectoryInfo item in subs ) this . SearchIncludedFolder ( item , includeSubs ) ;
132+ }
133+ }
134+ else this . Trace . Output ( new TraceViewerInvokerArgs ( ) { Status = JobProgress . Skip , Message = string . Format ( "This folder [{0}] is excluded outside the search scope!" , folder . FullName ) } ) ;
135+ }
136+ #endregion
137+
138+ #region IsExcludedFolder
139+ private bool IsExcludedFolder ( string path )
140+ {
141+ var enumerator = from item in this . AssemblyInformation . ExcludeFolders where item . SelectedPath . ToLower ( ) . Equals ( path . ToLower ( ) ) select item ;
142+ return enumerator . Count < FolderProperty > ( ) > 0 ;
143+ }
144+ #endregion
145+
146+ #region GetAssemblyFiles
147+ private FileInfo [ ] GetAssemblyFiles ( DirectoryInfo folder )
148+ {
149+ string filter = "" ;
150+ switch ( this . AssemblyInformation . PlatformID )
151+ {
152+ case Platform . CsharpAndVB : filter = "*.cs|*.vb" ; break ;
153+ case Platform . Csharp : filter = "*.cs" ; break ;
154+ case Platform . VisualBasic : filter = "*.vb" ; break ;
155+ }
156+ return folder . GetFiles ( filter , SearchOption . TopDirectoryOnly ) ;
80157 }
81158 #endregion
82159 }
0 commit comments