コード例 #1
0
        public void GetConnectionRequestByAppInstanceId()
        {
            RunWith10SecTimeout(async() =>
            {
                var client = CreateClient <EchoClient>();
                await client.ConnectAsync();

                var testClient = CreateClient <EchoClient>();

                var request = new GetConnectionsRequest {
                    AppInstanceId = testClient.ApplicationInstanceId
                };

                var response = await client.AppLifecycleService.GetConnections(request);
                response.Connections.Count.ShouldBe(0);

                await testClient.ConnectAsync();

                response = await client.AppLifecycleService.GetConnections(request);
                response.Connections.Count.ShouldBe(1);
                var descriptor = response.Connections.Single();
                descriptor.AppId.ShouldBe(testClient.ApplicationId);
                descriptor.AppInstanceId.ShouldBe(testClient.ApplicationInstanceId);
                descriptor.ConnectionId.ShouldBe(testClient.ConnectionId);
            });
        }
コード例 #2
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonGlueConfig config = new AmazonGlueConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonGlueClient client = new AmazonGlueClient(creds, config);

            GetConnectionsResponse resp = new GetConnectionsResponse();

            do
            {
                GetConnectionsRequest req = new GetConnectionsRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.GetConnections(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.ConnectionList)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
コード例 #3
0
        public void GetConnectionRequestByAppId()
        {
            RunWith10SecTimeout(async() =>
            {
                var client = CreateClient <EchoClient>();
                await client.ConnectAsync();

                var clients = new List <EchoClient>();
                for (int i = 0; i < 10; i++)
                {
                    clients.Add(CreateClient <EchoClient>());
                }

                await Task.WhenAll(clients.Select(echoClient => echoClient.ConnectAsync()));

                var request = new GetConnectionsRequest {
                    ApplicationId = EchoClient.Id
                };
                var connections = (await client.AppLifecycleService.GetConnections(request)).Connections;
                foreach (var echoClient in clients)
                {
                    connections.FirstOrDefault(descriptor => descriptor.AppId == EchoClient.Id && descriptor.AppInstanceId.Equals(echoClient.ApplicationInstanceId) && descriptor.ConnectionId.Equals(echoClient.ConnectionId)).ShouldNotBeNull();
                }
            });
        }
コード例 #4
0
 private GetConnectionsEvent CreateInitialGetConnectionsEvent(GetConnectionsRequest request)
 {
     return(new GetConnectionsEvent()
     {
         Connections = { GetOnlineConnections(request).Select(c => c.Info.ToProto()) }
     });
 }
コード例 #5
0
        private IEnumerable <IAppConnection> GetOnlineConnections(GetConnectionsRequest request)
        {
            var connectionId = request.ConnectionId.ToUniqueId();

            if (connectionId != UniqueId.Empty)
            {
                if (_appLifecycleManager.TryGetOnlineConnection(connectionId, out var connectionInfo))
                {
                    return(new[] { connectionInfo });
                }
                return(Enumerable.Empty <IAppConnection>());
            }

            var appId         = request.ApplicationId;
            var appInstanceId = request.AppInstanceId.ToUniqueId();

            if (appInstanceId != UniqueId.Empty)
            {
                if (!string.IsNullOrEmpty(appId))
                {
                    if (_appLifecycleManager.TryGetOnlineConnection(appInstanceId, appId, out var connection))
                    {
                        return(new[] { connection });
                    }
                }
                return(_appLifecycleManager.GetAppInstanceConnections(appInstanceId));
            }

            if (!string.IsNullOrEmpty(appId))
            {
                return(_appLifecycleManager.GetAppConnections(appId));
            }

            return(_appLifecycleManager.GetOnlineConnections());
        }
コード例 #6
0
        public void GetConnectionEventsByConnectionId()
        {
            RunWith10SecTimeout(async() =>
            {
                var client = CreateClient <EchoClient>();
                await client.ConnectAsync();

                var testClient = CreateClient <EchoClient>();
                await testClient.ConnectAsync();

                var request = new GetConnectionsRequest {
                    ConnectionId = testClient.ConnectionId
                };

                var responseStream    = client.AppLifecycleService.GetConnectionsStream(request).ResponseStream;
                var initialCollection = await responseStream.ReadAsync();
                initialCollection.EventCase.ShouldBe(GetConnectionsEvent.EventOneofCase.None);
                initialCollection.Connections.Count.ShouldBe(1);

                responseStream.TryRead(out _).ShouldBeFalse();

                await testClient.DisconnectAsync();

                var disconnectEvent = await responseStream.ReadAsync();
                disconnectEvent.EventCase.ShouldBe(GetConnectionsEvent.EventOneofCase.ClosedConnection);
                disconnectEvent.ClosedConnection.ConnectionId.ShouldBe(testClient.ConnectionId);
                disconnectEvent.Connections.Count.ShouldBe(0);

                responseStream.TryRead(out _).ShouldBeFalse();
            });
        }
コード例 #7
0
        public IEnumerable<ConnectionDetails> execute(GetConnectionsRequest the_request)
        {
            set_request(the_request)
                .get_connection();

            var result =
                connection_repository
                .Entities
                .AsEnumerable()
                .Where(cu => cu.ID != request.connection_id
                            && cu.GeoLocation.intersects(connection.GeoLocation))
                .OrderBy(cu => cu.GeoLocation.Geoposition.Distance(connection.GeoLocation.Geoposition))
                //.AsEnumerable()
                //Beacuse datetime queries cannot be executed on SQL Server, so this has to be done in memory
                .Where(cu => (Resources.current_date_time - cu.LastSeen).TotalMinutes < request.last_seen_age_in_minutes)
                .Select(cu => new ConnectionDetails()
                {
                    connection_id = cu.ID,
                    user_display_name = cu.User.DisplayName,
                    user_status_message = cu.User.StatusMessage,
                    long_lat_acc_geo_string = string.Format("{0},{1},{2}", cu.GeoLocation.Geoposition.Longitude, cu.GeoLocation.Geoposition.Latitude, cu.GeoLocation.AccuracyInMetres),
                    user_id = cu.User.ID
                });

            return result;
        }
コード例 #8
0
        /// <summary>
        /// Retrieves every connection matching the specified strategy. All connections are retrieved if no strategy is being specified. Accepts a list of fields to include or exclude in the resulting list of connection objects.
        /// </summary>
        /// <param name="request">Specifies criteria to use when querying connections.</param>
        /// <param name="pagination">Specifies pagination info to use when requesting paged results.</param>
        /// <returns>An <see cref="IPagedList{Connection}"/> containing the list of connections.</returns>
        public Task <IPagedList <Connection> > GetAllAsync(GetConnectionsRequest request, PaginationInfo pagination)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (pagination == null)
            {
                throw new ArgumentNullException(nameof(pagination));
            }

            var queryStrings = new Dictionary <string, string>
            {
                { "fields", request.Fields },
                { "include_fields", request.IncludeFields?.ToString().ToLower() },
                { "name", request.Name },
                { "page", pagination.PageNo.ToString() },
                { "per_page", pagination.PerPage.ToString() },
                { "include_totals", pagination.IncludeTotals.ToString().ToLower() }
            };

            // Add each strategy as a separate querystring
            if (request.Strategy != null)
            {
                foreach (var s in request.Strategy)
                {
                    queryStrings.Add("strategy", s);
                }
            }

            return(Connection.GetAsync <IPagedList <Connection> >("connections", null, queryStrings, null, new PagedListConverter <Connection>("connections")));
        }
