Esempio n. 1
0
 private static void RegisterDatasetLock(ContainerBuilder builder)
 {
     builder.Register(c => new DatasetLock())
     .OnActivated(
         a =>
     {
         DatasetLock obj          = a.Instance;
         var notifications        = a.Context.Resolve <IDatasetApplicationNotificationInvoker>();
         obj.OnLockForReading    += (s, e) => notifications.RaiseOnSwitchToEditingMode();
         obj.OnUnlockFromReading += (s, e) => notifications.RaiseOnSwitchToExecutingMode();
     })
     .As <ITrackDatasetLocks>()
     .SingleInstance();
 }
Esempio n. 2
0
        public void LockForReadingWithNoLocks()
        {
            using (var datasetLock = new DatasetLock())
            {
                Assert.IsFalse(datasetLock.IsLockedForReading);
                Assert.IsFalse(datasetLock.IsLockedForWriting);

                var eventWasRaised = false;
                datasetLock.OnLockForReading += (s, e) => { eventWasRaised = true; };
                var key = datasetLock.LockForReading();

                Assert.IsNotNull(key);
                Assert.IsTrue(eventWasRaised);
                Assert.IsTrue(datasetLock.IsLockedForReading);
                Assert.IsFalse(datasetLock.IsLockedForWriting);
            }
        }
Esempio n. 3
0
        public void LockForReadingWithNoLocks()
        {
            using (var datasetLock = new DatasetLock())
            {
                Assert.IsFalse(datasetLock.IsLockedForReading);
                Assert.IsFalse(datasetLock.IsLockedForWriting);

                var eventWasRaised = false;
                datasetLock.OnLockForReading += (s, e) => { eventWasRaised = true; };
                var key = datasetLock.LockForReading();

                Assert.IsNotNull(key);
                Assert.IsTrue(eventWasRaised);
                Assert.IsTrue(datasetLock.IsLockedForReading);
                Assert.IsFalse(datasetLock.IsLockedForWriting);
            }
        }
Esempio n. 4
0
        public void LockForReadingWithWriteLocks()
        {
            using (var datasetLock = new DatasetLock())
            {
                Assert.IsFalse(datasetLock.IsLockedForReading);
                Assert.IsFalse(datasetLock.IsLockedForWriting);

                var writeLockEventRaised   = false;
                var writeUnlockEventRaised = false;
                var readLockEventRaised    = false;
                datasetLock.OnLockForWriting    += (s, e) => { writeLockEventRaised = true; };
                datasetLock.OnUnlockFromWriting += (s, e) => { writeUnlockEventRaised = true; };
                datasetLock.OnLockForReading    += (s, e) => { readLockEventRaised = true; };
                var key1 = datasetLock.LockForWriting();

                var task = Task <DatasetLockKey> .Factory.StartNew(datasetLock.LockForReading);

                Assert.IsTrue(writeLockEventRaised);
                Assert.IsFalse(writeUnlockEventRaised);
                Assert.IsFalse(readLockEventRaised);

                var key2 = datasetLock.LockForWriting();
                Assert.IsNotNull(key2);
                Assert.IsTrue(writeLockEventRaised);
                Assert.IsFalse(writeUnlockEventRaised);
                Assert.IsFalse(readLockEventRaised);

                datasetLock.RemoveWriteLock(key1);
                Assert.IsTrue(writeLockEventRaised);
                Assert.IsFalse(writeUnlockEventRaised);
                Assert.IsFalse(readLockEventRaised);

                datasetLock.RemoveWriteLock(key2);
                var key3 = task.Result;

                Assert.IsNotNull(key3);
                Assert.IsTrue(writeLockEventRaised);
                Assert.IsTrue(writeUnlockEventRaised);
                Assert.IsTrue(readLockEventRaised);
            }
        }
Esempio n. 5
0
        public void LockForReadingWithWriteLocks()
        {
            using (var datasetLock = new DatasetLock())
            {
                Assert.IsFalse(datasetLock.IsLockedForReading);
                Assert.IsFalse(datasetLock.IsLockedForWriting);

                var writeLockEventRaised = false;
                var writeUnlockEventRaised = false;
                var readLockEventRaised = false;
                datasetLock.OnLockForWriting += (s, e) => { writeLockEventRaised = true; };
                datasetLock.OnUnlockFromWriting += (s, e) => { writeUnlockEventRaised = true; };
                datasetLock.OnLockForReading += (s, e) => { readLockEventRaised = true; };
                var key1 = datasetLock.LockForWriting();

                var task = Task<DatasetLockKey>.Factory.StartNew(datasetLock.LockForReading);

                Assert.IsTrue(writeLockEventRaised);
                Assert.IsFalse(writeUnlockEventRaised);
                Assert.IsFalse(readLockEventRaised);

                var key2 = datasetLock.LockForWriting();
                Assert.IsNotNull(key2);
                Assert.IsTrue(writeLockEventRaised);
                Assert.IsFalse(writeUnlockEventRaised);
                Assert.IsFalse(readLockEventRaised);

                datasetLock.RemoveWriteLock(key1);
                Assert.IsTrue(writeLockEventRaised);
                Assert.IsFalse(writeUnlockEventRaised);
                Assert.IsFalse(readLockEventRaised);

                datasetLock.RemoveWriteLock(key2);
                var key3 = task.Result;

                Assert.IsNotNull(key3);
                Assert.IsTrue(writeLockEventRaised);
                Assert.IsTrue(writeUnlockEventRaised);
                Assert.IsTrue(readLockEventRaised);
            }
        }