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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
            }
        }
示例#5
0
        public NetworkStateService(ISystemNotifier systemNotifier, IWaitHandle waitHandle) : base(waitHandle, false)
        {
            if (systemNotifier == null)
            {
                throw new ArgumentNullException("systemNotifier");
            }

            this.SystemNotifier = systemNotifier;
        }
 public NetworkStateService(ISystemNotifier systemNotifier, IWaitHandle waitHandle) : base(waitHandle, false)
 {
     if (systemNotifier == null)
     {
         throw new ArgumentNullException("systemNotifier");
     }
     
     this.SystemNotifier = systemNotifier;
 }
示例#7
0
        public ThreadWorker(IWaitHandle waitHandle, bool runOnStart)
        {
            if (waitHandle == null)
            {
                throw new ArgumentNullException("waitHandle");
            }

            this.WaitHandle = waitHandle;
            this.RunOnStart = runOnStart;
        }
示例#8
0
        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();
        }
示例#9
0
        public ThreadWorker(IWaitHandle waitHandle, bool runOnStart)
        {
            if (waitHandle == null)
            {
                throw new ArgumentNullException("waitHandle");
            }

            this.WaitHandle = waitHandle;
            this.RunOnStart = runOnStart;
        }
示例#10
0
 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;
     }
 }
示例#11
0
        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;
        }
示例#12
0
        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;
        }
示例#13
0
        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);
 }
示例#15
0
 public bool SignalAndWait(IWaitHandle toSignal, IWaitHandle toWaitOn)
 {
     return WaitHandle.SignalAndWait(toSignal.UnderlyingObject, toWaitOn.UnderlyingObject);
 }
示例#16
0
 public bool WaitAll(IWaitHandle[] waitHandles, int millisecondsTimeout)
 {
     return WaitHandle.WaitAll(waitHandles.Select(x => x.UnderlyingObject).ToArray(),millisecondsTimeout);
 }
示例#17
0
 public bool WaitAll(IWaitHandle[] waitHandles)
 {
     return WaitHandle.WaitAll(waitHandles.Select(x=>x.UnderlyingObject).ToArray());
 }
示例#18
0
 public bool SignalAndWait(IWaitHandle toSignal, IWaitHandle toWaitOn, int millisecondsTimeout, bool exitContext)
 {
     return WaitHandle.SignalAndWait(toSignal.UnderlyingObject, toWaitOn.UnderlyingObject, millisecondsTimeout, exitContext);
 }
示例#19
0
 public ServiceBase(IWaitHandle waitHandle, bool runOnStart)
     : base(waitHandle, runOnStart)
 {
 }
示例#20
0
 public bool SignalAndWait(IWaitHandle toSignal, IWaitHandle toWaitOn)
 {
     return WaitHandle.SignalAndWait((WaitHandle)toSignal, (WaitHandle)toWaitOn);
 }
示例#21
0
 public bool WaitAll(IWaitHandle[] waitHandles, int millisecondsTimeout)
 {
     return WaitHandle.WaitAll(waitHandles.Cast<WaitHandle>().ToArray(), millisecondsTimeout);
 }
示例#22
0
 public bool WaitAll(IWaitHandle[] waitHandles)
 {
     return WaitHandle.WaitAll(waitHandles.Cast<WaitHandle>().ToArray());
 }
示例#23
0
 public bool SignalAndWait(IWaitHandle toSignal, IWaitHandle toWaitOn, int millisecondsTimeout, bool exitContext)
 {
     return WaitHandle.SignalAndWait((WaitHandle)toSignal, (WaitHandle)toWaitOn, millisecondsTimeout, exitContext);
 }
示例#24
0
        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);
            }
        }
示例#25
0
 public bool SignalAndWait(IWaitHandle toSignal, IWaitHandle toWaitOn, int millisecondsTimeout, bool exitContext)
 {
     return(WaitHandle.SignalAndWait((WaitHandle)toSignal, (WaitHandle)toWaitOn, millisecondsTimeout, exitContext));
 }
示例#26
0
 public bool SignalAndWait(IWaitHandle toSignal, IWaitHandle toWaitOn)
 {
     return(WaitHandle.SignalAndWait((WaitHandle)toSignal, (WaitHandle)toWaitOn));
 }