public async Task LoadStaticData()
        {
            StaticTypeList existing = new StaticTypeList();
            var info = NetworkInformation.GetInternetConnectionProfile();
            if (info == null || info.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess)
            {
                existing.TypeTransactions = await LoadCachedTypeTransaction(STATIC_TYPETRANSACTION_FOLDER);
                existing.Categories = await LoadCachedCategory(STATIC_CATEGORY_FOLDER);
                existing.TypeTransactionReasons = await LoadCachedTypeTransactionReason(STATIC_TYPETRANSACTIONREASON_FOLDER);
                existing.TypeSavingsDencities = await LoadCachedTypeSavingsDencity(STATIC_TYPESAVINGFREQUENCY_FOLDER);
                existing.Notifications = await LoadCachedNotification(STATIC_NOTIFICATION_FOLDER);
                existing.TypeFrequencies = await LoadCachedTypeFrequency(STATIC_TYPEFREQUENCY_FOLDER);
                existing.TypeIntervals = await LoadCachedInterval(STATIC_TYPEINTERVAL_FOLDER);
                existing.BudgetThresholds = await LoadCachedBudgetThreshold(STATIC_BUDGETTHRESHOLD_FOLDER);                
            }
            else
            {
                existing = await LoadLiveStaticData();
                await UpdateCacheStaticData(existing);
            }
//            var live = await LoadLiveStaticData();

            LoadTypeTransactionData(existing.TypeTransactions);
            LoadTypeCategoryData(existing.Categories);
            LoadTypeSavingsDencityData(existing.TypeSavingsDencities);
            LoadTypeTransactionReasonData(existing.TypeTransactionReasons);
            LoadNotificationData(existing.Notifications);
            LoadTypeFrequencyData(existing.TypeFrequencies);
            LoadIntervalData(existing.TypeIntervals);
            LoadBudgetThresholdData(existing.BudgetThresholds);
            
        }
 private void SetupAllData(StaticTypeList existing)
 {
     SetupTypeTransactionData(existing.TypeTransactions, true);
     SetupNotificationData(existing.Notifications, true);
     SetupTypeFrequencyData(existing.TypeFrequencies, true);
     SetupIntervalData(existing.TypeIntervals, true);
 }
        private async Task UpdateCacheStaticData(StaticTypeList staticDataList)
        {
            await StorageUtility.Clear(STATIC_CATEGORY_FOLDER);
            await StorageUtility.Clear(STATIC_TYPESAVINGFREQUENCY_FOLDER);
            await StorageUtility.Clear(STATIC_TYPETRANSACTION_FOLDER);
            await StorageUtility.Clear(STATIC_TYPETRANSACTIONREASON_FOLDER);

            foreach (var item in staticDataList.Categories)
                await StorageUtility.SaveItem(STATIC_CATEGORY_FOLDER, item, item.CategoryId);

            foreach (var item in staticDataList.TypeTransactions)
                await StorageUtility.SaveItem(STATIC_TYPETRANSACTION_FOLDER, item, item.TypeTransactionId);

            foreach (var item in staticDataList.TypeTransactionReasons)
                await StorageUtility.SaveItem(STATIC_TYPETRANSACTIONREASON_FOLDER, item, item.TypeTransactionReasonId);

            foreach (var item in staticDataList.TypeSavingsDencities)
                await StorageUtility.SaveItem(STATIC_TYPESAVINGFREQUENCY_FOLDER, item, item.TypeSavingsDencityId);
        }
        public async Task SyncStaticData()
        {
            try
            {
                var staticData = new StaticTypeList();

                staticData.BudgetThresholds = await LoadCachedBudgetThreshold(STATIC_BUDGETTHRESHOLD_FOLDER);
                staticData.Categories = await LoadCachedCategory(STATIC_CATEGORY_FOLDER);
                staticData.TypeIntervals = await LoadCachedInterval(STATIC_TYPEINTERVAL_FOLDER);
                staticData.Notifications = await LoadCachedNotification(STATIC_NOTIFICATION_FOLDER);
                staticData.TypeFrequencies = await LoadCachedTypeFrequency(STATIC_TYPEFREQUENCY_FOLDER);
                //staticData.TypeSavingsDencities = await LoadCachedTypeSavingsDencity(STATIC_TYPESAVINGFREQUENCY_FOLDER);
                staticData.TypeTransactions = await LoadCachedTypeTransaction(STATIC_TYPETRANSACTION_FOLDER);
                staticData.TypeTransactionReasons = await LoadCachedTypeTransactionReason(STATIC_TYPETRANSACTIONREASON_FOLDER);

                var client = new BMAStaticDataService.StaticClient();
                var result = await client.SyncStaticDataAsync(staticData);

                ApplicationData.Current.LocalSettings.Values["IsSync"] = true;

                await UpdateCacheBudgetThresholds(result.BudgetThresholds);
                await UpdateCacheCategory(result.Categories);
                await UpdateCacheNotification(result.Notifications);
                await UpdateCacheTypeFrequency(result.TypeFrequencies);
                await UpdateCacheTypeInterval(result.TypeIntervals);
                //await UpdateCacheTypeSavingsDencity(result.TypeSavingsDencities);
                await UpdateCacheTypeTransaction(result.TypeTransactions);
                await UpdateCacheTypeTransactionReason(result.TypeTransactionReasons);

                LoadBudgetThresholdData(result.BudgetThresholds);
                LoadTypeCategoryData(result.Categories);
                LoadTypeFrequencyData(result.TypeFrequencies);
                LoadTypeSavingsDencityData(result.TypeSavingsDencities);
                LoadTypeTransactionData(result.TypeTransactions);
                LoadTypeTransactionReasonData(result.TypeTransactionReasons);
                LoadNotificationData(result.Notifications);
                LoadIntervalData(result.TypeIntervals);

            }
            catch (Exception)
            {
                throw;
            }
        }
        private static async Task<StaticTypeList> LoadLiveStaticData()
        {
            var retVal = new StaticTypeList();
            var info = NetworkInformation.GetInternetConnectionProfile();

            if (info == null || info.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess)
            {
                return retVal;
            }

            try
            {
                var client = new BMAStaticDataService.StaticClient();
                var result = await client.GetAllStaticDataAsync();

                retVal = result;
            }
            catch (Exception ex)
            {
                var dialog = new MessageDialog(string.Format("There was an error accessing the weather service.\n\r{0}", ex.Message));
                throw;
            }

            return retVal;
        }