Exemplo n.º 1
0
        ////////////////////////////////////////////
        // Internals

        private void CreateReplayRenderer(ref ReplayRenderer renderer, ref RemoteRenderer remote)
        {
            if (m_ProxyRenderer < 0)
            {
                renderer = StaticExports.CreateReplayRenderer(m_Logfile, ref LoadProgress);
                return;
            }

            remote = StaticExports.CreateRemoteReplayConnection(m_ReplayHost);

            if (remote == null)
            {
                var e = new System.ApplicationException("Failed to connect to remote replay host");
                e.Data.Add("status", ReplayCreateStatus.UnknownError);
                throw e;
            }

            renderer = remote.CreateProxyRenderer(m_ProxyRenderer, m_Logfile, ref LoadProgress);

            if (renderer == null)
            {
                remote.Shutdown();

                var e = new System.ApplicationException("Failed to connect to remote replay host");
                e.Data.Add("status", ReplayCreateStatus.UnknownError);
                throw e;
            }
        }
Exemplo n.º 2
0
        public static void Init()
        {
            var xinzhi = new XinzhiWeatherForcast("gxs3ezcux67dzvqa", "shanghai");//replace the key with your own, this is for my development only

            xinzhi.Start();
            manager.InfoManager.Providers.Add(xinzhi);
            manager.AddDefinition("preview", previewRenderer, Core.ClockRefreshIntervalEnum.OneTime);
            RemoteRenderer remote = new RemoteRenderer("192.168.0.220");

            manager.AddDefinition("PerMinute", remote, Core.ClockRefreshIntervalEnum.PerMinute);
        }
Exemplo n.º 3
0
    public CircuitHost(
        CircuitId circuitId,
        AsyncServiceScope scope,
        CircuitOptions options,
        CircuitClientProxy client,
        RemoteRenderer renderer,
        IReadOnlyList <ComponentDescriptor> descriptors,
        RemoteJSRuntime jsRuntime,
        RemoteNavigationManager navigationManager,
        CircuitHandler[] circuitHandlers,
        ILogger logger)
    {
        CircuitId = circuitId;
        if (CircuitId.Secret is null)
        {
            // Prevent the use of a 'default' secret.
            throw new ArgumentException($"Property '{nameof(CircuitId.Secret)}' cannot be null.", nameof(circuitId));
        }

        _scope             = scope;
        _options           = options ?? throw new ArgumentNullException(nameof(options));
        Client             = client ?? throw new ArgumentNullException(nameof(client));
        Renderer           = renderer ?? throw new ArgumentNullException(nameof(renderer));
        Descriptors        = descriptors ?? throw new ArgumentNullException(nameof(descriptors));
        JSRuntime          = jsRuntime ?? throw new ArgumentNullException(nameof(jsRuntime));
        _navigationManager = navigationManager ?? throw new ArgumentNullException(nameof(navigationManager));
        _circuitHandlers   = circuitHandlers ?? throw new ArgumentNullException(nameof(circuitHandlers));
        _logger            = logger ?? throw new ArgumentNullException(nameof(logger));

        Services = scope.ServiceProvider;

        Circuit = new Circuit(this);
        Handle  = new CircuitHandle()
        {
            CircuitHost = this,
        };

        // An unhandled exception from the renderer is always fatal because it came from user code.
        Renderer.UnhandledException += ReportAndInvoke_UnhandledException;
        Renderer.UnhandledSynchronizationException += SynchronizationContext_UnhandledException;

        JSRuntime.UnhandledException += ReportAndInvoke_UnhandledException;

        _navigationManager.UnhandledException += ReportAndInvoke_UnhandledException;
    }
