private async void ReceiveSurveys() { SurveysServices S_S1 = new SurveysServices(); ControlFile controlFile = new ControlFile(); string username = await controlFile.GetUserName(); S_S1.Set_UrlApi("ReceiveSurveysShared/" + username); List <Survey> ReceivedSurveys = await S_S1.GetSurveysAsync(); ExistenceCheckResult result = await folder.CheckExistsAsync("Receivedsurveys"); if (result == ExistenceCheckResult.FolderExists) { folder = await folder.CreateFolderAsync("Receivedsurveys", CreationCollisionOption.OpenIfExists); file = await folder.CreateFileAsync("Receivedsurveys", CreationCollisionOption.OpenIfExists); string Content = await file.ReadAllTextAsync(); List <Survey> OldreceiveSurveys = Serializable_Survey.deserialize(Content).ToList(); if (OldreceiveSurveys.Count < ReceivedSurveys.Count) { var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player.Load("NotificationReceive.mp3"); player.Play(); Plugin.LocalNotifications.CrossLocalNotifications.Current.Show(Lang.Resource.receivesurveys, Lang.Resource.BodyreceiveSurvey, 0); } } else if (result != ExistenceCheckResult.FolderExists && ReceivedSurveys.Count > 0) { var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player.Load("NotificationReceive.mp3"); player.Play(); Plugin.LocalNotifications.CrossLocalNotifications.Current.Show(Lang.Resource.receivesurveys, Lang.Resource.BodyreceiveSurvey, 0); } folder = FileSystem.Current.LocalStorage; folder = await folder.CreateFolderAsync("Receivedsurveys", CreationCollisionOption.ReplaceExisting); file = await folder.CreateFileAsync("Receivedsurveys", CreationCollisionOption.ReplaceExisting); string content = Serializable_Survey.serialize(ReceivedSurveys); await file.WriteAllTextAsync(content); }
private async void GetSurveys() { string content; folder = FileSystem.Current.LocalStorage; if (CheckNetwork.Check_Connectivity()) { ActivityIndicator.IsVisible = true; ActivityIndicator.IsRunning = true; contentpageEducation.IsVisible = false; SurveysServices S_S = new SurveysServices(); S_S.Set_UrlApi("ReceiveSurveysShared/" + username); ReceivedSurveys = await S_S.GetSurveysAsync(); ExistenceCheckResult result = await folder.CheckExistsAsync("Receivedsurveys"); if (result == ExistenceCheckResult.FolderExists) { folder = await folder.CreateFolderAsync("Receivedsurveys", CreationCollisionOption.OpenIfExists); file = await folder.CreateFileAsync("Receivedsurveys", CreationCollisionOption.OpenIfExists); content = await file.ReadAllTextAsync(); OldreceiveSurveys = Serializable_Survey.deserialize(content).ToList(); if (OldreceiveSurveys.Count < ReceivedSurveys.Count) { var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player.Load("NotificationReceive.mp3"); player.Play(); Plugin.LocalNotifications.CrossLocalNotifications.Current.Show(Lang.Resource.receivesurveys, Lang.Resource.BodyreceiveSurvey, 0); } } else if (result != ExistenceCheckResult.FolderExists && ReceivedSurveys.Count > 0) { var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player.Load("NotificationReceive.mp3"); player.Play(); Plugin.LocalNotifications.CrossLocalNotifications.Current.Show(Lang.Resource.receivesurveys, Lang.Resource.BodyreceiveSurvey, 0); } } else { ExistenceCheckResult Result = await folder.CheckExistsAsync("Receivedsurveys"); if (Result == ExistenceCheckResult.FolderExists) { ActivityIndicator.IsVisible = true; ActivityIndicator.IsRunning = true; contentpageEducation.IsVisible = false; folder = await folder.CreateFolderAsync("Receivedsurveys", CreationCollisionOption.OpenIfExists); file = await folder.CreateFileAsync("Receivedsurveys", CreationCollisionOption.OpenIfExists); content = await file.ReadAllTextAsync(); ReceivedSurveys = Serializable_Survey.deserialize(content).ToList(); Full_Lists_Surveys(); } else { Full_Lists_Surveys(); ActivityIndicator.IsVisible = false; ActivityIndicator.IsRunning = false; await Task.Delay(200); contentpageEducation.IsVisible = true; return; } } if (ReceivedSurveys.Count == 0) { Full_Lists_Surveys(); ActivityIndicator.IsVisible = false; ActivityIndicator.IsRunning = false; contentpageEducation.IsVisible = true; return; } else { folder = FileSystem.Current.LocalStorage; folder = await folder.CreateFolderAsync("Receivedsurveys", CreationCollisionOption.ReplaceExisting); file = await folder.CreateFileAsync("Receivedsurveys", CreationCollisionOption.ReplaceExisting); content = Serializable_Survey.serialize(ReceivedSurveys); await file.WriteAllTextAsync(content); Full_Lists_Surveys(); await Task.Delay(700); ActivityIndicator.IsVisible = false; ActivityIndicator.IsRunning = false; await Task.Delay(200); contentpageEducation.IsVisible = true; } }
private async void Get_Surveys() { try { ActivityIndicator.IsRunning = true; contentpageEducation.IsVisible = false; folder = FileSystem.Current.LocalStorage; ExistenceCheckResult Resultfolder = await folder.CheckExistsAsync("folderUser"); if (Resultfolder != ExistenceCheckResult.FolderExists) { await Navigation.PushAsync(new Login()); return; } username = await controlFile.GetUserName(); Resultfolder = await folder.CheckExistsAsync("foldersurveys" + username); if (Resultfolder != ExistenceCheckResult.FolderExists) { if (!CheckNetwork.Check_Connectivity()) { await Task.Delay(700); ActivityIndicator.IsRunning = false; contentpageEducation.IsVisible = true; return; } SurveysServices S_S1 = new SurveysServices(); S_S1.Set_UrlApi("ReceiveMySurveysSaved/" + username); ListSurveys = await S_S1.GetSurveysAsync(); if (ListSurveys == null || ListSurveys.Count == 0) { await Task.Delay(700); ActivityIndicator.IsRunning = false; contentpageEducation.IsVisible = true; return; } folder = await folder.CreateFolderAsync("foldersurveys" + username, CreationCollisionOption.ReplaceExisting); file = await folder.CreateFileAsync("filesurveys" + username, CreationCollisionOption.ReplaceExisting); string Content = Serializable_Survey.serialize(ListSurveys); await file.WriteAllTextAsync(Content); stackEducation.IsVisible = false; Full_Lists_Surveys(); await Task.Delay(700); ActivityIndicator.IsRunning = false; contentpageEducation.IsVisible = true; return; } folder = await folder.CreateFolderAsync("foldersurveys" + username, CreationCollisionOption.OpenIfExists); file = await folder.CreateFileAsync("filesurveys" + username, CreationCollisionOption.OpenIfExists); string content = await file.ReadAllTextAsync(); ListSurveys = Serializable_Survey.deserialize(content).ToList(); if (ListSurveys == null || ListSurveys.Count == 0) { await Task.Delay(700); ActivityIndicator.IsRunning = false; contentpageEducation.IsVisible = true; return; } stackEducation.IsVisible = false; Full_Lists_Surveys(); await Task.Delay(700); ActivityIndicator.IsRunning = false; contentpageEducation.IsVisible = true; } catch (Exception ex) { ActivityIndicator.IsVisible = false; ActivityIndicator.IsRunning = false; DependencyService.Get <SnackBar>().ShowSnackBar("Error ... cann't access to device storage"); } }