Skip to content

Commit

Permalink
handle code quality in DirectoryService.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
phmatray committed Feb 12, 2024
1 parent 768f0e5 commit 0ed4b59
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 14 deletions.
2 changes: 1 addition & 1 deletion MasterCommander.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/Highlighting/HighlightingSourceSnapshotLocation/@EntryValue">/Users/phmatray/Library/Caches/JetBrains/Rider2023.3/resharper-host/temp/Rider/vAny/CoverageData/_MasterCommander.1386933053/Snapshot/snapshot.utdcvr</s:String>



<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=9aa08aac_002D30e5_002D4059_002D8556_002D0dba901f36eb/@EntryIndexedValue">&lt;SessionState ContinuousTestingIsOn="True" ContinuousTestingMode="3" IsActive="True" Name="All tests from &amp;lt;MasterCommander.Tests&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
Expand Down
4 changes: 4 additions & 0 deletions docs/links
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ P:MasterCommander.Integrations.DirectoryService.HomeDirectory|DirectoryService.H
P:MasterCommander.Integrations.DirectoryService.MasterCommanderDirectory|DirectoryService.MasterCommanderDirectory.md|MasterCommanderDirectory
P:MasterCommander.Integrations.DirectoryService.WorkingDirectory|DirectoryService.WorkingDirectory.md|WorkingDirectory
M:MasterCommander.Integrations.DirectoryService.#ctor(MasterCommander.Core.Display.IConsole)|DirectoryService.DirectoryService(IConsole).md|DirectoryService(IConsole)
M:MasterCommander.Integrations.DirectoryService.SetWorkingDirectory(System.String)|DirectoryService.SetWorkingDirectory(string).md|SetWorkingDirectory(string)
M:MasterCommander.Integrations.DirectoryService.SetWorkingDirectory(System.String,System.Boolean)|DirectoryService.SetWorkingDirectory(string,bool).md|SetWorkingDirectory(string, bool)
M:MasterCommander.Integrations.DirectoryService.CreateNewDirectory(System.String,System.String)|DirectoryService.CreateNewDirectory(string,string).md|CreateNewDirectory(string, string)
M:MasterCommander.Integrations.DirectoryService.CreateNewDirectory(System.String,System.String,System.Boolean)|DirectoryService.CreateNewDirectory(string,string,bool).md|CreateNewDirectory(string, string, bool)
M:MasterCommander.Integrations.DirectoryService.ClearDirectory(System.String)|DirectoryService.ClearDirectory(string).md|ClearDirectory(string)
M:MasterCommander.Integrations.DirectoryService.CalculateDirectorySize(System.String)|DirectoryService.CalculateDirectorySize(string).md|CalculateDirectorySize(string)
Expand Down Expand Up @@ -73,7 +75,9 @@ T:MasterCommander.Core.CmdOptionValuesAttribute|CmdOptionValuesAttribute.md|CmdO
P:MasterCommander.Core.Services.IDirectoryService.HomeDirectory|IDirectoryService.HomeDirectory.md|HomeDirectory
P:MasterCommander.Core.Services.IDirectoryService.MasterCommanderDirectory|IDirectoryService.MasterCommanderDirectory.md|MasterCommanderDirectory
P:MasterCommander.Core.Services.IDirectoryService.WorkingDirectory|IDirectoryService.WorkingDirectory.md|WorkingDirectory
M:MasterCommander.Core.Services.IDirectoryService.SetWorkingDirectory(System.String)|IDirectoryService.SetWorkingDirectory(string).md|SetWorkingDirectory(string)
M:MasterCommander.Core.Services.IDirectoryService.SetWorkingDirectory(System.String,System.Boolean)|IDirectoryService.SetWorkingDirectory(string,bool).md|SetWorkingDirectory(string, bool)
M:MasterCommander.Core.Services.IDirectoryService.CreateNewDirectory(System.String,System.String)|IDirectoryService.CreateNewDirectory(string,string).md|CreateNewDirectory(string, string)
M:MasterCommander.Core.Services.IDirectoryService.CreateNewDirectory(System.String,System.String,System.Boolean)|IDirectoryService.CreateNewDirectory(string,string,bool).md|CreateNewDirectory(string, string, bool)
M:MasterCommander.Core.Services.IDirectoryService.ClearDirectory(System.String)|IDirectoryService.ClearDirectory(string).md|ClearDirectory(string)
M:MasterCommander.Core.Services.IDirectoryService.CalculateDirectorySize(System.String)|IDirectoryService.CalculateDirectorySize(string).md|CalculateDirectorySize(string)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#### [MasterCommander](MasterCommander.md 'MasterCommander')
### [MasterCommander.Integrations](MasterCommander.md#MasterCommander.Integrations 'MasterCommander.Integrations').[DirectoryService](DirectoryService.md 'MasterCommander.Integrations.DirectoryService')

