private MediaService GetMediaAccountFromCache(Customer customer, MediaServicesAccountConfig accountConfig)
        {
            var account = CloudCache.GetAs <MediaService>(accountConfig.Id);

            if (account != null)
            {
                customer.ChannelCount = account.Channels.Count;
                customer.OriginCount  = account.Origins.Count;
                customer.ProgramCount = account.Programs.Count;
                customer.ArchiveCount = account.Programs.Where(p => p.State == Sdk.ProgramState.Running.ToString()).Count();
                return(new MediaService
                {
                    Id = account.Id,
                    Name = account.Name,
                    Datacenter = account.Datacenter,
                    Health = account.Health
                });
            }
            return(null);
        }
        public IActionResult Get(string id)
        {
            Stopwatch watch            = new Stopwatch();
            var       mediaServicesSet = App.Config.GetCustomer(id);

            if (mediaServicesSet == null)
            {
                return(NotFound());
            }

            Customer customer = new Customer
            {
                Id       = mediaServicesSet.Name,
                Name     = mediaServicesSet.Name,
                Accounts = mediaServicesSet.MediaServicesAccounts.Select(accountConfig =>
                {
                    var account = CloudCache.GetAs <MediaService>(accountConfig.Id);
                    if (account == null)
                    {
                        Trace.TraceWarning("Cache miss for account:{0}", accountConfig.Id);
                        account = new MediaService
                        {
                            Id         = accountConfig.Id,
                            Name       = accountConfig.AccountName,
                            Datacenter = accountConfig.MetaData.Location
                        };
                    }
                    return(account);
                }).ToList()
            };

            // Get each of the account details in parallel.
            Parallel.ForEach(customer.Accounts.Where(account => account.Channels == null),
                             (account, state, i) => GetAccountDetails(mediaServicesSet.MediaServicesAccounts[(int)i], account));
            customer.Health = customer.Accounts.Select(account => account.Health).DefaultIfEmpty(HealthStatus.Healthy).Max();

            Trace.TraceInformation("Time taken load customer details...: {0}", watch.Elapsed);
            return(Ok(customer));
        }