public void CanCallDisposeMoreThanOnce() { using (var context = new EventContext(Guid.NewGuid(), HeaderCollection.Empty, new FakeEvent())) { context.Dispose(); context.Dispose(); } }
public void CannotDisposeContextOutOfOrder() { var context1 = new EventContext(Guid.NewGuid(), HeaderCollection.Empty, new FakeEvent()); var context2 = new EventContext(Guid.NewGuid(), HeaderCollection.Empty, new FakeEvent()); // ReSharper disable AccessToDisposedClosure var ex = Assert.Throws <InvalidOperationException>(() => context1.Dispose()); // ReSharper restore AccessToDisposedClosure context2.Dispose(); context1.Dispose(); Assert.Equal(Exceptions.EventContextInvalidThread, ex.Message); }
public void Dispose() { if (_db != null) { _db.Dispose(); _db = null; } }
protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); }
protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { context.Dispose(); } } disposed = true; }
public virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { db.Dispose(); } } disposed = true; }
public async Task LoadAsync() { var eventContext = new EventContext("ConsulRx.Configuration", "Load"); try { _consulState = await _consulClient.GetDependenciesAsync(_dependencies).ConfigureAwait(false); UpdateData(); eventContext["LoadedFrom"] = "Consul"; } catch (Exception exception) { eventContext.IncludeException(exception); if (_emergencyCache.TryLoad(out var cachedData)) { eventContext["LoadedFrom"] = "EmergencyCache"; Data = cachedData; } else { eventContext["LoadedFrom"] = "UnableToLoad"; throw new ConsulRxConfigurationException("Unable to load configuration from consul. It is likely down or the endpoint is misconfigured. Please check the InnerException for details.", exception); } } finally { eventContext.Dispose(); } if (_autoUpdate) { _consulClient.ObserveDependencies(_dependencies).DelayedRetry(_consulClient.Configuration.RetryDelay ?? TimeSpan.Zero).Subscribe(updatedState => { using (var reloadEventContext = new EventContext("ConsulRx.Configuration", "Reload")) { try { _consulState = updatedState; UpdateData(); OnReload(); } catch (Exception ex) { reloadEventContext.IncludeException(ex); } } }); } }
/// Spawn a new object from the object pool /// Add new objects, delete old objects, etc. public void Update(float delta) { if (!_halted) { Elapsed += delta; if ((Elapsed - _lastSpawn) > SpawnObjectEvery) { var req = _factory(); if (req.manager == null) { return; } _pool.Instance(req.origin).Then((gp) => { // Start animation var animation = new FollowPathAnimation(this); animation.PathGroup = req.path; var target = new SingleSpawned(gp); req.manager.Add(req.stream, animation, req.curve, target); _lastSpawn = Elapsed; var context = new EventContext(); req.manager.Events.AddEventHandler <AnimationCompleteEvent>((ep) => { if (ep.animation != animation) { return; } try { gp.GameObject.SetActive(false); // return object to pool } catch (MissingReferenceException) { // Probably already destroyed. } context.Dispose(); }, context); }); } } }
private void RenderTemplate() { var eventContext = new EventContext("ConsulRx", "RenderTemplate"); try { eventContext["TemplatePath"] = TemplatePath; using (var writer = OpenOutput()) { _renderer.Render(TemplatePath, writer, ConsulState, Properties); } } catch (Exception ex) { eventContext.IncludeException(ex); } finally { eventContext.Dispose(); } }
public void CannotDisposeEventFromAnotherThread() { var contextDisposedEvent = new ManualResetEvent(false); var contextCreatedEvent = new ManualResetEvent(false); var context = default(EventContext); Task.Factory.StartNew(() => { context = new EventContext(Guid.NewGuid(), HeaderCollection.Empty, new FakeEvent()); contextCreatedEvent.Set(); contextDisposedEvent.WaitOne(); context.Dispose(); }); contextCreatedEvent.WaitOne(); var ex = Assert.Throws <InvalidOperationException>(() => context.Dispose()); Assert.Equal(Exceptions.EventContextInterleaved, ex.Message); contextDisposedEvent.Set(); }
public void CannotDisposeEventFromAnotherThread() { var contextDisposedEvent = new ManualResetEvent(false); var contextCreatedEvent = new ManualResetEvent(false); var context = default(EventContext); Task.Factory.StartNew(() => { context = new EventContext(Guid.NewGuid(), HeaderCollection.Empty, new FakeEvent()); contextCreatedEvent.Set(); contextDisposedEvent.WaitOne(); context.Dispose(); }); contextCreatedEvent.WaitOne(); var ex = Assert.Throws<InvalidOperationException>(() => context.Dispose()); Assert.Equal(Exceptions.EventContextInterleaved, ex.Message); contextDisposedEvent.Set(); }
public void test_recursive_event_dispatch() { var handler1 = new EventHandler(); var handler2 = new EventHandler(); var handler3 = new EventHandler(); var count1 = 0; var count2 = 0; var count3 = 0; handler1.AddEventHandler <EventHandlerTests>((fp) => { count1 += 1; var context = new EventContext(); handler3.AddEventHandler <EventHandlerTests>((ep) => { count3 += 1; context.Dispose(); }, context); handler2.Trigger(this); }); handler2.AddEventHandler <EventHandlerTests>((fp) => { count2 += 1; handler3.Trigger(this); }); handler1.Trigger(this); Assert(count1 == 1); Assert(count2 == 1); Assert(count3 == 1); }
public void Dispose() { _context.Dispose(); }
public IObservable <ConsulState> ObserveDependencies(ConsulDependencies dependencies) { var consulState = new ConsulState(); var updateMutex = new object(); void WrapUpdate(string operationName, Action <EventContext> tryUpdate) { var eventContext = new EventContext("ConsulRx.ConsulState", operationName); try { lock (updateMutex) { tryUpdate(eventContext); } } catch (Exception ex) { eventContext.IncludeException(ex); throw; } finally { eventContext.Dispose(); } } var consulStateObservable = Observable.Create <ConsulState>(o => { var compositeDisposable = new CompositeDisposable { this.ObserveServices(dependencies.Services) .Select(services => services.ToService()) .Subscribe(service => { WrapUpdate("UpdateService", eventContext => { eventContext["ServiceName"] = service.Name; bool alreadyExisted = consulState.ContainsService(service.Name); if (consulState.TryUpdateService(service, out var updatedState)) { eventContext["UpdateType"] = alreadyExisted ? "Update" : "Add"; consulState = updatedState; o.OnNext(consulState); } else { eventContext["UpdateType"] = "Noop"; } }); }, o.OnError), this.ObserveKeys(dependencies.Keys) .Select(kv => kv.ToKeyValueNode()) .Subscribe(kvNode => { WrapUpdate("UpdateKey", eventContext => { eventContext["Key"] = kvNode.FullKey; eventContext["Value"] = kvNode.Value; bool alreadyExisted = consulState.ContainsKey(kvNode.FullKey); if (consulState.TryUpdateKVNode(kvNode, out var updatedState)) { eventContext["UpdateType"] = alreadyExisted ? "Update" : "Add"; consulState = updatedState; o.OnNext(consulState); } else { eventContext["UpdateType"] = "Noop"; } }); }, o.OnError), this.ObserveKeysRecursive(dependencies.KeyPrefixes) .Subscribe(kv => { WrapUpdate("UpdateKeys", eventContext => { eventContext["KeyPrefix"] = kv.KeyPrefix; eventContext["ChildKeyCount"] = kv.Result.Response?.Length ?? 0; if (kv.Result.Response == null || !kv.Result.Response.Any()) { if (consulState.TryMarkKeyPrefixAsMissingOrEmpty(kv.KeyPrefix, out var updatedState) ) { eventContext["UpdateType"] = "MarkAsMissing"; consulState = updatedState; o.OnNext(consulState); } else { eventContext["UpdateType"] = "Noop"; } } else { var kvNodes = kv.ToKeyValueNodes(); bool alreadyExisted = consulState.ContainsKeyStartingWith(kv.KeyPrefix); if (consulState.TryUpdateKVNodes(kvNodes, out var updatedState)) { eventContext["UpdateType"] = alreadyExisted ? "Update" : "Add"; consulState = updatedState; o.OnNext(consulState); } else { eventContext["UpdateType"] = "Noop"; } } }); }, o.OnError) }; return(compositeDisposable); }); return(consulStateObservable.Where(s => s.SatisfiesAll(dependencies))); }
public void Dispose() { _db.Dispose(); }
public void CannotDisposeContextOutOfOrder() { var context1 = new EventContext(Guid.NewGuid(), HeaderCollection.Empty, new FakeEvent()); var context2 = new EventContext(Guid.NewGuid(), HeaderCollection.Empty, new FakeEvent()); // ReSharper disable AccessToDisposedClosure var ex = Assert.Throws<InvalidOperationException>(() => context1.Dispose()); // ReSharper restore AccessToDisposedClosure context2.Dispose(); context1.Dispose(); Assert.Equal(Exceptions.EventContextInvalidThread, ex.Message); }
public void CanCallDisposeMoreThanOnce() { using (var context = new EventContext(Guid.NewGuid(), HeaderCollection.Empty, new FakeEvent())) { context.Dispose(); context.Dispose(); } }
public void Dispose() { _dbContext.Dispose(); }
public void OnDestroy() { _eventContext.Dispose(); }
public void Dispose() { _eventContext.Dispose(); }
public void Dispose() { Db.Dispose(); GC.SuppressFinalize(this); }