コード例 #9
0
        /// <summary>
        /// Retrieves every connection matching the specified strategy. All connections are retrieved if no strategy is being specified. Accepts a list of fields to include or exclude in the resulting list of connection objects.
        /// </summary>
        /// <param name="request">Specifies criteria to use when querying connections.</param>
        /// <param name="pagination">Specifies pagination info to use when requesting paged results.</param>
        /// <returns>An <see cref="IPagedList{Connection}"/> containing the list of connections.</returns>
        public Task <IPagedList <Connection> > GetAllAsync(GetConnectionsRequest request, PaginationInfo pagination)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (pagination == null)
            {
                throw new ArgumentNullException(nameof(pagination));
            }

            var queryStrings = new Dictionary <string, string>
            {
                { "fields", request.Fields },
                { "include_fields", request.IncludeFields?.ToString().ToLower() },
                { "name", request.Name },
                { "page", pagination.PageNo.ToString() },
                { "per_page", pagination.PerPage.ToString() },
                { "include_totals", pagination.IncludeTotals.ToString().ToLower() }
            };

            // Add each strategy as a separate querystring
            if (request.Strategy != null)
            {
                for (var i = 0; i < request.Strategy.Length; i++)
                {
                    queryStrings.Add($"strategy[{i}]", request.Strategy[i]);
                }
            }

            return(Connection.GetAsync <IPagedList <Connection> >(BuildUri("connections", queryStrings), DefaultHeaders, converters));
        }
コード例 #10
0
        private static bool IsSpecificConnectionId(GetConnectionsRequest request, out UniqueId connectionId)
        {
            connectionId = request.ConnectionId.ToUniqueId();
            var isSpecificConnectionId = connectionId != UniqueId.Empty;

            return(isSpecificConnectionId);
        }
