protected override void ApplicationStartup(TinyIoCContainer nancy, IPipelines pipelines)
        {
            // Create Simple Injector container
            Container container = new Container();

            PackageExtensions.RegisterPackages(container, System.AppDomain.CurrentDomain.GetAssemblies());
            //container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();

            // Register application components here, e.g.:
            //container.Register(typeof(ICommandHandler<>), AppDomain.CurrentDomain.GetAssemblies());

            // Register Nancy modules.
            foreach (var nancyModule in this.Modules)
            {
                container.Register(nancyModule.ModuleType);
            }

            // Cross-wire Nancy abstractions that application components require (if any). e.g.:
            //container.Register(nancy.Resolve<IModelValidator>);

            // Check the container.
            container.Verify();

            // Hook up Simple Injector in the Nancy pipeline.
            nancy.Register(typeof(INancyModuleCatalog), new SimpleInjectorModuleCatalog(container));
            nancy.Register(typeof(INancyContextFactory), new Injection.SimpleInjectorScopedContextFactory(
                               container, nancy.Resolve <INancyContextFactory>()));

            rootProvider = container.GetInstance <IRootPathProvider>();
        }
Ejemplo n.º 2
0
        public ICollection <NuGet.Versioning.NuGetVersion> GetVersions(UnresolvedPackage package)
        {
            var filePattern = package.GetSearchFileName();

            return(new DirectoryInfo(RootPath).GetFiles(filePattern)
                   .Select(i => PackageExtensions.GetPackageKeyFromFileName(i.Name).Version).ToArray());
        }
Ejemplo n.º 3
0
        public void Publish(string packagePath)
        {
            if (!CanPublish)
            {
                throw new Exception("Publish is not allowed");
            }

            var fileName = Path.GetFileName(packagePath);

            var searchPattern = PackageExtensions.GetPackageKeyFromFileName(fileName).GetRelatedSearchFileName();

            foreach (var relatedBuild in Directory.GetFiles(RootPath, searchPattern))
            {
                File.Delete(relatedBuild);
            }

            var targetPath = Path.Combine(RootPath, fileName);

            if (File.Exists(targetPath))
            {
                File.Delete(targetPath);
            }

            File.Move(packagePath, targetPath);
        }
Ejemplo n.º 4
0
        public void ToUiFormat_ProvideCorrectProvisioningFormUrl()
        {
            var stringGuid = "B4F93552-53C5-4EF1-BBA6-0AF52C3B785B";
            var testId     = Guid.Parse(stringGuid);
            var package    = TestHarness.CreatePackageModel(id: testId);

            package.PackageType = Models.PackageType.Tenant;
            var uiPackage = PackageExtensions.ToUiFormat(package, "https://example.com/testing", false);

            Assert.AreEqual(
                "https://example.com/testing/tenant/home/provision?packageId=B4F93552-53C5-4EF1-BBA6-0AF52C3B785B".ToLower(),
                uiPackage.ProvisioningFormUrl.ToLower());

            package.PackageType = Models.PackageType.Tenant;
            uiPackage           = PackageExtensions.ToUiFormat(package, "https://example.com", false);
            Assert.AreEqual(
                "https://example.com/tenant/home/provision?packageId=B4F93552-53C5-4EF1-BBA6-0AF52C3B785B".ToLower(),
                uiPackage.ProvisioningFormUrl.ToLower());

            package.PackageType = Models.PackageType.SiteCollection;
            uiPackage           = PackageExtensions.ToUiFormat(package, "https://example.com/testing", false);
            Assert.AreEqual(
                "https://example.com/testing/site/home/provision?packageId=B4F93552-53C5-4EF1-BBA6-0AF52C3B785B".ToLower(),
                uiPackage.ProvisioningFormUrl.ToLower());

            package.PackageType = Models.PackageType.SiteCollection;
            uiPackage           = PackageExtensions.ToUiFormat(package, "https://example.com", false);
            Assert.AreEqual(
                "https://example.com/site/home/provision?packageId=B4F93552-53C5-4EF1-BBA6-0AF52C3B785B".ToLower(),
                uiPackage.ProvisioningFormUrl.ToLower());
        }
