コード例 #1
0
        /// <inheritdoc/>
        public async Task <GatewayListModel> QueryGatewaysAsync(
            GatewayQueryModel model, int?pageSize, CancellationToken ct)
        {
            var query = "SELECT * FROM devices WHERE " +
                        $"tags.{TwinProperty.Type} = '{IdentityType.Gateway}' ";

            if (model?.SiteId != null)
            {
                // If site id provided, include it in search
                query +=
                    $"AND (tags.{TwinProperty.SiteId} = '{model.SiteId}' OR deviceId = '{model.SiteId}') ";
            }
            if (model?.Connected != null)
            {
                // If flag provided, include it in search
                if (model.Connected.Value)
                {
                    query += $"AND connectionState = 'Connected' ";
                }
                else
                {
                    query += $"AND connectionState != 'Connected' ";
                }
            }

            var queryResult = await _iothub.QueryDeviceTwinsAsync(query, null, pageSize, ct);

            return(new GatewayListModel {
                ContinuationToken = queryResult.ContinuationToken,
                Items = queryResult.Items
                        .Select(t => t.ToGatewayRegistration())
                        .Select(s => s.ToServiceModel())
                        .ToList()
            });
        }
コード例 #2
0
        /// <inheritdoc/>
        public async Task <GatewayListModel> QueryGatewaysAsync(
            GatewayQueryModel model, int?pageSize, CancellationToken ct)
        {
            var query = "SELECT * FROM devices WHERE " +
                        $"(tags.{TwinProperty.Type} = '{IdentityType.Gateway}' OR tags.iiotedge = true) ";

            if (model?.SiteId != null)
            {
                // If site id provided, include it in search
                query += $"AND (tags.{TwinProperty.SiteId} = '{model.SiteId}' OR deviceId = " +
                         $"'{model.SiteId})') ";
            }
            if (model?.Connected != null)
            {
                // If flag provided, include it in search
                if (model.Connected.Value)
                {
                    query += $"AND connectionState = 'Connected' ";
                    // Do not use connected property as module might have exited before updating.
                }
                else
                {
                    query += $"AND (connectionState = 'Disconnected' " +
                             $"OR properties.reported.{TwinProperty.Connected} != true) ";
                }
            }

            var queryResult = await _iothub.QueryDeviceTwinsAsync(query, null, pageSize, ct);

            return(new GatewayListModel {
                ContinuationToken = queryResult.ContinuationToken,
                Items = queryResult.Items
                        .Select(t => t.ToGatewayRegistration())
                        .Select(s => s.ToServiceModel())
                        .ToList()
            });
        }