コード例 #11
0
        private static bool IsSpecificAppIdWithInstanceId(GetConnectionsRequest request, out string appId, out UniqueId appInstanceId)
        {
            appId         = request.ApplicationId;
            appInstanceId = request.AppInstanceId.ToUniqueId();
            var isSpecificAppIdWithInstanceId = !string.IsNullOrEmpty(appId) && appInstanceId != UniqueId.Empty;

            return(isSpecificAppIdWithInstanceId);
        }
コード例 #12
0
 public Handle_Returns
 (
     WebApplicationFactory <Startup> aWebApplicationFactory,
     JsonSerializerSettings aJsonSerializerSettings
 ) : base(aWebApplicationFactory, aJsonSerializerSettings)
 {
     GetConnectionsRequest = CreateValidGetConnectionsRequest();
 }
コード例 #13
0
 public Returns
 (
     WebApplicationFactory <Startup> aWebApplicationFactory,
     JsonSerializerSettings aJsonSerializerSettings
 ) : base(aWebApplicationFactory, aJsonSerializerSettings)
 {
     GetConnectionsRequest = new GetConnectionsRequest();
 }
コード例 #14
0
 public async Task GetConnectionsStream(GetConnectionsRequest request, IWritableChannel <GetConnectionsEvent> responseStream, MethodCallContext context)
 {
     await _appLifecycleManager.ConnectionEventsStream
     .Where(e => IsEventFitRequest(request, e.Connection))
     .Select(e => CreateGetConnectionsEvent(request, e))
     .Where(e => e != null)
     .StartWith(CreateInitialGetConnectionsEvent(request))
     .PipeAsync(responseStream);
 }
コード例 #15
0
        private GetConnectionsEvent CreateGetConnectionsEvent(GetConnectionsRequest request, AppConnectionEvent appConnectionEvent)
        {
            var response = CreateInitialGetConnectionsEvent(request);

            if (appConnectionEvent.Type == ConnectionEventType.AppConnected)
            {
                response.NewConnection = appConnectionEvent.Connection.ToProto();
            }
            else
            {
                response.ClosedConnection = appConnectionEvent.Connection.ToProto();
            }
            return(response);
        }
コード例 #16
0
        public async Task ResetWalletResponse_and_reset_wallet()
        {
            // Arrage
            // Add something to the wallet
            await CreateAnInvitation();

            //Act
            ResetWalletResponse resetWalletResponse = await Send(ResetWalletRequest);

            // See what is in the wallet
            GetConnectionsRequest  getConnectionsRequest  = CreateValidGetConnectionsRequest();
            GetConnectionsResponse getConnectionsResponse = await Send(getConnectionsRequest);

            // Assert Item created isn't there
            getConnectionsResponse.ConnectionRecords.Count.Should().Be(0);

            ValidateResetWalletResponse(ResetWalletRequest, resetWalletResponse);
        }
コード例 #17
0
        private GetConnectionsEvent CreateGetConnectionsEvent(GetConnectionsRequest request, AppConnectionEvent appConnectionEvent)
        {
            var response = CreateInitialGetConnectionsEvent(request);

            switch (appConnectionEvent.Type)
            {
            case ConnectionEventType.AppConnected:
                response.NewConnection = appConnectionEvent.Connection.ToProto();
                return(response);

            case ConnectionEventType.AppDisconnected:
                response.ClosedConnection = appConnectionEvent.Connection.ToProto();
                return(response);

            default:
                return(null);
            }
        }
