Example #1
0
        public static List<Word> getDictionaryWords(MyDictionary d, User u)
        {
            XDocument doc;
            List<Word> WordList = new List<Word>();
            int i;
            bool b;
            int? test_count;
            int? attempts;
            bool knowing;

            if (d != null)
            {
                doc = XMLUtils.getXmlDocument(d.path);
                IEnumerable<XElement> elWord = from a in
                                                   (from w in doc.Descendants("Dictionary")
                                                    where long.Parse(w.Attribute("id").Value) == d.id
                                                    select w).Descendants("Word")
                                               orderby a.Element("Source").Value
                                               select a;

                IEnumerable<XElement> elUWs;
                XElement elUW;
                foreach (XElement w in elWord)
                {
                    try
                    {
                        elUWs = w.Descendants("User").Where(x => int.Parse(x.Attribute("id_user").Value) == u.id);
                        if (elUWs.Count() > 0)
                        {
                            elUW = elUWs.Single();
                            if ((elUW.Element("Test_count") != null) && int.TryParse(elUW.Element("Test_count").Value, out i))
                                test_count = i;
                            else
                                test_count = null;
                            if ((elUW.Element("Attempts") != null) && int.TryParse(elUW.Element("Attempts").Value, out i))
                                attempts = i;
                            else
                                attempts = null;
                            if ((elUW.Element("Knowing") != null) && bool.TryParse(elUW.Element("Knowing").Value, out b))
                                knowing = b;
                            else
                                knowing = false;
                        }
                        else
                        {
                            test_count = null;
                            attempts = null;
                            knowing = false;
                        }
                        WordList.Add(new Word(w.Element("Source").Value, w.Element("Translate").Value) { test_count = test_count, attempts = attempts, knowing = knowing });
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message + " / " + w.Element("Source").Value);
                    }
                }
            }
            return WordList;
        }
 public Controller_DictionaryEdit(Model model, MyDictionary dictionary)
 {
     this.model = model;
     this.dictionary = dictionary;
     view = new View_DictionaryEdit(this, dictionary);
     PrepareView();
     view.ShowDialog();
 }
 public Controller_DictionaryAdd(Model model)
 {
     this.model = model;
     this.dictionary = new MyDictionary("");
     view = new View_DictionaryEdit(this, dictionary);
     InitView();
     
     view.ShowDialog();
 }
Example #4
0
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.White;
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Black;
            MyDictionary<string> dic1 = new MyDictionary<string>();

            dic1.beginOfFile();
            string str; int n = 0;

            Console.WriteLine("\nThe capacity is: " + dic1.Capacity);
            while (n != 999)
            {
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.Write("\n\nPlease, enter the key: ");
                n = int.Parse(Console.ReadLine());

                Console.ForegroundColor = ConsoleColor.DarkMagenta;
                Console.Write("\nPlease, enter the value: ");
                str = Console.ReadLine();

                if (n != 999)
                dic1.Add(new NodeDic<string>(n, str));

                Console.Write("The amount of elemets is: " + dic1.Count);
            }

            dic1.endOfFile();
            int m = 0;

            Console.WriteLine();
            do
            {
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.Write("\nPlease, enter a key of the element you want to get:");
                m = int.Parse(Console.ReadLine());
                if (m != 999)
                {
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.Write("\nThe value is: {0}", dic1.Find(m));
                }
            } while (m != 999);

            Console.Write("\nPlease, enter a key for removing: ");
            dic1.Remove(int.Parse(Console.ReadLine()));

            do
            {
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.WriteLine("\nPlease, enter a key of the element you want to get:");
                m = int.Parse(Console.ReadLine());
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.WriteLine("\nThe value is: {0}", dic1.Find(m));
            } while (m != 999);

            Console.ReadKey();
        }
Example #5
0
 public Test(MyDictionary dictionary, TestTimings timing, TestPriorities priority, int WordCount)
 {
     this._dictionary = dictionary;
     this.timing = timing;
     this.priority = priority;
     this.wordCount = WordCount;
     this.selectedWords = new List<Word>();
     this.wrongWords = new List<Word>();
     this.CurrentPart = null;
 }
