Deprecated. Use Configuration class
        public static Configuration Read(XmlDocument xml)
        {
            var result = new Configuration();

            XmlNodeList nodes = xml.SelectNodes("//Parts");

            if (nodes != null)
            {
                if (nodes.Count > 0)
                {
                    XmlNode node = nodes[0];

                    OldConfiguration oldConfig = null;

                    foreach (XmlNode child in node.ChildNodes)
                    {
                        if (child.NodeType == XmlNodeType.Element)
                        {
                            if (child.Name.ToLower() == "event")
                            {
                                var partCountEvent = new PartCountEvent();

                                foreach (XmlNode eventChild in child.ChildNodes)
                                {
                                    if (eventChild.NodeType == XmlNodeType.Element)
                                    {
                                        if (eventChild.Name.ToLower() == "calculationtype")
                                        {
                                            switch (eventChild.InnerText.ToLower())
                                            {
                                            case "incremental": partCountEvent.CalculationType = CalculationType.INCREMENTAL; break;

                                            case "total": partCountEvent.CalculationType = CalculationType.TOTAL; break;
                                            }
                                        }
                                        else if (eventChild.Name.ToLower() == "valuetype")
                                        {
                                            switch (eventChild.InnerText.ToLower())
                                            {
                                            case "capture_item": partCountEvent.ValueType = ValueType.CAPTURE_ITEM; break;

                                            case "static_increment": partCountEvent.ValueType = ValueType.STATIC_INCREMENT; break;
                                            }
                                        }
                                        else
                                        {
                                            var type = typeof(PartCountEvent);

                                            PropertyInfo info = type.GetProperty(eventChild.Name);
                                            if (info != null)
                                            {
                                                Type t = info.PropertyType;
                                                info.SetValue(partCountEvent, Convert.ChangeType(eventChild.InnerText, t), null);
                                            }
                                        }
                                    }
                                }

                                result.Events.Add(partCountEvent);
                            }
                            else
                            {
                                if (oldConfig == null)
                                {
                                    oldConfig = new OldConfiguration();
                                }

                                if (child.Name.ToLower() == "calculationtype") // Deprecated
                                {
                                    switch (child.InnerText.ToLower())
                                    {
                                    case "incremental": oldConfig.CalculationType = CalculationType.INCREMENTAL; break;

                                    case "total": oldConfig.CalculationType = CalculationType.TOTAL; break;
                                    }
                                }
                                else // Deprecated
                                {
                                    var type = typeof(OldConfiguration);

                                    PropertyInfo info = type.GetProperty(child.Name);
                                    if (info != null)
                                    {
                                        Type t = info.PropertyType;
                                        info.SetValue(oldConfig, Convert.ChangeType(child.InnerText, t), null);
                                    }
                                }
                            }
                        }
                    }

                    if (oldConfig != null)
                    {
                        var partCountEvent = new PartCountEvent();

                        partCountEvent.EventName       = oldConfig.PartsEventName;
                        partCountEvent.EventValue      = oldConfig.PartsEventValue;
                        partCountEvent.CaptureItemLink = oldConfig.PartsCaptureItemLink;
                        partCountEvent.CalculationType = oldConfig.CalculationType;

                        result.Events.Add(partCountEvent);
                    }
                }
            }

            return(result);
        }
        public static Configuration Read(XmlDocument xml)
        {
            var result = new Configuration();

            XmlNodeList nodes = xml.SelectNodes("//Parts");

            if (nodes != null)
            {
                if (nodes.Count > 0)
                {
                    XmlNode node = nodes[0];

                    OldConfiguration oldConfig = null;

                    foreach (XmlNode child in node.ChildNodes)
                    {
                        if (child.NodeType == XmlNodeType.Element)
                        {
                            if (child.Name.ToLower() == "event")
                            {
                                var partCountEvent = new PartCountEvent();

                                foreach (XmlNode eventChild in child.ChildNodes)
                                {
                                    if (eventChild.NodeType == XmlNodeType.Element)
                                    {
                                        if (eventChild.Name.ToLower() == "calculationtype")
                                        {
                                            switch (eventChild.InnerText.ToLower())
                                            {
                                                case "incremental": partCountEvent.CalculationType = CalculationType.INCREMENTAL; break;
                                                case "total": partCountEvent.CalculationType = CalculationType.TOTAL; break;
                                            }
                                        }
                                        else if (eventChild.Name.ToLower() == "valuetype")
                                        {
                                            switch (eventChild.InnerText.ToLower())
                                            {
                                                case "capture_item": partCountEvent.ValueType = ValueType.CAPTURE_ITEM; break;
                                                case "static_increment": partCountEvent.ValueType = ValueType.STATIC_INCREMENT; break;
                                            }
                                        }
                                        else
                                        {
                                            var type = typeof(PartCountEvent);

                                            PropertyInfo info = type.GetProperty(eventChild.Name);
                                            if (info != null)
                                            {
                                                Type t = info.PropertyType;
                                                info.SetValue(partCountEvent, Convert.ChangeType(eventChild.InnerText, t), null);
                                            }
                                        }
                                    }
                                }

                                result.Events.Add(partCountEvent);
                            }
                            else
                            {
                                if (oldConfig == null) oldConfig = new OldConfiguration();

                                if (child.Name.ToLower() == "calculationtype") // Deprecated
                                {
                                    switch (child.InnerText.ToLower())
                                    {
                                        case "incremental": oldConfig.CalculationType = CalculationType.INCREMENTAL; break;
                                        case "total": oldConfig.CalculationType = CalculationType.TOTAL; break;
                                    }
                                }
                                else // Deprecated
                                {
                                    var type = typeof(OldConfiguration);

                                    PropertyInfo info = type.GetProperty(child.Name);
                                    if (info != null)
                                    {
                                        Type t = info.PropertyType;
                                        info.SetValue(oldConfig, Convert.ChangeType(child.InnerText, t), null);
                                    }
                                }
                            }
                        }
                    }

                    if (oldConfig != null)
                    {
                        var partCountEvent = new PartCountEvent();

                        partCountEvent.EventName = oldConfig.PartsEventName;
                        partCountEvent.EventValue = oldConfig.PartsEventValue;
                        partCountEvent.CaptureItemLink = oldConfig.PartsCaptureItemLink;
                        partCountEvent.CalculationType = oldConfig.CalculationType;

                        result.Events.Add(partCountEvent);
                    }
                }
            }

            return result;
        }