Example #1
0
        protected override void OnLockAcquired()
        {
            OperationManager.SafeExecute(() => {
                // Create Sentinel file for DWAS to check
                // DWAS will check for presence of this file incase a an app setting based recycle needs to be performed in middle of deployment
                // If this is present, DWAS will postpone the recycle so that deployment goes through first
                if (!String.IsNullOrEmpty(siteRoot))
                {
                    FileSystemHelpers.CreateDirectory(Path.Combine(siteRoot, @"ShutdownSentinel"));
                    string sentinelPath = Path.Combine(siteRoot, @"ShutdownSentinel\Sentinel.txt");

                    if (!FileSystemHelpers.FileExists(sentinelPath))
                    {
                        var file = FileSystemHelpers.CreateFile(sentinelPath);
                        file.Close();
                    }

                    // DWAS checks if write time of this file is in the future then only postpones the recycle
                    FileInfoBase sentinelFileInfo     = FileSystemHelpers.FileInfoFromFileName(sentinelPath);
                    sentinelFileInfo.LastWriteTimeUtc = DateTime.UtcNow.AddMinutes(20);
                }
            });

            IRepositoryFactory repositoryFactory = RepositoryFactory;

            if (repositoryFactory != null)
            {
                IRepository repository = repositoryFactory.GetRepository();
                if (repository != null)
                {
                    // Clear any left over repository-related lock since we have the actual lock
                    repository.ClearLock();
                }
            }
        }
Example #2
0
        public bool Acquire(ITracer tracer)
        {
            lock (_lock)
            {
                try
                {
                    // No timeout makes this call instant. No waiting for acquistion
                    bool acquired = _shutdownSemaphore.Wait(millisecondsTimeout: 0);

                    if (!acquired)
                    {
                        tracer.Trace("Could not acquire shutdown semaphore", new Dictionary <string, string>
                        {
                            { "SemaphoreCount", _shutdownSemaphore.CurrentCount.ToString() }
                        });

                        return(false);
                    }

                    //tracer.Trace("Acquired shutdown semaphore", new Dictionary<string, string>
                    //{
                    //    { "SemaphoreCount", _shutdownSemaphore.CurrentCount.ToString() }
                    //});

                    OperationManager.SafeExecute(() => {
                        if (Environment.IsAzureEnvironment() && OSDetector.IsOnWindows())
                        {
                            string siteRoot = PathUtilityFactory.Instance.ResolveLocalSitePath();

                            // Create Sentinel file for DWAS to check
                            // DWAS will check for presence of this file incase a an app setting based recycle needs to be performed in middle of deployment
                            // If this is present, DWAS will postpone the recycle so that deployment goes through first
                            if (!string.IsNullOrEmpty(siteRoot))
                            {
                                FileSystemHelpers.CreateDirectory(Path.Combine(siteRoot, @"ShutdownSentinel"));
                                string sentinelPath = Path.Combine(siteRoot, @"ShutdownSentinel\Sentinel.txt");

                                if (!FileSystemHelpers.FileExists(sentinelPath))
                                {
                                    //tracer.Trace("Creating shutdown sentinel file", new Dictionary<string, string>
                                    //{
                                    //    { "SemaphoreCount", _shutdownSemaphore.CurrentCount.ToString() }
                                    //});
                                    var file = FileSystemHelpers.CreateFile(sentinelPath);
                                    file.Close();
                                }

                                tracer.Trace("Updating shutdown sentinel last write time", new Dictionary <string, string>
                                {
                                    { "SemaphoreCount", _shutdownSemaphore.CurrentCount.ToString() }
                                });
                                // DWAS checks if write time of this file is in the future then only postpones the recycle
                                FileInfoBase sentinelFileInfo     = FileSystemHelpers.FileInfoFromFileName(sentinelPath);
                                sentinelFileInfo.LastWriteTimeUtc = DateTime.UtcNow.AddMinutes(20);
                            }
                        }
                    });
                }
                catch (Exception ex)
                {
                    tracer.TraceError(ex);
                    return(false);
                }

                return(true);
            }
        }