Exemplo n.º 1
0
        /// <summary>
        ///  Helper method to deserialize a batch serailized via the default serialization
        /// </summary>
        /// <returns>The deserialized batch</returns>
        public static Batch Deserialize(XmlReader xmlReader)
        {
            if (xmlReader.GoToElement())
            {
                Batch result = new Batch();
                LogBase.DeserializeData(xmlReader, result);

                xmlReader.ReadStartElement();

                List <Log> logs = new List <Log>();
                while (xmlReader.GoToSibling())
                {
                    switch (xmlReader.LocalName)
                    {
                    case Log.LogNodeName:
                        var log = Log.Deserialize(xmlReader);
                        logs.Add(log);
                        break;

                    default:
                        xmlReader.Skip();
                        break;
                    }
                }
                result.Logs = logs;
                xmlReader.ReadEndElement();
                return(result);
            }
            else
            {
                throw new Exception("Batch is empty");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deserializes a log from Xml. The type of log created will always be Log. To cast after the fact, call CreateLog or CastLog.
        /// </summary>
        public static Log Deserialize(XmlReader xmlReader)
        {
            Log result = new Log(new Dictionary <string, string>());

            if (!LogBase.DeserializeData(xmlReader, result))
            {
                throw new Exception("Log is empty");
            }
            return(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Deserializes the log from an xml reader
 /// </summary>
 /// <param name="xmlReader">XmlReader containing the log info</param>
 /// <param name="logBase">The log object you would like to populate</param>
 /// <returns>Indicates whether or not it was successful. If no data is found in the xml, it will return false</returns>
 public static bool DeserializeData(XmlReader xmlReader, LogBase logBase)
 {
     if (xmlReader.MoveToFirstAttribute())
     {
         do
         {
             logBase.Data[xmlReader.Name] = xmlReader.Value;
         } while (xmlReader.MoveToNextAttribute());
         return(true);
     }
     else
     {
         return(false);
     }
 }