Ejemplo n.º 1
0
 public Structure Read_from_string(string str)
 {
     Structure s = new Structure();
     DataContractSerializer ser = new DataContractSerializer(typeof(Structure));
     StringReader input = new StringReader(str);
     XmlTextReader reader = new XmlTextReader(input);
     s = (Structure)ser.ReadObject(reader);
     reader.Close();
     input.Close();
     return s;
 }
Ejemplo n.º 2
0
        public Structure Read_from_xml_file(string filename)
        {
            Structure s = new Structure();
            var path = filename;

            XmlTextReader xr = new XmlTextReader(path);
            XmlDictionaryReader reader = XmlDictionaryReader.CreateDictionaryReader(xr);
            DataContractSerializer ser = new DataContractSerializer(typeof(Structure));
            s = (Structure)ser.ReadObject(reader);
            reader.Close();
            xr.Close();
            return s;
        }
Ejemplo n.º 3
0
 private string Save_to_xml_string(Structure s)
 {
     DataContractSerializer ser = new DataContractSerializer(typeof(Structure));
     StringWriter output = new StringWriter();
     XmlTextWriter writer = new XmlTextWriter(output);
     ser.WriteObject(writer, s);
     return output.GetStringBuilder().ToString();
 }
Ejemplo n.º 4
0
 private void Save_to_xml_file(Structure s,string filename)
 {
     XmlTextWriter xw = new XmlTextWriter(filename, Encoding.UTF8);
     xw.Formatting = Formatting.Indented;
     XmlDictionaryWriter writer = XmlDictionaryWriter.CreateDictionaryWriter(xw);
     DataContractSerializer ser = new DataContractSerializer(typeof(Structure));
     ser.WriteObject(writer, s);
     writer.Close();
     xw.Close();
 }
Ejemplo n.º 5
0
 private void button7_Click(object sender, EventArgs e)
 {
     OpenFileDialog openFileDialog1 = new OpenFileDialog();
     openFileDialog1.Filter = "XML files (*.xml)|*.xml";
     openFileDialog1.FilterIndex = 1;
     openFileDialog1.RestoreDirectory = true;
     Structure s = new Structure();
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         try
         {
             s = (Structure)XML_Worker.Read_from_xml(typeof(Structure), openFileDialog1.FileName);
             foreach (Element el in s.list_of_elements)
             {
                 ocr.AddElement(el);
             }
             foreach (Relation r in s.list_of_relations)
             {
                 if (r.itRel())
                 {
                     int numelem1 = -1, numrel1 = -1;
                     for (int i = 0; i < ocr.GetCountOfElements(); i++)
                     {
                         if ((ocr.GetElement(i).Coordinate.X == r.GetElem(1).Coordinate.X) && (ocr.GetElement(i).Coordinate.Y == r.GetElem(1).Coordinate.Y))
                             numelem1 = i;
                     }
                     for (int i = 0; i < ocr.GetCountOfRelations(); i++)
                     {
                         if ((ocr.GetRelation(i).Coordinate.X == r.GetRel().Coordinate.X) && (ocr.GetRelation(i).Coordinate.Y == r.GetRel().Coordinate.Y))
                             numrel1 = i;
                     }
                     ocr.AddRelation(new Relation(ocr.GetRelation(numrel1), ocr.GetElement(numelem1), r.Coordinate.X, r.Coordinate.Y));
                 }
                 else
                 {
                     int numelem1 = -1, numelem2 = -1;
                     for (int i = 0; i < ocr.GetCountOfElements(); i++)
                     {
                         if ((ocr.GetElement(i).Coordinate.X==r.GetElem(1).Coordinate.X)&&(ocr.GetElement(i).Coordinate.Y==r.GetElem(1).Coordinate.Y))
                             numelem1 = i;
                         if ((ocr.GetElement(i).Coordinate.X == r.GetElem(2).Coordinate.X) && (ocr.GetElement(i).Coordinate.Y == r.GetElem(2).Coordinate.Y))
                             numelem2 = i;
                     }
                     ocr.AddRelation(new Relation(ocr.GetElement(numelem1), ocr.GetElement(numelem2), r.Coordinate.X, r.Coordinate.Y));
                 }
                 ocr.SetRelationParametrs(ocr.GetCountOfRelations() - 1, r);
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
         }
     }
 }
Ejemplo n.º 6
0
 private void button4_Click(object sender, EventArgs e)
 {
     Structure s = new Structure();
     s.list_of_elements = ocr.GetElements();
     s.list_of_relations = ocr.GetRelations();
     SaveFileDialog saveFileDialog1 = new SaveFileDialog();
     saveFileDialog1.Filter = "XML files (*.xml)|*.xml";
     saveFileDialog1.FilterIndex = 1;
     saveFileDialog1.RestoreDirectory = true;
     if (saveFileDialog1.ShowDialog() == DialogResult.OK)
     {
         XML_Worker.Save_to_xml_file(typeof(Structure),s, saveFileDialog1.FileName);
     }
 }