Beispiel #1
0
        public async Task <DeviceStatisticsServiceModel> GetDeviceStatisticsAsync(string query)
        {
            ResultWithContinuationToken <List <DeviceConnectionStatusCountModel> > data = null;

            if (this.kustoEnabled)
            {
                if (!string.IsNullOrWhiteSpace(query))
                {
                    // Try to translate clauses to query
                    query = QueryConditionTranslator.ToADXQueryString(query);
                }

                data = await this.GetTwinDataADXQueryAsync <DeviceConnectionStatusCountModel>(
                    KustoQueryPrefix,
                    query,
                    DeviceConnectionStateCountKustoQuery);
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(query))
                {
                    // Try to translate clauses to query
                    query = QueryConditionTranslator.ToQueryString(query);
                }

                data = await this.GetIotDataQueryAsync <DeviceConnectionStatusCountModel>(
                    DeviceConnectionStateCountQueryPrefix,
                    query,
                    DeviceConnectionState,
                    null,
                    MaximumGetList); // Currently data does not show correct edge device connected status count. Will be supported in future.
            }

            return(new DeviceStatisticsServiceModel(data.Result));
        }
Beispiel #2
0
        public async Task <DeviceServiceListModel> GetListFromADXAsync(string inputQuery)
        {
            string querytoBeCached = inputQuery;

            if (!string.IsNullOrWhiteSpace(inputQuery))
            {
                // Try to translate clauses to query
                inputQuery = QueryConditionTranslator.ToADXQueryString(inputQuery);
            }

            DeviceServiceListModel resultModel = null;

            // Commented cache.
            // string tenantId = this.tenantConnectionHelper.TenantId;
            // resultModel = await this.deviceQueryCache.GetCachedQueryResultAsync(tenantId, querytoBeCached);
            // if (resultModel != null)
            // {
            //     return resultModel;
            // }
            string query           = string.Empty;
            string deviceListValue = string.Empty;
            var    allTwins        = await this.GetTwinDataADXQueryAsync <DeviceTwinMirrorModel>(
                KustoQueryPrefix,
                inputQuery,
                KustoOrderByQuery);

            var connectedEdgeDevices = await this.GetConnectedEdgeDevices(allTwins.Result.Select(x => x.Twin).ToList());

            resultModel = new DeviceServiceListModel(
                allTwins.Result.Select(azureTwin => new DeviceServiceModel(
                                           azureTwin.Twin,
                                           this.tenantConnectionHelper.GetIotHubName(),
                                           connectedEdgeDevices.ContainsKey(azureTwin.DeviceId),
                                           azureTwin.DeviceCreatedDate,
                                           azureTwin.TimeStamp)),
                allTwins.ContinuationToken);

            // Commented cache.
            // this.deviceQueryCache.SetTenantQueryResult(
            //    this.tenantConnectionHelper.TenantId,
            //    querytoBeCached,
            //    new DeviceQueryCacheResultServiceModel
            //    {
            //        Result = resultModel,
            //        ResultTimestamp = DateTimeOffset.Now,
            //    });
            return(resultModel);
        }