Example #6
0
        public static void addDictionary(this XDocument doc, User u, MyDictionary d)
        {
            long id = Convert.ToInt64(DateTime.Now.ToString("ddMMyyhhmmss"));

            //doc.c
            XElement element = (from el in doc.Descendants("Dictionary")
                                select el).Single();
            element.SetAttributeValue("id", id);
            element.SetAttributeValue("name", d.name);
            element.SetAttributeValue("id_user", u.id);
            element.SetAttributeValue("opened", false);
        }
Example #7
0
 public void SelectedDictionaryChange(MyDictionary dict)
 {
     model.SetDictionary(dict);
     if (model.CurrentDictionary != null)
     {
         view.CanEditDictionary = true;
         view.CanDelDictionary = true;
         if (dict.wordList.Count > 0)
             view.CanTesting = true;
         else
             view.CanTesting = false;
         view.DictionaryWordsCount = dict.wordList.Count;
     }
     else
     {
         this.DictionaryReset();
     }
 }
Example #8
0
        static void Main(string[] args)
        { // key,value
            MyDictionary <int, string> ogrenciler = new MyDictionary <int, string>();

            ogrenciler.Add(456, "harun");
            //Console.WriteLine(ogrenciler.Length);
            ogrenciler.Add(123, "canan");
            Console.WriteLine("****************");
            Console.WriteLine("Listede bulunan öğrenci sayısı : " + ogrenciler.Length);
            Console.WriteLine("****************");
            Console.WriteLine("Öğrenci isimleri" + "\n");
            foreach (var item in ogrenciler.Values)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("****************");
            Console.WriteLine("Öğrenci numaraları" + "\n");
            foreach (var item in ogrenciler.Keys)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("****************");
        }
Example #9
0
        private void ButtonClickUpdate(object sender, RoutedEventArgs e)
        {
            if (checkboxNewCategoryModify.IsChecked != null)
            {
                string inputCategoryModify;
                if ((bool)checkboxNewCategoryModify.IsChecked)
                {
                    inputCategoryModify = inputNewCategoryModify.Text;
                    comboBoxCategory.Items.Add(newCategory);
                    comboBoxCategoryModify.Items.Add(newCategory);
                }
                else
                {
                    inputCategoryModify = comboBoxCategoryModify.Text;
                }
                MyDictionary.UpdateWord(((Word)WordsList.SelectedItem).Name, inputNameModify.Text, inputDescriptionModify.Text, inputCategoryModify);
            }

            AdministrationWindow window = new AdministrationWindow();

            window.Show();
            this.Close();
        }
Example #10
0
        private void ButtonClickAddNew(object sender, RoutedEventArgs e)
        {
            if (checkboxNewCategory.IsChecked != null)
            {
                string inputCategory;
                if ((bool)checkboxNewCategory.IsChecked)
                {
                    inputCategory = inputNewCategory.Text;
                    comboBoxCategory.Items.Add(inputCategory);
                    comboBoxCategoryModify.Items.Add(inputCategory);
                }
                else
                {
                    inputCategory = comboBoxCategory.SelectedItem.ToString();
                }
                MyDictionary.AddWord(inputName.Text, inputDescription.Text, inputCategory, path);
            }

            AdministrationWindow window = new AdministrationWindow();

            window.Show();
            this.Close();
        }
Example #11
0
        static void Main(string[] args)
        {
            Dictionary <string, int> itemler = new Dictionary <string, int>();

            itemler.Add("Halil", 1);
            itemler.Add("Enging", 2);

            foreach (KeyValuePair <string, int> item in itemler)
            {
                Console.WriteLine("Name:{0} Value: {1}", item.Key, item.Value);
            }

            MyDictionary <string, int> kisiler = new MyDictionary <string, int>();

            kisiler.Add("Halil", 10);
            kisiler.Add("Engin", 8);
            Console.WriteLine(kisiler.Length);

            for (int i = 0; i < kisiler.Length; i++)
            {
                Console.WriteLine("Key {0} Value {1}", kisiler.Key[i], kisiler.Value[i]);
            }
        }
