Exemple #1
0
		public Task Begin(CancellationToken cancel) {
			if (begun)
				throw new InvalidOperationException("The synchronisation is already in progress.");
			begun = true;

			var api = new QuizletApi();

			var sets = setIDs.Select(DataStore.Database.GetWordList).ToArray();
			if (sets.Any(s => s.SyncID == null))
				throw new InvalidOperationException("Cannot synchronise a list that has no SyncID.");

			return Task.WhenAll(from set in sets select SyncSet(api, set, cancel));
		}
Exemple #2
0
        public Task Begin(CancellationToken cancel)
        {
            if (begun)
            {
                throw new InvalidOperationException("The synchronisation is already in progress.");
            }
            begun = true;

            var api = new QuizletApi();

            var sets = setIDs.Select(DataStore.Database.GetWordList).ToArray();

            if (sets.Any(s => s.SyncID == null))
            {
                throw new InvalidOperationException("Cannot synchronise a list that has no SyncID.");
            }

            return(Task.WhenAll(from set in sets select SyncSet(api, set, cancel)));
        }
Exemple #3
0
        public async Task <WordList> BeginImportAsTask()
        {
            if (disposed)
            {
                throw new ObjectDisposedException("QuizletImporter");
            }

            if (setID == null)
            {
                throw new InvalidOperationException("Cannot begin quizlet import when Set is null");
            }

            var api = new QuizletApi();

            OnProgressChanged(stringTable["ContactingServer"].FormatUI(api.ServiceUri.Host), null);

            var set = await api.FetchSetInfo(setID.Value, cts.Token);

            if (set.Terms == null)
            {
                throw new FormatException("JSON for set information did not contain the terms of the set");
            }

            var list = DataStore.Database.CreateSet(set.Title, set.Author, null, set.Uri.ToString(), DateTime.Now);

            foreach (var term in set.Terms)
            {
                list.Add(new WordListEntry(list, term.Term, term.Definition));
            }

            foreach (var subject in set.Subjects.Distinct(StringComparer.CurrentCultureIgnoreCase))
            {
                list.Tag(subject);
            }

            list.SyncID     = setID;
            list.SyncDate   = DateTime.UtcNow;
            list.SyncNeeded = false;

            return(list);
        }