コード例 #1
0
        private static async Task RunAsync <TStartup>(IPC ipc, CancellationToken appLifetime)
        {
            DesktopJSRuntime = new DesktopJSRuntime(ipc);
            await PerformHandshakeAsync(ipc);

            AttachJsInterop(ipc, appLifetime);

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging(configure => configure.AddConsole());
            serviceCollection.AddSingleton <NavigationManager>(DesktopNavigationManager.Instance);
            serviceCollection.AddSingleton <IJSRuntime>(DesktopJSRuntime);
            serviceCollection.AddSingleton <INavigationInterception, DesktopNavigationInterception>();

            var startup = new ConventionBasedStartup(Activator.CreateInstance(typeof(TStartup)));

            startup.ConfigureServices(serviceCollection);

            var services = serviceCollection.BuildServiceProvider();
            var builder  = new DesktopApplicationBuilder(services);

            startup.Configure(builder, services);

            var loggerFactory = services.GetRequiredService <ILoggerFactory>();

            DesktopRenderer = new DesktopRenderer(services, ipc, loggerFactory);
            DesktopRenderer.UnhandledException += (sender, exception) =>
            {
                Console.Error.WriteLine(exception);
            };

            foreach (var rootComponent in builder.Entries)
            {
                _ = DesktopRenderer.AddComponentAsync(rootComponent.componentType, rootComponent.domElementSelector);
            }
        }
コード例 #2
0
        private static async Task RunAsync <TStartup>(IPC ipc, CancellationToken appLifetime)
        {
            var configurationBuilder = new ConfigurationBuilder()
                                       .SetBasePath(Directory.GetCurrentDirectory())
                                       .AddJsonFile("appsettings.json", optional: true);

            /* Configuration Log */
            AgLog.LogLevelSwitch.MinimumLevel = LogEventLevel.Information;
            string strLogTemplate = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {Level:u3}][APP:{ProcessName}][PID:{ProcessId}][THR:{ThreadId}]{operationId} {Message} ";

            strLogTemplate += "{MemberName} {FilePath}{LineNumber}{NewLine}{Exception}";

            Serilog.Log.Logger = new LoggerConfiguration()
                                 .Enrich.FromLogContext()
                                 .Enrich.WithProcessName()
                                 .Enrich.WithProcessId()
                                 .Enrich.WithThreadId()
                                 .Enrich.With <OperationIdEnricher>()
                                 .WriteTo.RollingFile("SecureGate-{Date}.Log",
                                                      //rollingInterval: RollingInterval.Day,
                                                      //rollOnFileSizeLimit: true,
                                                      fileSizeLimitBytes: 1024 * 1024 * 100,
                                                      retainedFileCountLimit: 31,
                                                      buffered: false,
                                                      outputTemplate: strLogTemplate)
                                 .WriteTo.Console(outputTemplate: strLogTemplate, theme: AnsiConsoleTheme.Literate)
                                 .MinimumLevel.ControlledBy(AgLog.LogLevelSwitch)
                                 .CreateLogger();

            DesktopJSRuntime = new DesktopJSRuntime(ipc);
            await PerformHandshakeAsync(ipc);

            AttachJsInterop(ipc, appLifetime);

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IConfiguration>(configurationBuilder.Build());
            serviceCollection.AddLogging(configure => configure.AddConsole()
                                         .AddSerilog(dispose: true));
            serviceCollection.AddSingleton <NavigationManager>(DesktopNavigationManager.Instance);
            serviceCollection.AddSingleton <IJSRuntime>(DesktopJSRuntime);
            serviceCollection.AddSingleton <INavigationInterception, DesktopNavigationInterception>();
            serviceCollection.AddSingleton(WebWindow);

            var startup = new ConventionBasedStartup(Activator.CreateInstance(typeof(TStartup)));

            startup.ConfigureServices(serviceCollection);

            var services = serviceCollection.BuildServiceProvider();
            var builder  = new DesktopApplicationBuilder(services);

            startup.Configure(builder, services);

            var loggerFactory = services.GetRequiredService <ILoggerFactory>();

            DesktopRenderer = new DesktopRenderer(services, ipc, loggerFactory);
            DesktopRenderer.UnhandledException += (sender, exception) =>
            {
                Console.Error.WriteLine(exception);
            };

            foreach (var rootComponent in builder.Entries)
            {
                _ = DesktopRenderer.AddComponentAsync(rootComponent.componentType, rootComponent.domElementSelector);
            }
        }