protected virtual CachedXmlDocument GetCachedXmlDocument(string fileName)
        {
            XmlDocument       xmlDocument       = LoadXmlDocument(fileName);
            CachedXmlDocument cachedXmlDocument = new CachedXmlDocument(xmlDocument, fileName, File.GetLastWriteTime(fileName));

            return(cachedXmlDocument);
        }
        protected virtual XmlDocument GetXmlDocument(string fileName)
        {
            CachedXmlDocument cachedXmlDocument = (CachedXmlDocument)cachedXmlDocuments[fileName];

            if (cachedXmlDocument == null)
            {
                cachedXmlDocument            = GetCachedXmlDocument(fileName);
                cachedXmlDocuments[fileName] = cachedXmlDocument;
            }
            return(cachedXmlDocument.XmlDocument);
        }
        protected virtual bool HasXmlDocument(string fileName)
        {
            CachedXmlDocument cachedXmlDocument = (CachedXmlDocument)cachedXmlDocuments[fileName];

            if (cachedXmlDocument != null)
            {
                return(true);
            }

            return(false);
        }
        protected virtual XmlDocument CreateObjectXmlDocument(IClassMap classMap, string fileName)
        {
            ISourceMap sourceMap = classMap.GetDocSourceMap();

            MemoryStream  ms        = new MemoryStream();
            XmlTextWriter xmlWriter = new XmlTextWriter(
                ms,
                Encoding.GetEncoding(sourceMap.GetDocEncoding()));

            xmlWriter.Formatting = Formatting.Indented;

            xmlWriter.WriteStartDocument(false);

            xmlWriter.WriteDocType("Object", null, null, null);
            xmlWriter.WriteComment("Serialized object");             // do not localize

            xmlWriter.WriteStartElement(classMap.GetDocElement(), null);

            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndDocument();

            //Write the XML to file and close the writer
            xmlWriter.Flush();
            string xml = Encoding.GetEncoding("utf-8").GetString(ms.ToArray(), 0, (int)ms.Length);

            xmlWriter.Close();

            //Obs fulhack!! Jag får ett konstigt skräptecken i början!!
            xml = xml.Substring(1);

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(xml);

            CachedXmlDocument cachedXmlDocument = new CachedXmlDocument(xmlDocument, fileName);

            cachedXmlDocuments[fileName] = cachedXmlDocument;

            return(xmlDocument);
        }
 protected virtual CachedXmlDocument GetCachedXmlDocument(string fileName)
 {
     XmlDocument xmlDocument = LoadXmlDocument(fileName);
     CachedXmlDocument cachedXmlDocument = new CachedXmlDocument(xmlDocument, fileName, File.GetLastWriteTime(fileName)) ;
     return cachedXmlDocument;
 }
        protected virtual XmlDocument CreateObjectXmlDocument(IClassMap classMap, string fileName)
        {
            ISourceMap sourceMap = classMap.GetDocSourceMap();

            MemoryStream ms = new MemoryStream() ;
            XmlTextWriter xmlWriter = new XmlTextWriter(
                ms,
                Encoding.GetEncoding( sourceMap.GetDocEncoding() ));

            xmlWriter.Formatting = Formatting.Indented;

            xmlWriter.WriteStartDocument(false);

            xmlWriter.WriteDocType("Object",null,null,null);
            xmlWriter.WriteComment("Serialized object"); // do not localize

            xmlWriter.WriteStartElement(classMap.GetDocElement(), null);

            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndDocument();

            //Write the XML to file and close the writer
            xmlWriter.Flush();
            string xml = Encoding.GetEncoding( "utf-8" ).GetString(ms.ToArray(),0,(int)ms.Length);
            xmlWriter.Close();

            //Obs fulhack!! Jag får ett konstigt skräptecken i början!!
            xml = xml.Substring(1);

            XmlDocument xmlDocument = new XmlDocument() ;
            xmlDocument.LoadXml(xml);

            CachedXmlDocument cachedXmlDocument = new CachedXmlDocument(xmlDocument, fileName) ;
            cachedXmlDocuments[fileName] = cachedXmlDocument;

            return xmlDocument;
        }
        protected virtual XmlDocument CreateDomainXmlDocument(IClassMap classMap, string fileName)
        {
            ISourceMap sourceMap = classMap.GetDocSourceMap();

            MemoryStream ms = new MemoryStream() ;
            XmlTextWriter xmlWriter = new XmlTextWriter(
                ms,
                Encoding.GetEncoding( sourceMap.GetDocEncoding() ));

            xmlWriter.Formatting = Formatting.Indented;

            xmlWriter.WriteStartDocument(false);

            xmlWriter.WriteDocType("Domain",null,null,null);
            xmlWriter.WriteComment("Serialized domain objects"); // do not localize

            xmlWriter.WriteStartElement(sourceMap.GetDocRoot() , null);

            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndDocument();

            //Write the XML to file and close the writer
            xmlWriter.Flush();
            string xml = Encoding.GetEncoding( "utf-8" ).GetString(ms.ToArray(),0,(int)ms.Length);
            xmlWriter.Close();

            //TODO: ugly hack!! Do this right way to avoid extra char in the beginning!!
            xml = xml.Substring(1);

            XmlDocument xmlDocument = new XmlDocument() ;
            xmlDocument.LoadXml(xml);

            CachedXmlDocument cachedXmlDocument = new CachedXmlDocument(xmlDocument, fileName) ;
            cachedXmlDocuments[fileName] = cachedXmlDocument;

            return xmlDocument;
        }