Example #12
0
        public static void incAttempts(this XDocument doc, User u, MyDictionary d, Word editWord)
        {
            XElement elWord = 
                (from el in doc.Descendants("Dictionary")
                 where long.Parse(el.Attribute("id").Value) == d.id
                 select el).Descendants("Word")
                    .Where(x => string.Compare(x.Element("Source").Value.ToString().Trim(), editWord.source.Trim(), true) == 0)
                    .Descendants("User").Where(x => int.Parse(x.Attribute("id_user").Value) == u.id).Single();               

            int i = 0;
            int.TryParse(elWord.getExistsOrCreateNewChild("Attempts").Value, out i);
            elWord.getExistsOrCreateNewChild("Attempts").Value = (++i).ToString();
            d.RefreshWordList();
        }
Example #13
0
        public static void updWord(this XDocument doc, MyDictionary d, User u, Word fromWord, Word toWord)
        {
            if ((fromWord.source != toWord.source) && !doc.checkWordUserDictUniq(d, toWord))
            {
                //MessageBox.Show("Слово не может быть изменено, т.к. уже присутствует в словаре пользователя!");
                throw new DuplicateWaitObjectException(toWord.source,"Слово не может быть изменено, т.к. уже присутствует в словаре пользователя!");
                //return;
            }

            XElement elWord =
                (from word in
                    (from el in doc.Descendants("Dictionary")
                     where long.Parse(el.Attribute("id").Value) == d.id
                     select el).Descendants("Word")
                        .Where(x => string.Compare(
                        x.Element("Source").Value.ToString().Trim(), fromWord.source.Trim(), true) == 0)
                 select word).Single();

            elWord.Element("Source").Value = toWord.source;
            elWord.getExistsOrCreateNewChild("Translate").Value = toWord.translate;

            int unodes = elWord.Descendants("User").Where(x => int.Parse(x.Attribute("id_user").Value) == u.id).Count();

            if (unodes == 0)
                elWord.Add(new XElement("User", new XAttribute("id_user", u.id)));

            XElement elWordUser = elWord.Descendants("User").Where(x => int.Parse(x.Attribute("id_user").Value) == u.id).Single();
            elWordUser.getExistsOrCreateNewChild("Knowing").Value = toWord.knowing.ToString();
            
            //elWord.getExistsOrCreateNewChild("Test_count").Value = toWord.test_count.ToString();
            //elWord.getExistsOrCreateNewChild("Attempts").Value = toWord.attempts.ToString();
            d.RefreshWordList();
        }
Example #14
0
 private void ApplicationExit(object sender, ExitEventArgs e)
 {
     MyDictionary.FinalizeDictionary();
 }
Example #15
0
 private void ApplicationStart(object sender, StartupEventArgs e)
 {
     MyDictionary.InitializeDictionary();
 }
Example #16
0
 public MyEnumerator(MyDictionary <TKey, TValue> myNumbers)
 {
     dictionary = myNumbers;
 }
Example #17
0
 static void Main(string[] args)
 {
     MyDictionary <int, string> Student = new MyDictionary <int, string>();
 }
Example #18
0
        public static int GetLessThen_N_TestCount(this XDocument doc, User u, MyDictionary d)
        {
            int i;
            int c = (from el in doc.Descendants("Dictionary")
                     where long.Parse(el.Attribute("id").Value) == d.id
                     select el).Descendants("Word").Descendants("User").Where(x => int.Parse(x.Attribute("id_user").Value) == u.id)
                .Where(x => (x.Element("Test_count")!=null) && int.TryParse(x.Element("Test_count").Value, out i) &&
                    (x.Element("Knowing") == null || !bool.Parse(x.Element("Knowing").Value))
                    )
                .Where(x => int.Parse(x.Element("Test_count").Value) < 2).Count();

            return c;
        }
