예제 #1
0
        internal static PackagingResult ExecutePhase(XmlDocument manifestXml, int phase, RepositoryStartSettings settings = null)
        {
            var manifest = Manifest.Parse(manifestXml, phase, true, new PackageParameter[0]);

            // Fill context with indexing folder, repo start settings, providers and other
            // parameters necessary for on-the-fly steps to run.
            var executionContext = ExecutionContext.Create("packagePath", "targetPath",
                                                           new string[0], "sandboxPath", manifest, phase, manifest.CountOfPhases,
                                                           null, null, settings);

            PackagingResult result;

            try
            {
                result = ExecuteCurrentPhase(manifest, executionContext);
            }
            finally
            {
                if (Repository.Started())
                {
                    SnTrace.System.Write("PackageManager: stopping repository ... ");
                    Repository.Shutdown();
                }
            }

            RepositoryVersionInfo.Reset();

            return(result);
        }
예제 #2
0
        private static SnPatch CreateSnPatch(Package package)
        {
            var xml = new XmlDocument();

            xml.LoadXml(package.Manifest);
            var manifest = Manifest.Parse(xml);

            var dependencies   = manifest.Dependencies.ToList();
            var selfDependency = dependencies.First(x => x.Id == package.ComponentId);

            dependencies.Remove(selfDependency);

            return(new SnPatch
            {
                Id = package.Id,
                ComponentId = package.ComponentId,
                Description = package.Description,
                ReleaseDate = package.ReleaseDate,
                Version = package.ComponentVersion,
                Boundary = selfDependency.Boundary,
                Dependencies = dependencies,
                ExecutionDate = package.ExecutionDate,
                ExecutionResult = package.ExecutionResult,
                ExecutionError = package.ExecutionError
            });
        }
예제 #3
0
        public static PackagingResult Execute(string packagePath, string targetPath, int phase, string[] parameters, TextWriter console)
        {
            var phaseCount = 1;

            var files = Directory.GetFiles(packagePath);

            Manifest  manifest = null;
            Exception manifestParsingException = null;

            if (files.Length == 1)
            {
                try
                {
                    manifest   = Manifest.Parse(files[0], phase == 0);
                    phaseCount = manifest.CountOfPhases;
                }
                catch (Exception e)
                {
                    manifestParsingException = e;
                }
            }

            if (files.Length == 0)
            {
                throw new InvalidPackageException(SR.Errors.ManifestNotFound);
            }
            if (files.Length > 1)
            {
                throw new InvalidPackageException(SR.Errors.PackageCanContainOnlyOneFileInTheRoot);
            }
            if (manifestParsingException != null)
            {
                throw new PackagingException("Manifest parsing error. See inner exception.", manifestParsingException);
            }
            if (manifest == null)
            {
                throw new PackagingException("Manifest was not found.");
            }

            SubstituteParameters(manifest, parameters);
            var sandboxPath = Path.Combine(Path.GetDirectoryName(packagePath), SANDBOXDIRECTORYNAME);

            Logger.LogTitle(String.Format("Executing phase {0}/{1}", phase + 1, phaseCount));

            var configEntry    = ConfigurationManager.AppSettings["NetworkTargets"];
            var networkTargets = string.IsNullOrEmpty(configEntry) ? new string[0] : configEntry.Split(',', ';').Select(x => x.Trim()).ToArray();

            var executionContext = new ExecutionContext(packagePath, targetPath, networkTargets, sandboxPath, manifest, phase, manifest.CountOfPhases, console);
            var result           = ExecuteCurrentPhase(manifest, executionContext);

            if (Repository.Started())
            {
                console.WriteLine("-------------------------------------------------------------");
                console.Write("Stopping repository ... ");
                Repository.Shutdown();
                console.WriteLine("Ok.");
            }

            return(result);
        }
예제 #4
0
        private static ComponentInstaller CreateInstaller(Package package)
        {
            var xml = new XmlDocument();

            xml.LoadXml(package.Manifest);
            var manifest = Manifest.Parse(xml);

            var dependencies = manifest.Dependencies.ToList();

            return(new ComponentInstaller
            {
                Id = package.Id,
                ComponentId = package.ComponentId,
                Description = package.Description,
                ReleaseDate = package.ReleaseDate,
                Version = package.ComponentVersion,
                Dependencies = dependencies,
                ExecutionDate = package.ExecutionDate,
                ExecutionResult = package.ExecutionResult,
                ExecutionError = package.ExecutionError
            });
        }
