示例#1
0
        private static RepositoryMetadata ReadRepository(XElement element)
        {
            var repositoryType   = element.Attribute("type");
            var repositoryUrl    = element.Attribute("url");
            var repositoryBranch = element.Attribute("branch");
            var repositoryCommit = element.Attribute("commit");
            var repository       = new RepositoryMetadata();

            if (!string.IsNullOrEmpty(repositoryType?.Value))
            {
                repository.Type = repositoryType.Value;
            }
            if (!string.IsNullOrEmpty(repositoryUrl?.Value))
            {
                repository.Url    = repositoryUrl.Value;
                repository.Branch = repositoryBranch?.Value;
                repository.Commit = repositoryCommit?.Value;
            }

            // Ensure the value is valid before returning it.
            if (!string.IsNullOrEmpty(repository.Type) && !string.IsNullOrEmpty(repository.Url))
            {
                return(repository);
            }

            return(null);
        }
        private static XElement GetXElementFromManifestRepository(XNamespace ns, RepositoryMetadata repository)
        {
            var attributeList = new List <XAttribute>();

            if (repository != null && !string.IsNullOrEmpty(repository.Type))
            {
                attributeList.Add(new XAttribute(NuspecUtility.Type, repository.Type));
            }

            if (repository != null && !string.IsNullOrEmpty(repository.Url))
            {
                attributeList.Add(new XAttribute(NuspecUtility.RepositoryUrl, repository.Url));
            }

            if (!string.IsNullOrEmpty(repository?.Branch))
            {
                attributeList.Add(new XAttribute(NuspecUtility.RepositoryBranch, repository.Branch));
            }

            if (!string.IsNullOrEmpty(repository?.Commit))
            {
                attributeList.Add(new XAttribute(NuspecUtility.RepositoryCommit, repository.Commit));
            }

            if (attributeList.Count > 0)
            {
                return(new XElement(ns + NuspecUtility.Repository, attributeList));
            }
            return(null);
        }
 public RepositoryMetadataLog(RepositoryMetadata repositoryMetadata, DateTime creationDate, string packageId, string packageVersion)
 {
     CreationDate       = creationDate;
     PackageId          = packageId;
     PackageVersion     = packageVersion;
     RepositoryMetadata = repositoryMetadata;
 }
示例#4
0
        public PackageMetadata(
            Dictionary <string, string> metadata,
            IEnumerable <PackageDependencyGroup> dependencyGroups,
            IEnumerable <FrameworkSpecificGroup> frameworkGroups,
            IEnumerable <NuGet.Packaging.Core.PackageType> packageTypes,
            NuGetVersion minClientVersion,
            RepositoryMetadata repositoryMetadata,
            LicenseMetadata licenseMetadata = null)
        {
            _metadata                 = new Dictionary <string, string>(metadata, StringComparer.OrdinalIgnoreCase);
            _dependencyGroups         = dependencyGroups.ToList().AsReadOnly();
            _frameworkReferenceGroups = frameworkGroups.ToList().AsReadOnly();
            _packageTypes             = packageTypes.ToList().AsReadOnly();

            SetPropertiesFromMetadata();
            MinClientVersion = minClientVersion;

            if (repositoryMetadata != null)
            {
                Uri.TryCreate(repositoryMetadata.Url, UriKind.Absolute, out var repoUrl);
                RepositoryUrl  = repoUrl;
                RepositoryType = repositoryMetadata.Type;
            }

            LicenseMetadata = licenseMetadata;
        }
        public void CopyFrom(IPackageMetadata source)
        {
            Id         = source.Id;
            Version    = source.Version;
            Title      = source.Title;
            Authors    = ConvertToString(source.Authors);
            Owners     = ConvertToString(source.Owners);
            IconUrl    = FixIconUrl(source.IconUrl);
            LicenseUrl = source.LicenseUrl;
            ProjectUrl = source.ProjectUrl;
            RequireLicenseAcceptance = source.RequireLicenseAcceptance;
            DevelopmentDependency    = source.DevelopmentDependency;
            Description               = source.Description;
            Summary                   = source.Summary;
            ReleaseNotes              = source.ReleaseNotes;
            Copyright                 = source.Copyright;
            Language                  = source.Language;
            Tags                      = source.Tags;
            Serviceable               = source.Serviceable;
            DependencySets            = new ObservableCollection <PackageDependencyGroup>(source.DependencyGroups);
            FrameworkAssemblies       = new ObservableCollection <FrameworkAssemblyReference>(source.FrameworkReferences);
            PackageAssemblyReferences = new ObservableCollection <PackageReferenceSet>();
            ContentFiles              = new ObservableCollection <ManifestContentFiles>(source.ContentFiles);
            PackageTypes              = new ObservableCollection <PackageType>(source.PackageTypes);
            Repository                = source.Repository;

            if (source.PackageAssemblyReferences != null)
            {
                PackageAssemblyReferences.AddRange(source.PackageAssemblyReferences);
            }
            MinClientVersion = source.MinClientVersion;
        }
 protected static MemoryStream GeneratePackageStream(
     string version = "1.2.3-alpha.0",
     RepositoryMetadata repositoryMetadata = null,
     bool isSigned = true,
     int?desiredTotalEntryCount         = null,
     Func <string> getCustomNuspecNodes = null,
     Uri iconUrl                       = null,
     Uri licenseUrl                    = null,
     string licenseExpression          = null,
     string licenseFilename            = null,
     string licenseFileContents        = null,
     byte[] licenseFileBinaryContents  = null,
     string iconFilename               = null,
     byte[] iconFileBinaryContents     = null,
     IReadOnlyList <string> entryNames = null)
 {
     return(PackageServiceUtility.CreateNuGetPackageStream(
                id: PackageId,
                version: version,
                repositoryMetadata: repositoryMetadata,
                isSigned: isSigned,
                desiredTotalEntryCount: desiredTotalEntryCount,
                getCustomNuspecNodes: getCustomNuspecNodes,
                licenseUrl: licenseUrl,
                iconUrl: iconUrl,
                licenseExpression: licenseExpression,
                licenseFilename: licenseFilename,
                licenseFileContents: GetBinaryLicenseFileContents(licenseFileBinaryContents, licenseFileContents),
                iconFilename: iconFilename,
                iconFileBinaryContents: iconFileBinaryContents,
                entryNames: entryNames));
 }
        public void RepositoryMetadataDefaultConstructor()
        {
            var metadata = new RepositoryMetadata();

            Assert.Equal(string.Empty, metadata.Type);
            Assert.Equal(string.Empty, metadata.Url);
            Assert.Equal(string.Empty, metadata.Branch);
            Assert.Equal(string.Empty, metadata.Commit);
        }
