-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
91 lines (77 loc) · 3.77 KB
/
Copy pathProgram.cs
File metadata and controls
91 lines (77 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using OwlCore.Diagnostics;
using WindowsAppCommunity.CommandLine;
using System.CommandLine;
using OwlCore.Nomad.Kubo;
using OwlCore.Kubo;
using OwlCore.Storage.System.IO;
using WindowsAppCommunity.CommandLine.Repo;
using WindowsAppCommunity.CommandLine.User;
using WindowsAppCommunity.CommandLine.Project;
using WindowsAppCommunity.CommandLine.Publisher;
using WindowsAppCommunity.CommandLine.Blog;
// Logging
var startTime = DateTime.Now;
Logger.MessageReceived += Logger_MessageReceived;
void Logger_MessageReceived(object? sender, LoggerMessageEventArgs e)
{
if (e.Level == LogLevel.Trace)
return;
Console.WriteLine($"+{Math.Round((DateTime.Now - startTime).TotalMilliseconds)}ms {Path.GetFileNameWithoutExtension(e.CallerFilePath)} {e.CallerMemberName} [{e.Level}] {e.Exception} {e.Message}");
}
// Capture and log unhandled or uncaught exceptions.
AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => Logger.LogError(e.ExceptionObject?.ToString() ?? "Error message not found", e.ExceptionObject as Exception);
// FirstChanceException captures all exceptions that are thrown, even if they are caught later.
//AppDomain.CurrentDomain.FirstChanceException += (object? sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e) => Logger.LogError(e.Exception?.ToString() ?? "Error message not found", e.Exception);
// UnobservedTaskException captures non-awaited (fire-and-forget) task exceptions.
//TaskScheduler.UnobservedTaskException += (object? sender, UnobservedTaskExceptionEventArgs e) => Logger.LogError(e.Exception?.ToString() ?? "Error message not found", e.Exception);
// Cancellation
var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;
Console.CancelKeyPress += (sender, eventArgs) =>
{
eventArgs.Cancel = true;
cancellationTokenSource.Cancel();
};
// Storage setup
var userProfileFolder = new SystemFolder(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
var wacsdkRepoFolder = (SystemFolder)await userProfileFolder.CreateFolderAsync(".wacsdk", overwrite: false, cancellationToken);
// Dedicated ipfs repo for testing in.
var kuboRepoFolder = (SystemFolder)await wacsdkRepoFolder.CreateFolderAsync(".ipfs", overwrite: false, cancellationToken);
// Bootstrap and start Kubo
var kubo = new KuboBootstrapper(kuboRepoFolder.Path)
{
GatewayUri = new Uri("http://127.0.0.1:8025"),
ApiUri = new Uri("http://127.0.0.1:5025"),
GatewayUriMode = ConfigMode.OverwriteExisting,
ApiUriMode = ConfigMode.OverwriteExisting,
LaunchConflictMode = BootstrapLaunchConflictMode.Attach,
RoutingMode = DhtRoutingMode.None,
};
await kubo.StartAsync(cancellationToken);
// Command data / config
var config = new WacsdkCommandConfig
{
CancellationToken = cancellationToken,
KuboOptions = new KuboOptions
{
IpnsLifetime = TimeSpan.FromDays(1),
ShouldPin = false,
UseCache = false,
},
Client = kubo.Client,
RepositoryStorage = wacsdkRepoFolder,
};
// Entry
var rootCommand = new RootCommand("Commands for interacting with the Windows App Community SDK.");
rootCommand.AddCommand(new WacsdkRepoCommands(config));
// Determines the Nomad repository used for creating, storing and retrieving WACSDK data.
// This is a required option for commands that interact with WACSDK data.
var repoOption = new Option<string>(name: "--repo-id", () => "default", description: "The ID of the WACSDK repository.")
{
IsRequired = true,
};
rootCommand.AddCommand(new WacsdkUserCommands(config, repoOption));
rootCommand.AddCommand(new WacsdkProjectCommands(config, repoOption));
rootCommand.AddCommand(new WacsdkPublisherCommands(config, repoOption));
rootCommand.AddCommand(new WacsdkBlogCommands());
await rootCommand.InvokeAsync(args);