public JsonNetResult GetSnapshot()
        {
            #region Get data from WCF


            var PlatformManagementServiceClient = new PlatformManagementService.PlatformManagementServiceClient();
            var infrastructureSnapshot          = new BillingSnapshot();

            try
            {
                PlatformManagementServiceClient.Open();
                infrastructureSnapshot = PlatformManagementServiceClient.GetBillingShapshot(Common.SharedClientKey);

                //Close the connection
                WCFManager.CloseConnection(PlatformManagementServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(PlatformManagementServiceClient, exceptionMessage, currentMethodString);

                #endregion
            }

            #endregion

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = infrastructureSnapshot;

            return(jsonNetResult);
        }
        public static BillingSnapshot GetBillingSnapshot()
        {
            var billingSnapshot = new BillingSnapshot();

            #region Generate Billing Snapshot

            #region Get from Redis Cache

            //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.PlatformManager_Multiplexer.GetDatabase();
            IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase();

            Object cachedBillingSnapshot = null;

            try
            {
                cachedBillingSnapshot = cache.HashGet(
                    Sahara.Core.Common.Redis.PlatformManagerServer.Hashes.SnapshotsHash.Key,
                    Sahara.Core.Common.Redis.PlatformManagerServer.Hashes.SnapshotsHash.Fields.Billing
                    );

                if (((RedisValue)cachedBillingSnapshot).HasValue)
                {
                    billingSnapshot = JsonConvert.DeserializeObject <BillingSnapshot>((RedisValue)cachedBillingSnapshot);
                }
            }
            catch
            {
            }


            #endregion

            #region Generate Snapshot

            if (((RedisValue)cachedBillingSnapshot).IsNullOrEmpty)
            {
                billingSnapshot = new BillingSnapshot();

                billingSnapshot.CreditsInCirculation             = AccountCreditsManager.GetCreditsInCirculation();
                billingSnapshot.CreditsInCirculationDollarAmount = Sahara.Core.Common.Methods.Commerce.ConvertCreditsAmountToDollars(billingSnapshot.CreditsInCirculation);

                billingSnapshot.Balance = PlatformBillingManager.GetBalance();

                billingSnapshot.UpcomingTransfers = new List <Billing.Models.Transfer>();
                billingSnapshot.LatestTransfers   = new List <Billing.Models.Transfer>();

                try
                {
                    var topTransfers = PlatformBillingManager.GetTransferHistory(10);

                    foreach (var transfer in topTransfers)
                    {
                        if (transfer.Status == "pending")
                        {
                            billingSnapshot.UpcomingTransfers.Add(transfer);
                        }
                        else if (transfer.Status == "paid" && billingSnapshot.LatestTransfers.Count < 2) //<-- We only show the latest 2 available transfers
                        {
                            billingSnapshot.LatestTransfers.Add(transfer);
                        }
                    }

                    //We reverse the upcoming list so the latest transfers show up first
                    billingSnapshot.UpcomingTransfers.Reverse();
                }
                catch
                {
                    billingSnapshot.LatestTransfers   = null;
                    billingSnapshot.UpcomingTransfers = null;
                }

                #region Store in Redis

                try
                {
                    //Store a copy in the Redis cache
                    cache.HashSet(
                        Sahara.Core.Common.Redis.PlatformManagerServer.Hashes.SnapshotsHash.Key,
                        Sahara.Core.Common.Redis.PlatformManagerServer.Hashes.SnapshotsHash.Fields.Billing,
                        JsonConvert.SerializeObject(billingSnapshot),
                        When.Always,
                        CommandFlags.FireAndForget
                        );

                    //Expire cache after set time
                    cache.KeyExpire(
                        Sahara.Core.Common.Redis.PlatformManagerServer.Hashes.SnapshotsHash.Key,
                        Sahara.Core.Common.Redis.PlatformManagerServer.Hashes.SnapshotsHash.Expiration,
                        CommandFlags.FireAndForget
                        );
                }
                catch
                {
                }

                #endregion
            }


            #endregion

            #endregion

            return(billingSnapshot);
        }