/// <summary> /// Creates a new REST client with a specified API writeKey and default config /// </summary> /// <param name="writeKey"></param> /// <param name="config"></param> public Client(string writeKey, Config config) { if (string.IsNullOrEmpty(writeKey)) throw new InvalidOperationException("Please supply a valid writeKey to initialize."); Statistics = new Statistics(); WriteKey = writeKey; Config = config; IRequestHandler requestHandler = new BlockingRequestHandler(config.Host, config.Timeout); IBatchFactory batchFactory = new SimpleBatchFactory(WriteKey); requestHandler.Succeeded += action => { Statistics.Succeeded += 1; Succeeded?.Invoke(action); }; requestHandler.Failed += (action, e) => { Statistics.Failed += 1; Failed?.Invoke(action, e); }; if (config.Async) { _flushHandler = new AsyncFlushHandler(batchFactory, requestHandler, config.MaxQueueSize); } else { _flushHandler = new BlockingFlushHandler(batchFactory, requestHandler); } }
/// <summary> /// Creates a new REST client with a specified API writeKey and default config /// </summary> /// <param name="writeKey"></param> /// <param name="config"></param> public Client(string writeKey, Config config) { if (String.IsNullOrEmpty(writeKey)) throw new InvalidOperationException("Please supply a valid writeKey to initialize."); this.Statistics = new Statistics(); this._writeKey = writeKey; this._config = config; IRequestHandler requestHandler = new BlockingRequestHandler(config.Host, config.Timeout); IBatchFactory batchFactory = new SimpleBatchFactory(this._writeKey); requestHandler.Succeeded += (action) => { this.Statistics.Succeeded += 1; if (Succeeded != null) Succeeded(action); }; requestHandler.Failed += (action, e) => { this.Statistics.Failed += 1; if (Failed != null) Failed(action, e); }; if (config.Async) _flushHandler = new AsyncFlushHandler(batchFactory, requestHandler, config.MaxQueueSize); else _flushHandler = new BlockingFlushHandler(batchFactory, requestHandler); }
/// <summary> /// Initialized the default Segment.io client with your API writeKey. /// </summary> /// <param name="writeKey"></param> public static void Initialize(string writeKey, Config config) { lock (padlock) { if (Client == null) { Client = new Client(writeKey, config); } } }