示例#8
0
 private static string WriteRepositoryMetadata(RepositoryMetadata repositoryMetadata)
 {
     return(repositoryMetadata == null
         ? string.Empty
         : "<repository type=\"" + repositoryMetadata.Type + "\" " +
            "url =\"" + repositoryMetadata.Url + "\" " +
            "commit=\"" + repositoryMetadata.Commit + "\" " +
            "branch=\"" + repositoryMetadata.Branch + "\"/>");
 }
        public void TestExtractRepositoryMetadataCustomCorrectly()
        {
            var repositoryMetadata = new RepositoryMetadata(typeof(ICustomFakeRepository <FakeEntity, int>));
            var domainType         = repositoryMetadata.EntityType;
            var typeId             = repositoryMetadata.IdType;

            AssertExpectedObject(typeof(FakeEntity), domainType);
            AssertExpectedObject(typeof(int), typeId);
        }
示例#10
0
        public static MemoryStream CreateTestPackageStream(
            string id                     = "theId",
            string version                = "1.0.42",
            string title                  = "Package Id",
            string summary                = "Package Summary",
            string authors                = "Package author",
            string owners                 = "Package owners",
            string description            = "Package Description",
            string tags                   = "Package tags",
            string language               = null,
            string copyright              = null,
            string releaseNotes           = null,
            string minClientVersion       = null,
            Uri licenseUrl                = null,
            Uri projectUrl                = null,
            Uri iconUrl                   = null,
            bool requireLicenseAcceptance = false,
            IEnumerable <PackageDependencyGroup> packageDependencyGroups = null,
            IEnumerable <ClientPackageType> packageTypes = null,
            RepositoryMetadata repositoryMetadata        = null,
            Action <ZipArchive> populatePackage          = null,
            bool isSymbolPackage               = false,
            int?desiredTotalEntryCount         = null,
            Func <string> getCustomNuspecNodes = null,
            string licenseExpression           = null,
            string licenseFilename             = null,
            byte[] licenseFileContents         = null)
        {
            return(CreateTestPackageStream(packageArchive =>
            {
                var nuspecEntry = packageArchive.CreateEntry(id + ".nuspec", CompressionLevel.Fastest);
                using (var stream = nuspecEntry.Open())
                {
                    WriteNuspec(stream, true, id, version, title, summary, authors, owners, description, tags, language,
                                copyright, releaseNotes, minClientVersion, licenseUrl, projectUrl, iconUrl,
                                requireLicenseAcceptance, packageDependencyGroups, packageTypes, isSymbolPackage, repositoryMetadata,
                                getCustomNuspecNodes, licenseExpression, licenseFilename);
                }

                if (licenseFileContents != null && licenseFilename != null)
                {
                    // enforce directory separators the same way as the client (see PackageArchiveReader.GetStream)
                    licenseFilename = PathUtility.StripLeadingDirectorySeparators(licenseFilename);
                    var licenseEntry = packageArchive.CreateEntry(licenseFilename, CompressionLevel.Fastest);
                    using (var licenseStream = licenseEntry.Open())
                    {
                        licenseStream.Write(licenseFileContents, 0, licenseFileContents.Length);
                    }
                }

                if (populatePackage != null)
                {
                    populatePackage(packageArchive);
                }
            }, desiredTotalEntryCount));
        }
