public async Task <Suvi.Data.Survey> DownloadSurvey(string surveyCode) { var request = HttpWebRequest.Create(Configuration.WebsiteUrl + "/s/" + surveyCode + ".json"); request.ContentType = "application/json"; request.Method = "GET"; try { // Send the request to the server and wait for the response: using (WebResponse response = await request.GetResponseAsync()) { // Get a stream representation of the HTTP web response: using (StreamReader reader = new StreamReader(response.GetResponseStream())) { var content = reader.ReadToEnd(); Console.Out.WriteLine("Response: {0}", content); Suvi.Data.Survey survey = JsonConvert.DeserializeObject <Suvi.Data.Survey> (content); if (!string.IsNullOrWhiteSpace(survey.Theme)) { await DownloadTheme(survey.Theme); } return(survey); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); return(null); } }
public Survey(Suvi.Data.Survey survey) { SurveyData = survey; LoadSurvey(); surveyService = Resolver.Resolve <ISurveyDownloader> (); networkManager = Resolver.Resolve <INetworkManager> (); NavigationPage.SetBackButtonTitle(this, "Home"); InitializeComponent(); }
public async Task GoToSelectedSurvey(string surveyCode) { //Check if survey is already downloaded var db = App.Database; Suvi.Data.Survey survey = null; if (!string.IsNullOrWhiteSpace(surveyCode)) { survey = db.GetSurvey(surveyCode); } var networkManager = Resolver.Resolve <INetworkManager> (); if (networkManager.IsConnected()) { //Download servey from server var surveyDownloader = Resolver.Resolve <ISurveyDownloader> (); var downloadedSurvey = await surveyDownloader.DownloadSurvey(surveyCode); if (survey == null && downloadedSurvey == null) { await DisplayAlert("Error", "There is no surey with this code!", "OK"); return; } if (downloadedSurvey != null) { db.SaveSurvey(downloadedSurvey); survey = downloadedSurvey; } } else if (survey == null) { await DisplayAlert("Alert", "There is no network connection!", "OK"); return; } var rPage = new Survey(survey); NavigationPage.SetHasNavigationBar(rPage, false); await Navigation.PushAsync(rPage); }