Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
10 changes: 5 additions & 5 deletions files-csharp/FileSystemWatcherExample/ExampleApp/FileUtil.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
public static class FileUtil
{
private static string? _dircetoryToMonitor;
private static string? _directoryToMonitor;

public static string DirectoryToMonitor
{
get
{
if(string.IsNullOrEmpty(_dircetoryToMonitor))
if(string.IsNullOrEmpty(_directoryToMonitor))
{
_dircetoryToMonitor = Path.Combine(Directory.GetCurrentDirectory(),"bin","DirectoryToMonitor");
Directory.CreateDirectory(_dircetoryToMonitor);
_directoryToMonitor = Path.Combine(Directory.GetCurrentDirectory(),"bin","DirectoryToMonitor");
Directory.CreateDirectory(_directoryToMonitor);
}

return _dircetoryToMonitor;
return _directoryToMonitor;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
var updatedContents = new string[] { "Hello World" };

using var manager = new TextFileManager(FileUtil.DirectoryToMonitor);
// The watcher raises its events on another thread, so the order of the output below is not guaranteed.
manager.Create(fileName, contents);
manager.Update(fileName, updatedContents);
manager.Rename(fileName, updatedFileName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
public class TextFileManager : IDisposable
{
private bool _desposed;
private readonly string _rootDirectory;
private readonly FileSystemWatcher _fileSystemWatcher;

Expand All @@ -17,7 +16,7 @@ public void Create(string fileName, IEnumerable<string> content)
{
var path = AbsolutePath(fileName);
if (File.Exists(path))
throw new Exception($"File With the same name exists: {fileName}");
throw new IOException($"File With the same name exists: {fileName}");

File.WriteAllLines(path, content);
}
Expand Down Expand Up @@ -102,27 +101,5 @@ private void HandleCreated(object sender, FileSystemEventArgs e)

private string AbsolutePath(string fileName) => Path.Combine(_rootDirectory, fileName);

~TextFileManager()
{
Dispose(false);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}

public virtual void Dispose(bool disposing)
{
if(_desposed)
return;

if(disposing)
{
_fileSystemWatcher.Dispose();
}

_desposed = true;
}
public void Dispose() => _fileSystemWatcher.Dispose();
}
10 changes: 5 additions & 5 deletions files-csharp/FileSystemWatcherExample/Tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.10.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="10.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading