public void ReadXml(XmlReader reader)
        {
            reader.MoveToContent();

            DisplayName = reader.GetAttribute("DisplayName");
            Guid guid;
            Guid.TryParse(reader.GetAttribute("ID"), out guid);
            ID = guid;
            Guid.TryParse(reader.GetAttribute("OriginalInstanceID"), out guid);
            OriginalInstanceID = guid;
            Guid.TryParse(reader.GetAttribute("ParentID"), out guid);
            ParentID = guid;
            Guid.TryParse(reader.GetAttribute("ServerID"), out guid);
            ServerID = guid;

            StateType state;
            Enum.TryParse(reader.GetAttribute("StateType"), out state);
            StateType = state;

            Guid.TryParse(reader.GetAttribute("SessionID"), out guid);
            SessionID = guid;

            while(reader.Read())
            {
                if(reader.IsStartElement("HasError"))
                {
                    var result = reader.ReadElementString("HasError");

                    bool boolean;
                    var exists = bool.TryParse(result, out boolean);
                    HasError = exists && boolean;
                }

                if(reader.IsStartElement("ErrorMessage"))
                {
                    ErrorMessage = reader.ReadElementString("ErrorMessage");
                }

                if(reader.IsStartElement("Version"))
                {
                    Version = reader.ReadElementString("Version");
                }

                if(reader.IsStartElement("Name"))
                {
                    Name = reader.ReadElementString("Name");
                }

                if(reader.IsStartElement("ActivityType"))
                {
                    var result = reader.ReadElementString("ActivityType");

                    ActivityType activityType;
                    Enum.TryParse(result, out activityType);
                    ActivityType = activityType;
                }

                if(reader.IsStartElement("Duration"))
                {
                    DurationString = reader.ReadElementString("Duration");
                }

                if(reader.IsStartElement("StartTime"))
                {
                    var result = reader.ReadElementString("StartTime");

                    DateTime date;
                    DateTime.TryParse(result, out date);
                    StartTime = date;
                }

                if(reader.IsStartElement("EndTime"))
                {
                    var result = reader.ReadElementString("EndTime");

                    DateTime date;
                    DateTime.TryParse(result, out date);
                    EndTime = date;
                }


                if(reader.IsStartElement("Inputs"))
                {
                    Inputs = new List<IDebugItem>();
                    reader.ReadStartElement();
                    while(reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "DebugItem")
                    {
                        var item = new DebugItem();
                        item.ReadXml(reader);
                        Inputs.Add(item);
                    }
                    reader.ReadEndElement();
                }

                if(reader.IsStartElement("Outputs"))
                {
                    Outputs = new List<IDebugItem>();
                    reader.ReadStartElement();
                    while(reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "DebugItem")
                    {
                        var item = new DebugItem();
                        item.ReadXml(reader);
                        Outputs.Add(item);
                    }
                    reader.ReadEndElement();
                }

                if(reader.IsStartElement("ExecutionOrigin"))
                {
                    var result = reader.ReadElementString("ExecutionOrigin");

                    ExecutionOrigin origin;
                    var exists = Enum.TryParse(result, out origin);
                    if(exists)
                    {
                        ExecutionOrigin = origin;
                    }
                }

                if(reader.IsStartElement("ExecutingUser"))
                {
                    ExecutingUser = reader.ReadElementString("ExecutingUser");
                }

                if(reader.IsStartElement("NumberOfSteps"))
                {
                    int numberOfSteps;
                    var success = int.TryParse(reader.ReadElementString("NumberOfSteps"), out numberOfSteps);
                    if(success)
                    {
                        NumberOfSteps = numberOfSteps;
                    }
                }

                if(reader.NodeType == XmlNodeType.EndElement && reader.Name == "DebugState")
                {
                    reader.ReadEndElement();
                    break;
                }
            }
        }
Beispiel #2
0
        public void ReadXml(XmlReader reader)
        {
            reader.MoveToContent();

            DisplayName = reader.GetAttribute("DisplayName");
            Guid guid;

            Guid.TryParse(reader.GetAttribute("ID"), out guid);
            ID = guid;
            Guid.TryParse(reader.GetAttribute("OriginalInstanceID"), out guid);
            OriginalInstanceID = guid;
            Guid.TryParse(reader.GetAttribute("ParentID"), out guid);
            ParentID = guid;
            Guid.TryParse(reader.GetAttribute("ServerID"), out guid);
            ServerID = guid;

            StateType state;

            Enum.TryParse(reader.GetAttribute("StateType"), out state);
            StateType = state;

            Guid.TryParse(reader.GetAttribute("SessionID"), out guid);
            SessionID = guid;

            while (reader.Read())
            {
                if (reader.IsStartElement("HasError"))
                {
                    var result = reader.ReadElementString("HasError");

                    bool boolean;
                    var  exists = bool.TryParse(result, out boolean);
                    HasError = exists && boolean;
                }

                if (reader.IsStartElement("ErrorMessage"))
                {
                    ErrorMessage = reader.ReadElementString("ErrorMessage");
                }

                if (reader.IsStartElement("Version"))
                {
                    Version = reader.ReadElementString("Version");
                }

                if (reader.IsStartElement("Name"))
                {
                    Name = reader.ReadElementString("Name");
                }

                if (reader.IsStartElement("ActivityType"))
                {
                    var result = reader.ReadElementString("ActivityType");

                    ActivityType activityType;
                    Enum.TryParse(result, out activityType);
                    ActivityType = activityType;
                }

                if (reader.IsStartElement("Duration"))
                {
                    DurationString = reader.ReadElementString("Duration");
                }

                if (reader.IsStartElement("StartTime"))
                {
                    var result = reader.ReadElementString("StartTime");

                    DateTime date;
                    DateTime.TryParse(result, out date);
                    StartTime = date;
                }

                if (reader.IsStartElement("EndTime"))
                {
                    var result = reader.ReadElementString("EndTime");

                    DateTime date;
                    DateTime.TryParse(result, out date);
                    EndTime = date;
                }


                if (reader.IsStartElement("Inputs"))
                {
                    Inputs = new List <IDebugItem>();
                    reader.ReadStartElement();
                    while (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "DebugItem")
                    {
                        var item = new DebugItem();
                        item.ReadXml(reader);
                        Inputs.Add(item);
                    }
                    reader.ReadEndElement();
                }

                if (reader.IsStartElement("Outputs"))
                {
                    Outputs = new List <IDebugItem>();
                    reader.ReadStartElement();
                    while (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "DebugItem")
                    {
                        var item = new DebugItem();
                        item.ReadXml(reader);
                        Outputs.Add(item);
                    }
                    reader.ReadEndElement();
                }

                if (reader.IsStartElement("ExecutionOrigin"))
                {
                    var result = reader.ReadElementString("ExecutionOrigin");

                    ExecutionOrigin origin;
                    var             exists = Enum.TryParse(result, out origin);
                    if (exists)
                    {
                        ExecutionOrigin = origin;
                    }
                }

                if (reader.IsStartElement("ExecutingUser"))
                {
                    ExecutingUser = reader.ReadElementString("ExecutingUser");
                }

                if (reader.IsStartElement("NumberOfSteps"))
                {
                    int numberOfSteps;
                    var success = int.TryParse(reader.ReadElementString("NumberOfSteps"), out numberOfSteps);
                    if (success)
                    {
                        NumberOfSteps = numberOfSteps;
                    }
                }

                if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "DebugState")
                {
                    reader.ReadEndElement();
                    break;
                }
            }
        }