public ActionResult Index()
        {
            DashboardFacts facts = subscriptionService.GetDashboardFacts();

            facts.NumberOfRules = dataService.GetAllRules().Count();
            ViewBag.Facts       = facts;
            return(View());
        }
        public DashboardFacts GetDashboardFacts()
        {
            DashboardFacts facts = new DashboardFacts();

            registryManager = RegistryManager.CreateFromConnectionString(connectionStringForPortal);
            List <Device> localDevices = new List <Device>();
            IEnumerable <Microsoft.Azure.Devices.Device> azureDevice = new List <Microsoft.Azure.Devices.Device>();// = registryManager.GetDevicesAsync(100);
            Task task = Task.Run(() => { azureDevice = registryManager.GetDevicesAsync(100).Result; });

            task.Wait();

            try
            {
                facts.TotalDevices = azureDevice.Count();
                foreach (var x in azureDevice)
                {
                    if (x.ConnectionState == DeviceConnectionState.Connected)
                    {
                        facts.ConnectedDevices++;
                    }
                    else
                    {
                        facts.OfflineDevices++;
                    }
                    facts.TotalCloudToDeviceMessages = x.CloudToDeviceMessageCount;
                }
                return(facts);
            }
            catch (DeviceAlreadyExistsException ex)
            {
                List <AzureException> exception = new List <AzureException>()
                {
                    new AzureException()
                    {
                        Exception = ex, Message = ex.Message
                    }
                };
                return(facts);
            }
        }