예제 #1
0
파일: XmlAdapter.cs 프로젝트: oqewok/gitter
        public void Store(Section section)
        {
            var doc     = new XmlDocument();
            var context = new XmlWriterContext(doc);

            SectionPersister.Store(context, section);
            using (var writer = XmlWriter.Create(_stream, new XmlWriterSettings()
            {
                CloseOutput = false,
                Encoding = System.Text.Encoding.UTF8,
                Indent = true,
                IndentChars = "\t",
            }))
            {
                doc.Save(writer);
            }
        }
예제 #2
0
파일: XmlAdapter.cs 프로젝트: oqewok/gitter
            public static void Store(XmlWriterContext context, Section section)
            {
                context.Push(section.Name);
                int sections   = section.SectionCount;
                int parameters = section.ParameterCount;

                if (parameters != 0 || sections != 0)
                {
                    bool saveDirect = sections == 0 || parameters == 0;
                    if (parameters == 0)
                    {
                        context.StoreInAttribute("Style", "NoParameters");
                    }
                    else if (sections == 0)
                    {
                        context.StoreInAttribute("Style", "NoSections");
                    }
                    if (section.SectionCount != 0)
                    {
                        if (!saveDirect)
                        {
                            context.Push("Sections");
                        }
                        try
                        {
                            foreach (var subsection in section.Sections)
                            {
                                SectionPersister.Store(context, subsection);
                            }
                        }
                        finally
                        {
                            if (!saveDirect)
                            {
                                context.Pop();
                            }
                        }
                    }
                    if (section.ParameterCount != 0)
                    {
                        if (!saveDirect)
                        {
                            context.Push("Parameters");
                        }
                        try
                        {
                            foreach (var parameter in section.Parameters)
                            {
                                ParameterPersister.Store(context, parameter);
                            }
                        }
                        finally
                        {
                            if (!saveDirect)
                            {
                                context.Pop();
                            }
                        }
                    }
                }
                context.Pop();
            }