Ejemplo n.º 5
0
 public void ConvertDependenciesToStringWhenDependsOnFramework()
 {
     Assert.Equal("::.NETStandard2.0",
                  PackageExtensions.ToDependenciesString(new Core.Entities.PackageDependency[1] {
         new Core.Entities.PackageDependency()
         {
             TargetFramework = ".NETStandard2.0"
         }
     }));
 }
        protected virtual void SetControllerFactory(PipelineArgs args)
        {
            var container = new Container();

            PackageExtensions.RegisterPackages(container, AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.StartsWith("SitecoreMVC."))); // you can customize this to what ever you need

            var simpleInjectorControllerFactory = new SimpleInjectorControllerFactory(container);
            var sitecoreControllerFactory       = new Sitecore.Mvc.Controllers.SitecoreControllerFactory(simpleInjectorControllerFactory);

            ControllerBuilder.Current.SetControllerFactory(sitecoreControllerFactory);
        }
Ejemplo n.º 7
0
 public void ConvertDependenciesToStringWhenFrameworkSpecific()
 {
     Assert.Equal("Consul:[0.7.2.6, ):.NETStandard2.0|YamlDotNet:[5.1.0, ):.NETStandard2.0",
                  PackageExtensions.ToDependenciesString(new Core.Entities.PackageDependency[2] {
         new Core.Entities.PackageDependency()
         {
             Id = "Consul", VersionRange = "[0.7.2.6, )", TargetFramework = ".NETStandard2.0"
         },
         new Core.Entities.PackageDependency()
         {
             Id = "YamlDotNet", VersionRange = "[5.1.0, )", TargetFramework = ".NETStandard2.0"
         }
     }));
 }
            [InlineData(2)]    // SemVerLevelKey.SemVer2
            public void MapsBasicPackagePropertiesCorrectly(int?semVerLevelKey)
            {
                // Arrange
                var packages = new List <Package>
                {
                    CreateFakeBasePackage()
                }.AsQueryable();

                // Act
                var projected = PackageExtensions.ProjectV2FeedPackage(
                    packages,
                    siteRoot: "http://nuget.org",
                    includeLicenseReport: true,
                    semVerLevelKey: semVerLevelKey).ToList();

                // Assert
                var actual = projected.Single();

                Assert.Equal("Hitchhikers.Guide", actual.Id);
                Assert.Equal(420000, actual.DownloadCount);
                Assert.Equal("04.02-harmless", actual.Version);
                Assert.Equal("4.2.0-harmless", actual.NormalizedVersion);
                Assert.Equal("Life, The Universe, Everything", actual.Authors);
                Assert.Equal("Megadodo Publications", actual.Copyright);
                Assert.Equal(new DateTime(1971, 4, 2), actual.Created);
                Assert.Equal("A|B|C", actual.Dependencies);
                Assert.Equal("The standard repository for all knowledge and wisdom", actual.Description);
                Assert.Equal("http://notreal.example/foo.ico", actual.IconUrl);
                Assert.False(actual.IsLatestVersion);
                Assert.True(actual.IsAbsoluteLatestVersion);
                Assert.True(actual.IsPrerelease);
                Assert.Equal(new DateTime(2002, 4, 30), actual.LastUpdated);
                Assert.Equal("en-GB", actual.Language);
                Assert.Equal("abc123", actual.PackageHash);
                Assert.Equal("ROT13", actual.PackageHashAlgorithm);
                Assert.Equal(4200, actual.PackageSize);
                Assert.Equal("https://en.wikipedia.org/wiki/The_Hitchhiker%27s_Guide_to_the_Galaxy_(fictional)", actual.ProjectUrl);
                Assert.Equal("Mostly Harmless", actual.ReleaseNotes);
                Assert.True(actual.RequireLicenseAcceptance);
                Assert.Equal(new DateTime(1979, 10, 12), actual.Published);
                Assert.Equal("A truly remarkable book", actual.Summary);
                Assert.Equal("Guide, Harmless, Mostly", actual.Tags);
                Assert.Equal("The Hitchhiker's Guide to the Galaxy", actual.Title);
                Assert.Equal(421, actual.VersionDownloadCount);
                Assert.Equal("4.2.8", actual.MinClientVersion);
                Assert.Equal("https://blarg/", actual.LicenseUrl);
                Assert.Equal("Foo Public License, Some Other License", actual.LicenseNames);
                Assert.Equal("https://reporturl", actual.LicenseReportUrl);
            }
        /// <summary>
        /// Convert a V2 IPackage into a V3 PackageDependencyInfo
        /// </summary>
        private SourcePackageDependencyInfo CreateDependencyInfo(IPackage packageVersion, NuGetFramework projectFramework)
        {
            var deps = Enumerable.Empty <V3PackageDependency>();

            var identity = new PackageIdentity(packageVersion.Id, NuGetVersion.Parse(packageVersion.Version.ToString()));

            if (packageVersion.DependencySets != null &&
                packageVersion.DependencySets.Any())
            {
                // Take only the dependency group valid for the project TFM
                var nearestFramework = _frameworkReducer.GetNearest(projectFramework, packageVersion.DependencySets.Select(GetFramework));

                if (nearestFramework != null)
                {
                    var matches = packageVersion.DependencySets.Where(e => (GetFramework(e).Equals(nearestFramework)));
                    IEnumerable <PackageDependency> dependencies = matches.First().Dependencies;
                    deps = dependencies.Select(item => GetPackageDependency(item));
                }
            }

            SourcePackageDependencyInfo result = null;

            var dataPackage = packageVersion as DataServicePackage;

            if (dataPackage != null)
            {
                // Online package
                result = new SourcePackageDependencyInfo(
                    identity,
                    deps,
                    PackageExtensions.IsListed(packageVersion),
                    _source,
                    dataPackage.DownloadUrl,
                    dataPackage.PackageHash);
            }
            else
            {
                // Offline package
                result = new SourcePackageDependencyInfo(
                    identity,
                    deps,
                    PackageExtensions.IsListed(packageVersion),
                    _source,
                    downloadUri: null,
                    packageHash: null);
            }

            return(result);
        }
