private static async void ReadUserWordsFile(ApolloDictionary app)
        {
            var readText = await PCLHelper.ReadAllTextAsync("MyDictionary.txt", App.folder);

            if (!string.IsNullOrEmpty(readText))
            {
                //split the string into sequence of words
                string[] separator   = { Environment.NewLine };
                string[] wordsAndDef = readText.Split(separator, StringSplitOptions.RemoveEmptyEntries);

                //take each word and split it into Name, Definition and Category
                //from the file, which is in this model: word1 -> definition1 -> category1,category2,category3
                string[] separator2 = { " -> " };
                foreach (string wordDef in wordsAndDef)
                {
                    string[] word = wordDef.Split(separator2, StringSplitOptions.RemoveEmptyEntries);

                    WordDefinition newWord = new WordDefinition
                    {
                        Name       = word[0],
                        Definition = word[1],
                        Category   = word[2]
                    };

                    try
                    {
                        //word is added to the Dictionary
                        app.AddSingleWord = newWord;
                    }
                    catch (Exception e)
                    {
                        //don't do anything
                    }
                }

                //Send a new message when the file was read
                MessagingCenter.Send(new ReadDictFiles(), "fileReadingDone");
            }
            else
            {
                //call function again until it gets a result from the file
                ReadUserWordsFile(app);
            }
        }
Пример #2
0
 private async void OpenFile()
 {
     folder = await PCLHelper.CreateFolder("userData");
 }
Пример #3
0
 public void writeNewWordsToStorage()
 {
     //writing in the file
     //model used: word1 -> definition1 -> category1,category2,category3
     PCLHelper.WriteTextAllAsync("MyDictionary.txt", new_words, App.folder);
 }