示例#1
0
        private async Task AddTranslationAsync(Models.TranslationResult translation)
        {
            CurrentTranslation = translation;
            TranslationsCardItems.Insert(1, translation);
            AllTranslations.Add(translation);
            UpdateSource();
            ShowNewTranslationControl = false;

            // Save translation in the file
            await _roamingStorageService.SaveFileAsync(translation.Filename, translation);

            // Add the new translation in the summaries list
            var translationSummaries = _roamingStorageService.Read <List <Models.TranslationSummary> >(StorageConstants.TranslationSummaries);

            if (translationSummaries == null)
            {
                translationSummaries = new List <Models.TranslationSummary>();
            }
            translationSummaries.Add(new Models.TranslationSummary
            {
                SearchedDate = DateTime.Now,
                Filename     = translation.Filename
            });
            _roamingStorageService.Save(StorageConstants.TranslationSummaries, translationSummaries);

            // Remove translations if it exceed size of the card list
            while (TranslationsCardItems.Count - 1 > AppConstants.MaxSavedTranslations)
            {
                TranslationsCardItems.RemoveAt(TranslationsCardItems.Count - 1);
            }
        }
示例#2
0
        private async Task CreateTranslationCardsAsync()
        {
            // Remove all cards
            TranslationsCardItems.Clear();

            // Add the card "new translation"
            TranslationsCardItems.Add("New Translation");

            // Retrieve list of translation summaries
            var translationSummaries = _roamingStorageService.Read <List <Models.TranslationSummary> >(StorageConstants.TranslationSummaries);

            if (translationSummaries != null)
            {
                var lastTranslations = translationSummaries
                                       .Where(ts => !ts.Removed)
                                       .OrderByDescending(ts => ts.SearchedDate)
                                       .Take(AppConstants.MaxSavedTranslations)
                                       .Reverse();

                foreach (var translationSummary in lastTranslations)
                {
                    var translation = await _roamingStorageService.ReadFileAsync <Models.TranslationResult>(translationSummary.Filename);

                    AllTranslations.Add(translation);
                    TranslationsCardItems.Insert(1, translation);
                }

                if (CurrentTranslation == null || AllTranslations.Last().Filename != CurrentTranslation.Filename)
                {
                    CurrentTranslation = AllTranslations.Last();
                    UpdateSource();
                }
            }
        }