Skip to content

Commit 00a9ea9

Browse files
committed
migrate to .net 6 + refactor + clean up
1 parent 1e4e6f4 commit 00a9ea9

11 files changed

Lines changed: 1120 additions & 0 deletions

v2/Demo/Demo.WinForms.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net6.0-windows</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<UseWindowsForms>true</UseWindowsForms>
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\FileWatcherEx\FileWatcherEx.csproj" />
13+
</ItemGroup>
14+
15+
</Project>

v2/Demo/Form1.Designer.cs

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

v2/Demo/Form1.cs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
2+
namespace Demo
3+
{
4+
public partial class Form1 : Form
5+
{
6+
private FileWatcherEx _fw = new();
7+
public Form1()
8+
{
9+
InitializeComponent();
10+
}
11+
12+
13+
14+
private void btnStart_Click(object sender, EventArgs e)
15+
{
16+
_fw = new FileWatcherEx(txtPath.Text.Trim());
17+
18+
_fw.OnRenamed += FW_OnRenamed;
19+
_fw.OnCreated += FW_OnCreated;
20+
_fw.OnDeleted += FW_OnDeleted;
21+
_fw.OnChanged += FW_OnChanged;
22+
_fw.OnError += FW_OnError;
23+
24+
_fw.SynchronizingObject = this;
25+
26+
_fw.Start();
27+
28+
btnStart.Enabled = false;
29+
btnSelectFolder.Enabled = false;
30+
txtPath.Enabled = false;
31+
btnStop.Enabled = true;
32+
}
33+
34+
private void FW_OnError(object sender, ErrorEventArgs e)
35+
{
36+
if (txtConsole.InvokeRequired)
37+
{
38+
txtConsole.Invoke(FW_OnError, sender, e);
39+
}
40+
else
41+
{
42+
txtConsole.Text += "[ERROR]: " + e.GetException().Message + "\r\n";
43+
}
44+
}
45+
46+
private void FW_OnChanged(object sender, FileChangedEvent e)
47+
{
48+
txtConsole.Text += string.Format("[cha] {0} | {1}",
49+
Enum.GetName(typeof(ChangeType), e.ChangeType),
50+
e.FullPath) + "\r\n";
51+
}
52+
53+
private void FW_OnDeleted(object sender, FileChangedEvent e)
54+
{
55+
txtConsole.Text += string.Format("[del] {0} | {1}",
56+
Enum.GetName(typeof(ChangeType), e.ChangeType),
57+
e.FullPath) + "\r\n";
58+
}
59+
60+
private void FW_OnCreated(object sender, FileChangedEvent e)
61+
{
62+
txtConsole.Text += string.Format("[cre] {0} | {1}",
63+
Enum.GetName(typeof(ChangeType), e.ChangeType),
64+
e.FullPath) + "\r\n";
65+
}
66+
67+
private void FW_OnRenamed(object sender, FileChangedEvent e)
68+
{
69+
txtConsole.Text += string.Format("[ren] {0} | {1} ----> {2}",
70+
Enum.GetName(typeof(ChangeType), e.ChangeType),
71+
e.OldFullPath,
72+
e.FullPath) + "\r\n";
73+
}
74+
75+
76+
77+
private void btnStop_Click(object sender, EventArgs e)
78+
{
79+
_fw.Stop();
80+
81+
btnStart.Enabled = true;
82+
btnSelectFolder.Enabled = true;
83+
txtPath.Enabled = true;
84+
btnStop.Enabled = false;
85+
}
86+
87+
88+
private void btnSelectFolder_Click(object sender, EventArgs e)
89+
{
90+
var fb = new FolderBrowserDialog();
91+
92+
93+
if (fb.ShowDialog() == DialogResult.OK)
94+
{
95+
txtPath.Text = fb.SelectedPath;
96+
97+
_fw.Stop();
98+
_fw.Dispose();
99+
}
100+
}
101+
102+
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
103+
{
104+
_fw.Stop();
105+
_fw.Dispose();
106+
}
107+
}
108+
}

v2/Demo/Form1.resx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<root>
2+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
3+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
4+
<xsd:element name="root" msdata:IsDataSet="true">
5+
<xsd:complexType>
6+
<xsd:choice maxOccurs="unbounded">
7+
<xsd:element name="metadata">
8+
<xsd:complexType>
9+
<xsd:sequence>
10+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
11+
</xsd:sequence>
12+
<xsd:attribute name="name" use="required" type="xsd:string" />
13+
<xsd:attribute name="type" type="xsd:string" />
14+
<xsd:attribute name="mimetype" type="xsd:string" />
15+
<xsd:attribute ref="xml:space" />
16+
</xsd:complexType>
17+
</xsd:element>
18+
<xsd:element name="assembly">
19+
<xsd:complexType>
20+
<xsd:attribute name="alias" type="xsd:string" />
21+
<xsd:attribute name="name" type="xsd:string" />
22+
</xsd:complexType>
23+
</xsd:element>
24+
<xsd:element name="data">
25+
<xsd:complexType>
26+
<xsd:sequence>
27+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
28+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
29+
</xsd:sequence>
30+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
31+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
32+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
33+
<xsd:attribute ref="xml:space" />
34+
</xsd:complexType>
35+
</xsd:element>
36+
<xsd:element name="resheader">
37+
<xsd:complexType>
38+
<xsd:sequence>
39+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
40+
</xsd:sequence>
41+
<xsd:attribute name="name" type="xsd:string" use="required" />
42+
</xsd:complexType>
43+
</xsd:element>
44+
</xsd:choice>
45+
</xsd:complexType>
46+
</xsd:element>
47+
</xsd:schema>
48+
<resheader name="resmimetype">
49+
<value>text/microsoft-resx</value>
50+
</resheader>
51+
<resheader name="version">
52+
<value>2.0</value>
53+
</resheader>
54+
<resheader name="reader">
55+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
56+
</resheader>
57+
<resheader name="writer">
58+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
59+
</resheader>
60+
</root>

v2/Demo/Program.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Demo
2+
{
3+
internal static class Program
4+
{
5+
/// <summary>
6+
/// The main entry point for the application.
7+
/// </summary>
8+
[STAThread]
9+
static void Main()
10+
{
11+
ApplicationConfiguration.Initialize();
12+
Application.Run(new Form1());
13+
}
14+
}
15+
}

v2/FileWatcherEx.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.1.31911.260
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileWatcherEx", "FileWatcherEx\FileWatcherEx.csproj", "{CF81727D-B6EC-4202-8E78-087C5D5EABF3}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo.WinForms", "Demo\Demo.WinForms.csproj", "{F973F462-7769-433C-AEC1-17AF2902ED2D}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{CF81727D-B6EC-4202-8E78-087C5D5EABF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{CF81727D-B6EC-4202-8E78-087C5D5EABF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{CF81727D-B6EC-4202-8E78-087C5D5EABF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{CF81727D-B6EC-4202-8E78-087C5D5EABF3}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{F973F462-7769-433C-AEC1-17AF2902ED2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{F973F462-7769-433C-AEC1-17AF2902ED2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{F973F462-7769-433C-AEC1-17AF2902ED2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{F973F462-7769-433C-AEC1-17AF2902ED2D}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {7A615E75-F056-422F-952E-9C0CD34E477B}
30+
EndGlobalSection
31+
EndGlobal

0 commit comments

Comments
 (0)