Skip to content

Commit 1f90d09

Browse files
authored
Merge pull request #82 from Atypical-Consulting/features/undo-redo
Features/undo redo
2 parents a60b778 + 2db33a0 commit 1f90d09

File tree

101 files changed

+2092
-1017
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+2092
-1017
lines changed

.github/dependabot.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@
55

66
version: 2
77
updates:
8-
- package-ecosystem: "nuget" # See documentation for possible values
9-
directory: "/" # Location of package manifests
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
1010
schedule:
11-
interval: "daily"
12-
open-pull-requests-limit: 25
11+
interval: daily
12+
time: "06:30"
13+
timezone: Europe/Brussels
14+
- package-ecosystem: nuget
15+
directory: "/"
16+
schedule:
17+
interval: daily
18+
time: "06:30"
19+
timezone: Europe/Brussels
20+
open-pull-requests-limit: 99
Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# This workflow will build a .NET project
2-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3-
41
name: Publish to NuGet
52

63
on:
@@ -9,39 +6,73 @@ on:
96
- v*
107

118
jobs:
12-
deploy:
13-
9+
build:
10+
runs-on: ubuntu-latest
11+
1412
env:
1513
BUILD_CONFIG: 'Release'
1614
SOLUTION: 'Atypical.VirtualFileSystem.sln'
1715

16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Setup .NET SDK
20+
uses: actions/setup-dotnet@v3
21+
with:
22+
dotnet-version: 8.x
23+
24+
- name: Cache NuGet packages
25+
uses: actions/cache@v3
26+
with:
27+
path: ~/.nuget/packages
28+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
29+
restore-keys: |
30+
${{ runner.os }}-nuget-
31+
32+
- name: Restore dependencies
33+
run: dotnet restore
34+
35+
- name: Build
36+
run: dotnet build $SOLUTION --configuration $BUILD_CONFIG --no-restore
37+
38+
test:
39+
needs: build
40+
runs-on: ubuntu-latest
41+
42+
env:
43+
BUILD_CONFIG: 'Release'
44+
45+
steps:
46+
- uses: actions/checkout@v3
47+
48+
- name: Setup .NET SDK
49+
uses: actions/setup-dotnet@v3
50+
with:
51+
dotnet-version: 8.x
52+
53+
- name: Run Test
54+
run: dotnet test --configuration $BUILD_CONFIG --no-build --verbosity normal --framework net7.0
55+
56+
publish:
57+
needs: test
1858
runs-on: ubuntu-latest
1959

2060
steps:
21-
- uses: actions/checkout@v3
22-
23-
- name: Get Build Version
24-
run: |
25-
Import-Module .\build\GetBuildVersion.psm1
26-
Write-Host $Env:GITHUB_REF
27-
$version = GetBuildVersion -VersionString $Env:GITHUB_REF
28-
echo "BUILD_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
29-
shell: pwsh
30-
31-
- name: Setup .NET SDK
32-
uses: actions/setup-dotnet@v3
33-
with:
34-
dotnet-version: 7.x
35-
36-
- name: Restore dependencies
37-
run: dotnet restore
38-
39-
- name: Build
40-
run: dotnet build $SOLUTION --configuration $BUILD_CONFIG -p:Version=$BUILD_VERSION --no-restore
41-
42-
- name: Run Test
43-
run: dotnet test --configuration $BUILD_CONFIG --no-build --verbosity normal --framework net7.0
44-
45-
- name: Publish to NuGet
46-
if: startsWith(github.ref, 'refs/tags')
47-
run: nuget push **\*.nupkg -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{secrets.NUGET_API_KEY}}
61+
- uses: actions/checkout@v3
62+
63+
- name: Get Build Version
64+
run: |
65+
Import-Module .\build\GetBuildVersion.psm1
66+
Write-Host $Env:GITHUB_REF
67+
$version = GetBuildVersion -VersionString $Env:GITHUB_REF
68+
echo "BUILD_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
69+
shell: pwsh
70+
71+
- name: Setup .NET SDK
72+
uses: actions/setup-dotnet@v3
73+
with:
74+
dotnet-version: 8.x
75+
76+
- name: Publish to NuGet
77+
if: startsWith(github.ref, 'refs/tags')
78+
run: nuget push **\*.nupkg -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{secrets.NUGET_API_KEY}}

