Example #1
0
 private void OnAppConnected(AppConnectionDescriptor appConnectionDescriptor)
 {
     if (IsLauncher(appConnectionDescriptor, out var applicationId))
     {
         SubscribeToApplicationLaunchedEventStream(applicationId, appConnectionDescriptor.ConnectionId);
     }
 }
Example #2
0
        private bool IsLauncher(AppConnectionDescriptor appConnectionDescriptor, out string applicationId)
        {
            applicationId = appConnectionDescriptor.ApplicationId;
            var isLauncherApplication = _registryProvider.Current.Applications[applicationId].ProvidedServices
                                        .Any(service => service.Service.Id == AppLauncherService.Id);

            return(isLauncherApplication);
        }
 private static Generated.AppConnectionDescriptor ConvertToProto(AppConnectionDescriptor connection)
 {
     return(new Generated.AppConnectionDescriptor
     {
         AppInstanceId = connection.ApplicationInstanceId.ToProto(),
         AppId = connection.ApplicationId,
         ConnectionId = connection.ConnectionId.ToProto(),
     });
 }
        public async Task <ResolveAppResponse> ResolveApp(ResolveAppRequest request, MethodCallContext context)
        {
            Log.Info("Resolving app by request {{{0}}} from {{{1}}}", request, context);
            var referrerConnectionInfo = new AppConnectionDescriptor(
                context.ConsumerConnectionId,
                context.ConsumerApplicationId,
                context.ConsumerApplicationInstanceId);
            var resolveMode = Convert(request.AppResolveMode);

            if (resolveMode == ResolveMode.SingleInstance)
            {
                var connection = _appLifecycleManager.GetOnlineConnections().FirstOrDefault(c => c.Info.ApplicationId.Equals(request.AppId));
                Log.Debug("Resolved connection for app {0} with mode {1} to online instance {{{2}}}", connection, resolveMode, connection);
                if (connection != null)
                {
                    return(new ResolveAppResponse
                    {
                        AppInstanceId = connection.Info.ApplicationInstanceId.ToProto(),
                        AppConnectionId = connection.Info.ConnectionId.ToProto(),
                        IsNewInstanceLaunched = false,
                    });
                }
            }

            var resolvedConnection = await _appLifecycleManager.LaunchAndConnectAsync(
                request.AppId, resolveMode, referrerConnectionInfo).ConfigureAwait(false);

            var info = resolvedConnection.AppConnection.Info;

            Log.Info("App connection {{{0}}} resolved by request from {{{1}}}", resolvedConnection, context);
            var response = new ResolveAppResponse
            {
                AppConnectionId       = info.ConnectionId.ToProto(),
                AppInstanceId         = info.ApplicationInstanceId.ToProto(),
                IsNewInstanceLaunched = resolvedConnection.IsNewInstance
            };

            return(response);
        }
        private static bool IsEventFitRequest(GetConnectionsRequest request, AppConnectionDescriptor connection)
        {
            var connectionId = request.ConnectionId.ToUniqueId();

            if (connectionId != UniqueId.Empty)
            {
                return(connectionId.Equals(connection.ConnectionId));
            }
            var appId         = request.ApplicationId;
            var appInstanceId = request.AppInstanceId.ToUniqueId();

            if (appInstanceId != UniqueId.Empty && !connection.ApplicationInstanceId.Equals(appInstanceId))
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(appId) && !connection.ApplicationId.Equals(appId))
            {
                return(false);
            }

            return(true);
        }