diff --git a/ZeroLevel.UnitTests/ConfigurationTest.cs b/ZeroLevel.UnitTests/ConfigurationTest.cs index b343c37..ea6fab3 100644 --- a/ZeroLevel.UnitTests/ConfigurationTest.cs +++ b/ZeroLevel.UnitTests/ConfigurationTest.cs @@ -1,9 +1,31 @@ using System.Collections.Generic; using System.Linq; using Xunit; +using ZeroLevel.Services.Config; namespace ZeroLevel.UnitTests { + public class Address + { + public string Host { get; set; } + public int Port { get; set; } + } + public class AddressParser + : IConfigRecordParser + { + public object Parse(string line) + { + var parts = line.Split(';').Where(part => string.IsNullOrWhiteSpace(part) == false).ToArray(); + var addresses = new Address[parts.Length]; + for (int i = 0; i < parts.Length; i++) + { + var hp = parts[i].Trim().Split(':'); + addresses[i] = new Address { Host = hp[0], Port = int.Parse(hp[1]) }; + } + return addresses; + } + } + public class AppConfig { public string Url; @@ -12,6 +34,8 @@ namespace ZeroLevel.UnitTests public int[] Port; public ServiceConfig Service; public IEnumerable List; + [ConfigRecordParse(typeof(AddressParser))] + public Address[] Hosts; } public class ServiceConfig @@ -22,6 +46,8 @@ namespace ZeroLevel.UnitTests public string ServiceType; } + + public class ConfigurationTest { [Fact] @@ -38,6 +64,8 @@ namespace ZeroLevel.UnitTests set.Default.Append("port", "90"); set.Default.Append("port", "8800"); set.Default.Append("list", "1-5,7,9"); + set.Default.Append("hosts", "host1:8800;host2:122;host3:1744"); + var section = set.CreateSection("service"); section.Append("AppName", "TestApp"); section.Append("AppKey", "test.app"); diff --git a/ZeroLevel/Services/Collections/FixSizeQueue.cs b/ZeroLevel/Services/Collections/FixSizeQueue.cs index 43e3ba4..1883fdb 100644 --- a/ZeroLevel/Services/Collections/FixSizeQueue.cs +++ b/ZeroLevel/Services/Collections/FixSizeQueue.cs @@ -123,7 +123,6 @@ namespace ZeroLevel.Services.Collections public IEnumerable Dump() { - var dump = new List(); lock (_accessLocker) { var cursor = _startIndex; @@ -131,12 +130,11 @@ namespace ZeroLevel.Services.Collections { do { - dump.Add(_array[cursor]); + yield return _array[cursor]; cursor = (cursor + 1) % _array.Length; } while (cursor != _nextIndex); } } - return dump; } } } \ No newline at end of file