public List <Product> GetProducts(User user)
        {
            if (user.ProductsRoles == null || !user.ProductsRoles.Any())
            {
                return(null);
            }

            return(_productManager.Products.Where(p =>
                                                  ProductRoleHelper.IsAvailable(p.Key, user.ProductsRoles)).ToList());
        }
        public List <Product> GetProducts(User user)
        {
            if (user.IsAdmin)
            {
                return(Products);
            }

            if (user.ProductsRoles == null || user.ProductsRoles.Count == 0)
            {
                return(null);
            }

            return(Products.Where(p =>
                                  ProductRoleHelper.IsAvailable(p.Key, user.ProductsRoles)).ToList());
        }
        public List <SensorData> GetSensorsTree(User user)
        {
            if (!_queueManager.IsUserRegistered(user))
            {
                _queueManager.AddUserSession(user);
            }

            List <SensorData> result = new List <SensorData>();
            var productsList         = _productManager.Products;

            //Show available products only
            if (!UserRoleHelper.IsAllProductsTreeAllowed(user))
            {
                productsList = productsList.Where(p =>
                                                  ProductRoleHelper.IsAvailable(p.Key, user.ProductsRoles)).ToList();
            }

            //foreach (var product in productsList)
            //{
            //result.AddRange();
            //var sensorsList = _productManager.GetProductSensors(product.Name);
            //foreach (var sensor in sensorsList)
            //{
            //    var cachedVal = _valuesCache.GetValue(product.Name, sensor.Path);
            //    if (cachedVal != null)
            //    {
            //        result.Add(cachedVal);
            //        continue;
            //    }
            //    var lastVal = _database.GetLastSensorValue(product.Name, sensor.Path);
            //    if (lastVal != null)
            //    {
            //        result.Add(_converter.Convert(lastVal, product.Name));
            //    }
            //}
            //}
            result.AddRange(_valuesCache.GetValues(productsList.Select(p => p.Name).ToList()));

            return(result);
        }
 public static bool IsSensorAvailable(this User user, string key)
 {
     return(ProductRoleHelper.IsAvailable(key, user.ProductsRoles));
 }