Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 4
0
    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);
    }
Exemplo n.º 5
0
        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 + ",");
        }
Exemplo n.º 6
0
 //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);
     }
 }
Exemplo n.º 7
0
 //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);
     }
 }
Exemplo n.º 8
0
 private void OnWordCardClicked(WordCard card)
 {
     TeamCard.Teams team = secretBoard.CheckSecret(card.GetIndex());
     if (card.GetComponent <TeamCard>())
     {
         card.GetComponent <TeamCard>().SetTeam(team);
     }
 }
Exemplo n.º 9
0
        public EditWordCard(WordCard wc, int index)
        {
            InitializeComponent();

            wordCard    = DeepClone(wc);
            oldWordCard = wc;
            editWordCardGrid.DataContext = wordCard;
            this.index = index;
        }
Exemplo n.º 10
0
        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)));
        }
Exemplo n.º 11
0
        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);
 }
Exemplo n.º 13
0
        public async Task <IHttpActionResult> GetWordCard(int id)
        {
            WordCard wordCard = await db.WordCards.FindAsync(id);

            if (wordCard == null)
            {
                return(NotFound());
            }

            return(Ok(wordCard));
        }
Exemplo n.º 14
0
 public Card GetCardByText(string cardText)
 {
     foreach (var item in PowerCards)
     {
         if (item.CardText == cardText)
         {
             return(item);
         }
     }
     return(WordCard.CreateCard(cardText));
 }
Exemplo n.º 15
0
        public void Pick(WordCard card)
        {
            HandlePendingCardResets();

            if (!UnsolvedPairs.Contains(card.Pair)) return;
            if (!HandlePreviousSelection(ActiveWordCard)) return;

            ActiveWordCard = card;
            card.State = CardState.Selected;

            CheckForMatch();
        }
Exemplo n.º 16
0
 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));
     }
 }
Exemplo n.º 17
0
 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
     }
 }
Exemplo n.º 18
0
        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));
        }
Exemplo n.º 19
0
        public void OpenWordCard(WordCardViewModel wm)
        {
            var wc = new WordCard();

            wc.DataContext = wm;
            Window window = new Window
            {
                Title   = wm.Word.Value,
                Content = wc
            };

            window.Show();
        }
Exemplo n.º 20
0
 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());
        }
Exemplo n.º 22
0
        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));
        }
Exemplo n.º 23
0
 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);
        }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 27
0
 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;
     }
 }
Exemplo n.º 28
0
 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));
         }
     }
 }
Exemplo n.º 29
0
        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);
        }
Exemplo n.º 30
0
        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);
        }
Exemplo n.º 31
0
    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;
        }
    }
Exemplo n.º 32
0
        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();
        }
Exemplo n.º 33
0
        //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);
                }
            }
        }
Exemplo n.º 34
0
        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);
        }
Exemplo n.º 35
0
        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.正解判定());
        }
Exemplo n.º 40
0
 public EditWordCard()
 {
     InitializeComponent();
     wordCard = new WordCard();
     editWordCardGrid.DataContext = wordCard;
 }
Exemplo n.º 41
0
 public string ToStringForSave(WordCard obj)
 {
     return($"{obj.Word};{obj.WordAnswer};{obj.Description};{obj.Hided};{obj.ImagePath};");
 }