Example #1
0
        public static async Task <string> GetValuesAsync(string deviceId, string date, string?sensorType)
        {
            DeviceMeasuredValues measuredValues = await AzureBlobRetriever.GetMeasuredValuesAsync(deviceId, date, sensorType);

            var result = Newtonsoft.Json.JsonConvert.SerializeObject(measuredValues);

            return(result);
        }
Example #2
0
        public async System.Threading.Tasks.Task <string?> GetAsync(string apiVersion, string deviceId, string date, string?sensorType)
        {
            var retVal = new DeviceMeasuredValues {
                Name = "Wrong API version"
            };
            var result = Newtonsoft.Json.JsonConvert.SerializeObject(retVal);

            string?deviceMeasuredValues = apiVersion.ToUpper() switch
            {
                "V1" => await V1.GetValuesAsync(deviceId, date, sensorType),
                "F1" => await F1.GetValuesAsync(deviceId, date, sensorType),
                _ => result
            };

            return(deviceMeasuredValues);
        }
    }
Example #3
0
        internal static async Task <DeviceMeasuredValues> GetMeasuredValuesAsync(string deviceId, string date, string?sensorType)
        {
            InitClient();
            var device = new DeviceMeasuredValues
            {
                Name = deviceId
            };

            CloudBlobContainer container = await GetContainerAsync(_Client);

            BlobResultSegment resultSegment = await container.ListBlobsSegmentedAsync(string.Empty, true, BlobListingDetails.Metadata, null, null, null, null);

            if (!CheckIfDeviceIdExist(resultSegment, deviceId))
            {
                device.Name = "DeviceId does not exist";
                return(device);
            }

            List <string> sensorTypes = GetSensorTypesForDevice(resultSegment, deviceId);

            if (sensorType != null && !sensorTypes.Contains(sensorType))
            {
                device.Name = "SensorType does not exist";
                return(device);
            }

            List <string> selectedSensorTypes = sensorType != null ? new List <string> {
                sensorType
            } : sensorTypes;

            List <MeasuredValue> allSensorValues = new List <MeasuredValue>();

            List <Task <List <MeasuredValue> > > tasks = new List <Task <List <MeasuredValue> > >();

            foreach (var sensor in selectedSensorTypes)
            {
                Task <List <MeasuredValue> > theTask = GetSensorFileAsync(container, deviceId, date, sensor);
                tasks.Add(theTask);
            }
            await Task.WhenAll(tasks);

            foreach (var task in tasks)
            {
                List <MeasuredValue> sensorFile = task.Result;
                if (task == tasks.First())
                {
                    allSensorValues = sensorFile;
                }
                else
                {
                    allSensorValues = allSensorValues.Zip(sensorFile, (first, second) =>
                    {
                        MeasuredValue mv = first;
                        mv.SensorValues.Add(second.SensorValues[0]);
                        return(mv);
                    }).ToList();
                }
            }

            if (allSensorValues.Count == 0)
            {
                device.Name = "No data found that date";
            }

            device.MeasuredValues = allSensorValues;

            return(device);
        }