/* * public static List<Apps> listApps() * { * List<AppInfo> mFileList = new List<AppInfo>(); * SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(context); * Resources res = context.getResources(); * AssetManager am = res.getAssets(); * string appList[], iconList[]; * try * { * appList = am.list("Apps"); * iconList = am.list("Icons"); * if (appList != null) * { * for (int i = 0; i < appList.length; i++) * { * AppInfo app = new AppInfo(); * app.Name = (appList[i].substring(0, appList[i].indexOf(".buildmlearn"))); * if (!SP.contains(app.Name)) * { * SharedPreferences.Editor editor1 = SP.edit(); * editor1.putBoolean(app.Name, false); * editor1.commit(); continue; * } * if (!SP.getBoolean(app.Name, false)) continue; * * app.AppIcon = BitmapFactory.decodeStream(am.open("Icons/" + iconList[i])); * BufferedReader br = new BufferedReader(new InputStreamReader(context.getAssets().open("Apps/" + appList[i]))); * string type = br.readLine(); * if (type.contains("InfoTemplate")) app.Type = 0; * else if (type.contains("QuizTemplate")) app.Type = 2; * else if (type.contains("FlashCardsTemplate")) app.Type = 1; * else if (type.contains("SpellingTemplate")) app.Type = 3; * br.readLine(); * type = br.readLine(); * int x = type.indexOf("<name>") + 6; * int y = type.indexOf("<", x + 1); * app.Author = type.substring(x, y); * mFileList.add(app); * } * } * } * catch (IOException e) * { * e.printStackTrace(); * } * AppList = mFileList; * return mFileList; * } */ /// <summary> /// It reads the Info App-Template, from the .buildmlearn file. /// </summary> /// <param name="fileName">Name of the file</param> public static void readInfoFile(string fileName) { try { InfoModel model = InfoModel.getInstance(); List <string> infoTitleList = new List <string>(); List <string> infoDescriptionList = new List <string>(); XmlDocument doc = new XmlDocument(); doc.LoadXml(XDocument.Load("Assets/Apps/" + fileName + ".xml").ToString()); model.setInfoName(doc.GetElementsByTagName("title").ElementAt(0).InnerText.Trim()); model.setInfoDescription(doc.GetElementsByTagName("description").ElementAt(0).InnerText.Trim()); string[] author = doc.GetElementsByTagName("author").ElementAt(0).InnerText.Split('\n'); model.setInfoAuthor(author[1].Trim()); model.setInfoAuthorEmail(author[2].Trim()); model.setInfoVersion(doc.GetElementsByTagName("version").ElementAt(0).InnerText.Trim()); XmlNodeList info_title = doc.GetElementsByTagName("item_title"); XmlNodeList info_description = doc.GetElementsByTagName("item_description"); for (int i = 0; i < info_title.Length; i++) { infoTitleList.Add(info_title.ElementAt(i).InnerText.Trim()); infoDescriptionList.Add(info_description.ElementAt(i).InnerText.Trim()); } model.setInfoTitleList(infoTitleList); model.setInfoDescriptionList(infoDescriptionList); } catch (Exception e) { } }
/// <summary> /// It reads the Flash-Card App-Template, from the .buildmlearn file. /// </summary> /// <param name="fileName">Name of the file</param> public static void readFlashFile(string fileName) { try { FlashModel model = FlashModel.getInstance(); List <Card> cardList = new List <Card>(); XmlDocument doc = new XmlDocument(); doc.LoadXml(XDocument.Load("Assets/Apps/" + fileName + ".xml").ToString()); model.setFlashName(doc.GetElementsByTagName("title").ElementAt(0).InnerText.Trim()); model.setFlashDescription(doc.GetElementsByTagName("description").ElementAt(0).InnerText.Trim()); string[] author = doc.GetElementsByTagName("author").ElementAt(0).InnerText.Split('\n'); model.setFlashAuthor(author[1].Trim()); model.setFlashAuthorEmail(author[2].Trim()); model.setFlashVersion(doc.GetElementsByTagName("version").ElementAt(0).InnerText.Trim()); XmlNodeList item = doc.GetElementsByTagName("item"); // looping through all item nodes <app> for (int i = 0; i < item.Length; i++) { string[] ar = item.ElementAt(i).InnerText.Split('\n'); Card card = new Card(ar[1].Trim(), ar[2].Trim(), ar[3].Trim(), ar[4].Trim()); cardList.Add(card); } model.setCardList(cardList); } catch (Exception) { } }
/// <summary> /// It reads the Spellings-Puzzle App-Template, from the .buildmlearn file. /// </summary> /// <param name="fileName">Name of the file</param> public static void readSpellingsFile(string fileName) { try { SpellingsModel model = SpellingsModel.getInstance(); List <WordModel> wordList = new List <WordModel>(); XmlDocument doc = new XmlDocument(); doc.LoadXml(XDocument.Load("Assets/Apps/" + fileName + ".xml").ToString()); model.setPuzzleName(doc.GetElementsByTagName("title").ElementAt(0).InnerText.Trim()); model.setPuzzleDescription(doc.GetElementsByTagName("description").ElementAt(0).InnerText.Trim()); string[] author = doc.GetElementsByTagName("author").ElementAt(0).InnerText.Split('\n'); model.setPuzzleAuthor(author[1].Trim()); model.setPuzzleAuthorEmail(author[2].Trim()); model.setPuzzleVersion(doc.GetElementsByTagName("version").ElementAt(0).InnerText.Trim()); XmlNodeList item = doc.GetElementsByTagName("item"); // looping through all item nodes <app> for (int i = 0; i < item.Length; i++) { string[] ar = item.ElementAt(i).InnerText.Split('\n'); WordModel word = new WordModel(ar[1].Trim(), ar[2].Trim()); wordList.Add(word); } model.setSpellingsList(wordList); } catch (Exception) { } }
/// <summary> /// It reads the Quiz App-Template, from the .buildmlearn file. /// </summary> /// <param name="fileName">Name of the file</param> public static void readQuizFile(string fileName) { try { QuizModel model = QuizModel.getInstance(); List <Question> mQuestionList = new List <Question>(); XmlDocument doc = new XmlDocument(); doc.LoadXml(XDocument.Load("Assets/Apps/" + fileName + ".xml").ToString()); model.setQuizName(doc.GetElementsByTagName("title").ElementAt(0).InnerText.Trim()); model.setQuizDescription(doc.GetElementsByTagName("description").ElementAt(0).InnerText.Trim()); string[] author = doc.GetElementsByTagName("author").ElementAt(0).InnerText.Split('\n'); model.setQuizAuthor(author[1].Trim()); model.setQuizAuthorEmail(author[2].Trim()); model.setQuizVersion(doc.GetElementsByTagName("version").ElementAt(0).InnerText.Trim()); XmlNodeList questions = doc.GetElementsByTagName("item"); for (int i = 0; i < questions.Length; i++) { Question q = new Question(); string[] ar = questions.ElementAt(i).InnerText.Split('\n'); List <string> options = new List <string>(); options.Add(ar[2].Trim()); options.Add(ar[3].Trim()); options.Add(ar[4].Trim()); options.Add(ar[5].Trim()); q.setOptionNumber(Convert.ToInt16(ar[6].Trim())); q.setAnswerOption(options); q.setQuestion(ar[1].Trim()); mQuestionList.Add(q); } model.setQueAnsList(mQuestionList); } catch (Exception) { } }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> protected async override void OnNavigatedTo(NavigationEventArgs e) { XmlNodeList _names = null, _scores = null; bool fileExists = true; try { StorageFile st = await ApplicationData.Current.LocalFolder.GetFileAsync("score.xml"); dom = await XmlDocument.LoadFromFileAsync(st); _names = dom.GetElementsByTagName("name"); _scores = dom.GetElementsByTagName("highscore"); } catch (Exception) { fileExists = false; } playerTable = new ObservableCollection <Player>(); if (fileExists) { for (int i = 0; i < _names.Count; i++) { string name = _names.ElementAt(i).InnerText; int score = Int32.Parse(_scores.ElementAt(i).InnerText); playerTable.Add(new Player(name, score)); } } playerTable = new ObservableCollection <Player>(playerTable.OrderByDescending(player => player.Score)); playerTable = new ObservableCollection <Player>(playerTable.Take(10)); foreach (var elem in playerTable) { LeaderBoardControl control = new LeaderBoardControl(elem.Name, elem.Score); leaderBoardList.Items.Add(control); } }
private async void nextButton_Click_1(object sender, RoutedEventArgs e) { if ("Exit".Equals(nextButton.Content.ToString())) { StorageFile st = null; bool exists = true; XmlNodeList _names = null, _scores = null; try { st = await ApplicationData.Current.LocalFolder.GetFileAsync("score.xml"); dom = await XmlDocument.LoadFromFileAsync(st); _names = dom.GetElementsByTagName("name"); _scores = dom.GetElementsByTagName("highscore"); } catch (Exception) { exists = false; } if (!exists) { st = await ApplicationData.Current.LocalFolder.CreateFileAsync("score.xml"); } ObservableCollection <Player> playerTable = new ObservableCollection <Player>(); if (_names != null) { for (int i = 0; i < _names.Count; i++) { string tempName = _names.ElementAt(i).InnerText; int tempScore = Int32.Parse(_scores.ElementAt(i).InnerText); playerTable.Add(new Player(tempName, tempScore)); } } playerTable.Add(new Player(playerName, score)); dom = new XmlDocument(); x = dom.CreateElement("users"); dom.AppendChild(x); foreach (var elem in playerTable) { XmlElement x1 = dom.CreateElement("user"); XmlElement x11 = dom.CreateElement("name"); x11.InnerText = elem.Name; x1.AppendChild(x11); XmlElement x12 = dom.CreateElement("highscore"); x12.InnerText = elem.Score.ToString(); x1.AppendChild(x12); x.AppendChild(x1); } await dom.SaveToFileAsync(st); Frame.Navigate(typeof(MainPage)); } else { var param = new Parameters(); param.Score = this.score + 10 + this.levelCount; param.Name = this.playerName; param.Level = this.levelCount + 1; param.Counter = this.futureCounter; Frame.Navigate(typeof(Level), param); } }