Skip to content

Commit 6767199

Browse files
1 parent eca487d commit 6767199

10 files changed

Lines changed: 286 additions & 19 deletions

File tree

AssemblyInfoEditor.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
<Compile Include="Commons\JobProgress.cs" />
6060
<Compile Include="Commons\MessageBoxCaptions.cs" />
6161
<Compile Include="Commons\Platform.cs" />
62+
<Compile Include="Commons\RegularExpressions\Regex.cs" />
63+
<Compile Include="Commons\RegularExpressions\RegexCategory.cs" />
6264
<Compile Include="Commons\XNamespaces.cs" />
6365
<Compile Include="ComponentModel\BaseForm.cs">
6466
<SubType>Form</SubType>

AssemblyInfoEditor.csproj.user

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#region README
2+
3+
/*
4+
* README
5+
*
6+
* Current Thread User : GUOCOLAND\wangyucai
7+
* Machine Name : GLCHQWYCWINW7
8+
* Visual Studio : Microsoft Visual Studio 2010 Ultimate Edition
9+
* Create Time : 2014-12-31 11:31:49
10+
* Common Language Runtime : 4.0.30319.18444
11+
* Minimum .Net Framework Version : 3.5
12+
*
13+
* SourcePro Studio 2014
14+
* Project Url : https://github.com/SourceproStudio/CodeTemplates
15+
* Home Page Url : https://github.com/SourceproStudio
16+
* E-mail Address : MasterDuner@yeah.net or Yucai.Wang-Public@outlook.com
17+
* QQ : 180261899
18+
*/
19+
20+
#endregion
21+
22+
using System;
23+
using System.Collections.Generic;
24+
using System.Xml;
25+
using System.IO;
26+
27+
namespace SourcePro.Csharp.Lab.Commons.RegularExpressions
28+
{
29+
/// <summary>
30+
/// <para>
31+
/// 提供了正则表达式匹配的基本方法。
32+
/// </para>
33+
/// <para>
34+
/// Namespace : <see cref="SourcePro.Csharp.Lab.Commons.RegularExpressions"/>
35+
/// </para>
36+
/// <para>
37+
/// Type : <see cref="Regex"/>
38+
/// </para>
39+
/// <para>
40+
/// The minimum .Net Framework version requirements : 3.5
41+
/// </para>
42+
/// </summary>
43+
/// <seealso cref="SourcePro.Csharp.Lab.Commons.RegularExpressions"/>
44+
public class Regex
45+
{
46+
private Dictionary<RegexCategory, string> _expressions;
47+
private XmlDocument _xConfigure;
48+
private static readonly string ConfigFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "aieditor.regex.xml");
49+
private XmlNamespaceManager _xNamespaces;
50+
private string _xmlns;
51+
52+
#region Expressions
53+
private Dictionary<RegexCategory, string> Expressions
54+
{
55+
get { return _expressions; }
56+
set { _expressions = value; }
57+
}
58+
#endregion
59+
60+
#region XConfigure
61+
private XmlDocument XConfigure
62+
{
63+
get { return _xConfigure; }
64+
set { _xConfigure = value; }
65+
}
66+
#endregion
67+
68+
#region XNamespaces
69+
private XmlNamespaceManager XNamespaces
70+
{
71+
get { return _xNamespaces; }
72+
set { _xNamespaces = value; }
73+
}
74+
#endregion
75+
76+
#region Xmlns
77+
private string Xmlns
78+
{
79+
get { return _xmlns; }
80+
set { _xmlns = value; }
81+
}
82+
#endregion
83+
84+
#region Regex Constructors
85+
86+
/// <summary>
87+
/// 用于初始化一个<see cref="Regex" />对象实例。
88+
/// </summary>
89+
/// <param name="platform"><see cref="Platform"/>中的一个值。</param>
90+
public Regex(Platform platform)
91+
{
92+
this.InitializeXmlnsPrefix(platform);
93+
this.Expressions = new Dictionary<RegexCategory, string>();
94+
if (!File.Exists(ConfigFile)) throw new FileNotFoundException("The regularexpressions config file not found!", ConfigFile);
95+
this.XConfigure = new XmlDocument();
96+
this.XConfigure.Load(ConfigFile);
97+
this.XNamespaces = new XmlNamespaceManager(this.XConfigure.NameTable);
98+
this.XNamespaces.AddNamespace("wyc", "https://github.com/SourceproStudio");
99+
this.XNamespaces.AddNamespace(this.Xmlns, string.Format("urn:{0}", platform));
100+
}
101+
102+
#endregion
103+
104+
#region InitializeXmlnsPrefix
105+
private void InitializeXmlnsPrefix(Platform platform)
106+
{
107+
switch (platform)
108+
{
109+
case Platform.CsharpAndVB: this.Xmlns = "all"; break;
110+
case Platform.Csharp: this.Xmlns = "cs"; break;
111+
case Platform.VisualBasic: this.Xmlns = "vb"; break;
112+
}
113+
}
114+
#endregion
115+
116+
#region InitializeExpressions
117+
private void InitializeExpressions()
118+
{
119+
}
120+
#endregion
121+
}
122+
}
123+
124+
/*
125+
* Copyright © 2014 Wang Yucai. All rights reserved.
126+
*/
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#region README
2+
3+
/*
4+
* README
5+
*
6+
* Current Thread User : GUOCOLAND\wangyucai
7+
* Machine Name : GLCHQWYCWINW7
8+
* Visual Studio : Microsoft Visual Studio 2010 Ultimate Edition
9+
* Create Time : 2014-12-31 11:28:21
10+
* Common Language Runtime : 4.0.30319.18444
11+
* Minimum .Net Framework Version : 3.5
12+
*
13+
* SourcePro Studio 2014
14+
* Project Url : https://github.com/SourceproStudio/CodeTemplates
15+
* Home Page Url : https://github.com/SourceproStudio
16+
* E-mail Address : MasterDuner@yeah.net or Yucai.Wang-Public@outlook.com
17+
* QQ : 180261899
18+
*/
19+
20+
#endregion
21+
22+
using System;
23+
24+
namespace SourcePro.Csharp.Lab.Commons.RegularExpressions
25+
{
26+
/// <summary>
27+
/// <para>
28+
/// 定义了正则表达式类别。
29+
/// </para>
30+
/// <para>
31+
/// Namespace : <see cref="SourcePro.Csharp.Lab.Commons.RegularExpressions"/>
32+
/// </para>
33+
/// <para>
34+
/// Type : <see cref="RegexCategory"/>
35+
/// </para>
36+
/// <para>
37+
/// The minimum .Net Framework version requirements : 3.5
38+
/// </para>
39+
/// </summary>
40+
/// <seealso cref="SourcePro.Csharp.Lab.Commons.RegularExpressions"/>
41+
[Serializable]
42+
public enum RegexCategory : int
43+
{
44+
FileFilter = 1,
45+
AssemblyTitle,
46+
AssemblyDescription,
47+
AssemblyCompany,
48+
AssemblyProduct,
49+
AssemblyCopyright,
50+
AssemblyTrademark,
51+
AssemblyVersion,
52+
AssemblyFileVersion
53+
}
54+
}
55+
56+
/*
57+
* Copyright © 2014 Wang Yucai. All rights reserved.
58+
*/

