public void Execute(Func<bool> function, IWaitHandle waitHandle) { do { bool result = true; while (result && !waitHandle.IsSet) { result = function(); } IEnumerator<int> enumerator = BackoffTimings.GetEnumerator(); enumerator.MoveNext(); int currentWaitTime = enumerator.Current; while (!result && !waitHandle.Wait(currentWaitTime)) { result = function(); if (!result) { if (enumerator.MoveNext()) { currentWaitTime = enumerator.Current; } } } } while (!waitHandle.IsSet); }
public void Execute(Func<bool> function, IWaitHandle waitHandle) { do { bool result = true; while (result && !waitHandle.IsSet) { result = function(); } IEnumerator<TimeSpan> enumerator = _backoffTimings.GetEnumerator(); enumerator.MoveNext(); TimeSpan currentWaitTime = enumerator.Current; if (!result) { _logger?.Verbose("BackoffPolicy - backing off to {0}ms", currentWaitTime.TotalMilliseconds); } while (!result && !waitHandle.Wait(currentWaitTime)) { result = function(); if (!result) { if (enumerator.MoveNext()) { currentWaitTime = enumerator.Current; } } } } while (!waitHandle.IsSet); }
public void Execute(Func <bool> function, IWaitHandle waitHandle) { do { bool result = true; while (result && !waitHandle.IsSet) { result = function(); } IEnumerator <TimeSpan> enumerator = _backoffTimings.GetEnumerator(); enumerator.MoveNext(); TimeSpan currentWaitTime = enumerator.Current; if (!result) { _logger?.LogTrace("BackoffPolicy - backing off to {WAITTIME}ms", currentWaitTime.TotalMilliseconds); } while (!result && !waitHandle.Wait(currentWaitTime)) { result = function(); if (!result) { if (enumerator.MoveNext()) { currentWaitTime = enumerator.Current; } } } }while (!waitHandle.IsSet); }
public ForwardService(IRepository sourceStore, IHttpClient httpClient, INetworkStateService networkStateService, IWaitHandle waitHandle, int temporaryErrorMilliseconds, int sleepMilliseconds, bool batchUpload, IReynaLogger logger) : base(sourceStore, waitHandle, true, logger) { if (httpClient == null) { throw new ArgumentNullException("httpClient"); } if (networkStateService != null) { this.NetworkStateService = networkStateService; this.NetworkStateService.NetworkConnected += this.OnNetworkConnected; } this.HttpClient = httpClient; this.TemporaryErrorMilliseconds = temporaryErrorMilliseconds; this.SleepMilliseconds = sleepMilliseconds; this.PeriodicBackoutCheck = new RegistryPeriodicBackoutCheck(new Registry(), @"Software\Reyna\PeriodicBackoutCheck"); if (batchUpload) { this.MessageProvider = new BatchProvider(sourceStore, this.PeriodicBackoutCheck); } else { this.MessageProvider = new MessageProvider(sourceStore); } }
public NetworkStateService(ISystemNotifier systemNotifier, IWaitHandle waitHandle) : base(waitHandle, false) { if (systemNotifier == null) { throw new ArgumentNullException("systemNotifier"); } this.SystemNotifier = systemNotifier; }
public ThreadWorker(IWaitHandle waitHandle, bool runOnStart) { if (waitHandle == null) { throw new ArgumentNullException("waitHandle"); } this.WaitHandle = waitHandle; this.RunOnStart = runOnStart; }
public StoreService(IRepository sourceStore, IRepository targetStore, IWaitHandle waitHandle) : base(sourceStore, waitHandle, false) { if (targetStore == null) { throw new ArgumentNullException("targetStore"); } this.TargetStore = targetStore; this.TargetStore.Initialise(); }
public void AssignWaitHandles(params IWaitHandle[] handles) { rawHandles = new WaitHandle[handles.Length]; for (int i = 0; i < handles.Length; i++) { IWaitHandle handle = handles[i]; WindowsWaitHandleBase windowsWaitHandleBase = (WindowsWaitHandleBase)handle; rawHandles[i] = windowsWaitHandleBase.WrappedWaitHandle; } }
public ServiceBase(IRepository sourceStore, IWaitHandle waitHandle, bool runOnStart) : base(waitHandle, runOnStart) { if (sourceStore == null) { throw new ArgumentNullException("sourceStore"); } this.SourceStore = sourceStore; this.SourceStore.Initialise(); this.SourceStore.MessageAdded += this.OnMessageAdded; }
public ServiceBase(IRepository sourceStore, IWaitHandle waitHandle, bool runOnStart, IReynaLogger logger) : base(waitHandle, runOnStart) { if (sourceStore == null) { throw new ArgumentNullException("sourceStore"); } this.SourceStore = sourceStore; this.Logger = logger; this.SourceStore.Initialise(); this.SourceStore.MessageAdded += this.OnMessageAdded; }
public ForwardService(IRepository sourceStore, IHttpClient httpClient, INetworkStateService networkState, IWaitHandle waitHandle, int temporaryErrorMilliseconds, int sleepMilliseconds) : base(sourceStore, waitHandle, true) { if (httpClient == null) { throw new ArgumentNullException("httpClient"); } if (networkState == null) { throw new ArgumentNullException("networkState"); } this.HttpClient = httpClient; this.NetworkState = networkState; this.TemporaryErrorMilliseconds = temporaryErrorMilliseconds; this.SleepMilliseconds = sleepMilliseconds; this.NetworkState.NetworkConnected += this.OnNetworkConnected; }
public void setup() { _item = Substitute.For<IWorkQueueItem<object>>(); _waitHandle = Substitute.For<IWaitHandle>(); _subject = new BoundedWorkQueueItem<object>(_item, _waitHandle); }
public bool SignalAndWait(IWaitHandle toSignal, IWaitHandle toWaitOn) { return WaitHandle.SignalAndWait(toSignal.UnderlyingObject, toWaitOn.UnderlyingObject); }
public bool WaitAll(IWaitHandle[] waitHandles, int millisecondsTimeout) { return WaitHandle.WaitAll(waitHandles.Select(x => x.UnderlyingObject).ToArray(),millisecondsTimeout); }
public bool WaitAll(IWaitHandle[] waitHandles) { return WaitHandle.WaitAll(waitHandles.Select(x=>x.UnderlyingObject).ToArray()); }
public bool SignalAndWait(IWaitHandle toSignal, IWaitHandle toWaitOn, int millisecondsTimeout, bool exitContext) { return WaitHandle.SignalAndWait(toSignal.UnderlyingObject, toWaitOn.UnderlyingObject, millisecondsTimeout, exitContext); }
public ServiceBase(IWaitHandle waitHandle, bool runOnStart) : base(waitHandle, runOnStart) { }
public bool SignalAndWait(IWaitHandle toSignal, IWaitHandle toWaitOn) { return WaitHandle.SignalAndWait((WaitHandle)toSignal, (WaitHandle)toWaitOn); }
public bool WaitAll(IWaitHandle[] waitHandles, int millisecondsTimeout) { return WaitHandle.WaitAll(waitHandles.Cast<WaitHandle>().ToArray(), millisecondsTimeout); }
public bool WaitAll(IWaitHandle[] waitHandles) { return WaitHandle.WaitAll(waitHandles.Cast<WaitHandle>().ToArray()); }
public bool SignalAndWait(IWaitHandle toSignal, IWaitHandle toWaitOn, int millisecondsTimeout, bool exitContext) { return WaitHandle.SignalAndWait((WaitHandle)toSignal, (WaitHandle)toWaitOn, millisecondsTimeout, exitContext); }
public ForwardService(IRepository sourceStore, IHttpClient httpClient, INetworkStateService networkStateService, IWaitHandle waitHandle, int temporaryErrorMilliseconds, int sleepMilliseconds, bool batchUpload, IReynaLogger logger) : base(sourceStore, waitHandle, true, logger) { if (httpClient == null) { throw new ArgumentNullException("httpClient"); } if (networkStateService != null) { this.NetworkStateService = networkStateService; this.NetworkStateService.NetworkConnected += this.OnNetworkConnected; } this.HttpClient = httpClient; this.TemporaryErrorMilliseconds = temporaryErrorMilliseconds; this.SleepMilliseconds = sleepMilliseconds; this.ContactInformation = new RegistryContactInformation(new Registry(), @"Software\Reyna"); this.PeriodicBackoutCheck = new RegistryPeriodicBackoutCheck(new Registry(), @"Software\Reyna\PeriodicBackoutCheck"); if (batchUpload) { this.MessageProvider = new BatchProvider(sourceStore, this.PeriodicBackoutCheck); } else { this.MessageProvider = new MessageProvider(sourceStore); } }
public bool SignalAndWait(IWaitHandle toSignal, IWaitHandle toWaitOn, int millisecondsTimeout, bool exitContext) { return(WaitHandle.SignalAndWait((WaitHandle)toSignal, (WaitHandle)toWaitOn, millisecondsTimeout, exitContext)); }
public bool SignalAndWait(IWaitHandle toSignal, IWaitHandle toWaitOn) { return(WaitHandle.SignalAndWait((WaitHandle)toSignal, (WaitHandle)toWaitOn)); }