Beispiel #1
0
        public void Serialize(Albumchart albumchart)
        {
            if (xmlFile.Exists)
            {
                xmlFile.Delete();
            }

            FileStream stream = new FileStream(xmlFile.FullName, FileMode.Create);

            serializer.Serialize(stream, albumchart);
            stream.Close();
        }
Beispiel #2
0
        public void SaveCopy(Albumchart albumchart)
        {
            FileInfo tmp = new FileInfo("copy.xml");

            if (tmp.Exists)
            {
                tmp.Delete();
            }

            Stream stream = new FileStream(tmp.FullName, FileMode.Create);

            serializer.Serialize(stream, albumchart);
            stream.Close();
        }
Beispiel #3
0
        public Albumchart Deserialize()
        {
            Albumchart albumchart = null;

            if (xmlFile.Exists)
            {
                using (StreamReader reader = new StreamReader(xmlFile.FullName))
                {
                    albumchart = (Albumchart)serializer.Deserialize(reader);
                }
            }
            else
            {
                throw new IOException();
            }
            return(albumchart);
        }
Beispiel #4
0
        public MainWindow()
        {
            InitializeComponent();

            albumchart       = new Albumchart();
            xmlSerialization = new XMLSerialization(@"..\..\albumchart.xml", @"..\..\\albumchart.xsd");
            if (!xmlSerialization.xmlFile.Exists)
            {
                MessageBox.Show("File " + xmlSerialization.xmlFile.FullName.ToString() + " not found!", "XML loading");
            }
            else
            {
                albumchart = xmlSerialization.Deserialize();
                MessageBox.Show("XML file " + xmlSerialization.xmlFile.Name + " loaded!");
            }

            update();


            unitsCombobox.Items.Add("h");
            unitsCombobox.Items.Add("min");
            unitsCombobox.Items.Add("sec");

            foreach (var item in albumchart.artists.artistList)
            {
                artistCombobox.Items.Add(item.Value);
            }

            foreach (var item in albumchart.genres.genresList)
            {
                genreCombobox.Items.Add(item.Value);
            }



            if (xmlSerialization.CheckSchema(albumchart))
            {
                MessageBox.Show("git");
            }
            else
            {
                MessageBox.Show("chuj");
            }
        }
Beispiel #5
0
        public bool CheckSchema(Albumchart albumchart)
        {
            SaveCopy(albumchart);

            XmlSchemaSet schemas = new XmlSchemaSet();

            schemas.Add("http://www.example.org/types", schemaFile.FullName);
            XDocument doc = XDocument.Load("copy.xml");
            string    msg = "";

            doc.Validate(schemas, (o, e) => {
                msg += e.Message + Environment.NewLine;
            });
            Console.WriteLine(msg == "" ? "Dokument jest poprawny." : "Dokument jest niepoprawny: " + msg);
            if (msg == "")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }