コード例 #1
0
        private static async Task RunAsync <TStartup>(IPC ipc, CancellationToken appLifetime)
        {
            var configurationBuilder = new ConfigurationBuilder()
                                       .SetBasePath(Directory.GetCurrentDirectory())
                                       .AddJsonFile("appsettings.json", optional: true);

            DesktopJSRuntime = new DesktopJSRuntime(ipc);
            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(photinoWindow);

            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
        public static void Run <TStartup>(IPhotinoWindow iphotinoWindow)
        {
            //DesktopSynchronizationContext.UnhandledException += (sender, exception) =>
            //{
            //    UnhandledException(exception);
            //};

            photinoWindow = iphotinoWindow;

            var completed = new ManualResetEventSlim();

            CancellationTokenSource appLifetimeCts = new CancellationTokenSource();

            Task.Factory.StartNew(async() =>
            {
                try
                {
                    var ipc = new IPC(photinoWindow);
                    await RunAsync <TStartup>(ipc, appLifetimeCts.Token, completed);
                }
                catch (Exception ex)
                {
                    UnhandledException(ex);
                    throw;
                }
            });

            try
            {
                completed.Wait(); // TODO We need to wait for the new IPC to finish before trying to navigate
                photinoWindow.Load(BlazorAppScheme + "://app/");
                photinoWindow.WaitForClose();
            }
            finally
            {
                appLifetimeCts.Cancel();
            }
        }
コード例 #3
0
 public DesktopJSRuntime(IPC ipc)
 {
     this.JsonSerializerOptions.Converters.Add(new ElementReferenceJsonConverter());
     _ipc = ipc ?? throw new ArgumentNullException(nameof(ipc));
 }
コード例 #4
0
 public DesktopRenderer(IServiceProvider serviceProvider, IPC ipc, ILoggerFactory loggerFactory)
     : base(serviceProvider, loggerFactory)
 {
     _ipc       = ipc ?? throw new ArgumentNullException(nameof(ipc));
     _jsRuntime = serviceProvider.GetRequiredService <IJSRuntime>();
 }
コード例 #5
0
 public DesktopJSRuntime(IPC ipc)
 {
     _ipc = ipc ?? throw new ArgumentNullException(nameof(ipc));
 }