Example #19
0
 public View_DictionaryEdit(AbstractOperationController controller, MyDictionary dictionary)
 {
     this.controller = controller;
     this.dictionary = dictionary;
     InitializeComponent();
 }
Example #20
0
 private void ButtonClickDelete(object sender, RoutedEventArgs e)
 {
     MyDictionary.RemoveWord(((Word)WordsList.SelectedItem).Name);
     WordsList.Items.Remove(WordsList.SelectedItem);
 }
Example #21
0
        public static void addWord(this XDocument doc, MyDictionary d, Word w)
        {
            if (!doc.checkWordUserDictUniq(d, w))
            {
                MessageBox.Show("Слово не может быть добавлено, т.к. уже присутствует в словаре пользователя!");
                return;
            }

            XElement Element = new XElement("Word",
                new XElement("Source", new XCData(w.source)),
                new XElement("Translate",new XCData(w.translate)));
 
            doc.Descendants("Dictionary")
                .Where(dict => long.Parse(dict.Attribute("id").Value) == d.id).Single().Add(Element);
            d.RefreshWordList();
        }
Example #22
0
        static void Main(string[] args)
        {
            MyDictionary <string, int> adYas = new MyDictionary <string, int>();

            adYas.Add("Baran", 11);
        }
Example #23
0
        private List<Word> getTestWords(MyDictionary dict)
        {
            Random rnd = new Random();
            List<Word> resultWords;

            int newCount = 0;

            Func<int?, int?, int> OrderFunc = delegate(int? tcount, int? att)
            {
                int range1 = 0;
                int range2 = 0;
                
                if (tcount == null) tcount = 0;
                if ((att == null) || (tcount == 0)) att = 0;
                if (att < tcount) att = tcount;

                switch (priority)
                {
                    case TestPriorities.NewWords:
                        if (tcount == 0)
                        {
                            range1 = 1;
                            range2 = wordCount;
                        }
                        else
                        {
                            range1 = wordCount + (int)(wordCount * tcount / att);
                            range2 = wordCount * 2 + (int)(wordCount * tcount / att);
                        }
                        break;

                    case TestPriorities.WrongWords:
                        if ((tcount > 0) && (tcount < att))
                        {
                            range1 = 1 + (int)(wordCount * (tcount / 5) * tcount / att);
                            range2 = 2 * (1 + (int)(wordCount * (tcount / 5) * tcount / att));
                        }
                        else if (tcount == 0)
                        {
                            range1 = 3 + 2 * wordCount;
                            range2 = 4 + 4 * wordCount;
                        }
                        else
                        {
                            range1 = 5 + 4 * wordCount + (int)att;
                            range2 = 9 + 4 * wordCount + (int)att;
                        }
                        break;

                    case TestPriorities.Balanced:
                        if ((tcount > 0) && (tcount < att))
                        {                           
                            range1 = 1001 + (int)(100 * tcount / att);
                            range2 = 1050 + (int)(100 * tcount / att);
                        }
                        else if (tcount == 0)
                        {
                            if ((newCount + 1) < (2 * wordCount / 3))
                            {
                                newCount++;
                                range1 = 1;
                                range2 = 1000;
                            }
                            else
                            {
                                range1 = 1111;
                                range2 = 1150;
                            }
                        }
                        else
                        {
                            range1 = 1081 + 5 * (int)tcount;
                            range2 = 1081 + 10 * (int)tcount;
                        }
                        break;

                    case TestPriorities.SeldomWords:
                        if (att == 0)
                        {
                            range1 = 0;
                            range2 = 0;
                        }
                        else
                        {
                            range1 = (int)tcount;
                            range2 = (int)tcount + (int)(tcount * 10 / att);
                        }
                        break;
                }
                return rnd.Next(range1,range2);
            };

            resultWords = (from l in dict.wordList
                           where l.knowing != true
                           orderby OrderFunc(l.test_count, l.attempts), l.GetHashCode() //rnd.Next(40)
                           select l).Take(wordCount).ToList();

            return resultWords;
        }
