Skip to content

Commit

Permalink
Merge pull request #82 from Atypical-Consulting/features/undo-redo
Browse files Browse the repository at this point in the history
Features/undo redo
  • Loading branch information
phmatray authored Apr 4, 2024
2 parents a60b778 + 2db33a0 commit 1f90d09
Show file tree
Hide file tree
Showing 101 changed files with 2,092 additions and 1,017 deletions.
16 changes: 12 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@

version: 2
updates:
- package-ecosystem: "nuget" # See documentation for possible values
directory: "/" # Location of package manifests
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 25
interval: daily
time: "06:30"
timezone: Europe/Brussels
- package-ecosystem: nuget
directory: "/"
schedule:
interval: daily
time: "06:30"
timezone: Europe/Brussels
open-pull-requests-limit: 99
95 changes: 63 additions & 32 deletions .github/workflows/publish-to-nuget.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: Publish to NuGet

on:
Expand All @@ -9,39 +6,73 @@ on:
- v*

jobs:
deploy:

build:
runs-on: ubuntu-latest

env:
BUILD_CONFIG: 'Release'
SOLUTION: 'Atypical.VirtualFileSystem.sln'

steps:
- uses: actions/checkout@v3

- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.x

- name: Cache NuGet packages
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build $SOLUTION --configuration $BUILD_CONFIG --no-restore

test:
needs: build
runs-on: ubuntu-latest

env:
BUILD_CONFIG: 'Release'

steps:
- uses: actions/checkout@v3

- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.x

- name: Run Test
run: dotnet test --configuration $BUILD_CONFIG --no-build --verbosity normal --framework net7.0

publish:
needs: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Get Build Version
run: |
Import-Module .\build\GetBuildVersion.psm1
Write-Host $Env:GITHUB_REF
$version = GetBuildVersion -VersionString $Env:GITHUB_REF
echo "BUILD_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
shell: pwsh

- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.x

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build $SOLUTION --configuration $BUILD_CONFIG -p:Version=$BUILD_VERSION --no-restore

- name: Run Test
run: dotnet test --configuration $BUILD_CONFIG --no-build --verbosity normal --framework net7.0

- name: Publish to NuGet
if: startsWith(github.ref, 'refs/tags')
run: nuget push **\*.nupkg -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{secrets.NUGET_API_KEY}}
- uses: actions/checkout@v3

- name: Get Build Version
run: |
Import-Module .\build\GetBuildVersion.psm1
Write-Host $Env:GITHUB_REF
$version = GetBuildVersion -VersionString $Env:GITHUB_REF
echo "BUILD_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
shell: pwsh

- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.x

- name: Publish to NuGet
if: startsWith(github.ref, 'refs/tags')
run: nuget push **\*.nupkg -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{secrets.NUGET_API_KEY}}
2 changes: 2 additions & 0 deletions .idea/.idea.Atypical.VirtualFileSystem/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .run/Atypical.VirtualFileSystem.DemoCli.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Atypical.VirtualFileSystem.DemoCli" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/Atypical.VirtualFileSystem.DemoCli/bin/Debug/net8.0/Atypical.VirtualFileSystem.DemoCli" />
<option name="PROGRAM_PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Atypical.VirtualFileSystem.DemoCli/bin/Debug/net8.0" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/Atypical.VirtualFileSystem.DemoCli/Atypical.VirtualFileSystem.DemoCli.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value="net8.0" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<ItemGroup>
<PackageReference Include="Spectre.Console" Version="0.48.0" />
<PackageReference Include="Spectre.Console.Cli" Version="0.48.0" />
</ItemGroup>

<ItemGroup>
Expand Down
112 changes: 112 additions & 0 deletions Atypical.VirtualFileSystem.DemoCli/Commands/DemonstrateVFS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using Spectre.Console.Cli;

namespace Atypical.VirtualFileSystem.DemoCli.Commands;

