Exemplo n.º 1
0
        public void UpdateDb()
        {
            var targetBuild  = _versionProvider.GetBuild();
            var currentBuild = GetCurrentBuild();

            if (targetBuild < currentBuild)
            {
                var exeption = new Exception($"Target Build version is lower than current, current {currentBuild}, target {targetBuild}");
                _logger.LogError(exeption, "Cannot Update DB");
                throw exeption;
            }

            if (targetBuild == currentBuild)
            {
                _logger.LogInformation("Build version is up to date, current {@currentBuild}, target {@targetBuild}", currentBuild, targetBuild);
                return;
            }

            _logger.LogInformation("Build version is out of date, current {@currentBuild}, target {@targetBuild}", currentBuild, targetBuild);

            var resourcesPrefix = "SSMSPlusDb.DbUpdate.Versions.";

            string[] resNames = _resourcesAssembly.GetManifestResourceNames().Where(p => p.StartsWith(resourcesPrefix)).OrderBy(p => p).ToArray();

            do
            {
                currentBuild++;
                var buildPrefix    = resourcesPrefix + "V" + currentBuild.ToString("0000") + ".";
                var buildResources = resNames.Where(p => p.StartsWith(buildPrefix)).ToArray();
                UpdateVersion(currentBuild, buildResources);
            } while (currentBuild < targetBuild);

            _logger.LogInformation("Build version update {@currentBuild} (finished)", currentBuild);
        }