Exemplo n.º 4
0
    public static CircuitHost Create(
        CircuitId?circuitId            = null,
        AsyncServiceScope?serviceScope = null,
        RemoteRenderer remoteRenderer  = null,
        IReadOnlyList <ComponentDescriptor> descriptors = null,
        CircuitHandler[] handlers      = null,
        CircuitClientProxy clientProxy = null)
    {
        serviceScope = serviceScope ?? new AsyncServiceScope(Mock.Of <IServiceScope>());
        clientProxy  = clientProxy ?? new CircuitClientProxy(Mock.Of <IClientProxy>(), Guid.NewGuid().ToString());
        var jsRuntime         = new RemoteJSRuntime(Options.Create(new CircuitOptions()), Options.Create(new HubOptions <ComponentHub>()), Mock.Of <ILogger <RemoteJSRuntime> >());
        var navigationManager = new RemoteNavigationManager(Mock.Of <ILogger <RemoteNavigationManager> >());
        var serviceProvider   = new Mock <IServiceProvider>();

        serviceProvider
        .Setup(services => services.GetService(typeof(IJSRuntime)))
        .Returns(jsRuntime);

        if (remoteRenderer == null)
        {
            remoteRenderer = new RemoteRenderer(
                serviceProvider.Object,
                NullLoggerFactory.Instance,
                new CircuitOptions(),
                clientProxy,
                NullLogger.Instance,
                jsRuntime,
                new CircuitJSComponentInterop(new CircuitOptions()));
        }

        handlers ??= Array.Empty <CircuitHandler>();
        return(new TestCircuitHost(
                   circuitId is null ? new CircuitId(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()) : circuitId.Value,
                   serviceScope.Value,
                   new CircuitOptions(),
                   clientProxy,
                   remoteRenderer,
                   descriptors ?? new List <ComponentDescriptor>(),
                   jsRuntime,
                   navigationManager,
                   handlers,
                   NullLogger <CircuitHost> .Instance));
    }
Exemplo n.º 5
0
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            refreshPacks();
            ImageSourceRenderer imgRenderer = new ImageSourceRenderer();

            this.imgResult.DataContext = imgRenderer.Data;
            render.Renderers.Add(new CombinedRendererItem(imgRenderer));
            WaveShareEink32Renderer einkRenderer = new WaveShareEink32Renderer();

            render.Renderers.Add(new CombinedRendererItem(einkRenderer, false));
            RemoteRenderer remoteRenderer = new RemoteRenderer("192.168.0.220");

            render.Renderers.Add(new CombinedRendererItem(remoteRenderer, false));
            lstRenders.ItemsSource = render.Renderers;
            var xinzhi = new XinzhiWeatherForcast("gxs3ezcux67dzvqa", "shanghai");//replace the key with your own, this is for my development only

            xinzhi.Start();
            manager.InfoManager.Providers.Add(xinzhi);
            manager.AddDefinition(CLOCK_NAME, render, SmartClock.Core.ClockRefreshIntervalEnum.PerSecond);
        }
Exemplo n.º 6
0
        public CircuitHost(
            IServiceScope scope,
            IClientProxy client,
            RendererRegistry rendererRegistry,
            RemoteRenderer renderer,
            Action <IBlazorApplicationBuilder> configure,
            IJSRuntime jsRuntime,
            CircuitSynchronizationContext synchronizationContext)
        {
            Scope                  = scope ?? throw new ArgumentNullException(nameof(scope));
            Client                 = client ?? throw new ArgumentNullException(nameof(client));
            RendererRegistry       = rendererRegistry ?? throw new ArgumentNullException(nameof(rendererRegistry));
            Renderer               = renderer ?? throw new ArgumentNullException(nameof(renderer));
            _configure             = configure ?? throw new ArgumentNullException(nameof(configure));
            JSRuntime              = jsRuntime ?? throw new ArgumentNullException(nameof(jsRuntime));
            SynchronizationContext = synchronizationContext ?? throw new ArgumentNullException(nameof(synchronizationContext));

            Services = scope.ServiceProvider;

            Circuit = new Circuit(this);

            Renderer.UnhandledException += Renderer_UnhandledException;
            SynchronizationContext.UnhandledException += SynchronizationContext_UnhandledException;
        }