.idea/.idea.Atypical.VirtualFileSystem/.idea/.gitignore

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Atypical.VirtualFileSystem.DemoCli" type="DotNetProject" factoryName=".NET Project">
3+
<option name="EXE_PATH" value="$PROJECT_DIR$/Atypical.VirtualFileSystem.DemoCli/bin/Debug/net8.0/Atypical.VirtualFileSystem.DemoCli" />
4+
<option name="PROGRAM_PARAMETERS" value="" />
5+
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Atypical.VirtualFileSystem.DemoCli/bin/Debug/net8.0" />
6+
<option name="PASS_PARENT_ENVS" value="1" />
7+
<option name="USE_EXTERNAL_CONSOLE" value="0" />
8+
<option name="USE_MONO" value="0" />
9+
<option name="RUNTIME_ARGUMENTS" value="" />
10+
<option name="PROJECT_PATH" value="$PROJECT_DIR$/Atypical.VirtualFileSystem.DemoCli/Atypical.VirtualFileSystem.DemoCli.csproj" />
11+
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
12+
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
13+
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
14+
<option name="PROJECT_KIND" value="DotNetCore" />
15+
<option name="PROJECT_TFM" value="net8.0" />
16+
<method v="2">
17+
<option name="Build" />
18+
</method>
19+
</configuration>
20+
</component>

Atypical.VirtualFileSystem.DemoCli/Atypical.VirtualFileSystem.DemoCli.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<ItemGroup>
88
<PackageReference Include="Spectre.Console" Version="0.48.0" />
9+
<PackageReference Include="Spectre.Console.Cli" Version="0.48.0" />
910
</ItemGroup>
1011

