예제 #1
0
        private static File DeserialiseFile(XmlNode fileNode)
        {
            File file = new File();
            file.Id = int.Parse(fileNode.Attributes["id"].Value);
            file.Name = fileNode.Attributes["name"].Value;
            file.Iterator = (IteratorTypes)Enum.Parse(typeof(IteratorTypes), fileNode.Attributes["iterator"].Value, true);
            file.Script = new Script();
            file.Script.Syntax = (Slyce.Common.TemplateContentLanguage)Enum.Parse(typeof(Slyce.Common.TemplateContentLanguage), fileNode.Attributes["syntax"].Value, true);

            if (fileNode.Attributes["encoding"] == null)
                file.Encoding = Encoding.Unicode;
            else
                switch (fileNode.Attributes["encoding"].Value)
                {
                    case "US-ASCII":
                        file.Encoding = Encoding.ASCII;
                        break;
                    case "Unicode":
                        file.Encoding = Encoding.Unicode;
                        break;
                    case "Unicode (UTF-8)":
                        file.Encoding = Encoding.UTF8;
                        break;
                    default:
                        throw new NotImplementedException("Encoding name not handled yet in DeserialiseFile(): " + fileNode.Attributes["encoding"].Value);
                }

            //var scriptNode = fileNode.SelectSingleNode("script");
            //file.Script = new Script();
            //file.Script.Body = scriptNode.InnerText;
            //file.Script.Syntax = (Slyce.Common.TemplateContentLanguage)Enum.Parse(typeof(Slyce.Common.TemplateContentLanguage), scriptNode.Attributes["syntax"].Value, true);

            return file;
        }
예제 #2
0
 private static void SerialiseFile(File file, XmlWriter writer)
 {
     writer.WriteStartElement("file");
     writer.WriteAttributeString("id", file.Id.ToString());
     writer.WriteAttributeString("name", file.Name);
     writer.WriteAttributeString("iterator", file.Iterator.ToString());
     writer.WriteAttributeString("syntax", file.Script.Syntax.ToString());
     writer.WriteAttributeString("encoding", file.Encoding.EncodingName);
     //SerialiseScript(file.Script, writer);
     writer.WriteEndElement();
 }