예제 #5
0
        public static PackagingResult Execute(string packagePath, string targetPath, int currentPhase, string[] parameters, TextWriter console)
        {
            var packageParameters = parameters?.Select(PackageParameter.Parse).ToArray() ?? new PackageParameter[0];
            var forcedReinstall   = "true" == (packageParameters
                                               .FirstOrDefault(p => p.PropertyName.ToLowerInvariant() == "forcedreinstall")?
                                               .Value?.ToLowerInvariant() ?? "");

            var phaseCount = 1;

            var files = Directory.GetFiles(packagePath);

            Manifest  manifest = null;
            Exception manifestParsingException = null;

            if (files.Length == 1)
            {
                try
                {
                    manifest   = Manifest.Parse(files[0], currentPhase, currentPhase == 0, packageParameters, forcedReinstall);
                    phaseCount = manifest.CountOfPhases;
                }
                catch (Exception e)
                {
                    manifestParsingException = e;
                }
            }

            if (files.Length == 0)
            {
                throw new InvalidPackageException(SR.Errors.ManifestNotFound);
            }
            if (files.Length > 1)
            {
                throw new InvalidPackageException(SR.Errors.PackageCanContainOnlyOneFileInTheRoot);
            }
            if (manifestParsingException != null)
            {
                throw new PackagingException("Manifest parsing error. See inner exception.", manifestParsingException);
            }
            if (manifest == null)
            {
                throw new PackagingException("Manifest was not found.");
            }

            Logger.LogTitle(String.Format("Executing phase {0}/{1}", currentPhase + 1, phaseCount));

            var sandboxDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var executionContext = new ExecutionContext(packagePath, targetPath, Configuration.Packaging.NetworkTargets,
                                                        sandboxDirectory, manifest, currentPhase, manifest.CountOfPhases, packageParameters, console);

            executionContext.LogVariables();

            PackagingResult result;

            try
            {
                result = ExecuteCurrentPhase(manifest, executionContext);
            }
            finally
            {
                if (Repository.Started())
                {
                    console.WriteLine("-------------------------------------------------------------");
                    console.Write("Stopping repository ... ");
                    Repository.Shutdown();
                    console.WriteLine("Ok.");
                }
            }

            return(result);
        }
예제 #6
0
        public static PackagingResult Execute(string packagePath, string targetPath, int currentPhase,
                                              PackageParameter[] parameters, TextWriter console,
                                              RepositoryBuilder builder = null, bool editConnectionString = false)
        {
            // Workaround for setting the packaging db provider: in normal cases this happens
            // when the repository starts, but in case of package execution the repository
            // is not yet started sometimes.
            if (null == DataStore.GetDataProviderExtension <IPackagingDataProviderExtension>())
            {
                DataStore.SetDataProviderExtension(typeof(IPackagingDataProviderExtension), new MsSqlPackagingDataProvider());
            }

            var packageParameters = parameters ?? new PackageParameter[0];
            var forcedReinstall   = "true" == (packageParameters
                                               .FirstOrDefault(p => p.PropertyName.ToLowerInvariant() == "forcedreinstall")?
                                               .Value?.ToLowerInvariant() ?? "");

            var phaseCount = 1;

            var files = Directory.GetFiles(packagePath);

            Manifest  manifest = null;
            Exception manifestParsingException = null;

            if (files.Length == 1)
            {
                try
                {
                    manifest = Manifest.Parse(files[0], currentPhase, currentPhase == 0, packageParameters,
                                              forcedReinstall, editConnectionString);
                    phaseCount = manifest.CountOfPhases;
                }
                catch (Exception e)
                {
                    manifestParsingException = e;
                }
            }

            if (files.Length == 0)
            {
                throw new InvalidPackageException(SR.Errors.ManifestNotFound);
            }
            if (files.Length > 1)
            {
                throw new InvalidPackageException(SR.Errors.PackageCanContainOnlyOneFileInTheRoot);
            }
            if (manifestParsingException != null)
            {
                throw new PackagingException("Manifest parsing error. See inner exception.", manifestParsingException);
            }
            if (manifest == null)
            {
                throw new PackagingException("Manifest was not found.");
            }

            Logger.LogTitle(String.Format("Executing phase {0}/{1}", currentPhase + 1, phaseCount));

            var sandboxDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var executionContext = ExecutionContext.Create(packagePath, targetPath, Configuration.Packaging.NetworkTargets,
                                                           sandboxDirectory, manifest, currentPhase, manifest.CountOfPhases, packageParameters, console, builder);

            executionContext.LogVariables();

            PackagingResult result;

            try
            {
                result = ExecuteCurrentPhase(manifest, executionContext);
            }
            finally
            {
                if (Repository.Started())
                {
                    console.WriteLine("-------------------------------------------------------------");
                    console.Write("Stopping repository ... ");
                    Repository.Shutdown();
                    console.WriteLine("Ok.");
                }
            }

            return(result);
        }