Exemplo n.º 1
0
        public RuntimeEnvironment(string extension, ISynchronizeInvoke synchronizingObject, TimeSpan workFolderStateMinimumIdle)
        {
            AxCryptExtension = extension;

            _workFolderWatcher = CreateFileWatcher(WorkFolder.FullName);
            _workFolderWatcher.FileChanged += HandleWorkFolderFileChangedEvent;

            _delayedWorkFolderStateChanged = new DelayedAction(OnWorkFolderStateChanged, workFolderStateMinimumIdle, synchronizingObject);
        }
Exemplo n.º 2
0
 public static void TestShortDelayButNoStart()
 {
     bool wasHere = false;
     using (DelayedAction delayedAction = new DelayedAction(() => { wasHere = true; }, new TimeSpan(0, 0, 0, 0, 1), null))
     {
         Thread.Sleep(50);
         Assert.That(wasHere, Is.False, "The event should not be triggered until started.");
     }
 }
Exemplo n.º 3
0
 public static void TestEventAfterDispose()
 {
     bool wasHere = false;
     using (DelayedAction delayedAction = new DelayedAction(() => { wasHere = true; }, new TimeSpan(0, 0, 0, 0, 1), null))
     {
         delayedAction.RestartIdleTimer();
         Assert.That(wasHere, Is.False, "The event should not be triggered immediately.");
     }
     Thread.Sleep(50);
     Assert.That(wasHere, Is.False, "The event should be note be triggered once disposed.");
 }
Exemplo n.º 4
0
 public static void TestShortDelayAndImmediateStart()
 {
     bool wasHere = false;
     using (DelayedAction delayedAction = new DelayedAction(() => { wasHere = true; }, new TimeSpan(0, 0, 0, 0, 1), null))
     {
         delayedAction.RestartIdleTimer();
         Thread.Sleep(50);
         Assert.That(wasHere, Is.True, "The event should be triggered once started.");
         wasHere = false;
         Thread.Sleep(50);
         Assert.That(wasHere, Is.False, "The event should not be triggered more than once.");
     }
 }
Exemplo n.º 5
0
 public static void TestManyRestartsButOnlyOneEvent()
 {
     int eventCount = 0;
     using (DelayedAction delayedAction = new DelayedAction(() => { ++eventCount; }, new TimeSpan(0, 0, 0, 0, 5), null))
     {
         for (int i = 0; i < 10; ++i)
         {
             delayedAction.RestartIdleTimer();
         }
         Thread.Sleep(50);
         Assert.That(eventCount, Is.EqualTo(1), "The event should be triggered exactly once.");
         Thread.Sleep(50);
         Assert.That(eventCount, Is.EqualTo(1), "The event should still be triggered exactly once.");
     }
 }
Exemplo n.º 6
0
 protected virtual void Dispose(bool disposing)
 {
     if (_workFolderWatcher != null)
     {
         _workFolderWatcher.Dispose();
         _workFolderWatcher = null;
     }
     if (_delayedWorkFolderStateChanged != null)
     {
         _delayedWorkFolderStateChanged.Dispose();
         _delayedWorkFolderStateChanged = null;
     }
 }
Exemplo n.º 7
0
 public static void TestObjectDisposedException()
 {
     DelayedAction delayedAction = new DelayedAction(() => { }, new TimeSpan(0, 0, 0, 0, 1), null);
     delayedAction.Dispose();
     Assert.Throws<ObjectDisposedException>(() => { delayedAction.RestartIdleTimer(); });
 }
Exemplo n.º 8
0
 public static void TestNullArgument()
 {
     Action nullAction = null;
     DelayedAction delayedAction;
     Assert.Throws<ArgumentNullException>(() => { delayedAction = new DelayedAction(nullAction, new TimeSpan(0, 0, 1), null); }, "The 'action' argument is not allowed to be null");
 }