示例#11
0
        public static MemoryStream CreateTestPackageStream(
            string id                     = "theId",
            string version                = "1.0.42",
            string title                  = "Package Id",
            string summary                = "Package Summary",
            string authors                = "Package author",
            string owners                 = "Package owners",
            string description            = "Package Description",
            string tags                   = "Package tags",
            string language               = null,
            string copyright              = null,
            string releaseNotes           = null,
            string minClientVersion       = null,
            Uri licenseUrl                = null,
            Uri projectUrl                = null,
            Uri iconUrl                   = null,
            bool requireLicenseAcceptance = false,
            bool?developmentDependency    = null,
            IEnumerable <PackageDependencyGroup> packageDependencyGroups = null,
            IEnumerable <ClientPackageType> packageTypes = null,
            RepositoryMetadata repositoryMetadata        = null,
            Action <ZipArchive> populatePackage          = null,
            bool isSymbolPackage               = false,
            int?desiredTotalEntryCount         = null,
            Func <string> getCustomNuspecNodes = null,
            string licenseExpression           = null,
            string licenseFilename             = null,
            byte[] licenseFileContents         = null,
            string iconFilename       = null,
            byte[] iconFileContents   = null,
            string readmeFilename     = null,
            byte[] readmeFileContents = null)
        {
            return(CreateTestPackageStream(packageArchive =>
            {
                var nuspecEntry = packageArchive.CreateEntry(id + ".nuspec", CompressionLevel.Fastest);
                using (var stream = nuspecEntry.Open())
                {
                    WriteNuspec(stream, true, id, version, title, summary, authors, owners, description, tags, language,
                                copyright, releaseNotes, minClientVersion, licenseUrl, projectUrl, iconUrl,
                                requireLicenseAcceptance, developmentDependency, packageDependencyGroups, packageTypes, isSymbolPackage, repositoryMetadata,
                                getCustomNuspecNodes, licenseExpression, licenseFilename, iconFilename, readmeFilename);
                }

                licenseFilename = AddBinaryFile(packageArchive, licenseFilename, licenseFileContents);
                iconFilename = AddBinaryFile(packageArchive, iconFilename, iconFileContents);
                readmeFilename = AddBinaryFile(packageArchive, readmeFilename, readmeFileContents);

                if (populatePackage != null)
                {
                    populatePackage(packageArchive);
                }
            }, desiredTotalEntryCount));
        }
示例#12
0
        public RepositoryMetadataViewModel(RepositoryMetadata metadata)
        {
            if (metadata is null)
            {
                throw new ArgumentNullException(nameof(metadata));
            }

            Type   = metadata.Type;
            Url    = metadata.Url;
            Branch = metadata.Branch;
            Commit = metadata.Commit;
        }
示例#13
0
 protected static Mock <TestPackageReader> GeneratePackage(
     string version = "1.2.3-alpha.0",
     RepositoryMetadata repositoryMetadata = null,
     bool isSigned = true,
     int?desiredTotalEntryCount = null)
 {
     return(PackageServiceUtility.CreateNuGetPackage(
                id: "theId",
                version: version,
                repositoryMetadata: repositoryMetadata,
                isSigned: isSigned,
                desiredTotalEntryCount: desiredTotalEntryCount));
 }
        public void RepositoryMetadataEquals(RepositoryMetadata metadata1, RepositoryMetadata metadata2, bool equals)
        {
            Assert.Equal(equals, metadata1 == metadata2);
            Assert.NotEqual(equals, metadata1 != metadata2);

            if (metadata1 != null)
            {
                Assert.Equal(equals, metadata1.Equals(metadata2));
            }
            if (metadata1 != null && metadata2 != null)
            {
                Assert.Equal(equals, metadata1.GetHashCode() == metadata2.GetHashCode());
            }
        }