Ejemplo n.º 10
0
        public static void Main(string[] args)
        {
            try
            {
                var cnt = new SimpleInjector.Container();
                PackageExtensions.RegisterPackages(cnt, System.AppDomain.CurrentDomain.GetAssemblies());

                //
                //var options = new OptionSet {
                //    { "instance=", "append a tag onto the instance name, to allow multiple services to run", (string r) => cfg.ApplicationInstanceId = r },
                //};
                //var test = options.Parse(args);

                HostFactory.Run(c =>
                {
                    var cfg = cnt.GetInstance <IConfiguration>();
                    c.UseSimpleInjector(cnt);

                    // TODO: Will need to change this to run as user later...
                    c.RunAsLocalSystem();
                    var instanceOverride   = cfg.ApplicationInstanceName;
                    var serviceDisplayName = string.Format("{0} - {1}", cfg.ApplicationName, instanceOverride);
                    var serviceName        = string.Format("{0} - {1}", cfg.ApplicationName, instanceOverride);
                    var serviceDescription = string.Format("{0} - {1}", cfg.ApplicationName, instanceOverride);

                    c.SetDisplayName(serviceDisplayName);
                    c.SetServiceName(serviceName);
                    c.SetDescription(serviceDescription);
                    c.EnableServiceRecovery(rc =>
                    {
                        rc.RestartService(1); // restart the service after 1 minute
                        rc.RestartService(2); // restart the service after 2 minute
                        rc.RestartService(3); // restart the service after 3 minute
                        rc.SetResetPeriod(1); // set the reset interval to one day
                    });
                    c.Service <ISecureBootstrapListenerService>(srv =>
                    {
                        srv.ConstructUsingSimpleInjector();
                        srv.WhenStarted((service) => service.Start());
                        srv.WhenStopped((service) => service.Stop());
                    });
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception: {ex.Message} at {ex.StackTrace}");
            }
        }
Ejemplo n.º 11
0
        public PackageManifest GetManifest(PackageKey key, NuGet.Frameworks.NuGetFramework projectFramework)
        {
            if (key.Framework != null)
            {
                var fullPath = Path.Combine(RootPath, key.GetFileName());

                if (!File.Exists(fullPath))
                {
                    throw new FileNotFoundException("package not found");
                }

                using (IPackageReader reader = _packageReaderFactory.Get(RepositoryType.Pundit, File.OpenRead(fullPath)))
                    return(reader.ReadManifest());
            }

            // From here on, we resolve packages that come from a NuGet package and therefore, have no FW

            var filePattern = key.GetNoFrameworkFileName();

            var results = new DirectoryInfo(RootPath).GetFiles(filePattern).ToArray();

            if (results.Length == 0)
            {
                return(null);
            }

            var matches = 0;

            foreach (var info in results)
            {
                var tempKey   = PackageExtensions.GetPackageKeyFromFileName(info.Name);
                var nearestFw = NuGet.Frameworks.NuGetFrameworkUtility.GetNearest(new[] { new FakedFrameworkGroup(tempKey.Framework) }, projectFramework);

                if (nearestFw.TargetFramework.GetShortFolderName() == tempKey.Framework)
                {
                    matches++;
                }
            }

            if (matches != 1)
            {
                throw new NotSupportedException("Error, 0 or more than 1 package found matching the framework.");
            }

            using (IPackageReader reader = _packageReaderFactory.Get(RepositoryType.Pundit, File.OpenRead(results[0].FullName)))
                return(reader.ReadManifest());
        }
Ejemplo n.º 12
0
            public void ReturnsNullLicenseReportInfoIfFeatureDisabled()
            {
                // Arrange
                var packages = new List <Package>()
                {
                    CreateFakeBasePackage()
                }.AsQueryable();

                // Act
                var projected = PackageExtensions.ProjectV2FeedPackage(
                    packages,
                    siteRoot: "http://nuget.org",
                    includeLicenseReport: false).ToList();

                // Assert
                var actual = projected.Single();

                Assert.Null(actual.LicenseNames);
                Assert.Null(actual.LicenseReportUrl);
            }
Ejemplo n.º 13
0
            public void InjectsGalleryUrlsCorrectly()
            {
                // Arrange
                var packages = new List <Package>()
                {
                    CreateFakeBasePackage()
                }.AsQueryable();

                // Act
                var projected = PackageExtensions.ProjectV2FeedPackage(
                    packages,
                    siteRoot: "http://nuget.org",
                    includeLicenseReport: true).ToList();

                // Assert
                var actual = projected.Single();

                Assert.Equal("http://nuget.org/packages/Hitchhikers.Guide/4.2.0-harmless", actual.GalleryDetailsUrl);
                Assert.Equal("http://nuget.org/package/ReportAbuse/Hitchhikers.Guide/4.2.0-harmless", actual.ReportAbuseUrl);
            }
Ejemplo n.º 14
0
        public IEnumerable <PackageKey> Search(string substring)
        {
            foreach (var file in new DirectoryInfo(RootPath).GetFiles("*" + substring + "*"))
            {
                PackageKey key = null;

                try
                {
                    key = PackageExtensions.GetPackageKeyFromFileName(file.Name);
                }
                catch (ArgumentException)
                {
                }

                if (key != null)
                {
                    yield return(key);
                }
            }
        }
Ejemplo n.º 15
0
            public void InjectsDummyDateIfNotListed()
            {
                // Arrange
                var package = CreateFakeBasePackage();

                package.Listed = false;
                var packages = new List <Package>()
                {
                    package
                }.AsQueryable();

                // Act
                var projected = PackageExtensions.ProjectV2FeedPackage(
                    packages,
                    siteRoot: "http://nuget.org",
                    includeLicenseReport: true).ToList();

                // Assert
                var actual = projected.Single();

                Assert.Equal(PackageExtensions.UnpublishedDate, actual.Published);
            }
Ejemplo n.º 16
0
        private static void RegisterMappings()
        {
            // Packages

            TypeAdapterConfig <PackageSpec, XmlPackageSpec> .NewConfig()
            .Map(dst => dst.Platform, src => src.Framework.GetShortFolderName());

            TypeAdapterConfig <XmlPackageSpec, PackageSpec> .NewConfig()
            .Map(dst => dst.Framework, src => PackageExtensions.GetFramework(src.Platform));

            TypeAdapterConfig <PackageManifestRoot, XmlPackageManifestRoot> .NewConfig()
            .Map(dst => dst.Platform, src => src.Framework.GetShortFolderName());

            TypeAdapterConfig <XmlPackageManifestRoot, PackageManifestRoot> .NewConfig()
            .Map(dst => dst.Framework, src => PackageExtensions.GetFramework(src.Platform));

            TypeAdapterConfig <PackageManifest, XmlPackageManifest> .NewConfig()
            .Include <PackageSpec, XmlPackageSpec>()
            .Include <PackageManifestRoot, XmlPackageManifestRoot>()
            .Map(dst => dst.Version, src => src.Version.ToString())
            .Map(dst => dst.Platform, src => src.LegacyFramework);

            TypeAdapterConfig <XmlPackageManifest, PackageManifest> .NewConfig()
            .Include <XmlPackageSpec, PackageSpec>()
            .Include <XmlPackageManifestRoot, PackageManifestRoot>()
            .Map(dst => dst.Version, src => NuGet.Versioning.NuGetVersion.Parse(src.Version))
            .Map(dst => dst.LegacyFramework, src => src.Platform);

            TypeAdapterConfig <XmlPackageLegacyCrap, XmlPackageManifestRoot> .NewConfig();

            TypeAdapterConfig <XmlPackageLegacyCrap, XmlPackageSpec> .NewConfig();


            TypeAdapterConfig <PackageDependency, XmlPackageDependency> .NewConfig()
            .Map(dst => dst.VersionPattern, src => src.AllowedVersions.OriginalString)
            .Map(dst => dst.Platform, src => src.Framework);

            TypeAdapterConfig <XmlPackageDependency, PackageDependency> .NewConfig()
            .ConstructUsing(xml => new PackageDependency(xml.PackageId, VersionExtensions.GetVersionRangeFromDependency(xml.VersionPattern)))
            .Ignore(dst => dst.PackageId, src => src.AllowedVersions)
            .Map(dst => dst.Framework, src => src.Platform)
            .AfterMapping((src, dst) =>
            {
                if (src.DevTimeOnly)
                {
                    if (src.Scope == XmlDependencyScope.Normal)
                    {
                        dst.Scope = DependencyScope.Build;
                    }
                }
                else
                {
                    if (src.Scope != XmlDependencyScope.Normal)
                    {
                        dst.Scope = DependencyScope.Normal;
                    }
                }
            });

            TypeAdapterConfig <SourceFiles, XmlSourceFiles> .NewConfig();

            TypeAdapterConfig <XmlSourceFiles, SourceFiles> .NewConfig();

            TypeAdapterConfig <XmlRegisteredRepositories, RegisteredRepositories> .NewConfig();

            TypeAdapterConfig <XmlRegisteredRepository, RegisteredRepository> .NewConfig();

            TypeAdapterConfig <XmlRepositoryType, RepositoryType> .NewConfig();


            // PackagesManager
            TypeAdapterConfig <XmlInstalledPackagesIndex, InstalledPackagesIndex> .NewConfig()
            .ConstructUsing(src => new InstalledPackagesIndex(MapContext.Current.Parameters["location"].ToString()));

            TypeAdapterConfig <InstalledPackagesIndex, XmlInstalledPackagesIndex> .NewConfig();

            TypeAdapterConfig <XmlPackageKey, PackageKey> .NewConfig()
            .ConstructUsing(src => new PackageKey(src.PackageId, NuGet.Versioning.NuGetVersion.Parse(src.Version), src.Framework));

            TypeAdapterConfig <PackageKey, XmlPackageKey> .NewConfig()
            .Map(dst => dst.Version, src => src.Version.OriginalVersion);
        }
Ejemplo n.º 17
0
 public void ConvertDependenciesToStringWhenNull()
 {
     Assert.Null(PackageExtensions.ToDependenciesString(null));
 }
Ejemplo n.º 18
0
 public void ConvertDependenciesToStringWhenEmpty()
 {
     Assert.Null(PackageExtensions.ToDependenciesString(new Core.Entities.PackageDependency[0]));
 }