public static void Init() { AppConfigurationModel configModel = null; AppConfig dbRow = null; try { using (var con = DependencyService.Get <IDatabase>().GetConnection(ConnectionType.AppConfig)) { dbRow = con.Table <AppConfig>().FirstOrDefault(each => true); if (TryToUpdateCurrentConfigInDb(out configModel, con, dbRow)) { } else { configModel = JsonConvert .DeserializeObject <AppConfigurationModel>(dbRow.ApplicationConfiguration); } CurrentLanguage = dbRow.ConfigInt; SetConfigurations(configModel); } } catch (Exception e) { //wtf var mes = e.Message; } }
public static void ChangeConfiguration(int id) { if (!Busy) { Busy = true; Utility.ShowIndicator = true; if (id != CurrentLanguage) { AppConfigurationModel buffer = default(AppConfigurationModel); bool success = false; using (var con = DependencyService.Get <IDatabase>().GetConnection(ConnectionType.AppConfig)) { success = TryToUpdateCurrentConfigInDb(out buffer, con, new AppConfig { ConfigInt = id }); } if (success) { CurrentLanguage = id; SetConfigurations(buffer); SetColors(); } else { (Application.Current.MainPage as MainPage).DisplayAlert("HomeM8", "İnternet bağlantınızda sorun olabilir", "Tamam"); } } Busy = false; Utility.ShowIndicator = false; } }
static bool TryToUpdateCurrentConfigInDb(out AppConfigurationModel bufferConfigModel, SQLiteConnection con, AppConfig dbRow) { AppConfigResponseModel buffer = null; Task.Run(() => buffer = JsonConvert.DeserializeObject <AppConfigResponseModel>(Helper .httpGetAsync($"{Utility.BaseURL}/api/app/GetAppConfiguration?id={dbRow.ConfigInt}").Result)).Wait(); if (buffer.responseVal == 0) { con.Table <AppConfig>().Delete(each => true); con.Insert(new AppConfig() { ConfigInt = dbRow.ConfigInt, ApplicationConfiguration = buffer.languageJsonString }); bufferConfigModel = JsonConvert.DeserializeObject <AppConfigurationModel>(buffer.languageJsonString); return(true); } else { bufferConfigModel = null; return(false); } }
static void SetConfigurations(AppConfigurationModel configModel) { Instance.DecidePageContent = configModel.DecidePageContent; Instance.AppColorConfiguration = configModel.AppColorConfiguration; Instance.ForgotPasswordPageContent = configModel.ForgotPasswordPageContent; Instance.LoginPageContent = configModel.LoginPageContent; Instance.RegisterPageContent = configModel.RegisterPageContent; Instance.HomePageContent = configModel.HomePageContent; Instance.ApplicationContent = configModel.ApplicationContent; Instance.AccountPageContent = configModel.AccountPageContent; }
public void ChangeConfiguration(int id) { AppConfigurationModel.ChangeConfiguration(id); }
public App() { InitializeComponent(); AppConfigurationModel.SetColors(); MainPage = new MainPage(); }