Exemplo n.º 7
0
        private void RunThread()
        {
            try
            {
                ReplayRenderer renderer = null;
                RemoteRenderer remote   = null;
                CreateReplayRenderer(ref renderer, ref remote);
                if (renderer != null)
                {
                    System.Diagnostics.Debug.WriteLine("Renderer created");

                    Running = true;

                    while (Running)
                    {
                        List <InvokeHandle> queue = new List <InvokeHandle>();
                        lock (m_renderQueue)
                        {
                            foreach (var cmd in m_renderQueue)
                            {
                                queue.Add(cmd);
                            }

                            m_renderQueue.Clear();
                        }

                        foreach (var cmd in queue)
                        {
                            if (cmd.method != null)
                            {
                                cmd.method(renderer);
                            }

                            cmd.processed = true;
                        }

                        m_WakeupEvent.WaitOne(10);
                    }

                    lock (m_renderQueue)
                    {
                        foreach (var cmd in m_renderQueue)
                        {
                            cmd.processed = true;
                        }

                        m_renderQueue.Clear();
                    }

                    renderer.Shutdown();
                    if (remote != null)
                    {
                        remote.Shutdown();
                    }
                }
            }
            catch (ApplicationException ex)
            {
                InitException = ex;
            }
        }
Exemplo n.º 8
0
    public async ValueTask <CircuitHost> CreateCircuitHostAsync(
        IReadOnlyList <ComponentDescriptor> components,
        CircuitClientProxy client,
        string baseUri,
        string uri,
        ClaimsPrincipal user,
        IPersistentComponentStateStore store)
    {
        var scope     = _scopeFactory.CreateAsyncScope();
        var jsRuntime = (RemoteJSRuntime)scope.ServiceProvider.GetRequiredService <IJSRuntime>();

        jsRuntime.Initialize(client);

        var navigationManager      = (RemoteNavigationManager)scope.ServiceProvider.GetRequiredService <NavigationManager>();
        var navigationInterception = (RemoteNavigationInterception)scope.ServiceProvider.GetRequiredService <INavigationInterception>();

        if (client.Connected)
        {
            navigationManager.AttachJsRuntime(jsRuntime);
            navigationManager.Initialize(baseUri, uri);

            navigationInterception.AttachJSRuntime(jsRuntime);
        }
        else
        {
            navigationManager.Initialize(baseUri, uri);
        }

        var appLifetime = scope.ServiceProvider.GetRequiredService <ComponentStatePersistenceManager>();
        await appLifetime.RestoreStateAsync(store);

        var jsComponentInterop = new CircuitJSComponentInterop(_options);
        var renderer           = new RemoteRenderer(
            scope.ServiceProvider,
            _loggerFactory,
            _options,
            client,
            _loggerFactory.CreateLogger <RemoteRenderer>(),
            jsRuntime,
            jsComponentInterop);

        var circuitHandlers = scope.ServiceProvider.GetServices <CircuitHandler>()
                              .OrderBy(h => h.Order)
                              .ToArray();

        var circuitHost = new CircuitHost(
            _circuitIdFactory.CreateCircuitId(),
            scope,
            _options,
            client,
            renderer,
            components,
            jsRuntime,
            navigationManager,
            circuitHandlers,
            _loggerFactory.CreateLogger <CircuitHost>());

        Log.CreatedCircuit(_logger, circuitHost);

        // Initialize per - circuit data that services need
        (circuitHost.Services.GetRequiredService <ICircuitAccessor>() as DefaultCircuitAccessor).Circuit = circuitHost.Circuit;
        circuitHost.SetCircuitUser(user);

        return(circuitHost);
    }
Exemplo n.º 9
0
 private TestCircuitHost(CircuitId circuitId, AsyncServiceScope scope, CircuitOptions options, CircuitClientProxy client, RemoteRenderer renderer, IReadOnlyList <ComponentDescriptor> descriptors, RemoteJSRuntime jsRuntime, RemoteNavigationManager navigationManager, CircuitHandler[] circuitHandlers, ILogger logger)
     : base(circuitId, scope, options, client, renderer, descriptors, jsRuntime, navigationManager, circuitHandlers, logger)
 {
 }