public void Release(ITracer tracer) { lock (_lock) { _shutdownSemaphore.Release(); //tracer.Trace("Released shut down semaphore", new Dictionary<string, string> //{ // { "SemaphoreCount", _shutdownSemaphore.CurrentCount.ToString() } //}); if (_shutdownSemaphore.CurrentCount == InitialAndMaxCount) { OperationManager.SafeExecute(() => { string siteRoot = PathUtilityFactory.Instance.ResolveLocalSitePath(); // Delete the Sentinel file to signal DWAS that deployment is complete if (!string.IsNullOrEmpty(siteRoot)) { string sentinelPath = Path.Combine(siteRoot, @"ShutdownSentinel\Sentinel.txt"); if (FileSystemHelpers.FileExists(sentinelPath)) { tracer.Trace("Deleting shutdown sentinel file", new Dictionary <string, string> { { "SemaphoreCount", _shutdownSemaphore.CurrentCount.ToString() } }); FileSystemHelpers.DeleteFile(sentinelPath); } } }); } } }
// we cannot use FileSystemHelpers.DeleteFileSafe. // it does not handled IOException due to 'file in used'. private void DeleteFileSafe() { try { FileSystemHelpers.DeleteFile(_path); } catch (Exception ex) { TraceIfUnknown(ex); } }
private void TryRemovedLockFile() { if (!FileSystemHelpers.FileExists(_path)) { return; } FileSystemHelpers.DeleteFile(_path); // check if file still exists if (FileSystemHelpers.FileExists(_path)) { throw new Exception("Tried removing but the lock file still exists, would retry the removal"); } }
// we cannot use FileSystemHelpers.DeleteFileSafe. // it does not handled IOException due to 'file in used'. private void DeleteFileSafe() { // Only clean up lock on Windows Env // When running on Mono with SMB share, delete action would cause wierd behavior on later OpenWrite action if a file has already been opened by another process if (OSDetector.IsOnWindows()) { try { FileSystemHelpers.DeleteFile(_path); } catch (Exception ex) { TraceIfUnknown(ex); } } }
// we cannot use FileSystemHelpers.DeleteFileSafe. // it does not handled IOException due to 'file in used'. private void DeleteFileSafe() { // Only clean up lock on Windows Env try { FileSystemHelpers.DeleteFile(_path); OperationManager.Attempt(() => // throws exception if file is still present TryRemovedLockFile() , 10, 250); } catch (Exception ex) { TraceIfUnknown(ex); } }
protected override void OnLockRelease() { base.OnLockRelease(); OperationManager.SafeExecute(() => { // Delete the Sentinel file to signal DWAS that deployment is complete if (!String.IsNullOrEmpty(siteRoot)) { string sentinelPath = Path.Combine(siteRoot, @"ShutdownSentinel\Sentinel.txt"); if (FileSystemHelpers.FileExists(sentinelPath)) { FileSystemHelpers.DeleteFile(sentinelPath); } } }); }
protected override void OnLockRelease() { base.OnLockRelease(); if (ScmHostingConfigurations.FunctionsSyncTriggersDelayBackground && shutdownDelayed) { ShutdownDelaySemaphore.GetInstance().Release(_traceFactory.GetTracer()); } else { OperationManager.SafeExecute(() => { // Delete the Sentinel file to signal DWAS that deployment is complete if (!String.IsNullOrEmpty(siteRoot)) { string sentinelPath = Path.Combine(siteRoot, @"ShutdownSentinel\Sentinel.txt"); if (FileSystemHelpers.FileExists(sentinelPath)) { FileSystemHelpers.DeleteFile(sentinelPath); } } }); } }