Skip to content
Open
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
24 changes: 18 additions & 6 deletions csharp/FileManager/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,45 @@ internal class Program
/// </para>
/// <para></para>
/// </summary>
public static List<ITrigger<Context>> Handlers = new()
public static readonly List<ITrigger<Context>> Handlers = new()
{
new CreateTrigger(),
new DeleteTrigger(),
new HelpTrigger(),
new LinksPrinterTrigger(),
new ShowTrigger(),
new HelpTrigger(),
new CreateFileSetTrigger(),
new GetFilesByFileSetNameTrigger()
};
private static async Task Main(string[] args)
{
using ConsoleCancellation cancellation = new();
var dbContext = new FileStorage(ConsoleHelpers.GetOrReadArgument(0, "Database file name", args));
new HelpTrigger().Action(new Context { FileStorage = dbContext, Args = args });
await new HelpTrigger().Action(new Context { FileStorage = dbContext, Args = args });
try
{
while (!cancellation.Token.IsCancellationRequested)
{
var input = Console.ReadLine();
var Context = new Context { FileStorage = dbContext, Args = input.Split() };
if (string.IsNullOrWhiteSpace(input))
{
continue;
}

var context = new Context { FileStorage = dbContext, Args = input.Split() };
foreach (var handler in Handlers)
{
if (await handler.Condition(Context))
try
{
if (await handler.Condition(context))
{
await handler.Action(context);
break;
}
}
catch (Exception ex)
{
handler.Action(Context);
Console.WriteLine($"Error processing handler {handler.GetType().Name}: {ex.Message}");
}
}
}
Expand Down
Loading