Ejemplo n.º 1
0
        protected virtual void OnInstallPackages(FileTransaction fileTransaction, IEnumerable <PackageInfo> packages,
                                                 IProductConfigurationProvider productConfigProvider,
                                                 IPackageConfigurationProvider packageConfigProvider,
                                                 IDeploymentStartegyProvider deploymentStartegy)
        {
            foreach (var package in packages)
            {
                var files          = deploymentStartegy.GetPackageFiles(package.Id, package.PackagePath).ToList();
                var installedFiles = new List <string>();

                var e = new BeforePackageInstalledEvent();
                e.FilesToInstall.AddRange(files);
                RaiseDeploymentEvent(e, package.Id);

                foreach (var file in e.FilesToInstall)
                {
                    if (file.Action == FileAction.Copy)
                    {
                        fileTransaction.InstallFile(file);
                        installedFiles.Add(file.TargetFileName);
                    }
                    else if (file.Action == FileAction.Delete)
                    {
                        fileTransaction.DeleteFile(file.TargetFileName);
                    }
                }

                var cfg = packageConfigProvider.GetPackageConfiguration(package.Id, package.PackagePath);
                productConfigProvider.SetPackageConfiguration(cfg, installedFiles, package.Dependencies.Select(x => x.Id.ToString()));

                RaiseDeploymentEvent(new AfterPackageInstalledEvent(), package.Id);
                Logger.Info($"Package {package.Id} installed");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes the action under the specified transaction.
        /// </summary>
        /// <param name="transaction">The transaction.</param>
        /// <seealso cref="IDeploymentTransaction" />
        public override void Execute(IDeploymentTransaction transaction)
        {
            var files          = _deploymentStrategy.GetPackageFiles(_deploymentPackage.Id, _deploymentPackage.PackagePath).ToList();
            var installedFiles = new List <PackageFileInfo>();

            var e = new BeforePackageInstalledEvent();

            e.FilesToInstall.AddRange(files);
            RaiseDeploymentEvent(e, _deploymentPackage.Id);

            var productPathLength = DeploymentContext.ProductPath.Length;

            foreach (var file in e.FilesToInstall)
            {
                if (file.Action == FileAction.Copy)
                {
                    transaction.InstallFile(file);

                    var filePath = file.TargetFileName;
                    if (filePath.StartsWith(DeploymentContext.ProductPath))
                    {
                        filePath = filePath.Remove(0, productPathLength).TrimStart('/', '\\');
                    }

                    installedFiles.Add(new PackageFileInfo(filePath));
                }
                else if (file.Action == FileAction.Delete)
                {
                    transaction.DeleteFile(new PackageFileInfo(file.TargetFileName));
                }
            }

            var cfg = _packageConfigProvider.GetPackageConfiguration(_deploymentPackage.Id, _deploymentPackage.PackagePath);

            transaction.TrackInstalledPackage(cfg, installedFiles);

            RaiseDeploymentEvent(new AfterPackageInstalledEvent(), _deploymentPackage.Id);
            Info($"{_deploymentPackage.Id} installed");
        }