コード例 #18
0
        public Task <GetConnectionsResponse> GetConnections(GetConnectionsRequest request, MethodCallContext context)
        {
            var response = CreateConnectionsResponse(GetOnlineConnections(request));

            if (response.Connections.Count == 0 && IsSingleConnectionRequest(request))
            {
                if (IsSpecificConnectionId(request, out var connectionId))
                {
                    throw new InvalidOperationException($"No connection with {connectionId} is found");
                }

                if (IsSpecificAppIdWithInstanceId(request, out var appId, out var appInstanceId))
                {
                    throw new InvalidOperationException($"No connection with for {appInstanceId} application instance id with {appId} app id is found");
                }
            }

            return(Task.FromResult(response));
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        public override async Task ProcessAsync(Auth0ResourceTemplate template)
        {
            using var managementClient = await _managementApiClientFactory.CreateAsync();

            var templatedConnection = _converter.Convert(template);

            var getConnectionsRequest = new GetConnectionsRequest
            {
                IncludeFields = true,
                Fields        = "name,id"
            };
            var allConnections = managementClient.Connections.GetAllAsync(getConnectionsRequest, Reporter);

            var matchingConnection = await allConnections.FirstOrDefaultAsync(x => string.Equals(x.Name, templatedConnection.Name));

            if (matchingConnection == null)
            {
                var createRequest = Reflectorisor.CopyMembers <Connection, ConnectionCreateRequest>(templatedConnection);
                await Create(
                    async() => await managementClient.Connections.CreateAsync(createRequest),
                    request => request.Id,
                    templatedConnection.Name
                    );
            }
            else
            {
                var updateRequest = Reflectorisor.CopyMembers <Connection, ConnectionUpdateRequest>(templatedConnection);
                //Remove the name property. It's not allowed on an update.
                updateRequest.Name = null;

                await Update(
                    async() => await managementClient.Connections.UpdateAsync(matchingConnection.Id, updateRequest),
                    matchingConnection.Id,
                    templatedConnection.Name
                    );
            }
        }
コード例 #21
0
 public static IAsyncEnumerable <Connection> GetAllAsync(this ConnectionsClient client, GetConnectionsRequest request, IReporter reporter = null)
 {
     return(GetAllAsyncInternal(page => client.GetAllAsync(request, page), "connections", reporter));
 }
コード例 #22
0
        private GetConnections set_request(GetConnectionsRequest the_request)
        {
            request = Guard.IsNotNull(the_request, "the_request");

            return this;
        }
コード例 #23
0
 internal static void ValidateGetConnectionsResponse(GetConnectionsRequest aGetConnectionsRequest, GetConnectionsResponse aGetConnectionsResponse)
 {
     aGetConnectionsResponse.CorrelationId.Should().Be(aGetConnectionsRequest.CorrelationId);
     aGetConnectionsResponse.ConnectionRecords.Should().NotBeNull();
     aGetConnectionsResponse.ConnectionRecords.Count.Should().Be(1);
 }
コード例 #24
0
        public GetConnectionsResponse Post(GetConnectionsRequest req)
        {
            GetConnectionsResponse resp = new GetConnectionsResponse();

            resp.EBSolutionConnections = new EbSolutionConnections();

            if (req.ConnectionType == 0)
            {
                EbSolutionConnections dummy = this.Redis.Get <EbSolutionConnections>(string.Format("EbSolutionConnections_{0}", req.TenantAccountId));

                resp.EBSolutionConnections = dummy;

                if (resp.EBSolutionConnections.DataDbConnection != null)
                {
                    resp.EBSolutionConnections.DataDbConnection.Password = "******";
                }

                if (resp.EBSolutionConnections.ObjectsDbConnection != null)
                {
                    resp.EBSolutionConnections.ObjectsDbConnection.Password = "******";
                }

                if (resp.EBSolutionConnections.SMTPConnection != null)
                {
                    resp.EBSolutionConnections.SMTPConnection.Password = "******";
                }
            }

            else if (req.ConnectionType == (int)EbConnectionTypes.SMTP)
            {
                EbSolutionConnections dummy = this.Redis.Get <EbSolutionConnections>(string.Format("EbSolutionConnections_{0}", req.TenantAccountId));

                resp.EBSolutionConnections.SMTPConnection = new SMTPConnection();
                resp.EBSolutionConnections.SMTPConnection = dummy.SMTPConnection;

                if (resp.EBSolutionConnections.SMTPConnection != null)
                {
                    resp.EBSolutionConnections.SMTPConnection.Password = "******";
                }
            }

            else if (req.ConnectionType == (int)EbConnectionTypes.EbDATA)
            {
                EbSolutionConnections dummy = this.Redis.Get <EbSolutionConnections>(string.Format("EbSolutionConnections_{0}", req.TenantAccountId));

                resp.EBSolutionConnections.DataDbConnection = new EbDataDbConnection();
                resp.EBSolutionConnections.DataDbConnection = dummy.DataDbConnection;

                if (resp.EBSolutionConnections.DataDbConnection != null)
                {
                    resp.EBSolutionConnections.DataDbConnection.Password = "******";
                }
            }

            else if (req.ConnectionType == (int)EbConnectionTypes.SMS)
            {
                EbSolutionConnections dummy = this.Redis.Get <EbSolutionConnections>(string.Format("EbSolutionConnections_{0}", req.TenantAccountId));

                resp.EBSolutionConnections.SMSConnection = new SMSConnection();
                resp.EBSolutionConnections.SMSConnection = dummy.SMSConnection;

                if (resp.EBSolutionConnections.DataDbConnection != null)
                {
                    resp.EBSolutionConnections.SMSConnection.Password = "******";
                }
            }

            return(resp);
        }
コード例 #25
0
 private static bool IsSingleConnectionRequest(GetConnectionsRequest request)
 {
     return(IsSpecificConnectionId(request, out _) || IsSpecificAppIdWithInstanceId(request, out _, out _));
 }