public class DemonstrateVFS : Command
{
public override int Execute(CommandContext context)
{
// Create a virtual file system
var factory = new VirtualFileSystemFactory();
var vfs = factory.CreateFileSystem();

// Subscribe to VFS events
SubscribeToWriteVFSEvents(vfs, OnChange);

// Display a banner
AnsiConsole.Write(
new FigletText("VFS Demo")
.LeftJustified()
.Color(Color.Gold1));

// Create a directory structure
ProcessStep(vfs, "CREATE A FILE STRUCTURE", () =>
{
vfs.CreateDirectory(new VFSDirectoryPath("/heroes"));
vfs.CreateFile(new VFSFilePath("/heroes/ironman.txt"), "Tony Stark");
vfs.CreateFile(new VFSFilePath("/heroes/captain_america.txt"), "Steve Rogers");
vfs.CreateFile(new VFSFilePath("/heroes/hulk.txt"), "Bruce Banner");
vfs.CreateFile(new VFSFilePath("/heroes/thor.txt"), "Thor Odinson");
vfs.CreateFile(new VFSFilePath("/heroes/black_widow.txt"), "Natasha Romanoff");

vfs.CreateDirectory(new VFSDirectoryPath("/villains"));
vfs.CreateFile(new VFSFilePath("/villains/loki.txt"), "Loki Laufeyson");
vfs.CreateFile(new VFSFilePath("/villains/ultron.txt"), "Ultron");
vfs.CreateFile(new VFSFilePath("/villains/thanos.txt"), "Thanos");
});

// Rename a file
ProcessStep(vfs, "RENAME A FILE",
() => vfs.RenameFile(new VFSFilePath("/heroes/ironman.txt"), "tommy_stark.txt"));

// UNDO
ProcessStep(vfs, "UNDO", () => vfs.ChangeHistory.Undo());

// REDO
ProcessStep(vfs, "REDO", () => vfs.ChangeHistory.Redo());

// Move a file
ProcessStep(vfs, "MOVE A FILE",
() => vfs.MoveFile(new VFSFilePath("/heroes/tony_stark.txt"), new VFSFilePath("/villains/tony_stark.txt")));

// Delete a file
ProcessStep(vfs, "DELETE A FILE",
() => vfs.DeleteFile(new VFSFilePath("/villains/tony_stark.txt")));

// Delete a directory
ProcessStep(vfs, "DELETE DIRECTORY",
() => vfs.DeleteDirectory(new VFSDirectoryPath("/villains")));

// Move a directory
ProcessStep(vfs, "MOVE DIRECTORY",
() => vfs.MoveDirectory(new VFSDirectoryPath("/heroes"), new VFSDirectoryPath("/avengers")));

// Rename a directory
// TODO: fix rename directory
// ProcessStep(vfs, "RENAME DIRECTORY",
// () => vfs.RenameDirectory(new VFSDirectoryPath("/avengers"), new VFSDirectoryPath("/heroes")));

return 0;
}

private static void SubscribeToWriteVFSEvents(
IVirtualFileSystem virtualFileSystem,
Action<VFSEventArgs> action)
{
virtualFileSystem.DirectoryCreated += action;
virtualFileSystem.FileCreated += action;
virtualFileSystem.DirectoryDeleted += action;
virtualFileSystem.FileDeleted += action;
virtualFileSystem.DirectoryMoved += action;
virtualFileSystem.FileMoved += action;
virtualFileSystem.DirectoryRenamed += action;
virtualFileSystem.FileRenamed += action;
}

private static void OnChange(VFSEventArgs args)
{
AnsiConsole.Write(new Markup($" - {args.MessageWithMarkup}"));
AnsiConsole.WriteLine();
}

private static void ProcessStep(IVirtualFileSystem virtualFileSystem, string sectionHeader, Action action)
{
WriteSectionHeader(sectionHeader);
action();
WriteTree(virtualFileSystem);
}

private static void WriteSectionHeader(string header = "")
{
AnsiConsole.Write(new Markup($"[underline yellow]{header}[/]"));
AnsiConsole.WriteLine();
AnsiConsole.WriteLine();
}

private static void WriteTree(IVirtualFileSystem virtualFileSystem)
{
AnsiConsole.WriteLine();
AnsiConsole.Write(new Tree("Marvel Universe").FillTree(virtualFileSystem));
AnsiConsole.WriteLine();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

using Atypical.VirtualFileSystem.Core.Contracts;
using Spectre.Console.Rendering;

namespace Atypical.VirtualFileSystem.DemoCli.Extensions;
Expand Down
3 changes: 3 additions & 0 deletions Atypical.VirtualFileSystem.DemoCli/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Global using directives

global using Atypical.VirtualFileSystem.Core;
global using Atypical.VirtualFileSystem.Core.Contracts;
global using Atypical.VirtualFileSystem.DemoCli.Extensions;
global using Spectre.Console;
Loading

0 comments on commit 1f90d09

Please sign in to comment.