Пример #1
0
        public App()
        {
            Translation.SetLocale ();

            var netLanguage = DependencyService.Get<ILocale>().GetCurrent();
            AppResources.Culture = new CultureInfo (netLanguage);

            Database = new MediandoDatabase ();
            //SyncData (Database);
            Device.OnPlatform(
                iOS: () => {
                    var homePage = new StartView ();
                    MainPage = homePage;
                },
                Android:() => {
                    var homePage = new NavigationPage (new StartView ()) {
                        BarBackgroundColor = Color.Black,
                        BarTextColor = Color.White,
                    };
                    MainPage = homePage;
                },
                WinPhone:()=>{
                    var homePage = new StartView ();
                    MainPage = homePage;
                }
            );

            App.AppSelected = ApplicationID.Default;
        }
		public static async Task SyncLanguageData (MediandoDatabase db)
		{

			var client = new HttpClient ();
			try {
				string result = await client.GetStringAsync (WebApiConfig.Language);
				var data = JsonConvert.DeserializeObject<IEnumerable<Language>> (result).ToList ();
				db.UpdateLanguages (data);

			} catch (Exception ex) {
				var stri = ex.InnerException.StackTrace;
			}	
		}
		public static async Task CheckForDataUpdate (MediandoDatabase db)
		{
			var client = new HttpClient ();
			try {
				if (App.IsOnline ()) {
					GlobalVariables.IsDownloadingData = true;
					string result = await client.GetStringAsync (WebApiConfig.CurrentVersion);
					var data = JsonConvert.DeserializeObject<IEnumerable<AppVersion>> (result).FirstOrDefault ();
					var currentversion = db.GetAppVersion();
					if(currentversion != null){
						if(currentversion.Major != data.Major || 
							currentversion.Minor != data.Minor){
						    Task.Factory.StartNew (async () => {
								await HttpService.SyncLanguageData (db);
								await HttpService.SyncFiltersData (db);
								await HttpService.SyncCategoriesData (db);
								await HttpService.SyncCatalogData (db);

							});
							Task.WaitAll ();
						}
						else if(currentversion.DataVersion != data.DataVersion){
							await Task.Factory.StartNew (async () => {
								await HttpService.SyncCatalogData (db);

							});
							Task.WaitAll ();
						}
					}
					else{
						await Task.Factory.StartNew (async () => {
							await HttpService.SyncLanguageData (db);
							await HttpService.SyncFiltersData (db);
							await HttpService.SyncCategoriesData (db);
							await HttpService.SyncCatalogData (db);

						});
						Task.WaitAll ();
					}

					db.UpdateAppVersion(data);
				}
			} catch (Exception ex) {
				var stri = ex.InnerException.StackTrace;
			} finally {
				GlobalVariables.IsDownloadingData = false;
			}
		}