internal static LoggingConfig Load(XmlReader reader)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            LoggingConfig result = new LoggingConfig();

            reader.GoToElement();
            if (!reader.IsEmptyElement)
            {
                reader.ReadStartElement();
                while (reader.GoToSibling())
                {
                    switch (reader.LocalName)
                    {
                        default:
                            reader.Skip();
                            break;
                    }
                }
                reader.ReadEndElement();
            }
            else
                reader.Skip();

            return result;
        }
        internal static EdgeServerConfig Load(XmlReader reader)
        {
            if (reader == null) throw new ArgumentNullException("reader");

            var result = new EdgeServerConfig();

            reader.GoToElement();
            reader.ReadStartElement();
            if (!reader.IsEmptyElement)
            {
                while (reader.GoToSibling())
                {
                    switch (reader.LocalName)
                    {
                        case "EdgeServerRules":
                            if (!reader.IsEmptyElement)
                            {
                                result.EdgeServerRulesCollection.Add(EdgeServerRules.Load(reader));
                            }
                            else
                                reader.Skip();
                            break;

                        default:
                            reader.Skip();
                            break;
                    }
                }
                reader.ReadEndElement();
            }
            else
                reader.Skip();

            return result;
        }
        internal static BatchingConfig Load(XmlReader reader)
        {
            BatchingConfig result = null;
            IBatchAgent batchAgent = null;

            reader.GoToElement();
            if (reader.LocalName != "Configuration")
                throw new Exception("Invalid config Xml");
            reader.ReadStartElement();
            if (!reader.IsEmptyElement)
            {
                while (reader.GoToSibling())
                {
                    switch (reader.LocalName)
                    {
                        case "BatchingConfig":
                            result = BatchingConfig.Load(reader);
                            break;
                        case "Service":
                            batchAgent = BatchAgentFactory.Load(reader);
                            break;
                        default:
                            reader.Skip();
                            break;
                    }
                }
                reader.ReadEndElement();
            }
            else
                reader.Skip();

            if (result == null || batchAgent == null)
                throw new Exception("Invalid Configuraiton");
            result.BatchAgent = batchAgent;
            return result;
        }
        /// <summary>
        /// Creates an instance of the main diagnostic config object from an XmlReader
        /// </summary>
        internal static AnalyticsConfig Load(XmlReader reader)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            var result = new AnalyticsConfig();
            result.LatencyAlertThreshold = null;

            reader.GoToElement();
            reader.ReadStartElement();
            if (!reader.IsEmptyElement)
            {
                while (reader.GoToSibling())
                {
                    switch (reader.LocalName)
                    {
                        case "AdditionalData":
                            result.AdditionalData = reader.ReadElementContentAsString().Split(',').Select(kvp => kvp.Split('=')).ToDictionary(kvp => kvp[0], kvp => kvp[1]);
                            break;
                        case "Logging":
                            if (!reader.IsEmptyElement)
                            {
                                result.LoggingConfig = LoggingConfig.Load(reader);
                            }
                            else reader.Skip();
                            break;
                        case "Diagnostics":
                            if (!reader.IsEmptyElement)
                            {
                                reader.ReadStartElement();
                                while (reader.GoToSibling())
                                {
                                    switch (reader.LocalName)
                                    {
                                        case "TrackQuality":
                                            result.TrackQuality = Convert.ToBoolean(reader.ReadElementContentAsInt());
                                            break;
                                        case "TrackDownloadErrors":
                                            result.TrackDownloadErrors = Convert.ToBoolean(reader.ReadElementContentAsInt());
                                            break;
                                        case "AggregationIntervalMilliseconds":
                                            result.AggregationInterval = TimeSpan.FromMilliseconds(reader.ReadElementContentAsInt());
                                            break;
                                        case "PollingMilliseconds":
                                            result.PollingInterval = TimeSpan.FromMilliseconds(reader.ReadElementContentAsInt());
                                            break;
                                        case "LatencyAlertThreshold":
                                            result.LatencyAlertThreshold = reader.ReadElementContentAsDouble();
                                            break;
                                        case "QualityTracking":
                                            result.QualityConfig = QualityConfig.Load(reader);
                                            break;
                                        default:
                                            reader.Skip();
                                            break;
                                    }
                                }
                                reader.ReadEndElement();
                            }
                            else
                                reader.Skip();
                            break;

                        default:
                            reader.Skip();
                            break;
                    }
                }
                reader.ReadEndElement();
            }
            else
                reader.Skip();

            return result;
        }
        /// <summary>
        /// Loads a new instance of the EdgeServerRules class from Xml.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        internal static EdgeServerRules Load(XmlReader reader)
        {
            if (reader == null) throw new ArgumentNullException("reader");

            var result = new EdgeServerRules();

            reader.GoToElement();
            if (!reader.IsEmptyElement)
            {
                result.Domain = reader.GetAttribute("Domain");
                reader.ReadStartElement();
                while (reader.GoToSibling())
                {
                    switch (reader.LocalName)
                    {
                        case "EdgeResolverUrlPattern":
                            result.EdgeResolverUrlPattern = reader.ReadElementContentAsString();
                            break;
                        case "EdgeRegEx":
                            result.EdgeRegex = reader.ReadElementContentAsString();
                            break;
                        case "ClientIpRegEx":
                            result.ClientIPRegex = reader.ReadElementContentAsString();
                            break;
                        case "ClientIpHeader":
                            result.ClientIPHeader = reader.ReadElementContentAsString();
                            break;
                        case "EdgeResolverHeaders":
                            result.EdgeResolverHeaders = reader.ReadElementContentAsString().Split(',');
                            break;
                        case "EdgeHeader":
                            result.EdgeHeader = reader.ReadElementContentAsString();
                            break;
                        default:
                            reader.Skip();
                            break;
                    }
                }
                reader.ReadEndElement();
            }
            else reader.Skip();

            return result;
        }
        internal static QualityConfig Load(XmlReader reader)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            QualityConfig result = new QualityConfig();

            reader.GoToElement();
            if (!reader.IsEmptyElement)
            {
                reader.ReadStartElement();
                while (reader.GoToSibling())
                {
                    switch (reader.LocalName)
                    {
                        case "DroppedFrames":
                            result.DroppedFrames = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "RenderedFrames":
                            result.RenderedFrames = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "ProcessCPULoad":
                            result.ProcessCpuLoad = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "SystemCPULoad":
                            result.SystemCpuLoad = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "Bitrate":
                            result.Bitrate = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "BitrateMax":
                            result.BitrateMax = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "BitrateMaxDuration":
                            result.BitrateMaxDuration = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "PerceivedBandwidth":
                            result.PerceivedBandwidth = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "VideoBufferSize":
                            result.VideoBufferSize = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "AudioBufferSize":
                            result.AudioBufferSize = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "Buffering":
                            result.Buffering = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "BitrateChangeCount":
                            result.BitrateChangeCount = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "VideoDownloadLatency":
                            result.VideoDownloadLatency = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "AudioDownloadLatency":
                            result.AudioDownloadLatency = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "DvrOperationCount":
                            result.DvrOperationCount = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "FullScreenChangeCount":
                            result.FullScreenChangeCount = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;
                        case "HttpErrorCount":
                            result.DownloadErrorCount = Convert.ToBoolean(reader.ReadElementContentAsInt());
                            break;

                        default:
                            reader.Skip();
                            break;
                    }
                }
                reader.ReadEndElement();
            }
            else
                reader.Skip();

            return result;
        }