Example #24
0
        //  ----    End Words layer ----     //

        public static int GetHitWordsCount(this XDocument doc, User u, MyDictionary d)
        {
            IEnumerable<XElement> el_s= (from el in doc.Descendants("Dictionary")
                           where long.Parse(el.Attribute("id").Value) == d.id
                           select el).Descendants("Word").Descendants("User").Where(x => int.Parse(x.Attribute("id_user").Value) == u.id).
                           Descendants("Test_count");
            int i;
            int c = el_s.Where(x => int.TryParse(x.Value, out i)).Where(x => int.Parse(x.Value) > 0).Count();
  
            return c;
        }
Example #25
0
        public static void delDictionary(this XDocument doc, User u, MyDictionary d)
        {
            IEnumerable<XElement> elDictionary = 
                from uel in
                    (from el in doc.Descendants("Dictionary")
                     where int.Parse(el.Attribute("id").Value) == d.id &&
                     el.Attribute("opened").Value == "true"
                     select el).Descendants("User")
                where int.Parse(uel.Attribute("id_user").Value) == u.id
                select uel;

            elDictionary.Remove();
        }
Example #26
0
        public static void updDictionary(this XDocument doc, MyDictionary d)
        {
            IEnumerable<XElement> elDictionary =
               from el in doc.Descendants("Dictionary")
               where int.Parse(el.Attribute("id").Value) == d.id
               select el;

            elDictionary.Single().Attribute("name").Value = d.name;
        }
Example #27
0
        public static void delWord(this XDocument doc, MyDictionary d, Word w)
        {
            IEnumerable<XElement> elWord =
               from dict in doc.Descendants("Dictionary")
               where long.Parse(dict.Attribute("id").Value) == d.id
               from word in dict.Descendants("Word")
               where string.Compare(word.Element("Source").Value.Trim(), w.source.Trim(), true) == 0
               select word;

            elWord.Single().Remove();
            d.RefreshWordList();
        }
 public Controller_DictionaryDel(Model model, MyDictionary dictionary)
 {
     this.model = model;
     this.dictionary = dictionary;
     this.ExecOperation();
 }
Example #29
0
        static void Main(string[] args)
        {
            MyDictionary <string> kelimeler = new MyDictionary <string>();

            kelimeler.Add("araba");
        }
Example #30
0
        public static int GetKnowingWordsCount(this XDocument doc, User u, MyDictionary d)
        {
            int i;
            int c = (from el in doc.Descendants("Dictionary")
                     where long.Parse(el.Attribute("id").Value) == d.id
                     select el).Descendants("Word").Descendants("User").Where(x => int.Parse(x.Attribute("id_user").Value) == u.id)
                .Where(x =>
                    (x.Element("Knowing") != null && bool.Parse(x.Element("Knowing").Value)) ||
                    ((x.Element("Test_count") != null) && (x.Element("Attempts") != null) && int.TryParse(x.Element("Test_count").Value, out i) && int.TryParse(x.Element("Attempts").Value, out i) &&
                    ((float.Parse(x.Element("Test_count").Value)+(int)(float.Parse(x.Element("Test_count").Value)/6)) / float.Parse(x.Element("Attempts").Value)) > 0.5 &&
                    int.Parse(x.Element("Test_count").Value) >= 2)
                    ).Count();

            return c;
        }
Example #31
0
        static void Main(string[] args)
        {
            MyDictionary <int, string> ogrenciler = new MyDictionary <int, string>();

            ogrenciler.Add(123, "Özge");
        }
Example #32
0
      //  ----    Begin Words layer  ----  //
      public static bool checkWordUserDictUniq(this XDocument doc, MyDictionary d, Word w)
      {
          int WordsCount = (from el in doc.Descendants("Word")
                            //проверяем слово на уникальность только в рамках конкретного словаря
                            where string.Compare(el.Element("Source").Value.Trim(), w.source.Trim(), true) == 0
                            select el).Count();
 
          if (WordsCount > 0)
          {
              //MessageBox.Show("Слово уже присутствует в словаре");
              //throw new DuplicateWaitObjectException();
              return false;
          }
          return true;
      }