|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Linq;
|
4 | 4 | using System.Text;
|
| 5 | +using Segment.Model; |
5 | 6 |
|
6 | 7 | namespace Segment
|
7 | 8 | {
|
@@ -50,30 +51,36 @@ public class Config
|
50 | 51 | /// <param name="send">Don’t send data to Segment</param>
|
51 | 52 | /// <param name="userAgent">Sets User Agent Header</param>
|
52 | 53 | public Config(
|
53 |
| - string host = null, |
| 54 | + string host = "https://api.segment.io", |
54 | 55 | string proxy = null,
|
55 | 56 | TimeSpan? timeout = null,
|
56 |
| - int? maxQueueSize = null, |
57 |
| - int? flushAt = null, |
58 |
| - bool? async = null, |
59 |
| - int? threads = null, |
60 |
| - double? flushInterval = null, |
61 |
| - bool? gzip = null, |
62 |
| - bool? send = null, |
| 57 | + int maxQueueSize = 10000, |
| 58 | + int flushAt = 20, |
| 59 | + bool async = true, |
| 60 | + int threads = 1, |
| 61 | + double flushInterval = 10, |
| 62 | + bool gzip = false, |
| 63 | + bool send = false, |
63 | 64 | string userAgent = null
|
64 | 65 | )
|
65 | 66 | {
|
66 |
| - this.Host = host ?? Defaults.Host; |
| 67 | + this.Host = host; |
67 | 68 | this.Proxy = proxy ?? "";
|
68 |
| - this.Timeout = timeout ?? Defaults.Timeout; |
69 |
| - this.MaxQueueSize = maxQueueSize ?? Defaults.MaxQueueCapacity; |
70 |
| - this.FlushAt = flushAt ?? Defaults.FlushAt; |
71 |
| - this.Async = async ?? Defaults.Async; |
72 |
| - this.FlushIntervalInMillis = (int)((flushInterval ?? Defaults.FlushInterval) * 1000); |
73 |
| - this.Gzip = gzip ?? Defaults.Gzip; |
74 |
| - this.Send = send ?? false; |
75 |
| - this.UserAgent = userAgent ?? Defaults.UserAgent; |
76 |
| - this.Threads = threads ?? Defaults.Threads; |
| 69 | + this.Timeout = timeout ?? TimeSpan.FromSeconds(5); |
| 70 | + this.MaxQueueSize = maxQueueSize; |
| 71 | + this.FlushAt = flushAt; |
| 72 | + this.Async = async; |
| 73 | + this.FlushIntervalInMillis = (int)(flushInterval * 1000); |
| 74 | + this.Gzip = gzip; |
| 75 | + this.Send = send; |
| 76 | + this.UserAgent = userAgent ?? GetDefaultUserAgent(); |
| 77 | + this.Threads = threads; |
| 78 | + } |
| 79 | + |
| 80 | + private static string GetDefaultUserAgent() |
| 81 | + { |
| 82 | + var lib = new Context()["library"] as Dict; |
| 83 | + return $"{lib["name"]}/{lib["version"]}"; |
77 | 84 | }
|
78 | 85 |
|
79 | 86 |
|
|
0 commit comments