public bool ValidateWordPair(string Word, string Translation) { var query = from wordCard in selectedWordsList where wordCard.Word == Word && wordCard.Translation.Equals(Translation) select wordCard; WordCard wc = new WordCard(); if (query.ToList().Count != 0) { wc = query.ToList()[0]; } else { return(false); } int index = DictionaryLoader.ActiveDictionary.Dictionary.IndexOf(wc); //selectedWordsList.IndexOf(wc); if (index != -1) { DictionaryLoader.ActiveDictionary.Dictionary[index].TimesAnsweredCorrectly++; // increment correct answers DictionaryLoader.ActiveDictionary.UpdateDictionaryXml(); // save changes return(true); } else { return(false); } }
public async Task <IHttpActionResult> PutWordCard(int id, WordCard wordCard) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != wordCard.Id) { return(BadRequest()); } db.Entry(wordCard).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WordCardExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Test1() { Assert.Throws<ArgumentNullException>(() => { new WordCard(text: null); }); { var wordCard = new WordCard("ABC"); // Assert.AreEqual(new SizeF(50, 50), wordCard.Size); Assert.AreEqual(5, wordCard.PaddingLeft); Assert.AreEqual(5, wordCard.PaddingTop); Assert.AreEqual(5, wordCard.PaddingRight); Assert.AreEqual(5, wordCard.PaddingBottom); Assert.AreEqual(StringAlignment.Center, wordCard.StringFormat.Alignment); Assert.AreEqual(StringAlignment.Center, wordCard.StringFormat.LineAlignment); Assert.AreEqual(Color.Blue, wordCard.Color); Assert.AreEqual(Color.AliceBlue, wordCard.BackColor); Assert.True(wordCard.BorderLine); Assert.True(wordCard is EigoTestButtonItem); Assert.True(wordCard.IsVisible); Assert.True(wordCard.IsClickable); } { var wordCard = new WordCard("ABC"); Assert.Greater(wordCard.Size.Width, 10); Assert.Greater(wordCard.Size.Height, 10); Assert.True(wordCard is EigoTestButtonItem); } }
public Card RandomCard() { int random = Random.Range(0, 100); if (random < 10) { return(RandomPowerCard()); } else if (random >= 10 && random < 50) { return(WordCard.CreateCard((Nouns[Random.Range(0, Nouns.Length)]))); } else if (random >= 50 && random < 65) { return(WordCard.CreateCard((Adjectives[Random.Range(0, Adjectives.Length)]))); } else if (random >= 65 && random < 70) { return(WordCard.CreateCard((Adverbs[Random.Range(0, Adverbs.Length)]))); } else if (random >= 70 && random < 85) { return(WordCard.CreateCard((Verbs[Random.Range(0, Verbs.Length)]))); } else if (random >= 85 && random < 95) { return(WordCard.CreateCard((HelpingVerbs[Random.Range(0, HelpingVerbs.Length)]))); } else if (random >= 95 && random < 100) { return(WordCard.CreateCard((QuestionWords[Random.Range(0, QuestionWords.Length)]))); } return(null); }
public void AddOneWord(WordCard word) { var newWordBookPath = Constants.Book.BookPath + Constants.BookName.NewWordBook; var jsonString = JsonConvert.SerializeObject(word); _fileManager.CheckFileIfExistThenCreate(newWordBookPath); File.AppendAllText(newWordBookPath, jsonString + ","); }
//POST: add word card public static async Task AddWordCard(WordCard card) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:37533/"); await client.PostAsJsonAsync("api/wordcards", card); } }
//PUT: update word card public static async Task UpdateWordCard(int id, WordCard card) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:37533/"); await client.PutAsJsonAsync("api/wordcards/" + id, card); } }
private void OnWordCardClicked(WordCard card) { TeamCard.Teams team = secretBoard.CheckSecret(card.GetIndex()); if (card.GetComponent <TeamCard>()) { card.GetComponent <TeamCard>().SetTeam(team); } }
public EditWordCard(WordCard wc, int index) { InitializeComponent(); wordCard = DeepClone(wc); oldWordCard = wc; editWordCardGrid.DataContext = wordCard; this.index = index; }
public List <TagContent> GetCardAsTags(WordCard card, Stream stream = null) { if (stream == null) { return(RecursiveCardParser.DivideSiblingTags(FileHelper.GetBlockFromFile(card.CardFileTextBlock, FileName))); } stream.Position = 0; return(RecursiveCardParser.DivideSiblingTags(FileHelper.GetBlockFromStream(card.CardFileTextBlock, stream))); }
public void SaveOneWord(WordCard word) { var jsonString = JsonConvert.SerializeObject(word); if (!File.Exists("Word.txt")) { File.Create("Word.txt"); } File.AppendAllText("Word.txt", jsonString + ","); }
public void MonochromeTest() { var wordCard = new WordCard("ABC"); Assert.False(wordCard.Monochrome); var CardBox = new CardBox(); CardBox.Items.Add(wordCard); Assert.False(wordCard.Monochrome); wordCard.IsClickable = false; Assert.True(wordCard.Monochrome); }
public async Task <IHttpActionResult> GetWordCard(int id) { WordCard wordCard = await db.WordCards.FindAsync(id); if (wordCard == null) { return(NotFound()); } return(Ok(wordCard)); }
public Card GetCardByText(string cardText) { foreach (var item in PowerCards) { if (item.CardText == cardText) { return(item); } } return(WordCard.CreateCard(cardText)); }
public void Pick(WordCard card) { HandlePendingCardResets(); if (!UnsolvedPairs.Contains(card.Pair)) return; if (!HandlePreviousSelection(ActiveWordCard)) return; ActiveWordCard = card; card.State = CardState.Selected; CheckForMatch(); }
public async Task <IActionResult> UpdateCard([FromBody] WordCard wordCard) { try { return(Ok(await _cardsService.UpdateCard(wordCard))); } catch (Exception ex) { var errorMessage = "There was an error while trying to list Word Cards from MongoDB"; return(BadRequest(errorMessage + "\n" + ex)); } }
private void EditWordCardBtn_Click(object sender, RoutedEventArgs e) { if (listViewWordCards.SelectedItem != null) { WordCard wc = UnSerializeXmlElement <WordCard>(listViewWordCards.SelectedItem as XmlElement); int index = listViewWordCards.SelectedIndex; EditWordCard editDialog = new EditWordCard(wc, index); editDialog.Owner = Window.GetWindow(this); editDialog.ShowDialog(); LoadXmlWithWordCards(); // update output } }
public async Task <IHttpActionResult> PostWordCard(WordCard wordCard) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.WordCards.Add(wordCard); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = wordCard.Id }, wordCard)); }
public void OpenWordCard(WordCardViewModel wm) { var wc = new WordCard(); wc.DataContext = wm; Window window = new Window { Title = wm.Word.Value, Content = wc }; window.Show(); }
public static bool AddWordCard(WordCard wc) { if (activeDictionary != null) { activeDictionary.AddWordCard(wc); int index = metadata.IndexOf(new DictionaryNameAndAmount(activeDictionary.DictionaryName, activeDictionary.Count)); metadata[index].Size++; return(true); } else { return(false); } }
public void GetTextsTest() { var cardBox = new CardBox() { Width = 1000, }; var wordCard1 = new WordCard("abc") { Size = new SizeF(100, 100), }; var wordCard2 = new WordCard("def") { Size = new SizeF(100, 100), }; var wordCard3 = new WordCard("fg") { Size = new SizeF(100, 100), IsVisible = false, IsClickable = true, }; var wordCard4 = new WordCard("hi") { Size = new SizeF(100, 100), IsVisible = true, IsClickable = false, }; cardBox.Items.Add(wordCard1); cardBox.Items.Add(wordCard2); cardBox.Items.Add(wordCard3); cardBox.Items.Add(wordCard4); CollectionAssert.AreEqual(new [] { "abc", "def", "hi" }, cardBox.GetTexts()); }
public async Task <IHttpActionResult> DeleteWordCard(int id) { WordCard wordCard = await db.WordCards.FindAsync(id); if (wordCard == null) { return(NotFound()); } db.WordCards.Remove(wordCard); await db.SaveChangesAsync(); return(Ok(wordCard)); }
public void Pick(WordCard card) { //if (card.Pair == CurrentPair) //{ // if (UnsolvedPairs.Count == 0) // Observer?.OnWon(); // else // { // ActivateNext(); // Observer?.OnRefresh(); // } //} //else Observer?.OnWrongMove(); }
public void 折り返し機能のテスト() { var wordCard1 = new WordCard("a") {}; var wordCard2 = new WordCard("b") {}; var wordCard3 = new WordCard("c") {}; foreach (var wordCard in new [] { wordCard1, wordCard2, wordCard3 }) { wordCard.PaddingLeft = wordCard.PaddingTop = wordCard.PaddingRight = wordCard.PaddingBottom = 0; wordCard.MarginLeft = wordCard.MarginTop = wordCard.MarginRight = wordCard.MarginBottom = 0; wordCard.Width = 10; wordCard.Height = 100; wordCard.MarginRight = 5; wordCard.MarginBottom = 50; } var cardBox = new CardBox() { PaddingLeft = 0, PaddingTop = 0, PaddingRight = 0, PaddingBottom = 0, MarginLeft = 0, MarginTop = 0, MarginRight = 0, MarginBottom = 0, Width = 40, Height = 1000, }; cardBox.Items.Add(wordCard1); cardBox.Items.Add(wordCard2); cardBox.Items.Add(wordCard3); Assert.AreEqual(0, wordCard1.Left); Assert.AreEqual(0, wordCard1.Top); Assert.AreEqual(15, wordCard2.Left); Assert.AreEqual(0, wordCard2.Top); Assert.AreEqual(0, wordCard3.Left); Assert.AreEqual(150, wordCard3.Top); cardBox.上寄せ = false; Assert.AreEqual(0, wordCard1.Left); Assert.AreEqual(700, wordCard1.Top); Assert.AreEqual(15, wordCard2.Left); Assert.AreEqual(700, wordCard2.Top); Assert.AreEqual(0, wordCard3.Left); Assert.AreEqual(850, wordCard3.Top); }
private void DeleteWordCardBtn_Click(object sender, RoutedEventArgs e) { WordCard wc = UnSerializeXmlElement <WordCard>(listViewWordCards.SelectedItem as XmlElement); int index = listViewWordCards.SelectedIndex; DeleteConfirmation deleteDialog = new DeleteConfirmation(wc.Word); deleteDialog.Owner = Window.GetWindow(this); deleteDialog.ShowDialog(); if (deleteDialog.GetResult()) { DictionaryLoader.ActiveDictionary.Dictionary.RemoveAt(index); DictionaryLoader.ActiveDictionary.UpdateDictionaryXml(); LoadXmlWithWordCards(); // update output } }
public void Test1() { var cardBox = new CardBox() { Width = 1000, }; var wordCard1 = new WordCard("abc") { Size = new SizeF(100, 100), }; var wordCard2 = new WordCard("def") { Size = new SizeF(100, 100), }; var label = new EigoTestLabelItem(); Assert.Throws<ArgumentException>(() => { cardBox.Items.Add(label); }); cardBox.Items.Add(wordCard1); cardBox.Items.Add(wordCard2); Assert.AreEqual(0, wordCard1.Location.X); Assert.AreEqual(0, wordCard1.Location.Y); Assert.AreEqual(5 + 100 + 5 + 10, wordCard2.Location.X); Assert.AreEqual(0, wordCard2.Location.Y); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); VM = e.Parameter as WordCard; if (VM != null) { WordBookTitle.Text = (await WordBooksApiRequest.GetWordBooksList()).FirstOrDefault(m => m.Id == VM.Id).Title; IsNewCard = false; } else { VM = new WordCard(); VM.BookId = (e.Parameter as WordBook).Id; WordBookTitle.Text = (e.Parameter as WordBook).Title; IsNewCard = true; } }
public WordCardReturn(WordCard obj) { Id = obj.Id; ImagePath = obj.ImagePath; Word = obj.Word; WordAnswer = obj.WordAnswer; Hided = obj.Hided; Description = obj.Description; UserId = obj.UserId; Lists = new List <WordCardWordListReturn>(); if (obj.WordCardWordList != null) { foreach (var lst in obj.WordCardWordList) { Lists.Add(new WordCardWordListReturn(lst)); } } }
public string GetCardAsHtmlString(WordCard card, Stream stream = null) { if (stream == null) { return(DslToHtmlRegexpConverter.ConvertStringToHtml(FileHelper.GetBlockFromFile(card.CardFileTextBlock, FileName))); } stream.Position = 0; var time = DateTime.Now; var block = FileHelper.GetBlockFromStream(card.CardFileTextBlock, stream); var time2 = DateTime.Now; var result = DslToHtmlRegexpConverter.ConvertStringToHtml(block); var time3 = DateTime.Now; var deltaStream = time2 - time; var deltaParse = time3 - time2; return(result); }
public async Task <WordCard> UpdateCard(WordCard wordCard) { var existingWord = await _cardsUnitOfWork.WordCardsRepo.GetById(wordCard.ID); if (existingWord == null) { throw new Exception($"Can't find card {wordCard.Word} in database."); } existingWord.Word = wordCard.Word; var result = await _cardsUnitOfWork.WordCardsRepo.Update(existingWord); if (!result) { throw new Exception($"Can't update card {existingWord.Word} to mongoDB"); } return(wordCard); }
public void GenerateWords() { wordCards.Clear(); foreach (Transform child in transform) { child.GetComponent <WordCard>().WordCardClicked -= OnWordCardClicked; Destroy(child.gameObject); } wordsList.Shuffle(); for (int i = 0; i < 25; i++) { WordCard card = Instantiate(wordCard, transform); wordCards.Add(card); card.UpdateWord(i, wordsList[i]); card.WordCardClicked += OnWordCardClicked; } }
private static void SaveWord() { var word = new WordCard(); Console.WriteLine("Word:"); word.Word = Console.ReadLine(); Console.WriteLine("Meaning:"); var charArray = Console.ReadKey(true); Console.InputEncoding = System.Text.Encoding.Unicode; word.Meaning = Console.ReadLine(); Console.WriteLine("Difficulty(1-4):"); var input = Console.ReadLine(); word.Difficulty = int.Parse(string.IsNullOrEmpty(input) ? "100" : input); var saveWord = new SaveWord(); saveWord.SaveOneWord(word); Console.Clear(); }
//GET: get word card by id public static async Task <WordCard> GetWordCard(int id) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:37533/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.GetAsync("api/wordcards/" + id); if (response.IsSuccessStatusCode) { WordCard card = await response.Content.ReadAsAsync <WordCard>(); return(card); } else { return(null); } } }
public async Task <WordCard> AddCard(string word) { var existingCard = await _cardsUnitOfWork.WordCardsRepo.GetByWord(word); if (existingCard != null) { throw new Exception($"Card {existingCard.Word} already exists."); } var wordCard = new WordCard { Word = word }; var result = await _cardsUnitOfWork.WordCardsRepo.Save(wordCard); if (!result) { throw new Exception($"Can't save card {word} to mongoDB"); } return(wordCard); }
private bool FillWordCardFromInputModelEdit(WordCard baseObj, WordCardInputModel newObj) { bool changed = false; if (baseObj.Word != newObj.Word) { baseObj.Word = newObj.Word; changed = true; } if (baseObj.Description != newObj.Description) { baseObj.Description = newObj.Description; changed = true; } if (baseObj.WordAnswer != newObj.WordAnswer) { baseObj.WordAnswer = newObj.WordAnswer; changed = true; } return(changed); }
public void WordCardContainerにWordCard以外のものを入れたら例外() { var ankimonRowContainer = new AnkimonRowContainer(); var wordCardContainer = ankimonRowContainer.WordCardContainer; var a = new WordCard("a"); wordCardContainer.Items.Add(a); Assert.Throws<InvalidCastException>(() => { var b = new EigoTestLabelItem("b"); wordCardContainer.Items.Add(b); }); }
public void Test2() { var ankimonRowContainer = new AnkimonRowContainer() { Left = 1, Top = 10, }; var label = ankimonRowContainer.Label; var wordCardContainer = ankimonRowContainer.WordCardContainer; // label Assert.AreSame(ankimonRowContainer.Items[0], label); Assert.AreEqual(DrawingObjectPosition.Static, label.Position); Assert.AreEqual(label.Height, ankimonRowContainer.Height); Assert.AreEqual ( new PointF(1, 10), new PointF(ankimonRowContainer.OuterLeft, ankimonRowContainer.OuterTop) ); // wordCardContainer Assert.AreSame(ankimonRowContainer.Items[1], wordCardContainer); Assert.AreEqual(DrawingObjectPosition.Absolute, wordCardContainer.Position); Assert.AreEqual ( new PointF(1 + label.OuterWidth, 10), new PointF(wordCardContainer.OuterLeft, wordCardContainer.OuterTop) ); var a = new WordCard("a"); var b = new WordCard("b"); wordCardContainer.Items.Add(a); wordCardContainer.Items.Add(b); // a // Assert.AreEqual(50, a.Width); Assert.AreEqual ( new PointF(wordCardContainer.OuterLeft, 10f), new PointF(a.OuterLeft, a.OuterTop) ); // b // Assert.AreEqual(50, b.Width); // リリースビルドだと誤差が出る。 { var s = new PointF(a.OuterRight, 10f); var t = new PointF(b.OuterLeft, b.OuterTop); Assert.AreEqual(s.X, t.X, 0.0001d); Assert.AreEqual(s.Y, t.Y, 0.0001d); } // aの幅変更 a.Width = 30; Assert.AreEqual ( new PointF(a.OuterRight, 10f), new PointF(b.OuterLeft, b.OuterTop) ); }
public void Test2() { var wordCard = new WordCard("ABC"); wordCard.PropertyChanged += (sender, e) => { if ("Width" == e.PropertyName) { Assert.Pass(); } }; wordCard.Width = 10; Assert.Fail(); }
public void 正解判定テスト() { var ankimonItem = new AnkimonItem("", new [] { "a", "b", "." }.Select(x => new MondaiWord(x))); var ankimonRowContainer = new AnkimonRowContainer(); var wordCardContainer = ankimonRowContainer.WordCardContainer; ankimonRowContainer.AnkimonItem = ankimonItem; var a = new WordCard("a"); wordCardContainer.Items.Add(a); var b = new WordCard("b"); wordCardContainer.Items.Add(b); Assert.False(ankimonRowContainer.正解判定()); var d = new WordCard("."); wordCardContainer.Items.Add(d); Assert.True(ankimonRowContainer.正解判定()); }
public EditWordCard() { InitializeComponent(); wordCard = new WordCard(); editWordCardGrid.DataContext = wordCard; }
public string ToStringForSave(WordCard obj) { return($"{obj.Word};{obj.WordAnswer};{obj.Description};{obj.Hided};{obj.ImagePath};"); }