示例#15
0
        /// <summary>
        /// Source control repository information.
        /// </summary>
        public RepositoryMetadata GetRepositoryMetadata()
        {
            var repository = new RepositoryMetadata();
            var node       = MetadataNode.Elements(XName.Get(Repository, MetadataNode.GetDefaultNamespace().NamespaceName)).FirstOrDefault();

            if (node != null)
            {
                repository.Type   = GetAttributeValue(node, "type") ?? string.Empty;
                repository.Url    = GetAttributeValue(node, "url") ?? string.Empty;
                repository.Branch = GetAttributeValue(node, "branch") ?? string.Empty;
                repository.Commit = GetAttributeValue(node, "commit") ?? string.Empty;
            }

            return(repository);
        }
 protected static Mock <TestPackageReader> GeneratePackage(
     string version = "1.2.3-alpha.0",
     RepositoryMetadata repositoryMetadata = null,
     bool isSigned = true,
     int?desiredTotalEntryCount         = null,
     IReadOnlyList <string> entryNames  = null,
     Func <string> getCustomNuspecNodes = null)
 => GeneratePackageWithUserContent(
     version: version,
     repositoryMetadata: repositoryMetadata,
     isSigned: isSigned,
     desiredTotalEntryCount: desiredTotalEntryCount,
     getCustomNuspecNodes: getCustomNuspecNodes,
     licenseUrl: new Uri("https://licenses.nuget.org/MIT"),
     licenseExpression: "MIT",
     licenseFilename: null,
     licenseFileContents: null,
     licenseFileBinaryContents: null,
     entryNames: entryNames);
示例#17
0
        public static Stream CreateTestPackageStream(
            string id,
            string version,
            string title                  = "Package Id",
            string summary                = "Package Summary",
            string authors                = "Package author",
            string owners                 = "Package owners",
            string description            = "Package Description",
            string tags                   = "Package tags",
            string language               = null,
            string copyright              = null,
            string releaseNotes           = null,
            string minClientVersion       = null,
            Uri licenseUrl                = null,
            Uri projectUrl                = null,
            Uri iconUrl                   = null,
            bool requireLicenseAcceptance = false,
            IEnumerable <PackageDependencyGroup> packageDependencyGroups = null,
            IEnumerable <ClientPackageType> packageTypes = null,
            RepositoryMetadata repositoryMetadata        = null,
            Action <ZipArchive> populatePackage          = null,
            bool isSymbolPackage       = false,
            int?desiredTotalEntryCount = null)
        {
            return(CreateTestPackageStream(packageArchive =>
            {
                var nuspecEntry = packageArchive.CreateEntry(id + ".nuspec", CompressionLevel.Fastest);
                using (var stream = nuspecEntry.Open())
                {
                    WriteNuspec(stream, true, id, version, title, summary, authors, owners, description, tags, language,
                                copyright, releaseNotes, minClientVersion, licenseUrl, projectUrl, iconUrl,
                                requireLicenseAcceptance, packageDependencyGroups, packageTypes, isSymbolPackage, repositoryMetadata);
                }

                if (populatePackage != null)
                {
                    populatePackage(packageArchive);
                }
            }, desiredTotalEntryCount));
        }
            protected static Mock <TestPackageReader> GeneratePackageWithUserContent(
                string version = "1.2.3-alpha.0",
                RepositoryMetadata repositoryMetadata = null,
                bool isSigned = true,
                int?desiredTotalEntryCount         = null,
                Func <string> getCustomNuspecNodes = null,
                Uri iconUrl                       = null,
                Uri licenseUrl                    = null,
                string licenseExpression          = null,
                string licenseFilename            = null,
                string licenseFileContents        = null,
                byte[] licenseFileBinaryContents  = null,
                string iconFilename               = null,
                byte[] iconFileBinaryContents     = null,
                string readmeFilename             = null,
                string readmeFileContents         = null,
                byte[] readmeFileBinaryContents   = null,
                IReadOnlyList <string> entryNames = null)
            {
                var packageStream = GeneratePackageStream(
                    version: version,
                    repositoryMetadata: repositoryMetadata,
                    isSigned: isSigned,
                    desiredTotalEntryCount: desiredTotalEntryCount,
                    getCustomNuspecNodes: getCustomNuspecNodes,
                    iconUrl: iconUrl,
                    licenseUrl: licenseUrl,
                    licenseExpression: licenseExpression,
                    licenseFilename: licenseFilename,
                    licenseFileContents: licenseFileContents,
                    licenseFileBinaryContents: licenseFileBinaryContents,
                    iconFilename: iconFilename,
                    iconFileBinaryContents: iconFileBinaryContents,
                    readmeFilename: readmeFilename,
                    readmeFileContents: readmeFileContents,
                    readmeFileBinaryContents: readmeFileBinaryContents,
                    entryNames: entryNames);

                return(PackageServiceUtility.CreateNuGetPackage(packageStream));
            }
        public static Mock <TestPackageReader> CreateNuGetPackage(
            string id                     = "theId",
            string version                = "01.0.42.0",
            string title                  = "theTitle",
            string summary                = "theSummary",
            string authors                = "theFirstAuthor, theSecondAuthor",
            string owners                 = "Package owners",
            string description            = "theDescription",
            string tags                   = "theTags",
            string language               = null,
            string copyright              = "theCopyright",
            string releaseNotes           = "theReleaseNotes",
            string minClientVersion       = null,
            Uri licenseUrl                = null,
            Uri projectUrl                = null,
            Uri iconUrl                   = null,
            bool requireLicenseAcceptance = true,
            bool?developmentDependency    = true,
            IEnumerable <PackageDependencyGroup> packageDependencyGroups = null,
            IEnumerable <NuGet.Packaging.Core.PackageType> packageTypes  = null,
            RepositoryMetadata repositoryMetadata = null,
            bool isSigned = false,
            int?desiredTotalEntryCount         = null,
            Func <string> getCustomNuspecNodes = null,
            string licenseExpression           = null,
            string licenseFilename             = null,
            byte[] licenseFileContents         = null)
        {
            var testPackage = CreateNuGetPackageStream(id, version, title,
                                                       summary, authors, owners, description, tags, language,
                                                       copyright, releaseNotes, minClientVersion, licenseUrl, projectUrl,
                                                       iconUrl, requireLicenseAcceptance, developmentDependency, packageDependencyGroups,
                                                       packageTypes, repositoryMetadata, isSigned, desiredTotalEntryCount,
                                                       getCustomNuspecNodes, licenseExpression, licenseFilename,
                                                       licenseFileContents);

            return(CreateNuGetPackage(testPackage));
        }
