示例#1
0
        public InteropContext(string metadataDir, IRegistryProvider registryProvider)
        {
            RegistryProvider = registryProvider;
            var appRegistryProvider = JsonFileAppRegistryProvider.Initialize(Path.Combine(metadataDir, "apps.json"));

            _nativeAppLauncherClient = new NativeAppLauncherClient(metadataDir);

            var clientLazy = new Lazy <IClient>(() => _lifecycleManagerClient);

            _appLifecycleManager = new AppLifecycleManager(appRegistryProvider, clientLazy);
            var appLaunchedEventProvider = new AppLaunchedEventProvider(_appLifecycleManager, registryProvider, clientLazy);

            var appMetadataService = new AppMetadataServiceImpl(appRegistryProvider, registryProvider);

            _appLifecycleService   = new AppLifecycleServiceImpl(_appLifecycleManager);
            _contextLinkageService = new ContextLinkageServiceImpl(registryProvider, _appLifecycleManager, appLaunchedEventProvider);

            _lifecycleManagerClient = new AppLifecycleManagerClient(
                _appLifecycleService,
                appMetadataService,
                _contextLinkageService,
                s => s.WithBrokerWorkingDir(Directory.GetCurrentDirectory()));

            OnStop(_nativeAppLauncherClient.Stop);
            OnStop(_lifecycleManagerClient.Disconnect);
        }
 private void SetConnectedClient(AppLifecycleManagerClient client)
 {
     lock (_lifecycleClientAccess)
     {
         _lifecycleManagerClient = client;
     }
     _clientConnections.OnNext(client);
 }
        public async Task <AppLifecycleManagerClient> GetClientAsync()
        {
            AppLifecycleManagerClient runningClient = GetRunningClient();

            if (runningClient != null)
            {
                return(runningClient);
            }

            return(await _clientConnections.AsObservable().FirstOrDefaultAsync());
        }
        private void RemoveCurrentClient()
        {
            AppLifecycleManagerClient client;

            lock (_lifecycleClientAccess)
            {
                client = _lifecycleManagerClient;
                _lifecycleManagerClient = null;
            }
            client?.Dispose();
        }
        private void SubscribeToLaunchedEventStream(AppLifecycleManagerClient client, UniqueId connectionId, string applicationId, ProvidedMethodReference methodCallDescriptor)
        {
            Task.Factory.StartNew(async() =>
            {
                Log.Info($"Subscribing client '{client.ApplicationInstanceId}' to ApplicationLaunchedEventStream of {connectionId} application ({applicationId})");

                await client.CallInvoker
                .CallServerStreaming <Empty, AppLaunchedEvent>(methodCallDescriptor.CallDescriptor, new Empty())
                .ResponseStream.PipeAsync(_appLaunchedEventConsumer.AppLaunchedEventObserver).ConfigureAwait(false);
                Log.Info($"Subscription to ApplicationLaunchedEventStream of {connectionId} application ({applicationId}) have finished");
            }, TaskCreationOptions.LongRunning);
        }
        public IObservable <AppLifecycleManagerClient> GetClientObservable()
        {
            var clientObservable = _clientConnections.AsObservable();

            AppLifecycleManagerClient runningClient = GetRunningClient();

            if (runningClient != null)
            {
                return(Observable.Return(runningClient).Merge(clientObservable).DistinctUntilChanged());
            }

            return(clientObservable);
        }
 private void Disconnect(AppLifecycleManagerClient client)
 {
     client?.Disconnect();
 }