private void SubscribeToApplicationLaunchedEventStream(string applicationId, UniqueId connectionId) { var appLauncherServiceId = AppLauncherService.Id; var appLaunchedEventStreamMethodId = AppLauncherService.AppLaunchedEventStreamMethodId; var methodCallDescriptor = ProvidedMethodReference.Create(appLauncherServiceId, appLaunchedEventStreamMethodId, applicationId, connectionId); Task.Factory.StartNew(async() => { Log.Info($"Subscribing to ApplicationLaunchedEventStream of {connectionId} application ({applicationId})"); await _client.Value.CallInvoker .CallServerStreaming <Empty, AppLaunchedEvent>(methodCallDescriptor.CallDescriptor, new Empty()) .ResponseStream.PipeAsync(_appLaunchedSubject).ConfigureAwait(false); Log.Info($"Subscription to ApplicationLaunchedEventStream of {connectionId} application ({applicationId}) have finished"); }, TaskCreationOptions.LongRunning); }
public async ValueTask <UniqueId> LaunchAsync(string appId) { Log.Info("Launching {0}", appId); if (string.Equals(appId, "interop.NativeAppLauncher")) { return((await _startNativeAppLauncherTask.Value.ConfigureAwait(false)).Id); } var appDto = _appsDto.Apps.FirstOrDefault(x => string.Equals(x.Id, appId)); if (appDto == null) { throw new InvalidOperationException($"The requested application {appId} is not defined in application registry"); } if (string.IsNullOrEmpty(appDto.LauncherId)) { throw new InvalidOperationException($"Launcher is not defined for application {appId}"); } var launchMethodReference = ProvidedMethodReference.Create("interop.AppLauncherService", "Launch", appDto.LauncherId); var response = await _client .CallUnary <AppLaunchRequest, AppLaunchResponse>( launchMethodReference.CallDescriptor, new AppLaunchRequest { AppId = appId, LaunchParamsJson = appDto.LauncherParams.ToString() }) .ConfigureAwait(false); var appInstanceId = UniqueId.FromHiLo(response.AppInstanceId.Hi, response.AppInstanceId.Lo); Log.Info("Launched app {0} instance {1}", appId, appInstanceId); return(appInstanceId); }