示例#20
0
        public static void AddMetadata(FileInfo fileInfo, int fileId)
        {
            string ext = Util.GetFileExtension(fileInfo.Extension);

            List <string> txt = new List <string> {
                "Length", "Name", "CreationTime", "IsReadOnly", "LastAccessTime", "LastWriteTime", "Attributes"
            };
            List <string> jpg = new List <string> {
                "Length", "Name", "CreationTime", "IsReadOnly", "LastAccessTime", "LastWriteTime", "Attributes"
            };
            List <string> pdf = new List <string> {
                "Length", "Name", "CreationTime", "IsReadOnly", "LastAccessTime", "LastWriteTime", "Attributes"
            };

            //if the set of metadatas for the new extension does not exist in the database use the defaultList of metadata
            List <string> defaultList = new List <string> {
                "Length", "Name", "CreationTime", "IsReadOnly", "LastAccessTime", "LastWriteTime", "Attributes"
            };


            //all the metadata extensions
            Dictionary <string, List <string> > extensions = new Dictionary <string, List <string> >()
            {
                { "default", defaultList },
                { "txt", txt },
                { "jpg", jpg },
                { "pdf", pdf }
            };

            ext = extensions.ContainsKey(ext) ? ext : "default";
            foreach (string metadataTypeName in extensions[ext])
            {
                var metadata = new Model.Metadata();
                metadata.Value = ReflectPropertyValuefileInfo(fileInfo, metadataTypeName).ToString();

                RepositoryMetadata.SaveMetadataToDb(metadata, GetMetadataTypeId(metadataTypeName), fileId);
            }
        }
示例#21
0
        private static RepositoryMetadata ReadRepository(XElement element)
        {
            var repositoryType = element.Attribute("type");
            var repositoryUrl  = element.Attribute("url");
            var repository     = new RepositoryMetadata();

            if (!string.IsNullOrEmpty(repositoryType?.Value))
            {
                repository.Type = repositoryType.Value;
            }
            if (!string.IsNullOrEmpty(repositoryUrl?.Value))
            {
                repository.Url = repositoryUrl.Value;
            }
            if (string.IsNullOrEmpty(repository.Type) && string.IsNullOrEmpty(repository.Type))
            {
                return(null);
            }
            else
            {
                return(repository);
            }
        }
