Ejemplo n.º 1
0
        public void Configure(DesktopApplicationBuilder app, IServiceProvider services)
        {
            try
            {
                var method = GetConfigureMethod();
                Debug.Assert(method != null);

                var parameters = method.GetParameters();
                var arguments  = new object[parameters.Length];
                for (var i = 0; i < parameters.Length; i++)
                {
                    var parameter = parameters[i];
                    arguments[i] = parameter.ParameterType == typeof(DesktopApplicationBuilder)
                        ? app
                        : services.GetRequiredService(parameter.ParameterType);
                }

                method.Invoke(Instance, arguments);
            }
            catch (Exception ex)
            {
                if (ex is TargetInvocationException)
                {
                    ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
                }

                throw;
            }
        }
Ejemplo n.º 2
0
        private static async Task RunAsync <TStartup>(IPC ipc, CancellationToken appLifetime, ManualResetEventSlim completed)
        {
            var configurationBuilder = new ConfigurationBuilder()
                                       .SetBasePath(Directory.GetCurrentDirectory())
                                       .AddJsonFile("appsettings.json", optional: true);

            DesktopJSRuntime = new DesktopJSRuntime(ipc);
            completed.Set();

            await PerformHandshakeAsync(ipc);

            AttachJsInterop(ipc, appLifetime);

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IConfiguration>(configurationBuilder.Build());
            serviceCollection.AddLogging(configure => configure.AddConsole());
            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);
            }
        }
Ejemplo n.º 3
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);
            }
        }