//=============================================================================== // Name: Function NewInstance // Input: None // Output: ActiveLock interface. // Purpose: Obtains a new instance of an object that implements IActiveLock interface. // <p>As of 2.0.5, this method will no longer initialize the instance automatically. // Callers will have to call Init() by themselves subsequent to obtaining the instance. // Remarks: None //=============================================================================== public _IActiveLock NewInstance() { _IActiveLock NewInst = null; NewInst = new ActiveLock(); return(NewInst); }
internal override IList <ActiveLock> WaitingOnLocks() { IList <ActiveLock> locks = new List <ActiveLock>(); switch (_mode) { case Org.Neo4j.Kernel.impl.locking.ActiveLock_Fields.EXCLUSIVE_MODE: foreach (long resourceId in _resourceIds) { locks.Add(ActiveLock.exclusiveLock(_resourceType, resourceId)); } break; case Org.Neo4j.Kernel.impl.locking.ActiveLock_Fields.SHARED_MODE: foreach (long resourceId in _resourceIds) { locks.Add(ActiveLock.sharedLock(_resourceType, resourceId)); } break; default: throw new System.ArgumentException("Unsupported type of lock mode: " + _mode); } return(locks); }
public static void PrintActiveLock(ActiveLock @lock) { Console.WriteLine(">>>LOCK"); Console.WriteLine("LockRoot: {0}", @lock.LockRoot); Console.WriteLine("LockToken: {0}", @lock.LockToken); Console.WriteLine("LockScope: {0}", @lock.LockScope.HasValue ? Enum.GetName(typeof(LockScope), @lock.LockScope) : "null"); Console.WriteLine("LockOwner: {0}", @lock.Owner != null ? @lock.Owner.Value : "null"); Console.WriteLine("ApplyTo: {0}", @lock.ApplyTo.HasValue ? Enum.GetName(typeof(ApplyTo.Lock), @lock.ApplyTo.Value) : "null"); Console.WriteLine("Timeout: {0}", @lock.Timeout?.TotalSeconds.ToString(CultureInfo.InvariantCulture) ?? "infinity"); Console.WriteLine(); }
static void Main(string[] args) { NetworkCredential credential = new NetworkCredential("username", "password"); WebdavSession session = new WebdavSession(credential); Resource resource = new Resource(session); //Lock file for 10 minutes ActiveLock fileLock = resource.Lock("http://myserver/dav/file1.dat", Depth.Zero, 600); //Unlock file resource.Unlock("http://myserver/dav/file1.dat", fileLock); }
public override bool Equals(object o) { if (this == o) { return(true); } if (!(o is ActiveLock)) { return(false); } ActiveLock that = ( ActiveLock )o; return(ResourceIdConflict == that.ResourceId() && Objects.Equals(Mode(), that.Mode()) && Objects.Equals(ResourceTypeConflict, that.ResourceType())); }
public async Task UIT_WebDavClient_LockRefreshLockUnlock() { // This won't work on ownCloud/Nextcloud because they do not support WebDAV locking. // These unit integration test are skipped for ownCloud/Nextcloud. if (webDavRootFolder.Contains("nextcloud") || webDavRootFolder.Contains("owncloud")) { return; } using (var client = CreateWebDavClientWithDebugHttpMessageHandler()) { var userEmail = "*****@*****.**"; // Lock. var lockInfo = new LockInfo() { LockScope = LockScope.CreateExclusiveLockScope(), LockType = LockType.CreateWriteLockType(), OwnerHref = userEmail }; var response = await client.LockAsync(webDavRootFolder, WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromMinutes(1)), WebDavDepthHeaderValue.Infinity, lockInfo); var lockResponseSuccess = response.IsSuccessStatusCode; LockToken lockToken = await WebDavHelper.GetLockTokenFromWebDavResponseMessage(response); ActiveLock activeLock = await WebDavHelper.GetActiveLockFromWebDavResponseMessage(response); // Refresh lock. response = await client.RefreshLockAsync(webDavRootFolder, WebDavTimeoutHeaderValue.CreateWebDavTimeout(TimeSpan.FromSeconds(10)), lockToken); var refreshLockResponseSuccess = response.IsSuccessStatusCode; // Unlock. response = await client.UnlockAsync(webDavRootFolder, lockToken); var unlockResponseSuccess = response.IsSuccessStatusCode; Assert.IsTrue(lockResponseSuccess); Assert.IsNotNull(lockToken); Assert.AreEqual(userEmail, activeLock.OwnerHref); Assert.IsTrue(refreshLockResponseSuccess); Assert.IsTrue(unlockResponseSuccess); } }
//Locks the given Resource and returns the LockToken //if the locking was successfull //If not null will be returned public string LockResource(WebDavClient client, string destUri, LockScope lockScope) { _logger.Debug("Locking remote element " + destUri); LockResponse lockResponse = client.Lock(destUri, new LockParameters() { LockScope = lockScope, Owner = _owner, }).Result; if (lockResponse.IsSuccessful) { _logger.Debug("Successfully locked"); ActiveLock ActiveLock = lockResponse.ActiveLocks.Where(x => x.Owner.Value.Equals(_owner.Value)).FirstOrDefault(); return(ActiveLock.LockToken); } else { _logger.Error("Locking ressource failed! description: " + lockResponse.Description); } return(null); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void detectBlockedTransactionsBySharedLock() public virtual void DetectBlockedTransactionsBySharedLock() { Dictionary <KernelTransactionHandle, IList <QuerySnapshot> > map = new Dictionary <KernelTransactionHandle, IList <QuerySnapshot> >(); TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 0, singletonList(ActiveLock.sharedLock(ResourceTypes.NODE, 1))); TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction()); map[handle1] = singletonList(CreateQuerySnapshot(1)); map[handle2] = singletonList(CreateQuerySnapshotWaitingForLock(2, true, ResourceTypes.NODE, 1)); TransactionDependenciesResolver resolver = new TransactionDependenciesResolver(map); assertFalse(resolver.IsBlocked(handle1)); assertTrue(resolver.IsBlocked(handle2)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void blockingChainDescriptionForChainedBlockedTransaction() public virtual void BlockingChainDescriptionForChainedBlockedTransaction() { Dictionary <KernelTransactionHandle, IList <QuerySnapshot> > map = new Dictionary <KernelTransactionHandle, IList <QuerySnapshot> >(); TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 4, singletonList(ActiveLock.exclusiveLock(ResourceTypes.NODE, 1))); TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 5, singletonList(ActiveLock.sharedLock(ResourceTypes.NODE, 2))); TestKernelTransactionHandle handle3 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 6); map[handle1] = singletonList(CreateQuerySnapshot(1)); map[handle2] = singletonList(CreateQuerySnapshotWaitingForLock(2, false, ResourceTypes.NODE, 1)); map[handle3] = singletonList(CreateQuerySnapshotWaitingForLock(3, true, ResourceTypes.NODE, 2)); TransactionDependenciesResolver resolver = new TransactionDependenciesResolver(map); assertThat(resolver.DescribeBlockingTransactions(handle1), EmptyString); assertEquals("[transaction-4]", resolver.DescribeBlockingTransactions(handle2)); assertEquals("[transaction-4, transaction-5]", resolver.DescribeBlockingTransactions(handle3)); }
private bool IsLabelOrRelationshipType(ActiveLock activeLock) { return((activeLock.ResourceType() == ResourceTypes.LABEL) || (activeLock.ResourceType() == ResourceTypes.RELATIONSHIP_TYPE)); }
private bool IsBlocked(ActiveLock activeLock, IList <ActiveLock> activeLocks) { return(Org.Neo4j.Kernel.impl.locking.ActiveLock_Fields.EXCLUSIVE_MODE.Equals(activeLock.Mode()) ? HaveAnyLocking(activeLocks, activeLock.ResourceType(), activeLock.ResourceId()) : HaveExclusiveLocking(activeLocks, activeLock.ResourceType(), activeLock.ResourceId())); }