1112
<ItemGroup>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
using Spectre.Console.Cli;
2+
3+
namespace Atypical.VirtualFileSystem.DemoCli.Commands;
4+
5+
public class DemonstrateVFS : Command
6+
{
7+
public override int Execute(CommandContext context)
8+
{
9+
// Create a virtual file system
10+
var factory = new VirtualFileSystemFactory();
11+
var vfs = factory.CreateFileSystem();
12+
13+
// Subscribe to VFS events
14+
SubscribeToWriteVFSEvents(vfs, OnChange);
15+
16+
// Display a banner
17+
AnsiConsole.Write(
18+
new FigletText("VFS Demo")
19+
.LeftJustified()
20+
.Color(Color.Gold1));
21+
22+
// Create a directory structure
23+
ProcessStep(vfs, "CREATE A FILE STRUCTURE", () =>
24+
{
25+
vfs.CreateDirectory(new VFSDirectoryPath("/heroes"));
26+
vfs.CreateFile(new VFSFilePath("/heroes/ironman.txt"), "Tony Stark");
27+
vfs.CreateFile(new VFSFilePath("/heroes/captain_america.txt"), "Steve Rogers");
28+
vfs.CreateFile(new VFSFilePath("/heroes/hulk.txt"), "Bruce Banner");
29+
vfs.CreateFile(new VFSFilePath("/heroes/thor.txt"), "Thor Odinson");
30+
vfs.CreateFile(new VFSFilePath("/heroes/black_widow.txt"), "Natasha Romanoff");
31+
32+
vfs.CreateDirectory(new VFSDirectoryPath("/villains"));
33+
vfs.CreateFile(new VFSFilePath("/villains/loki.txt"), "Loki Laufeyson");
34+
vfs.CreateFile(new VFSFilePath("/villains/ultron.txt"), "Ultron");
35+
vfs.CreateFile(new VFSFilePath("/villains/thanos.txt"), "Thanos");
36+
});
37+
38+
// Rename a file
39+
ProcessStep(vfs, "RENAME A FILE",
40+
() => vfs.RenameFile(new VFSFilePath("/heroes/ironman.txt"), "tommy_stark.txt"));
41+
42+
// UNDO
43+
ProcessStep(vfs, "UNDO", () => vfs.ChangeHistory.Undo());
44+
45+
// REDO
46+
ProcessStep(vfs, "REDO", () => vfs.ChangeHistory.Redo());
47+
48+
// Move a file
49+
ProcessStep(vfs, "MOVE A FILE",
50+
() => vfs.MoveFile(new VFSFilePath("/heroes/tony_stark.txt"), new VFSFilePath("/villains/tony_stark.txt")));
51+
52+
// Delete a file
53+
ProcessStep(vfs, "DELETE A FILE",
54+
() => vfs.DeleteFile(new VFSFilePath("/villains/tony_stark.txt")));
55+
56+
// Delete a directory
57+
ProcessStep(vfs, "DELETE DIRECTORY",
58+
() => vfs.DeleteDirectory(new VFSDirectoryPath("/villains")));
59+
60+
// Move a directory
61+
ProcessStep(vfs, "MOVE DIRECTORY",
62+
() => vfs.MoveDirectory(new VFSDirectoryPath("/heroes"), new VFSDirectoryPath("/avengers")));
63+
64+
// Rename a directory
65+
// TODO: fix rename directory
66+
// ProcessStep(vfs, "RENAME DIRECTORY",
67+
// () => vfs.RenameDirectory(new VFSDirectoryPath("/avengers"), new VFSDirectoryPath("/heroes")));
68+
69+
return 0;
70+
}
71+
72+
private static void SubscribeToWriteVFSEvents(
73+
IVirtualFileSystem virtualFileSystem,
74+
Action<VFSEventArgs> action)
75+
{
76+
virtualFileSystem.DirectoryCreated += action;
77+
virtualFileSystem.FileCreated += action;
78+
virtualFileSystem.DirectoryDeleted += action;
79+
virtualFileSystem.FileDeleted += action;
80+
virtualFileSystem.DirectoryMoved += action;
81+
virtualFileSystem.FileMoved += action;
82+
virtualFileSystem.DirectoryRenamed += action;
83+
virtualFileSystem.FileRenamed += action;
84+
}
85+
86+
private static void OnChange(VFSEventArgs args)
87+
{
88+
AnsiConsole.Write(new Markup($" - {args.MessageWithMarkup}"));
89+
AnsiConsole.WriteLine();
90+
}
91+
92+
private static void ProcessStep(IVirtualFileSystem virtualFileSystem, string sectionHeader, Action action)
93+
{
94+
WriteSectionHeader(sectionHeader);
95+
action();
96+
WriteTree(virtualFileSystem);
97+
}
98+
99+
private static void WriteSectionHeader(string header = "")
100+
{
101+
AnsiConsole.Write(new Markup($"[underline yellow]{header}[/]"));
102+
AnsiConsole.WriteLine();
103+
AnsiConsole.WriteLine();
104+
}
105+
106+
private static void WriteTree(IVirtualFileSystem virtualFileSystem)
107+
{
108+
AnsiConsole.WriteLine();
109+
AnsiConsole.Write(new Tree("Marvel Universe").FillTree(virtualFileSystem));
110+
AnsiConsole.WriteLine();
111+
}
112+
}

Atypical.VirtualFileSystem.DemoCli/Extensions/TreeExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// This source code is licensed under the BSD-style license found in the
55
// LICENSE file in the root directory of this source tree.
66

7-
using Atypical.VirtualFileSystem.Core.Contracts;
87
using Spectre.Console.Rendering;
98

109
namespace Atypical.VirtualFileSystem.DemoCli.Extensions;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
// Global using directives
22

3+
global using Atypical.VirtualFileSystem.Core;
4+
global using Atypical.VirtualFileSystem.Core.Contracts;
5+
global using Atypical.VirtualFileSystem.DemoCli.Extensions;
36
global using Spectre.Console;

0 commit comments

Comments
 (0)