示例#1
0
        protected bool WaitAll(WaitHandle[] events, IWaitController waitCtrl)
        {
            var index =
                waitCtrl == null
                    ? WaitHandleUtils.WaitOneOrAllOthers(_disposeEvent, events)
                    : waitCtrl.WaitOneOrAllOthers(_disposeEvent, events);

            return(index != 0);
        }
示例#2
0
        protected bool WaitAny(
            WaitHandle[] events, out int occurredEventIndex, int timeout, IWaitController waitCtrl)
        {
            var eventsEx          = new WaitHandle[events.Length + 1];
            var disposeEventIndex = events.Length;

            events.CopyTo(eventsEx, 0);
            eventsEx[disposeEventIndex] = _disposeEvent;
            occurredEventIndex          =
                waitCtrl == null
                    ? WaitHandle.WaitAny(eventsEx, timeout)
                    : waitCtrl.WaitAny(eventsEx, timeout);

            return(occurredEventIndex != disposeEventIndex);
        }
示例#3
0
 public bool WaitForSynchronizationFinished(IWaitController waitCtrl)
 {
     while (true)
     {
         if (!WaitOne(_synchronizationFinished, waitCtrl))
         {
             return(false);
         }
         lock (s_syncResultSync)
         {
             if (_lastSyncResult == SynchronizationResult.SyncRequestIgnored)
             {
                 _synchronizationFinished.Reset();
                 continue;
             }
             return(_lastSyncResult == SynchronizationResult.SynchronizationNotEnabled ||
                    _lastSyncResult == SynchronizationResult.Succeeded);
         }
     }
 }
示例#4
0
 public object GetDataTransmittedFromRemoteScanner(string name, IWaitController waitCtrl)
 {
     CodeContract.Requires(!string.IsNullOrEmpty(name));
     while (true)
     {
         var data = FindTransmittedData(name);
         if (data != null)
         {
             return(data);
         }
         int index;
         var res = WaitAny(
             new[] { _remoteScannerDisconnected, _newDataTransmitted },
             out index,
             1000,   // 1 сек
             waitCtrl);
         if (!res || index == 0)
         {
             return(null);
         }
     }
 }
示例#5
0
文件: Common.cs 项目: xoposhiy/KOIB
        private int SetIndicatorAndPlayPhrase(
            IWaitController waitController,
            WaitHandle[] waitedEventsDuringPlaying,
            EventWaitHandle playSoundFinishedEvent,
            string text, string[] sounds, bool silent)
        {
            if (!string.IsNullOrEmpty(text))
            {
                _logger.LogInfo(Message.WorkflowText, text);
                _scannerManager.SetIndicator(text);
            }
            var occurredEventIndex = -1;

            if (!silent)
            {
                ResetEvents(waitedEventsDuringPlaying);
                _soundManager.PlaySounds(sounds, (sender, e) => playSoundFinishedEvent.Set());
                try
                {
                    occurredEventIndex = waitController.WaitAny(waitedEventsDuringPlaying);
                    if (occurredEventIndex <= waitedEventsDuringPlaying.Length - 2)
                    {
                        _soundManager.StopPlaying();
                        return(occurredEventIndex);
                    }
                    occurredEventIndex = -1;
                }
                catch (ActivityExecutionInterruptException)
                {
                    _soundManager.StopPlaying();
                    _logger.LogVerbose(Message.WorkflowSoundPlayingStoppedByActivityExecutionInterrupt);
                    throw;
                }
            }
            return(occurredEventIndex);
        }
示例#6
0
 protected bool WaitOne(WaitHandle ev, int timeout, IWaitController waitCtrl)
 {
     int index;
     return WaitAny(new[] { ev }, out index, timeout, waitCtrl);
 }
示例#7
0
 protected bool WaitAny( 
     WaitHandle[] events, out int occurredEventIndex, int timeout, IWaitController waitCtrl)
 {
     var eventsEx = new WaitHandle[events.Length + 1];
     var disposeEventIndex = events.Length;
     events.CopyTo(eventsEx, 0);
     eventsEx[disposeEventIndex] = _disposeEvent;
     occurredEventIndex =
         waitCtrl == null
             ? WaitHandle.WaitAny(eventsEx, timeout)
             : waitCtrl.WaitAny(eventsEx, timeout);
     return occurredEventIndex != disposeEventIndex;
 }
