Example #1
0
        /// <summary>
        /// Helper method to deserialize mapping rules form xml
        /// </summary>
        internal static MappingRules Load(XmlReader reader)
        {
            MappingRules result = new MappingRules();

            reader.ReadStartElement();
            while (reader.GoToSibling())
            {
                switch (reader.LocalName)
                {
                case "Log":
                    var mapping = LogMappings.Load(reader);
                    result.LogMappingsRules.Add(mapping);
                    break;

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

            return(result);
        }
        /// <summary>
        /// Helper method to deserialize mapping rules form xml
        /// </summary>
        internal static MappingRules Load(XmlReader reader)
        {
            MappingRules result = new MappingRules();
            reader.ReadStartElement();
            while (reader.GoToSibling())
            {
                switch (reader.LocalName)
                {
                    case "Log":
                        var mapping = LogMappings.Load(reader);
                        result.LogMappingsRules.Add(mapping);
                        break;
                    default:
                        reader.Skip();
                        break;
                }
            }
            reader.ReadEndElement();

            return result;
        }
        //public static IAsyncOperation<BatchingConfig> Load(Uri source)
        //{
        //    return AsyncInfo.Run(c => InternalLoad(source));
        //}

        //internal static async Task<BatchingConfig> InternalLoad(Uri source)
        //{
        //    var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(source);
        //    using (var stream = await file.OpenStreamForReadAsync())
        //    {
        //        return Load(XmlReader.Create(stream));
        //    }
        //}

        internal static BatchingConfig Load(XmlReader reader)
        {
            BatchingConfig result = new BatchingConfig();

            reader.GoToElement();
            reader.ReadStartElement();
            if (!reader.IsEmptyElement)
            {
                while (reader.GoToSibling())
                {
                    switch (reader.LocalName)
                    {
                    case "Application":
                        if (!reader.IsEmptyElement)
                        {
                            reader.ReadStartElement();
                            while (reader.GoToSibling())
                            {
                                switch (reader.LocalName)
                                {
                                case "Id":
                                    result.ApplicationId = new Guid(reader.ReadElementContentAsString());
                                    break;

                                case "Name":
                                    result.ApplicationName = reader.ReadElementContentAsString();
                                    break;

                                case "Version":
                                    result.ApplicationVersion = reader.ReadElementContentAsString();
                                    break;

                                case "Enabled":
                                    result.LoggingEnabled = reader.ReadElementContentAsBoolean();
                                    break;

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

                    case "Queue":
                        if (!reader.IsEmptyElement)
                        {
                            reader.ReadStartElement();
                            while (reader.GoToSibling())
                            {
                                switch (reader.LocalName)
                                {
                                case "maxLength":
                                    result.MaxQueueLength = reader.ReadElementContentAsInt();
                                    break;

                                case "maxBatchLength":
                                    result.MaxBatchLength = reader.ReadElementContentAsInt();
                                    break;

                                case "maxSendErrors":
                                    result.MaxSendErrors = reader.ReadElementContentAsInt();
                                    break;

                                case "maxSendErrorsThrottled":
                                    result.MaxSendErrorsThrottled = reader.ReadElementContentAsInt();
                                    break;

                                case "pollingIntervalSeconds":
                                    result.QueuePollingInterval = TimeSpan.FromSeconds(reader.ReadElementContentAsInt());
                                    break;

                                case "pollingIntervalThrottledSeconds":
                                    result.QueuePollingIntervalThrottled = TimeSpan.FromSeconds(reader.ReadElementContentAsInt());
                                    break;

                                case "maxRetries":
                                    result.MaxRetries = reader.ReadElementContentAsInt();
                                    break;

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

                    case "Session":
                        if (!reader.IsEmptyElement)
                        {
                            reader.ReadStartElement();
                            while (reader.GoToSibling())
                            {
                                switch (reader.LocalName)
                                {
                                case "maxSessionLogs":
                                    result.MaxSessionLogs = reader.ReadElementContentAsInt();
                                    break;

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

                    case "MappingRules":
                        if (!reader.IsEmptyElement)
                        {
                            result.MappingRules = MappingRules.Load(reader);
                        }
                        else
                        {
                            reader.Skip();
                        }
                        break;

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

            return(result);
        }