static public ObservableCollection <Survey> deserialize(string Content) { ObservableCollection <Survey> surveys = new ObservableCollection <Survey>(); List <Question> questions = new List <Question>(); int iter = 0; char i = Content[iter]; string count_surveys = ""; while (i != '~') { count_surveys += i.ToString(); iter++; i = Content[iter]; } int Count_Surveys = Int32.Parse(count_surveys); for (int j = 0; j < Count_Surveys; j++) { string count_questions = ""; string id = ""; questions = new List <Question>(); iter++; i = Content[iter]; while (i != '~') { id += i.ToString(); iter++; i = Content[iter]; } iter++; i = Content[iter]; while (i != '~') { count_questions += i.ToString(); iter++; i = Content[iter]; } int Count_Questions = Int32.Parse(count_questions); for (int k = 0; k < Count_Questions; k++) { iter++; i = Content[iter]; string typequestion = ""; while (i != '~') { typequestion += i.ToString(); iter++; i = Content[iter]; } if (typequestion.Contains("Text")) { KeyValuePair <Text_Question, int> Pair = Serializable_Questions.deserialize_Text_Question(Content, iter); questions.Add(Pair.Key); iter = Pair.Value; } else if (typequestion.Contains("Multible") || typequestion.Contains("MultiChoice") || typequestion.Contains("DropDown")) { KeyValuePair <Multible, int> Pair = Serializable_Questions.deserialize_MultibleChoice(Content, iter, typequestion); questions.Add(Pair.Key); iter = Pair.Value; } //else if (typequestion.Contains("DropDown")) //{ // KeyValuePair<DropDown, int> Pair = Serializable_Questions.deserialize_DropDown(Content, iter); // questions.Add(Pair.Key); // iter = Pair.Value; //} else if (typequestion.Contains("Slider")) { KeyValuePair <Slider_Question, int> Pair = Serializable_Questions.deserialize_Slider(Content, iter); questions.Add(Pair.Key); iter = Pair.Value; } //else if (typequestion.Contains("TextDescription")) //{ // Question question = new Question(TypeQuestion.TextDescription, Int32.Parse(id)); // questions.Add(question); //} } iter++; i = Content[iter]; string user = ""; string title = ""; string description = ""; string date_publish = ""; string number_of = ""; string type = ""; while (i != '~') { user += i.ToString(); iter++; i = Content[iter]; } iter++; i = Content[iter]; while (i != '~') { title += i.ToString(); iter++; i = Content[iter]; } iter++; i = Content[iter]; while (i != '~') { description += i.ToString(); iter++; i = Content[iter]; } iter++; i = Content[iter]; while (i != '~') { number_of += i.ToString(); iter++; i = Content[iter]; } iter++; i = Content[iter]; while (i != '~') { type += i.ToString(); iter++; i = Content[iter]; } iter++; i = Content[iter]; while (i != '~') { date_publish += i.ToString(); iter++; i = Content[iter]; } Survey survey = new Survey(questions, user, title, description, date_publish); survey.Id = Int32.Parse(id); survey.Number_of_Participants = Int32.Parse(number_of); TypeSurvey _type = TypeSurvey.Education; if (type.Equals("Sport")) { _type = TypeSurvey.Sport; } else if (type.Equals("Marketing")) { _type = TypeSurvey.Marketing; } else if (type.Equals("Other")) { _type = TypeSurvey.Other; } survey.type_Property = _type; surveys.Add(survey); } return(surveys); }
private async void Save_Survey(object sender, EventArgs e, TypeSurvey type) { string content; List <Question> list = new List <Question>(); folder = FileSystem.Current.LocalStorage; Survey survey = new Survey(list, username, title, description, (DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss")).Substring(0, DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss").Length - 8)); survey.type_Property = type; ExistenceCheckResult Result = await folder.CheckExistsAsync("foldersurveys" + username); if (Result != ExistenceCheckResult.FolderExists) { folder = await folder.CreateFolderAsync("foldersurveys" + username, CreationCollisionOption.ReplaceExisting); } else { folder = await folder.CreateFolderAsync("foldersurveys" + username, CreationCollisionOption.OpenIfExists); } Result = await folder.CheckExistsAsync("filesurveys" + username); if (Result != ExistenceCheckResult.FileExists) { file = await folder.CreateFileAsync("filesurveys" + username, CreationCollisionOption.ReplaceExisting); survey.Id = 1; ListSurveys.Add(survey); content = Serializable_Survey.serialize(ListSurveys); await file.WriteAllTextAsync(content); Full_Lists_Surveys(); if (CheckNetwork.Check_Connectivity()) { SurveysServices S_S1 = new SurveysServices(); S_S1.Set_UrlApi("SaveSurveys/"); await S_S1.PostSurveysAsync(survey); } stackEducation.IsVisible = false; Cancel(sender, e); return; } file = await folder.CreateFileAsync("filesurveys" + username, CreationCollisionOption.OpenIfExists); content = await file.ReadAllTextAsync(); ListSurveys = Serializable_Survey.deserialize(content).ToList(); if (ListSurveys.Count != 0) { survey.Id = ListSurveys[ListSurveys.Count - 1].Id + 1; } else { survey.Id = 1; } ListSurveys.Add(survey); content = Serializable_Survey.serialize(ListSurveys); await file.WriteAllTextAsync(content); Full_Lists_Surveys(); if (CheckNetwork.Check_Connectivity()) { SurveysServices S_S = new SurveysServices(); S_S.Set_UrlApi("SaveSurveys/"); await S_S.PostSurveysAsync(survey); } stackEducation.IsVisible = false; Cancel(sender, e); }