public static void readAndBuildDictionary(ApolloDictionary app)
        {
            string resourcePrefix = null;

            #if __IOS__
            resourcePrefix = "Wilson_oficial.iOS.";
            #elif __ANDROID__
            resourcePrefix = "Wilson_oficial.Droid.";
            #endif

            //Get the files from the source folder
            var    assembly = typeof(ReadDictFiles).GetTypeInfo().Assembly;
            Stream stream1  = assembly.GetManifestResourceStream(resourcePrefix + "Dictionaries.Governor_Dictionary.txt");
            Stream stream2  = assembly.GetManifestResourceStream(resourcePrefix + "Dictionaries.nhs-acronym-dictionary.txt");

            //read each file from Stream and make it into usable data
            var dictionary = new List <WordDefinition>();
            dictionary.AddRange(processWords(stream1));
            dictionary.AddRange(processWords(stream2));

            //get words from the personalized filesystem, which contains all the new words the user had added
            ReadUserWordsFile(app);

            //update main Dictionary
            app.List = dictionary;
        }
Пример #2
0
        public App()
        {
            InitializeComponent();

            //open file and get the file pointer
            OpenFile();

            //initialize the dictionary
            app = new ApolloDictionary();
            ReadDictFiles.readAndBuildDictionary(app);

            //initializing the History methods to get user stored words
            userProp = new UserProperties();

            MainPage = new Wilson_oficial.Pages.HomePage();
        }
        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);
            }
        }