예제 #1
0
 /// <summary>
 /// Loads the cached list
 /// </summary>
 /// <returns>Returns whether loading of the cached list
 /// succeeded.</returns>
 private bool LoadCachedList()
 {
     try
     {
         FileInfo cacheFile = new FileInfo(Settings.FileListCacheDir + m_sourceHash + ".xml");
         if (cacheFile.Exists)
         {
             ObjectFromXMLDeserializer <CachedFileList.CachedFileList> deser       = new ObjectFromXMLDeserializer <Gawa.ACRender.DynamicParser.CachedFileList.CachedFileList>();
             XmlDeserializationResult <CachedFileList.CachedFileList>  deserResult = deser.Deserialize(cacheFile.FullName, XSDType.CachedFileList);
             if (deserResult.Success)
             {
                 m_fileGroups.Clear();
                 foreach (FileGroup group in deserResult.Value.FileGroup)
                 {
                     m_fileGroups.Add(group.number, group);
                 }
                 return(true);
             }
         }
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #2
0
        /// <summary>
        /// Reads the active mapping into memory
        /// </summary>
        public void ReadMapping()
        {
            // open the XML file
            //string xmlFileLocation = @"G:\gawa\code\ACRender\ACRender\DynamicParser\DataStructures.xml";
            string xmlFileLocation = @"E:\gawa\code\ACRender_ToD\ACRender\DynamicParser\DataStructures.xml";

            ObjectFromXMLDeserializer <Structures> deser       = new ObjectFromXMLDeserializer <Structures>();
            XmlDeserializationResult <Structures>  deserResult = deser.Deserialize(xmlFileLocation, XSDType.DataStructures);

            if (!deserResult.Success)
            {
                throw new Exception("Failed to load the data structure definition");
            }

            // clear the lookup tables
            m_typeDefs.Clear();

            // we've read the structure into memory.. put them into the lookup tables
            Structures structures = deserResult.Value;

            foreach (TypeDef typeDef in structures.TypeDef)
            {
                m_typeDefs.Add(typeDef.Name, typeDef);
            }
            foreach (DataFileDef dataFileDef in structures.DataFileDef)
            {
                m_dataFileDefs.Add(dataFileDef.Name, dataFileDef);
            }
        }
        /// <summary>
        /// Attempts to deserialize an object from the specified xml stream, using
        /// the xsd stream as a means of validating the contents
        /// </summary>
        /// <param name="xmlStream">The stream containing the XML that we wish to deserialize</param>
        /// <param name="xsdStream">The stream containing the XSD file for this XML</param>
        /// <param name="dontLogErrors">When set, there will be no errors written to the logfiles</param>
        /// <returns>Returns the result of the deserialization operation</returns>
        public XmlDeserializationResult <T> Deserialize(Stream xmlStream, Stream xsdStream)
        {
            m_result = new XmlDeserializationResult <T>();
            XmlReader reader = null;

            try
            {
                // create a reader for the XSD
                XmlReader xsdReader = XmlReader.Create(xsdStream);

                // create a schema set with that XSD
                XmlSchemaSet xss = new XmlSchemaSet();
                xss.Add(null, xsdReader);

                // create serialization options
                XmlReaderSettings xrs = new XmlReaderSettings();
                xrs.ValidationType          = ValidationType.Schema;
                xrs.Schemas                 = xss;
                xrs.ValidationEventHandler += new ValidationEventHandler(xrs_ValidationEventHandler);

                // create the reader
                reader = XmlReader.Create(xmlStream, xrs);

                // create the serializer and deserialize the object
                XmlSerializer xs = new XmlSerializer(typeof(T));
                m_result.Value = (T)xs.Deserialize(reader);
            }
            catch (Exception ex)
            {
                m_result.Errors.Add(ex.Message);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(m_result);
        }