예제 #1
0
 public static string vocabToXml(Vocabulary voc)
 {
     Type t = typeof(Vocabulary);
     StringBuilder sb = new StringBuilder();
     sb.AppendLine("<Vocabulary>");
     foreach (var val in t.GetProperties())
     {
         if (val.Name == "words")
         {
             sb.AppendLine("\t<words>");
             foreach (VocWord word in voc.words)
             {
                 sb.AppendLine(
                     String.Format("\t\t<word fromVal=\"{0}\" toVal=\"{1}\" desc=\"{2}\" />",
                     word.fromVal,
                     word.toVal,
                     word.desc
                     ));
             }
             sb.AppendLine("\t</words>");
         }
         else
         {
             sb.AppendLine(
                 String.Format("\t<item key=\"{0}\">{1}</item>",
                 val.Name,
                 val.GetValue(voc,null).ToString()));
         }
     }
     sb.AppendLine("</Vocabulary>");
     return sb.ToString();
 }
예제 #2
0
        public AddVocabulary(Vocabulary vocab_)
        {
            InitializeComponent();
            vocab = vocab_;
            updateList();

            textBox_name.Text = vocab.name;
            textBox_desc.Text = vocab.desc;
            textBox_1lang.Text = vocab.fromLang;
            textBox_2lang.Text = vocab.toLang;
        }
예제 #3
0
 /// <summary>
 /// Gets a identifier to identify which vocabulary is selected in the treeview
 /// </summary>
 /// <param name="vocab">The vocabulary to identify</param>
 /// <param name="large">If it needs a identifer for the vocabulary or the languages (true for vocabulary)</param>
 /// <returns>a string view the identifier</returns>
 private string getIdentifier(Vocabulary vocab, bool large)
 {
     if (large)
     {
         return vocab.fromLang + "," + vocab.toLang + "," + vocab.name + "," + vocab.desc + "," + vocab.date;
     }
     else
     {
         return vocab.fromLang + "," + vocab.toLang;
     }
 }
예제 #4
0
        public static Vocabulary xmlToVocab(string xml)
        {
            StringReader s = new StringReader(xml);
            XmlReader xmlr = XmlReader.Create(s);
            Vocabulary current = null;

            while (xmlr.Read())
            {
                if (xmlr.Name == "Vocabulary" && xmlr.NodeType == XmlNodeType.Element)
                {
                    current = new Vocabulary("","",new List<VocWord>(), "","","","");
                }
                if (xmlr.Name == "item" && xmlr.NodeType == XmlNodeType.Element)
                {
                    string nodekey = xmlr.GetAttribute("key");
                    Type ptype = current.GetType().GetProperty(nodekey).PropertyType;
                    current.GetType().GetProperty(nodekey).SetValue(current,
                        Convert.ChangeType(xmlr.ReadElementContentAsString(),ptype),
                        null);
                }
                if (xmlr.Name == "word")
                {
                    VocWord currentWord = new VocWord(
                        xmlr.GetAttribute("fromVal"),
                        xmlr.GetAttribute("toVal"),
                        xmlr.GetAttribute("desc")
                        );
                    current.words.Add(currentWord);
                }
                if (xmlr.Name == "Vocabulary" && xmlr.NodeType == XmlNodeType.EndElement)
                {
                    return current;
                }
            }

            return new Vocabulary();
        }