/// <summary> /// Creates a new instance of BatchingLogAgent from the required configuration. /// </summary> /// <param name="Config">The required configuration object.</param> public BatchingLogAgent(BatchingConfig Config) : this() { if (Config == null) { throw new ArgumentNullException("Config"); } Configuration = Config; if (Configuration.MappingRules != null) { Configuration.MappingRules.MappingError += MappingRules_MappingError; } StartSession(); }
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); }
//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); }