示例#22
0
        public HttpResponseMessage GetFileLevelMetadata(int fileId, int repositoryId)
        {
            List <FileLevelMetadata> fileLevelMetadataList = new List <FileLevelMetadata>();

            DM.File file = fileService.GetFileByFileId(fileId);
            if (file == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, MessageStrings.FileNotFound));
            }

            DM.Repository repository = this.repositoryService.GetRepositoryById(repositoryId);
            if (repository == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, MessageStrings.Repository_Not_Found));
            }

            if (repository.RepositoryMetadata == null || !repository.RepositoryMetadata.Any())
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, MessageStrings.NoMetadataFould));
            }

            RepositoryMetadata repositoryMetadata = repository.RepositoryMetadata.FirstOrDefault(m => m.IsActive == true);

            if (repositoryMetadata == null || repositoryMetadata.RepositoryMetadataFields == null || !repositoryMetadata.RepositoryMetadataFields.Any())
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, MessageStrings.NoMetadataFould));
            }

            file.RepositoryId = repositoryId;
            foreach (RepositoryMetadataField repositoryMetadataField in repositoryMetadata.RepositoryMetadataFields)
            {
                FileLevelMetadata fileLevelMetadata = new FileLevelMetadata()
                {
                    RepositoryMetadataId      = repositoryMetadataField.RepositoryMetadataId,
                    RepositoryMetadataFieldId = repositoryMetadataField.RepositoryMetadataFieldId,
                    MetaDataTypeId            = repositoryMetadataField.MetadataTypeId,
                    FieldName   = repositoryMetadataField.Name,
                    Description = repositoryMetadataField.Description,
                    IsRequired  = repositoryMetadataField.IsRequired,
                    Datatype    = repositoryMetadataField.MetadataTypeId.ToString()
                };

                if (!string.IsNullOrWhiteSpace(repositoryMetadataField.Range))
                {
                    float[] range = repositoryMetadataField.Range.Split(new string[] { Constants.RangeSeparator }, StringSplitOptions.RemoveEmptyEntries).Select(v => Convert.ToSingle(v)).ToArray();
                    fileLevelMetadata.RangeValues = range;
                }

                FileMetadataField fileMetadataField = null;
                // first try to get the values from the database
                if (file.FileMetadataFields != null && file.FileMetadataFields.Any())
                {
                    fileMetadataField = file.FileMetadataFields.Where(p => p.RepositoryMetadataFieldId == repositoryMetadataField.RepositoryMetadataFieldId).FirstOrDefault();
                }

                if (fileMetadataField != null)
                {
                    fileLevelMetadata.FileMetadataFieldId = fileMetadataField.FileMetadataFieldId;
                    fileLevelMetadata.FieldValue          = fileMetadataField.MetadataValue;
                }

                fileLevelMetadataList.Add(fileLevelMetadata);
            }

            return(Request.CreateResponse(HttpStatusCode.OK, fileLevelMetadataList));
        }
