Esempio n. 1
0
 /// <summary>
 /// Save the state of the view model.  Used for when the application may teardown the memory losing the property
 /// values of the view model.
 /// </summary>
 /// <param name="vm">Vm.</param>
 /// <typeparam name="T">The 1st type parameter.</typeparam>
 public static void SaveState <T>(this T vm) where T : CoreViewModel, new()
 {
     Task.Run(async() =>
     {
         await CoreDependencyService.GetService <IFileStore, FileStore>(true)?.SaveAsync <T>(typeof(T).FullName, vm);
     });
 }
Esempio n. 2
0
        private static void ParseCVS(string data)
        {
            var storage   = (IFileStore)CoreDependencyService.GetService <IFileStore, FileStore>(true);
            var lines     = data.Split('\r');
            var fileNames = lines[0].Split(',');
            var fileData  = new Dictionary <string, Dictionary <string, string> >();

            for (int x = 1; x < fileNames.Length; x++)
            {
                fileData.Add(fileNames[x], new Dictionary <string, string>());
            }

            for (int x = 1; x < lines.Length; x++)
            {
                var columns = lines[x].Split(',');
                var varName = columns[0];
                for (int y = 1; y < columns.Length; y++)
                {
                    var lang = fileNames[y];
                    fileData[lang].Add(varName, columns[y].Replace("\n", string.Empty));
                }
            }

            foreach (var key in fileData.Keys)
            {
                storage.SaveAsync <Dictionary <string, string> >($"{key}.json", fileData[key]).ContinueOn();
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Loads the state of the view model to ensure if torndown by the OS, it can regain the property values.
 /// </summary>
 /// <param name="vm">Vm.</param>
 /// <typeparam name="T">The 1st type parameter.</typeparam>
 public static void LoadState <T>(this T vm) where T : CoreViewModel, new()
 {
     Task.Run(async() =>
     {
         var result = await CoreDependencyService.GetService <IFileStore, FileStore>(true)?.GetAsync <T>(typeof(T).FullName);
         if (result.Error == null)
         {
             foreach (var prop in typeof(T).GetProperties())
             {
                 prop.SetValue(vm, prop.GetValue(result.Response));
             }
         }
     });
 }
Esempio n. 4
0
        public LocalizationService()
        {
            var culture  = CoreDependencyService.GetDependency <ILocalize>().GetCurrentCultureInfo();
            var fileName = $"{culture.TwoLetterISOLanguageName.ToLower()}.json";

            var storage = (IFileStore)CoreDependencyService.GetService <IFileStore, FileStore>(true);

            storage.GetAsync <Dictionary <string, string> >(fileName).ContinueWith((data) =>
            {
                if (data.Result.Success)
                {
                    IsLoaded    = true;
                    localString = data.Result.Response;
                    CoreDependencyService.SendViewModelMessage(CoreSettings.LocalizationLoaded, null);
                }
            });
        }
Esempio n. 5
0
        public static void Init(string version)
        {
            var savedVersion = CrossSettings.Current.GetValueOrDefault("localizationversion", null);

            if (savedVersion == null || !savedVersion.Equals(version))
            {
                var fileString = ResourceLoader.GetEmbeddedResourceString(Assembly.GetAssembly(typeof(ResourceLoader)), "localization.csv");
                if (fileString.Error == null)
                {
                    ParseCVS(fileString.Response);
                }
                CrossSettings.Current.AddOrUpdateValue("localizationversion", version);
                CoreDependencyService.GetService <ILocalizationService, LocalizationService>(true);
            }
            else
            {
                CoreDependencyService.GetService <ILocalizationService, LocalizationService>(true);
            }
        }