ComponentModel/Trace/TraceManager.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ public void Output(TraceViewerInvokerArgs args)
8484
private void InternalOutput(TraceViewerInvokerArgs args)
8585
{
8686
if (this.Console.InvokeRequired) this.Console.Invoke(this.Event, args);
87-
else this.Console.AppendText(args.ToString());
87+
else
88+
{
89+
this.Console.AppendText(args.ToString());
90+
this.Console.ScrollToCaret();
91+
}
8892
}
8993
#endregion
9094
}

Forms/BuildForm.Designer.cs

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Forms/BuildForm.Methods.cs

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
using SourcePro.Csharp.Lab.ComponentModel.Trace;
2424
using System.ComponentModel;
2525
using SourcePro.Csharp.Lab.Commons;
26+
using System.IO;
27+
using SourcePro.Csharp.Lab.Commons.Entity;
28+
using System.Threading;
29+
using System.Linq;
2630

2731
namespace 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
}

Forms/BuildForm.Variables.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System;
2323
using SourcePro.Csharp.Lab.Commons.Entity;
2424
using SourcePro.Csharp.Lab.ComponentModel.Trace;
25+
using System.Threading;
2526

2627
namespace SourcePro.Csharp.Lab.Forms
2728
{
@@ -44,6 +45,15 @@ partial class BuildForm
4445
{
4546
private AssemblyInformation _assemblyInformation;
4647
private TraceManager _trace;
48+
private Thread _backgroundJob;
49+
50+
#region BackgroundJob
51+
private Thread BackgroundJob
52+
{
53+
get { return _backgroundJob; }
54+
set { _backgroundJob = value; }
55+
}
56+
#endregion
4757

4858
#region AssemblyInformation
4959
public AssemblyInformation AssemblyInformation

Forms/BuildForm.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120-
<metadata name="CtrlBackgroundWorker_BuildJob.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121-
<value>17, 17</value>
122-
</metadata>
123120
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
124121
<data name="CtrlPictureBox_Progress.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
125122
<value>

0 commit comments

Comments
 (0)