示例#1
0
        public async Task WriteData(string path, Flashcard card)
        {
            using (var stream = File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Write))
            {
                var data = await ReadAndDesToLString(path, stream);

                if (data == null)
                {
                    data = new List <Flashcard>();
                }
                data.Add(card);
                stream.SetLength(0);
                var dataJson = JsonConvert.SerializeObject(data);
                var buffer   = Encoding.Default.GetBytes(dataJson);
                await stream.WriteAsync(buffer, 0, buffer.Length);
            }
        }
示例#2
0
        private async Task EnterData()
        {
            while (true)
            {
                var key = userInteractor.QuestionAnswerKey($"If you want enter flashcards in {topicMet.Topic}, press 'Enter',\n\r" +
                                                           $"If not - press else");
                if (key == UserAction.Enter)
                {
                    var front         = userInteractor.QuestionAnswerInUkr("Write front or foreign translation");
                    var transcription = userInteractor.QuestionAnswerInUkr("Write transcription");
                    var back          = userInteractor.QuestionAnswerInUkr("Write back or original word");
                    var newCard       = new Flashcard(topicMet.Topic, front, transcription, back);
                    await fileMaster.WriteData(topicMet.PathTopic, newCard);

                    userInteractor.WriteLine("Your card has been added!");
                }
                else
                {
                    return;
                }
            }
        }