Exemplo n.º 1
0
        protected override void OnLockAcquired()
        {
            if (ScmHostingConfigurations.FunctionsSyncTriggersDelayBackground)
            {
                shutdownDelayed = ShutdownDelaySemaphore.GetInstance().Acquire(_traceFactory.GetTracer());
            }
            else
            {
                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();
                }
            }
        }
Exemplo n.º 2
0
        private static bool TryGetAspNet5Sdk(string rootPath, out AspNet5Sdk aspNetSdk)
        {
            aspNetSdk = null;
            var globalJson = Path.Combine(rootPath, "global.json");

            if (FileSystemHelpers.FileExists(globalJson))
            {
                var parsedGlobalJson = JObject.Parse(FileSystemHelpers.ReadAllText(globalJson));
                if (parsedGlobalJson["sdk"] != null)
                {
                    aspNetSdk = parsedGlobalJson["sdk"].ToObject <AspNet5Sdk>();
                    if (string.IsNullOrEmpty(aspNetSdk.Architecture))
                    {
                        aspNetSdk.Architecture = GetDefaultAspNet5RuntimeArchitecture();
                    }
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        private static string ResolveNpmVersion(string nodeVersion)
        {
            string programFiles         = SystemEnvironment.GetFolderPath(SystemEnvironment.SpecialFolder.ProgramFilesX86);
            string appSettingNpmVersion = SystemEnvironment.GetEnvironmentVariable("WEBSITE_NPM_DEFAULT_VERSION");

            if (!string.IsNullOrEmpty(appSettingNpmVersion))
            {
                return(appSettingNpmVersion);
            }
            else if (nodeVersion.Equals("4.1.2", StringComparison.OrdinalIgnoreCase))
            {
                // This case is only to work around node version 4.1.2 with npm 2.x failing to publish ASP.NET 5 apps due to long path issues.
                return("3.3.6");
            }
            else
            {
                string npmTxtPath = Path.Combine(programFiles, "nodejs", nodeVersion, "npm.txt");

                return(FileSystemHelpers.FileExists(npmTxtPath) ? FileSystemHelpers.ReadAllTextFromFile(npmTxtPath).Trim() : DefaultNpmVersion);
            }
        }
Exemplo n.º 4
0
        private static bool TryGetAspNet5Sdk(string rootPath, IFileFinder fileFinder, out AspNet5Sdk aspNetSdk)
        {
            aspNetSdk = null;
            var globalJsonFiles = fileFinder.ListFiles(rootPath, SearchOption.AllDirectories, new[] { "*global.json" })
                                  .Where(path => Path.GetFileName(path).Equals("global.json", StringComparison.OrdinalIgnoreCase))
                                  .ToList();

            if (globalJsonFiles.Count == 1 && FileSystemHelpers.FileExists(globalJsonFiles.First()))
            {
                var parsedGlobalJson = JObject.Parse(FileSystemHelpers.ReadAllText(globalJsonFiles.First()));
                if (parsedGlobalJson["sdk"] != null)
                {
                    aspNetSdk = parsedGlobalJson["sdk"].ToObject <AspNet5Sdk>();
                    if (string.IsNullOrEmpty(aspNetSdk.Architecture))
                    {
                        aspNetSdk.Architecture = GetDefaultAspNet5RuntimeArchitecture();
                    }
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 5
0
        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);
                        }
                    }
                });
            }
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
 private static bool IsNodeVersionInstalled(string version)
 {
     string programFiles = SystemEnvironment.GetFolderPath(SystemEnvironment.SpecialFolder.ProgramFilesX86);
     return (!String.IsNullOrEmpty(version)) &&
            FileSystemHelpers.FileExists(Path.Combine(programFiles, "nodejs", version, "node.exe"));
 }
Exemplo n.º 8
0
        private void EnsureProperties()
        {
            if (_initialized)
            {
                return;
            }

            _projectName = _projectNameProperty.GetValue <string>(_projectInstance);
            var projectType  = _projectTypeProperty.GetValue <SolutionProjectType>(_projectInstance);
            var relativePath = _relativePathProperty.GetValue <string>(_projectInstance);

            _isWebSite = projectType == SolutionProjectType.WebProject;

            // When using websites with IISExpress, the relative path property becomes a URL.
            // When that happens we're going to grab the path from the Release.AspNetCompiler.PhysicalPath
            // property in the solution.

            Uri uri;

            if (_isWebSite && Uri.TryCreate(relativePath, UriKind.Absolute, out uri))
            {
                var aspNetConfigurations = _aspNetConfigurationsProperty.GetValue <Hashtable>(_projectInstance);

                // Use the release configuraiton and debug if it isn't available
                object configurationObject = aspNetConfigurations["Release"] ?? aspNetConfigurations["Debug"];

                // REVIEW: Is there always a configuration object (i.e. can this ever be null?)

                // The aspNetPhysicalPath contains the relative to the website
                FieldInfo aspNetPhysicalPathField = configurationObject.GetType().GetField("aspNetPhysicalPath", BindingFlags.NonPublic | BindingFlags.Instance);

                relativePath = (string)aspNetPhysicalPathField.GetValue(configurationObject);
            }

            _absolutePath = Path.Combine(Path.GetDirectoryName(_solutionPath), relativePath);
            if (FileSystemHelpers.FileExists(_absolutePath))
            {
                // used to determine project type
                _projectTypeGuids = VsHelper.GetProjectTypeGuids(_absolutePath);
                if (AspNetCoreHelper.IsDotnetCoreFromProjectFile(_absolutePath, _projectTypeGuids))
                {
                    _isAspNetCore = true;
                }
                else if (projectType == SolutionProjectType.KnownToBeMSBuildFormat)
                {
                    // KnownToBeMSBuildFormat: C#, VB, and VJ# projects
                    // Check if it's a wap
                    _isWap = VsHelper.IsWap(_projectTypeGuids);

                    _isExecutable = VsHelper.IsExecutableProject(_absolutePath);
                }
                else if (FunctionAppHelper.LooksLikeFunctionApp())
                {
                    _isFunctionApp = true;
                }
            }
            else
            {
                _projectTypeGuids = Enumerable.Empty <Guid>();
            }

            _initialized = true;
        }