Ejemplo n.º 1
0
        public string Import(string data, out List <OneRabbit> exportRab, out List <OneRabbit> ascendants, out BreedsList breeds, out RabNamesList names)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(data);

            exportRab  = new List <OneRabbit>();
            ascendants = new List <OneRabbit>();
            breeds     = new BreedsList();
            names      = new RabNamesList();

            int     fromClientId;
            XmlNode rootNode = doc.FirstChild.NextSibling;

            int.TryParse(rootNode.Attributes["clientId"].Value, out fromClientId);
            if (fromClientId == _client.ID && rootNode.Attributes["dbGuid"].Value == _myDbGuid)
            {
                throw new RabNetException("Файл был экспортирован с этой же фермы");
            }

            XmlNode tmpNode = rootNode.SelectSingleNode("exports");

            foreach (XmlNode child in tmpNode.ChildNodes)
            {
                exportRab.Add(fillOneRabbit(child, fromClientId));
            }

            tmpNode = rootNode.SelectSingleNode("ascendants");
            foreach (XmlNode child in tmpNode.ChildNodes)
            {
                ascendants.Add(fillOneRabbit(child, fromClientId));
            }

            tmpNode = rootNode.SelectSingleNode("breeds");
            foreach (XmlNode child in tmpNode.ChildNodes)
            {
                breeds.Add(fillBreed(child));
            }

            tmpNode = rootNode.SelectSingleNode("names");
            foreach (XmlNode child in tmpNode.ChildNodes)
            {
                names.Add(fillName(child));
            }

            return(rootNode.Attributes["fileGuid"].Value);
        }
Ejemplo n.º 2
0
        public string Export(List <OneRabbit> exportRab, List <OneRabbit> ascendants, BreedsList breeds, RabNamesList names)
        {
            XmlDocument doc = new XmlDocument();

            doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", "no"));
            XmlElement rootNode = doc.CreateElement("export_rabbits");

            ReportHelper.AppendAttribute(rootNode, doc, "clientId", _client.ID.ToString());
            ReportHelper.AppendAttribute(rootNode, doc, "clientName", _client.Name.ToString());
            ReportHelper.AppendAttribute(rootNode, doc, "clientAddress", _client.Address.ToString());
            ReportHelper.AppendAttribute(rootNode, doc, "dbGuid", _myDbGuid.ToString());
            ReportHelper.AppendAttribute(rootNode, doc, "fileGuid", Guid.NewGuid().ToString());

            XmlElement tmpNode = doc.CreateElement("exports");

            foreach (OneRabbit r in exportRab)
            {
                tmpNode.AppendChild(getRabXml(tmpNode, doc, r));
            }
            rootNode.AppendChild(tmpNode);

            tmpNode = doc.CreateElement("ascendants");
            foreach (OneRabbit r in ascendants)
            {
                tmpNode.AppendChild(getRabXml(tmpNode, doc, r));
            }
            rootNode.AppendChild(tmpNode);

            tmpNode = doc.CreateElement("breeds");
            foreach (Breed b in breeds)
            {
                tmpNode.AppendChild(getBreedXml(tmpNode, doc, b));
            }
            rootNode.AppendChild(tmpNode);

            tmpNode = doc.CreateElement("names");
            foreach (RabName n in names)
            {
                tmpNode.AppendChild(getNameXml(tmpNode, doc, n));
            }
            rootNode.AppendChild(tmpNode);

            doc.AppendChild(rootNode);
            return(doc.InnerXml);
        }