<commit_before>﻿using Core.Models;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.RetryPolicies;
using Microsoft.WindowsAzure.Storage.Table;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Core.Services
{
    /// <summary>
    /// Thread safe type to perform operations against Azure's storage service.
    /// </summary>
    public class AzureTableStorageService : ITableService
    {
        private const string TABLE_SENSORS_STATE = "SensorsState";
        private const int RETRY_COUNT = 3;
        private readonly TimeSpan RETRY_INTERVAL = TimeSpan.FromMilliseconds(500);

        private readonly CloudStorageAccount _account;
        private readonly ILogger _logger;

        public AzureTableStorageService(string connectionString, ILogger logger)
        {
            if (String.IsNullOrEmpty(connectionString)) throw new ArgumentNullException(nameof(connectionString));
            if (logger == null) throw new ArgumentNullException(nameof(logger));

            _logger = logger;
            _account = CloudStorageAccount.Parse(connectionString);
        }


        public async Task<IList<SensorStatePersisted>> GetSensorsStateAsync(IList<Client> clients)
        {
            if (clients == null) throw new ArgumentNullException(nameof(clients));
            if (clients.Count == 0) throw new ArgumentException(nameof(clients));

            var operationsTasks = new List<Task<TableResult>>();
            var tableRef = getTableReference(TABLE_SENSORS_STATE);

            foreach (var client in clients)
            {
                foreach (var sensor in client.Sensors)
                {
                    operationsTasks.Add(tableRef.ExecuteAsync(TableOperation.Retrieve(
                        client.ClientId.ToString(), $"{sensor.sensorType}_{sensor.sensorId}")));
                }
            }

            var result = await Task.WhenAll(operationsTasks);<commit_msg>Removed exception when no online clients<commit_after>﻿using Core.Models;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.RetryPolicies;
using Microsoft.WindowsAzure.Storage.Table;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Core.Services
{
    /// <summary>
    /// Thread safe type to perform operations against Azure's storage service.
    /// </summary>
    public class AzureTableStorageService : ITableService
    {
        private const string TABLE_SENSORS_STATE = "SensorsState";
        private const int RETRY_COUNT = 3;
        private readonly TimeSpan RETRY_INTERVAL = TimeSpan.FromMilliseconds(500);

        private readonly CloudStorageAccount _account;
        private readonly ILogger _logger;

        public AzureTableStorageService(string connectionString, ILogger logger)
        {
            if (String.IsNullOrEmpty(connectionString)) throw new ArgumentNullException(nameof(connectionString));
            if (logger == null) throw new ArgumentNullException(nameof(logger));

            _logger = logger;
            _account = CloudStorageAccount.Parse(connectionString);
        }


        public async Task<IList<SensorStatePersisted>> GetSensorsStateAsync(IList<Client> clients)
        {
            if (clients == null) throw new ArgumentNullException(nameof(clients));
            if (clients.Count == 0) return new List<SensorStatePersisted>();

            var operationsTasks = new List<Task<TableResult>>();
            var tableRef = getTableReference(TABLE_SENSORS_STATE);

            foreach (var client in clients)
            {
                foreach (var sensor in client.Sensors)
                {
                    operationsTasks.Add(tableRef.ExecuteAsync(TableOperation.Retrieve(
                        client.ClientId.ToString(), $"{sensor.sensorType}_{sensor.sensorId}")));
                }
            }

            var result = await Task.WhenAll(operationsTasks);
{'fraction_non_alphanumeric': 0.08383233532934131, 'fraction_numerical': 0.00249500998003992, 'mean_word_length': 2.796401515151515, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5991961', 'n_tokens_mistral': 991, 'n_tokens_neox': 971, 'n_words': 240}