## DirectoryService.CreateNewDirectory(string, string) Method

Creates a new directory within a specified base directory.

```csharp
public string CreateNewDirectory(string baseDirectory, string newDirectoryName);
```
#### Parameters

<a name='MasterCommander.Integrations.DirectoryService.CreateNewDirectory(string,string).baseDirectory'></a>

`baseDirectory` [System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String')

The base directory where the new directory will be created.

<a name='MasterCommander.Integrations.DirectoryService.CreateNewDirectory(string,string).newDirectoryName'></a>

`newDirectoryName` [System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String')

The name of the new directory to create.

Implements [CreateNewDirectory(string, string)](IDirectoryService.CreateNewDirectory(string,string).md 'MasterCommander.Core.Services.IDirectoryService.CreateNewDirectory(string, string)')

#### Returns
[System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String')
The path of the newly created directory.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Creates a new directory within a specified base directory.

```csharp
public string CreateNewDirectory(string baseDirectory, string newDirectoryName, bool overwrite=false);
public string CreateNewDirectory(string baseDirectory, string newDirectoryName, bool overwrite);
```
#### Parameters

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#### [MasterCommander](MasterCommander.md 'MasterCommander')
### [MasterCommander.Integrations](MasterCommander.md#MasterCommander.Integrations 'MasterCommander.Integrations').[DirectoryService](DirectoryService.md 'MasterCommander.Integrations.DirectoryService')

## DirectoryService.SetWorkingDirectory(string) Method

Sets the working directory to the directory where the specified solution is located.

```csharp
public void SetWorkingDirectory(string relativePath);
```
#### Parameters

<a name='MasterCommander.Integrations.DirectoryService.SetWorkingDirectory(string).relativePath'></a>

`relativePath` [System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String')

The relative path from the MasterCommander directory to the solution directory.

Implements [SetWorkingDirectory(string)](IDirectoryService.SetWorkingDirectory(string).md 'MasterCommander.Core.Services.IDirectoryService.SetWorkingDirectory(string)')
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Sets the working directory to the directory where the specified solution is located.

```csharp
public void SetWorkingDirectory(string relativePath, bool createIfNotExists=false);
public void SetWorkingDirectory(string relativePath, bool createIfNotExists);
```
#### Parameters

Expand Down
2 changes: 2 additions & 0 deletions docs/master-commander/DirectoryService.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ Implements [IDirectoryService](IDirectoryService.md 'MasterCommander.Core.Servic
| [ClearDirectory(string)](DirectoryService.ClearDirectory(string).md 'MasterCommander.Integrations.DirectoryService.ClearDirectory(string)') | Clears the contents of a specified directory. |
| [CompressDirectory(string, string)](DirectoryService.CompressDirectory(string,string).md 'MasterCommander.Integrations.DirectoryService.CompressDirectory(string, string)') | Compresses the specified directory into a ZIP file, including all its files and subdirectories. |
| [CreateNewDirectory(string, string, bool)](DirectoryService.CreateNewDirectory(string,string,bool).md 'MasterCommander.Integrations.DirectoryService.CreateNewDirectory(string, string, bool)') | Creates a new directory within a specified base directory. |
| [CreateNewDirectory(string, string)](DirectoryService.CreateNewDirectory(string,string).md 'MasterCommander.Integrations.DirectoryService.CreateNewDirectory(string, string)') | Creates a new directory within a specified base directory. |
| [CreateTemporaryDirectory()](DirectoryService.CreateTemporaryDirectory().md 'MasterCommander.Integrations.DirectoryService.CreateTemporaryDirectory()') | Creates a temporary directory for use during application execution, which can optionally be cleaned up afterwards. |
| [DecompressToDirectory(string, string)](DirectoryService.DecompressToDirectory(string,string).md 'MasterCommander.Integrations.DirectoryService.DecompressToDirectory(string, string)') | Decompresses a ZIP file into a specified directory, extracting all its contents. |
| [SetWorkingDirectory(string, bool)](DirectoryService.SetWorkingDirectory(string,bool).md 'MasterCommander.Integrations.DirectoryService.SetWorkingDirectory(string, bool)') | Sets the working directory to the directory where the specified solution is located. |
| [SetWorkingDirectory(string)](DirectoryService.SetWorkingDirectory(string).md 'MasterCommander.Integrations.DirectoryService.SetWorkingDirectory(string)') | Sets the working directory to the directory where the specified solution is located. |
| [WatchDirectory(string, Action&lt;FileSystemEventArgs&gt;)](DirectoryService.WatchDirectory(string,Action_FileSystemEventArgs_).md 'MasterCommander.Integrations.DirectoryService.WatchDirectory(string, System.Action<System.IO.FileSystemEventArgs>)') | Monitors a directory for any changes, such as file or subdirectory creation, deletion, or modification, and triggers a callback action when a change is detected. |
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#### [MasterCommander](MasterCommander.md 'MasterCommander')
### [MasterCommander.Core.Services](MasterCommander.md#MasterCommander.Core.Services 'MasterCommander.Core.Services').[IDirectoryService](IDirectoryService.md 'MasterCommander.Core.Services.IDirectoryService')

## IDirectoryService.CreateNewDirectory(string, string) Method

Creates a new directory within a specified base directory.

```csharp
string CreateNewDirectory(string baseDirectory, string newDirectoryName);
```
#### Parameters

<a name='MasterCommander.Core.Services.IDirectoryService.CreateNewDirectory(string,string).baseDirectory'></a>

`baseDirectory` [System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String')

The base directory where the new directory will be created.

<a name='MasterCommander.Core.Services.IDirectoryService.CreateNewDirectory(string,string).newDirectoryName'></a>

`newDirectoryName` [System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String')

The name of the new directory to create.

#### Returns
[System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String')
The path of the newly created directory.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Creates a new directory within a specified base directory.

```csharp
string CreateNewDirectory(string baseDirectory, string newDirectoryName, bool overwrite=false);
string CreateNewDirectory(string baseDirectory, string newDirectoryName, bool overwrite);
```
#### Parameters

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#### [MasterCommander](MasterCommander.md 'MasterCommander')
### [MasterCommander.Core.Services](MasterCommander.md#MasterCommander.Core.Services 'MasterCommander.Core.Services').[IDirectoryService](IDirectoryService.md 'MasterCommander.Core.Services.IDirectoryService')

## IDirectoryService.SetWorkingDirectory(string) Method

Sets the working directory to the directory where the specified solution is located.

```csharp
void SetWorkingDirectory(string relativePath);
```
#### Parameters

<a name='MasterCommander.Core.Services.IDirectoryService.SetWorkingDirectory(string).relativePath'></a>

`relativePath` [System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String')

The relative path from the MasterCommander directory to the solution directory.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Sets the working directory to the directory where the specified solution is located.

```csharp
void SetWorkingDirectory(string relativePath, bool createIfNotExists=false);
void SetWorkingDirectory(string relativePath, bool createIfNotExists);
```
#### Parameters

Expand Down
2 changes: 2 additions & 0 deletions docs/master-commander/IDirectoryService.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ Derived
| [ClearDirectory(string)](IDirectoryService.ClearDirectory(string).md 'MasterCommander.Core.Services.IDirectoryService.ClearDirectory(string)') | Clears the contents of a specified directory. |
| [CompressDirectory(string, string)](IDirectoryService.CompressDirectory(string,string).md 'MasterCommander.Core.Services.IDirectoryService.CompressDirectory(string, string)') | Compresses the specified directory into a ZIP file, including all its files and subdirectories. |
| [CreateNewDirectory(string, string, bool)](IDirectoryService.CreateNewDirectory(string,string,bool).md 'MasterCommander.Core.Services.IDirectoryService.CreateNewDirectory(string, string, bool)') | Creates a new directory within a specified base directory. |
| [CreateNewDirectory(string, string)](IDirectoryService.CreateNewDirectory(string,string).md 'MasterCommander.Core.Services.IDirectoryService.CreateNewDirectory(string, string)') | Creates a new directory within a specified base directory. |
| [CreateTemporaryDirectory()](IDirectoryService.CreateTemporaryDirectory().md 'MasterCommander.Core.Services.IDirectoryService.CreateTemporaryDirectory()') | Creates a temporary directory for use during application execution, which can optionally be cleaned up afterwards. |
| [DecompressToDirectory(string, string)](IDirectoryService.DecompressToDirectory(string,string).md 'MasterCommander.Core.Services.IDirectoryService.DecompressToDirectory(string, string)') | Decompresses a ZIP file into a specified directory, extracting all its contents. |
| [SetWorkingDirectory(string, bool)](IDirectoryService.SetWorkingDirectory(string,bool).md 'MasterCommander.Core.Services.IDirectoryService.SetWorkingDirectory(string, bool)') | Sets the working directory to the directory where the specified solution is located. |
| [SetWorkingDirectory(string)](IDirectoryService.SetWorkingDirectory(string).md 'MasterCommander.Core.Services.IDirectoryService.SetWorkingDirectory(string)') | Sets the working directory to the directory where the specified solution is located. |
| [WatchDirectory(string, Action&lt;FileSystemEventArgs&gt;)](IDirectoryService.WatchDirectory(string,Action_FileSystemEventArgs_).md 'MasterCommander.Core.Services.IDirectoryService.WatchDirectory(string, System.Action<System.IO.FileSystemEventArgs>)') | Monitors a directory for any changes, such as file or subdirectory creation, deletion, or modification, and triggers a callback action when a change is detected. |
18 changes: 16 additions & 2 deletions src/library/MasterCommander/Core/Services/IDirectoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,26 @@ public interface IDirectoryService
/// <value>The working directory.</value>
string? WorkingDirectory { get; }

/// <summary>
/// Sets the working directory to the directory where the specified solution is located.
/// </summary>
/// <param name="relativePath">The relative path from the MasterCommander directory to the solution directory.</param>
void SetWorkingDirectory(string relativePath);

/// <summary>
/// Sets the working directory to the directory where the specified solution is located.
/// </summary>
/// <param name="relativePath">The relative path from the MasterCommander directory to the solution directory.</param>
/// <param name="createIfNotExists">A value indicating whether the directory should be created if it does not exist.</param>
void SetWorkingDirectory(string relativePath, bool createIfNotExists = false);
void SetWorkingDirectory(string relativePath, bool createIfNotExists);

/// <summary>
/// Creates a new directory within a specified base directory.
/// </summary>
/// <param name="baseDirectory">The base directory where the new directory will be created.</param>
/// <param name="newDirectoryName">The name of the new directory to create.</param>
/// <returns>The path of the newly created directory.</returns>
string CreateNewDirectory(string baseDirectory, string newDirectoryName);

/// <summary>
/// Creates a new directory within a specified base directory.
Expand All @@ -41,7 +55,7 @@ public interface IDirectoryService
/// <param name="newDirectoryName">The name of the new directory to create.</param>
/// <param name="overwrite">A value indicating whether an existing directory should be overwritten.</param>
/// <returns>The path of the newly created directory.</returns>
string CreateNewDirectory(string baseDirectory, string newDirectoryName, bool overwrite = false);
string CreateNewDirectory(string baseDirectory, string newDirectoryName, bool overwrite);

/// <summary>
/// Clears the contents of a specified directory.
Expand Down
29 changes: 22 additions & 7 deletions src/library/MasterCommander/Integrations/DirectoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,38 @@ public DirectoryService(IConsole console)
public string? WorkingDirectory { get; set; }

/// <inheritdoc />
public void SetWorkingDirectory(string relativePath, bool createIfNotExists = false)
public void SetWorkingDirectory(string relativePath)
{
WorkingDirectory = Path.Combine(MasterCommanderDirectory, relativePath);
}

/// <inheritdoc />
public void SetWorkingDirectory(string relativePath, bool createIfNotExists)
{
WorkingDirectory = createIfNotExists
? CreateNewDirectory(MasterCommanderDirectory, relativePath, true)
: Path.Combine(MasterCommanderDirectory, relativePath);
}

/// <inheritdoc />
public string CreateNewDirectory(string baseDirectory, string newDirectoryName, bool overwrite = false)
public string CreateNewDirectory(string baseDirectory, string newDirectoryName)
{
var newDirectory = Path.Combine(baseDirectory, newDirectoryName);

if (!Directory.Exists(newDirectory))
{
Directory.CreateDirectory(newDirectory);
}
else if (overwrite)

return newDirectory;
}

/// <inheritdoc />
public string CreateNewDirectory(string baseDirectory, string newDirectoryName, bool overwrite)
{
var newDirectory = CreateNewDirectory(baseDirectory, newDirectoryName);

if (overwrite)
{
ClearDirectory(newDirectory);
}
Expand Down Expand Up @@ -112,10 +127,10 @@ public void WatchDirectory(string directoryPath, Action<FileSystemEventArgs> onC
EnableRaisingEvents = true
};

watcher.Changed += (sender, e) => onChangeCallback(e);
watcher.Created += (sender, e) => onChangeCallback(e);
watcher.Deleted += (sender, e) => onChangeCallback(e);
watcher.Renamed += (sender, e) => onChangeCallback(e);
watcher.Changed += (_, e) => onChangeCallback(e);
watcher.Created += (_, e) => onChangeCallback(e);
watcher.Deleted += (_, e) => onChangeCallback(e);
watcher.Renamed += (_, e) => onChangeCallback(e);
}

/// <inheritdoc />
Expand Down

0 comments on commit 0ed4b59

Please sign in to comment.