Exemplo n.º 1
0
 public static void WriteVocab(string path, MyVocabulary voc)
 {
     using (XmlTextWriter serializer = new XmlTextWriter(path, Encoding.UTF8))
     {
         serializer.Formatting = Formatting.Indented;
         XmlDictionaryWriter    writer = XmlDictionaryWriter.CreateDictionaryWriter(serializer);
         DataContractSerializer ser    = new DataContractSerializer(typeof(MyVocabulary));
         ser.WriteObject(writer, voc);
         writer.Close();
     }
 }
Exemplo n.º 2
0
        private static void OvnerMenu()
        {
            //Console.OutputEncoding = System.Text.Encoding.GetEncoding(1251);
            View.OwnerMenu();
            while (true)
            {
                Console.SetCursorPosition(40, 15);
                switch (Console.ReadKey().Key)
                {
                case ConsoleKey.Escape:
                    return;

                case ConsoleKey.D1:
                    path       = "English-Ukrainian.xml";
                    vocabulary = SerializeVocabularu.LoadVocab(path);
                    SecondMenu(path, vocabulary);
                    break;

                case ConsoleKey.D2:
                    path       = "Ukrainian-English.xml";
                    vocabulary = SerializeVocabularu.LoadVocab(path);
                    SecondMenu(path, vocabulary);
                    break;

                case ConsoleKey.NumPad1:
                    path       = "English-Ukrainian.xml";
                    vocabulary = SerializeVocabularu.LoadVocab(path);
                    SecondMenu(path, vocabulary);
                    break;

                case ConsoleKey.NumPad2:
                    path       = "Ukrainian-English.xml";
                    vocabulary = SerializeVocabularu.LoadVocab(path);
                    SecondMenu(path, vocabulary);
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 3
0
        public static MyVocabulary LoadVocab(string path)
        {
            FileStream fs = new FileStream(path, FileMode.OpenOrCreate);

            if (fs.Length < 50)
            {
                fs.Close();
                WriteVocab(path, new MyVocabulary());
            }
            else
            {
                fs.Close();
            }
            MyVocabulary vocabulary = null;

            using (fs = new FileStream(path, FileMode.Open))
            {
                XmlDictionaryReader    reader = XmlDictionaryReader.CreateTextReader(fs, Encoding.UTF8, new XmlDictionaryReaderQuotas(), null);
                DataContractSerializer ser    = new DataContractSerializer(typeof(MyVocabulary));
                vocabulary = (MyVocabulary)ser.ReadObject(reader);
            }
            return(vocabulary);
        }
Exemplo n.º 4
0
        private static void SecondMenu(string path, MyVocabulary vocabulary)
        {
            View.SecondMenu();
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.SetCursorPosition(40, 1);
            Console.Write(vocabulary.name);

            while (true)
            {
                Console.SetCursorPosition(40, 20);
                switch (Console.ReadKey().Key)
                {
                case ConsoleKey.Escape:
                    SerializeVocabularu.WriteVocab(path, vocabulary);
                    View.OwnerMenu();
                    return;

                case ConsoleKey.D1:
                    menu(1);
                    break;

                case ConsoleKey.D2:
                    menu(2);
                    break;

                case ConsoleKey.D3:
                    menu(3);
                    break;

                case ConsoleKey.D4:
                    menu(4);
                    break;

                case ConsoleKey.D5:
                    menu(5);
                    break;

                case ConsoleKey.D6:
                    menu(6);
                    break;

                case ConsoleKey.D7:
                    menu(7);
                    break;

                case ConsoleKey.D8:
                    break;

                case ConsoleKey.D9:
                    break;

                case ConsoleKey.NumPad1:
                    menu(1);
                    break;

                case ConsoleKey.NumPad2:
                    menu(2);
                    break;

                case ConsoleKey.NumPad3:
                    menu(3);
                    break;

                case ConsoleKey.NumPad4:
                    menu(4);
                    break;

                case ConsoleKey.NumPad5:
                    menu(5);
                    break;

                case ConsoleKey.NumPad6:
                    menu(6);
                    break;

                case ConsoleKey.NumPad7:
                    menu(7);
                    break;

                case ConsoleKey.NumPad8:
                    break;

                case ConsoleKey.NumPad9:
                    break;

                default:
                    break;
                }
            }
        }