private void CopyResourcesFromPackages()
        {
            var stopwatch   = Stopwatch.StartNew();
            var _fileSyncer = new FileSyncer(_logProvider);

            _fileSyncer.AddDestinations(_rhetosBuildEnvironment.GeneratedAssetsFolder); // Even if there are no packages, the old folder content must be emptied.

            string ResourcesPathPrefix = "Resources" + Path.DirectorySeparatorChar;
            string HostApplicationResourcesPathPrefix = ResourcesPathPrefix + "Rhetos" + Path.DirectorySeparatorChar;

            var resourceFiles = _installedPackages.Packages
                                .SelectMany(package => package.ContentFiles
                                            .Where(file => file.InPackagePath.StartsWith(ResourcesPathPrefix))
                                            .Where(file => !file.PhysicalPath.StartsWith(_rhetosBuildEnvironment.ProjectFolder)) // Prevent from including the generated output folder as in input.
                                            .Select(file => new
            {
                Package = package,
                Source  = file.PhysicalPath,
                Target  = Path.Combine(SimplifyPackageName(package.Id), file.InPackagePath.Substring(ResourcesPathPrefix.Length))
            }))
                                //The resource files that are used by Rhetos are located in the Resources folder of a NuGet package.
                                //We also want to add the possibility that a Rhetos resource file can be added in the current project by the application developer.
                                //The Resources folder can be used as in any other NuGet Rhetos package but this way unwanted files could be copied in the RhetosAssets folder
                                //because the Resources folder in a project is usually used to store other resource files.
                                .Union(_installedPackages.Packages
                                       .SelectMany(package => package.ContentFiles
                                                   .Where(file => file.PhysicalPath.StartsWith(_rhetosBuildEnvironment.ProjectFolder)) // Prevent from including the generated output folder as in input.
                                                   .Where(file => file.InPackagePath.StartsWith(HostApplicationResourcesPathPrefix))
                                                   .Select(file => new
            {
                Package = package,
                Source  = file.PhysicalPath,
                Target  = Path.Combine(SimplifyPackageName(package.Id), file.InPackagePath.Substring(HostApplicationResourcesPathPrefix.Length))
            })))
                                .ToList();

            var similarPackages = resourceFiles.Select(file => file.Package).Distinct()
                                  .GroupBy(package => SimplifyPackageName(package.Id), StringComparer.OrdinalIgnoreCase)
                                  .FirstOrDefault(group => group.Count() > 1);

            if (similarPackages != null)
            {
                throw new UserException($"Incompatible package names, resource files would result in the same target folder '{similarPackages.Key}'."
                                        + $"\r\nPackage 1: {similarPackages.First().Report()}"
                                        + $"\r\nPackage 2: {similarPackages.Last().Report()}");
            }

            foreach (var file in resourceFiles)
            {
                _fileSyncer.AddFile(file.Source, _rhetosBuildEnvironment.GeneratedAssetsFolder, file.Target);
            }

            _logger.Info($"Copying {resourceFiles.Count} resource files.");
            _fileSyncer.UpdateDestination(false, false);

            _performanceLogger.Write(stopwatch, "Resources generated.");
        }
Пример #2
0
        /// <summary>
        /// Downloads the packages from the provided sources, if not already downloaded.
        /// Unpacks the packages, if not already unpacked.
        /// </summary>
        public InstalledPackages GetPackages()
        {
            var sw = Stopwatch.StartNew();
            var installedPackages = new List <InstalledPackage>();

            // These Rhetos framework packages are already integrated in Rhetos application when using DeployPackages build process.
            installedPackages.Add(new InstalledPackage("Rhetos", SystemUtility.GetRhetosVersion(), new List <PackageRequest>(), Paths.RhetosServerRootPath,
                                                       new PackageRequest {
                Id = "Rhetos", VersionsRange = null, Source = null, RequestedBy = "Rhetos framework"
            }, ".", new List <ContentFile> {
            }));
            installedPackages.Add(new InstalledPackage("Rhetos.MSBuild", SystemUtility.GetRhetosVersion(), new List <PackageRequest>(), Paths.RhetosServerRootPath,
                                                       new PackageRequest {
                Id = "Rhetos.MSBuild", VersionsRange = null, Source = null, RequestedBy = "Rhetos framework"
            }, ".", new List <ContentFile> {
            }));

            var binFileSyncer = new FileSyncer(_logProvider);

            binFileSyncer.AddDestinations(Paths.PluginsFolder); // Even if there are no packages, this folder must be emptied.

            _filesUtility.SafeCreateDirectory(_packagesCacheFolder);
            var packageRequests = _deploymentConfiguration.PackageRequests;

            while (packageRequests.Any())
            {
                var newDependencies = new List <PackageRequest>();
                foreach (var request in packageRequests)
                {
                    _logger.Trace(() => $"Getting package {request.ReportIdVersionRequestSource()}.");
                    if (!CheckAlreadyDownloaded(request, installedPackages))
                    {
                        var installedPackage = GetPackage(request, binFileSyncer);
                        ValidatePackage(installedPackage, request);
                        installedPackages.Add(installedPackage);
                        newDependencies.AddRange(installedPackage.Dependencies);
                    }
                }
                packageRequests = newDependencies;
            }

            DeleteObsoletePackages(installedPackages);
            SortByDependencies(installedPackages);

            binFileSyncer.UpdateDestination();

            _performanceLogger.Write(sw, "GetPackages.");

            return(new InstalledPackages {
                Packages = installedPackages
            });
        }