示例#23
0
        public static void WriteNuspec(
            Stream stream,
            bool leaveStreamOpen,
            string id,
            string version,
            string title                  = "Package Id",
            string summary                = "Package Summary",
            string authors                = "Package author",
            string owners                 = "Package owners",
            string description            = "Package Description",
            string tags                   = "Package tags",
            string language               = null,
            string copyright              = null,
            string releaseNotes           = null,
            string minClientVersion       = null,
            Uri licenseUrl                = null,
            Uri projectUrl                = null,
            Uri iconUrl                   = null,
            bool requireLicenseAcceptance = false,
            IEnumerable <PackageDependencyGroup> packageDependencyGroups = null,
            IEnumerable <ClientPackageType> packageTypes = null,
            bool isSymbolPackage = false,
            RepositoryMetadata repositoryMetadata = null)
        {
            var fullNuspec = (@"<?xml version=""1.0""?>
                <package xmlns=""http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"">
                    <metadata" + (!string.IsNullOrEmpty(minClientVersion) ? @" minClientVersion=""" + minClientVersion + @"""" : string.Empty) + @">
                        <id>" + id + @"</id>
                        <version>" + version + @"</version>
                        <title>" + title + @"</title>
                        <summary>" + summary + @"</summary>
                        <description>" + description + @"</description>
                        <tags>" + tags + @"</tags>
                        <requireLicenseAcceptance>" + requireLicenseAcceptance + @"</requireLicenseAcceptance>
                        <authors>" + authors + @"</authors>
                        <owners>" + owners + @"</owners>
                        <language>" + (language ?? string.Empty) + @"</language>
                        <copyright>" + (copyright ?? string.Empty) + @"</copyright>
                        <releaseNotes>" + (releaseNotes ?? string.Empty) + @"</releaseNotes>
                        <licenseUrl>" + (licenseUrl?.ToString() ?? string.Empty) + @"</licenseUrl>
                        <projectUrl>" + (projectUrl?.ToString() ?? string.Empty) + @"</projectUrl>
                        <iconUrl>" + (iconUrl?.ToString() ?? string.Empty) + @"</iconUrl>
                        <packageTypes>" + WritePackageTypes(packageTypes) + @"</packageTypes>
                        <dependencies>" + WriteDependencies(packageDependencyGroups) + @"</dependencies>
                        " + WriteRepositoryMetadata(repositoryMetadata) + @"
                    </metadata>
                </package>");

            var symbolNuspec = (@"<?xml version=""1.0""?>
                    <package xmlns=""http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"">
                        <metadata" + (!string.IsNullOrEmpty(minClientVersion) ? @" minClientVersion=""" + minClientVersion + @"""" : string.Empty) + @">
                            <id>" + id + @"</id>
                            <version>" + version + @"</version>
                            <description>" + description + @"</description>
                            <requireLicenseAcceptance>" + requireLicenseAcceptance + @"</requireLicenseAcceptance>
                            <packageTypes>" + WritePackageTypes(packageTypes) + @"</packageTypes>
                        </metadata>
                    </package>");

            using (var streamWriter = new StreamWriter(stream, new UTF8Encoding(false, true), 1024, leaveStreamOpen))
            {
                streamWriter.WriteLine(isSymbolPackage ? symbolNuspec : fullNuspec);
            }
        }
示例#24
0
 public static List <Metadata> GetMetadataByType(int metadataTypeId)
 {
     return(RepositoryMetadata.GetMetadataByType(metadataTypeId));
 }
示例#25
0
        public static MemoryStream CreateNuGetPackageStream(string id                     = "theId",
                                                            string version                = "01.0.42.0",
                                                            string title                  = "theTitle",
                                                            string summary                = "theSummary",
                                                            string authors                = "theFirstAuthor, theSecondAuthor",
                                                            string owners                 = "Package owners",
                                                            string description            = "theDescription",
                                                            string tags                   = "theTags",
                                                            string language               = null,
                                                            string copyright              = "theCopyright",
                                                            string releaseNotes           = "theReleaseNotes",
                                                            string minClientVersion       = null,
                                                            Uri licenseUrl                = null,
                                                            Uri projectUrl                = null,
                                                            Uri iconUrl                   = null,
                                                            bool requireLicenseAcceptance = true,
                                                            bool?developmentDependency    = true,
                                                            IEnumerable <PackageDependencyGroup> packageDependencyGroups = null,
                                                            IEnumerable <NuGet.Packaging.Core.PackageType> packageTypes  = null,
                                                            RepositoryMetadata repositoryMetadata = null,
                                                            bool isSigned = false,
                                                            int?desiredTotalEntryCount         = null,
                                                            Func <string> getCustomNuspecNodes = null,
                                                            string licenseExpression           = null,
                                                            string licenseFilename             = null,
                                                            byte[] licenseFileContents         = null,
                                                            string iconFilename               = null,
                                                            byte[] iconFileBinaryContents     = null,
                                                            string readmeFilename             = null,
                                                            byte[] readmeFileContents         = null,
                                                            IReadOnlyList <string> entryNames = null)
        {
            if (packageDependencyGroups == null)
            {
                packageDependencyGroups = new[]
                {
                    new PackageDependencyGroup(
                        new NuGetFramework("net40"),
                        new[]
                    {
                        new NuGet.Packaging.Core.PackageDependency(
                            "theFirstDependency",
                            VersionRange.Parse("[1.0.0, 2.0.0)")),

                        new NuGet.Packaging.Core.PackageDependency(
                            "theSecondDependency",
                            VersionRange.Parse("[1.0]")),

                        new NuGet.Packaging.Core.PackageDependency(
                            "theThirdDependency")
                    }),

                    new PackageDependencyGroup(
                        new NuGetFramework("net35"),
                        new[]
                    {
                        new NuGet.Packaging.Core.PackageDependency(
                            "theFourthDependency",
                            VersionRange.Parse("[1.0]"))
                    })
                };
            }

            if (packageTypes == null)
            {
                packageTypes = new[]
                {
                    new NuGet.Packaging.Core.PackageType("dependency", new Version("1.0.0")),
                    new NuGet.Packaging.Core.PackageType("DotNetCliTool", new Version("2.1.1"))
                };
            }

            return(TestPackage.CreateTestPackageStream(
                       id, version, title, summary, authors, owners,
                       description, tags, language, copyright, releaseNotes,
                       minClientVersion, licenseUrl, projectUrl, iconUrl,
                       requireLicenseAcceptance, developmentDependency,
                       packageDependencyGroups, packageTypes, repositoryMetadata,
                       archive =>
            {
                if (isSigned)
                {
                    var entry = archive.CreateEntry(SigningSpecifications.V1.SignaturePath);
                    using (var stream = entry.Open())
                        using (var writer = new StreamWriter(stream))
                        {
                            writer.Write("Fake signature file.");
                        }
                }

                if (entryNames != null)
                {
                    foreach (var entryName in entryNames)
                    {
                        WriteEntry(archive, entryName);
                    }
                }
            },
                       desiredTotalEntryCount: desiredTotalEntryCount,
                       getCustomNuspecNodes: getCustomNuspecNodes,
                       licenseExpression: licenseExpression,
                       licenseFilename: licenseFilename,
                       licenseFileContents: licenseFileContents,
                       iconFilename: iconFilename,
                       iconFileContents: iconFileBinaryContents,
                       readmeFilename: readmeFilename,
                       readmeFileContents: readmeFileContents));
        }
 public static void SaveMetadataIntoDb(Metadata metadata, string metadataTypeName, int fileId)
 {
     RepositoryMetadata.SaveMetadataToDb(metadata, GetMetadataTypeId(metadataTypeName), fileId);
 }
 public static List <Metadata> GetAllMetadaForFile()
 {
     return(RepositoryMetadata.GetAllMetadataFiles());
 }
 public static List <int> GetListOfMetadataId(string nameOfMetadata, string valueOfMetadata)
 {
     return(RepositoryMetadata.GetListOfMetadataId(nameOfMetadata, valueOfMetadata));
 }
示例#29
0
        public static Mock <TestPackageReader> CreateNuGetPackage(
            string id                     = "theId",
            string version                = "01.0.42.0",
            string title                  = "theTitle",
            string summary                = "theSummary",
            string authors                = "theFirstAuthor, theSecondAuthor",
            string owners                 = "Package owners",
            string description            = "theDescription",
            string tags                   = "theTags",
            string language               = null,
            string copyright              = "theCopyright",
            string releaseNotes           = "theReleaseNotes",
            string minClientVersion       = null,
            Uri licenseUrl                = null,
            Uri projectUrl                = null,
            Uri iconUrl                   = null,
            bool requireLicenseAcceptance = true,
            IEnumerable <PackageDependencyGroup> packageDependencyGroups = null,
            IEnumerable <NuGet.Packaging.Core.PackageType> packageTypes  = null,
            RepositoryMetadata repositoryMetadata = null,
            bool isSigned = false,
            int?desiredTotalEntryCount = null)
        {
            if (packageDependencyGroups == null)
            {
                packageDependencyGroups = new[]
                {
                    new PackageDependencyGroup(
                        new NuGetFramework("net40"),
                        new[]
                    {
                        new NuGet.Packaging.Core.PackageDependency(
                            "theFirstDependency",
                            VersionRange.Parse("[1.0.0, 2.0.0)")),

                        new NuGet.Packaging.Core.PackageDependency(
                            "theSecondDependency",
                            VersionRange.Parse("[1.0]")),

                        new NuGet.Packaging.Core.PackageDependency(
                            "theThirdDependency")
                    }),

                    new PackageDependencyGroup(
                        new NuGetFramework("net35"),
                        new[]
                    {
                        new NuGet.Packaging.Core.PackageDependency(
                            "theFourthDependency",
                            VersionRange.Parse("[1.0]"))
                    })
                };
            }

            if (packageTypes == null)
            {
                packageTypes = new[]
                {
                    new NuGet.Packaging.Core.PackageType("dependency", new Version("1.0.0")),
                    new NuGet.Packaging.Core.PackageType("DotNetCliTool", new Version("2.1.1"))
                };
            }

            var testPackage = TestPackage.CreateTestPackageStream(
                id, version, title, summary, authors, owners,
                description, tags, language, copyright, releaseNotes,
                minClientVersion, licenseUrl, projectUrl, iconUrl,
                requireLicenseAcceptance, packageDependencyGroups, packageTypes, repositoryMetadata,
                archive =>
            {
                if (isSigned)
                {
                    var entry = archive.CreateEntry(SigningSpecifications.V1.SignaturePath);
                    using (var stream = entry.Open())
                        using (var writer = new StreamWriter(stream))
                        {
                            writer.Write("Fake signature file.");
                        }
                }
            }, desiredTotalEntryCount: desiredTotalEntryCount);

            var mock = new Mock <TestPackageReader>(testPackage);

            mock.CallBase = true;
            return(mock);
        }