internal string Initialize(ILogger logger)
        {
            try
            {
                // Parse and process the function app dependencies defined in the manifest.
                _dependenciesFromManifest = _storage.GetDependencies().ToArray();

                if (!_dependenciesFromManifest.Any())
                {
                    logger.Log(isUserOnlyLog: true, LogLevel.Warning, PowerShellWorkerStrings.FunctionAppDoesNotHaveRequiredModulesToInstall);
                    return(null);
                }

                _currentSnapshotPath = _installedDependenciesLocator.GetPathWithAcceptableDependencyVersionsInstalled()
                                       ?? _storage.CreateNewSnapshotPath();

                _backgroundSnapshotMaintainer.Start(_currentSnapshotPath, _dependenciesFromManifest, logger);
                _newerSnapshotDetector.Start(_currentSnapshotPath, logger);
                _currentSnapshotContentLogger.Start(_currentSnapshotPath, logger);

                return(_currentSnapshotPath);
            }
            catch (Exception e)
            {
                var errorMsg = string.Format(PowerShellWorkerStrings.FailToInstallFuncAppDependencies, e.Message);
                throw new DependencyInstallationException(errorMsg, e);
            }
        }
        public string GetPathWithAcceptableDependencyVersionsInstalled()
        {
            var lastSnapshotPath = _storage.GetLatestInstalledSnapshot();

            if (lastSnapshotPath == null)
            {
                _logger.Log(isUserOnlyLog: false, Level.Information, string.Format(PowerShellWorkerStrings.NoInstalledDependencySnapshot, lastSnapshotPath));
                return(null);
            }

            _logger.Log(isUserOnlyLog: false, Level.Information, string.Format(PowerShellWorkerStrings.LastInstalledDependencySnapshotFound, lastSnapshotPath));

            if (_storage.IsEquivalentDependencyManifest(lastSnapshotPath))
            {
                _logger.Log(isUserOnlyLog: false, Level.Information, string.Format(PowerShellWorkerStrings.EquivalentDependencySnapshotManifest, lastSnapshotPath));
                return(lastSnapshotPath);
            }

            var dependencies = _storage.GetDependencies();

            if (dependencies.All(entry => IsAcceptableVersionInstalled(lastSnapshotPath, entry)))
            {
                _logger.Log(isUserOnlyLog: false, Level.Information, string.Format(PowerShellWorkerStrings.DependencySnapshotContainsAcceptableModuleVersions, lastSnapshotPath));
                return(lastSnapshotPath);
            }

            _logger.Log(isUserOnlyLog: false, Level.Information, string.Format(PowerShellWorkerStrings.DependencySnapshotDoesNotContainAcceptableModuleVersions, lastSnapshotPath));
            return(null);
        }
Exemple #3
0
        public string GetPathWithAcceptableDependencyVersionsInstalled()
        {
            var lastSnapshotPath = _storage.GetLatestInstalledSnapshot();

            if (lastSnapshotPath != null)
            {
                var dependencies = _storage.GetDependencies();
                if (dependencies.All(entry => IsAcceptableVersionInstalled(lastSnapshotPath, entry)))
                {
                    return(lastSnapshotPath);
                }
            }

            return(null);
        }