Пример #3
0
        /// <summary>
        /// Downloads the packages from the provided sources, if not already downloaded.
        /// Unpacks the packages, if not already unpacked.
        /// </summary>
        public List <InstalledPackage> GetPackages()
        {
            var sw = Stopwatch.StartNew();
            var installedPackages = new List <InstalledPackage>();

            installedPackages.Add(new InstalledPackage("Rhetos", SystemUtility.GetRhetosVersion(), new List <PackageRequest>(), Paths.RhetosServerRootPath,
                                                       new PackageRequest {
                Id = "Rhetos", VersionsRange = "", Source = "", RequestedBy = "Rhetos framework"
            }, ".", new List <ContentFile> {
            }));

            var binFileSyncer = new FileSyncer(_logProvider);

            binFileSyncer.AddDestinations(Paths.PluginsFolder, Paths.ResourcesFolder); // Even if there are no packages, those folders must be created and emptied.

            _filesUtility.SafeCreateDirectory(Paths.PackagesCacheFolder);
            var packageRequests = _deploymentConfiguration.PackageRequests;

            while (packageRequests.Any())
            {
                var newDependencies = new List <PackageRequest>();
                foreach (var request in packageRequests)
                {
                    if (!CheckAlreadyDownloaded(request, installedPackages))
                    {
                        var installedPackage = GetPackage(request, binFileSyncer);
                        ValidatePackage(installedPackage, request, installedPackages);
                        installedPackages.Add(installedPackage);
                        newDependencies.AddRange(installedPackage.Dependencies);
                    }
                }
                packageRequests = newDependencies;
            }

            DeleteObsoletePackages(installedPackages);
            SortByDependencies(installedPackages);

            binFileSyncer.UpdateDestination();

            foreach (var package in installedPackages)
            {
                _packagesLogger.Trace(() => package.Report());
            }

            _performanceLogger.Write(sw, "PackageDownloader.GetPackages.");

            return(installedPackages);
        }
Пример #4
0
        private void CopyResourcesFromPackages()
        {
            var stopwatch   = Stopwatch.StartNew();
            var _fileSyncer = new FileSyncer(_logProvider);

            _fileSyncer.AddDestinations(Paths.ResourcesFolder); // Even if there are no packages, the old folder content must be emptied.

            const string ResourcesPathPrefix = @"Resources\";

            var resourceFiles = _installedPackages.Packages
                                .SelectMany(package => package.ContentFiles
                                            .Where(file => file.InPackagePath.StartsWith(ResourcesPathPrefix))
                                            .Where(file => !file.PhysicalPath.StartsWith(Paths.ResourcesFolder)) // Prevent from including the generated output folder as in input.
                                            .Select(file => new
            {
                Package = package,
                Source  = file.PhysicalPath,
                Target  = Path.Combine(SimplifyPackageName(package.Id), file.InPackagePath.Substring(ResourcesPathPrefix.Length))
            }))
                                .ToList();

            var similarPackages = resourceFiles.Select(file => file.Package).Distinct()
                                  .GroupBy(package => SimplifyPackageName(package.Id), StringComparer.OrdinalIgnoreCase)
                                  .FirstOrDefault(group => group.Count() > 1);

            if (similarPackages != null)
            {
                throw new UserException($"Incompatible package names, resource files would result in the same target folder '{similarPackages.Key}'."
                                        + $"\r\nPackage 1: {similarPackages.First().ReportIdVersionRequestSource()}"
                                        + $"\r\nPackage 2: {similarPackages.Last().ReportIdVersionRequestSource()}");
            }

            foreach (var file in resourceFiles)
            {
                _fileSyncer.AddFile(file.Source, Paths.ResourcesFolder, file.Target);
            }

            _logger.Info($"Copying {resourceFiles.Count} resource files.");
            _fileSyncer.UpdateDestination();

            _performanceLogger.Write(stopwatch, "Resources generated.");
        }