示例#8
0
 protected bool WaitAny(WaitHandle[] events, out int occurredEventIndex, IWaitController waitCtrl)
 {
     return WaitAny(events, out occurredEventIndex, Timeout.Infinite, waitCtrl);
 }
示例#9
0
 protected bool WaitAll(WaitHandle[] events, IWaitController waitCtrl)
 {
     var index =
         waitCtrl == null
             ? WaitHandleUtils.WaitOneOrAllOthers(_disposeEvent, events)
             : waitCtrl.WaitOneOrAllOthers(_disposeEvent, events);
     return index != 0;
 }
示例#10
0
 protected bool Sleep(TimeSpan timeout, IWaitController waitCtrl)
 {
     return !(waitCtrl == null ? _disposeEvent.WaitOne(timeout) : waitCtrl.WaitOne(_disposeEvent, timeout));
 }
示例#11
0
        protected bool WaitOne(WaitHandle ev, int timeout, IWaitController waitCtrl)
        {
            int index;

            return(WaitAny(new[] { ev }, out index, timeout, waitCtrl));
        }
示例#12
0
 protected bool Sleep(TimeSpan timeout, IWaitController waitCtrl)
 {
     return(!(waitCtrl == null ? _disposeEvent.WaitOne(timeout) : waitCtrl.WaitOne(_disposeEvent, timeout)));
 }
示例#13
0
 protected bool WaitAny(WaitHandle[] events, out int occurredEventIndex, IWaitController waitCtrl)
 {
     return(WaitAny(events, out occurredEventIndex, Timeout.Infinite, waitCtrl));
 }
示例#14
0
文件: Common.cs 项目: nico-izo/KOIB
 private int SetIndicatorAndPlayPhrase( 
     IWaitController waitController, 
     WaitHandle[] waitedEventsDuringPlaying, 
     EventWaitHandle playSoundFinishedEvent, 
     string text, string[] sounds, bool silent)
 {
     if (!string.IsNullOrEmpty(text))
     {
         _logger.LogInfo(Message.WorkflowText, text);
         _scannerManager.SetIndicator(text);
     }
     var occurredEventIndex = -1;
     if (!silent)
     {
         ResetEvents(waitedEventsDuringPlaying);
         _soundManager.PlaySounds(sounds, (sender, e) => playSoundFinishedEvent.Set());
         try
         {
             occurredEventIndex = waitController.WaitAny(waitedEventsDuringPlaying);
             if (occurredEventIndex <= waitedEventsDuringPlaying.Length - 2)
             {
                 _soundManager.StopPlaying();
                 return occurredEventIndex;
             }
             occurredEventIndex = -1;
         }
         catch (ActivityExecutionInterruptException)
         {
             _soundManager.StopPlaying();
             _logger.LogVerbose(Message.WorkflowSoundPlayingStoppedByActivityExecutionInterrupt);
             throw;
         }
     }
     return occurredEventIndex;
 }
示例#15
0
 public bool WaitForSynchronizationFinished(IWaitController waitCtrl)
 {
     while (true)
     {
         if (!WaitOne(_synchronizationFinished, waitCtrl))
             return false;
         lock (s_syncResultSync)
         {
             if (_lastSyncResult == SynchronizationResult.SyncRequestIgnored)
             {
                 _synchronizationFinished.Reset();
                 continue;
             }
             return (_lastSyncResult == SynchronizationResult.SynchronizationNotEnabled ||
                     _lastSyncResult == SynchronizationResult.Succeeded);
         }
     }
 }
示例#16
0
 public object GetDataTransmittedFromRemoteScanner(string name, IWaitController waitCtrl)
 {
     CodeContract.Requires(!string.IsNullOrEmpty(name));
     while (true)
     {
         var data = FindTransmittedData(name);
         if (data != null)
             return data;
         int index;
         var res = WaitAny(
             new[] { _remoteScannerDisconnected, _newDataTransmitted },
             out index,
             1000,   // 1 сек
             waitCtrl);
         if (!res || index == 0)
             return null;
     }
 }