public Client(Settings settings) { Settings = settings; connectedEvent = new ManualResetEventAsync(false); var protocolSettings = new Protocol.Settings(settings.UriProvider, settings.ReconnectTimeout, settings.ResponseTimeout); protocolSettings.ConnectionLost += ClientConnectionLost; protocolSettings.ConnectionReestablished += ClientConnectionReestablished; protocolSettings.EventReceived += ClientEventReceived; protocolSettings.Failed += ClientFailed; isConnected = false; state.StateInitial += StateOnStateInitial; state.StateChanged += StateOnStateChanged; state.StateColInitial += StateOnStateColInitial; state.StateColAdded += StateOnStateColAdded; state.StateColChanged += StateOnStateColChanged; state.StateColRemoved += StateOnStateColRemoved; protocolClient = new Protocol.Client(protocolSettings); }
public void ManualResetEventAsyncShouldAwaitWhenStopAwaitCalledBefore() { var resetEventAsync = new ManualResetEventAsync(false); resetEventAsync.StopAwait(); bool result = resetEventAsync.WaitAsync().Wait(50); Assert.False(result); }
/// <summary> /// Конструктор для создания <see cref="BufferingTarget{TItem}"/>. /// </summary> /// <param name="target">Цель, куда будут отправляться элементы из буфера.</param> /// <param name="exceptionHandler">Обработчик исключения, которые могут возникнуть при отпрвки элементов.</param> /// <param name="bifferConsumersCount">Кол-во потребителей буфера.</param> public BufferingTarget(ITarget <TItem> target, IExceptionHandler exceptionHandler, int bifferConsumersCount = 1) { Contract.Requires <ArgumentNullException>(target != null); Contract.Requires <ArgumentNullException>(exceptionHandler != null); Contract.Requires <ArgumentException>(bifferConsumersCount >= 1); _target = target; _exceptionHandler = exceptionHandler; _bifferConsumersCount = bifferConsumersCount; _event = new ManualResetEventAsync(allowToStopWaitBeforeAwaited: true); _itemsBuffer = new ConcurrentQueue <TItem>(); BeginAwaitForConsumtion(); }
public async Task CanExecute() { var target = new ManualResetEventAsync(false); var actual = new ConcurrentBag <int>(); var task1 = Task.Factory.StartNew(async() => actual.Add(await _Execute(target, 1))); var task2 = Task.Factory.StartNew(async() => actual.Add(await _Execute(target, 2))); Thread.Sleep(TimeSpan.FromMilliseconds(500)); CollectionAssert.IsEmpty(actual); target.Set(); Thread.Sleep(TimeSpan.FromMilliseconds(500)); CollectionAssert.AreEquivalent(Enumerable.Range(1, 2), actual); Assert.IsTrue(task1.IsCompletedSuccessfully); Assert.IsTrue(task2.IsCompletedSuccessfully); }
public Packet(int id, string type, string resourceId = null, string method = null, object param = null) { Id = id; Type = type; ResourceId = resourceId; Method = method; Params = param; Handled = new ManualResetEventAsync(false, false); var m = new StringBuilder(); m.Append(type); if (!string.IsNullOrWhiteSpace(resourceId)) { m.Append("."); m.Append(resourceId); } if (!string.IsNullOrWhiteSpace(method)) { m.Append("."); m.Append(method); } var obj = new Dictionary <string, object> { { "id", id }, { "method", m.ToString() } }; if (param != null) { obj["params"] = param; } Content = JsonConvert.SerializeObject(obj, Formatting.None); }
public void SetUp() { _resetEventAsync = new ManualResetEventAsync(); }
private async Task <int> _Execute(ManualResetEventAsync target, int id) { await target.WaitAsync(); return(id); }
public ManualResetEventAsyncTests() { this.testee = new ManualResetEventAsync(); }