Exemplo n.º 1
0
        public async Task <AppLaunchResponse> Launch(AppLaunchRequest request, MethodCallContext context)
        {
            if (!_clientFactories.TryGetValue(request.AppId, out var clientFactory))
            {
                throw new InvalidOperationException($"Unknown application launch requested: {request.AppId}");
            }

            var client = await clientFactory.CreateClientAsync(
                _broker,
                UniqueId.FromHiLo(
                    request.SuggestedAppInstanceId.Hi,
                    request.SuggestedAppInstanceId.Lo));

            OnStop(client.Disconnect);
            await client.ConnectAsync().ConfigureAwait(false);

            return(new AppLaunchResponse
            {
                AppInstanceId = new Generated.UniqueId
                {
                    Hi = client.ApplicationInstanceId.Hi,
                    Lo = client.ApplicationInstanceId.Lo
                }
            });
        }
Exemplo n.º 2
0
        public async Task <AppLaunchResponse> Launch(AppLaunchRequest request, MethodCallContext context)
        {
            var appId = request.AppId;
            var suggestedAppInstanceId = UniqueId.FromHiLo(
                request.SuggestedAppInstanceId.Hi,
                request.SuggestedAppInstanceId.Lo);
            Task <IClient> clientTask = null;

            lock (_sync)
            {
                if (request.LaunchMode == AppLaunchMode.SingleInstance &&
                    _createdClients.TryGetValue(appId, out var clientList) &&
                    clientList.Any())
                {
                    var existingClient = clientList.First();
                    clientTask = Task.FromResult(existingClient);
                }

                if (request.LaunchMode != AppLaunchMode.MultiInstance && clientTask == null)
                {
                    if (_createClientTasks.TryGetValue(appId, out var list) && list.Any())
                    {
                        clientTask = list.First();
                    }
                }

                clientTask = clientTask ?? CreateClientAsync(appId, suggestedAppInstanceId);
            }

            var client = await clientTask.ConfigureAwait(false);

            OnStop(client.Disconnect);

            await client.ConnectAsync().ConfigureAwait(false);

            if (client.ApplicationInstanceId == suggestedAppInstanceId)
            {
                lock (_sync)
                {
                    if (_createClientTasks.TryGetValue(appId, out var list))
                    {
                        list.Remove(clientTask);
                        if (!list.Any())
                        {
                            _createClientTasks.Remove(appId);
                        }
                    }
                }
            }

            return(new AppLaunchResponse
            {
                AppInstanceId = new Generated.UniqueId
                {
                    Hi = client.ApplicationInstanceId.Hi,
                    Lo = client.ApplicationInstanceId.Lo
                }
            });
        }
        Task <AppLaunchResponse> AppLauncherService.ILaunchImpl.Launch(AppLaunchRequest request, MethodCallContext context)
        {
            Log.Debug("Launch request received: {0}", request);
            var paramsDto = JsonConvert.Deserialize <NativeAppLauncherParamsDto>(request.LaunchParamsJson);
            var cmd       = Path.Combine(_cmdBasePath, paramsDto.Cmd);
            var id        = _subProcessLauncher.Launch(cmd, paramsDto.Args);

            Log.Trace("Launched app instance {0} by request: {1}", id, request);
            return(Task.FromResult(new AppLaunchResponse
            {
                AppInstanceId = new UniqueId
                {
                    Lo = id.Lo,
                    Hi = id.Hi
                }
            }));
        }
Exemplo n.º 4
0
        private Task <AppLaunchResponse> LaunchAsync(AppLaunchRequest request, MethodCallContext context)
        {
            Log.Debug("Launch request received: {0}", request);
            var paramsDto = _jsonSerializer.Deserialize <NativeAppLauncherParamsDto>(
                new JTokenReader(JToken.Parse(request.LaunchParamsJson)));
            var cmd = Path.Combine(_cmdBasePath, paramsDto.Cmd);
            var id  = _subProcessLauncher.Launch(cmd, paramsDto.Args);

            Log.Trace("Launched app instance {0} by request: {1}", id, request);
            return(Task.FromResult(new AppLaunchResponse
            {
                AppInstanceId = new UniqueId
                {
                    Lo = id.Lo,
                    Hi = id.Hi
                }
            }));
        }
Exemplo n.º 5
0
        private async Task <AppLaunchResponse> LaunchAppAsync(AppLaunchRequest request, MethodCallContext context)
        {
            if (!_clients.TryGetValue(request.AppId, out var clientOptions))
            {
                throw new InvalidOperationException($"Unknown application launch requested: {request.AppId}");
            }
            var instanceId = UniqueId.Generate();
            var client     = ClientFactory.Instance.Create(clientOptions.WithAppInstanceId(instanceId).Build());
            await client.ConnectAsync().ConfigureAwait(false);

            return(new AppLaunchResponse
            {
                AppInstanceId = new Generated.UniqueId
                {
                    Hi = instanceId.Hi,
                    Lo = instanceId.Lo
                }
            });
        }