Esempio n. 1
0
        public bool VersionHigherThan(Package entity)
        {
            if (string.IsNullOrWhiteSpace(Version))
                return false;
            if (string.IsNullOrWhiteSpace(entity.Version))
                return true;

            string[] currVersion = Version.Split('.', '-');
            string[] otherVersion = entity.Version.Split('.', '-');

            int maxSteps = Math.Max(currVersion.Length, otherVersion.Length);

            for (int i = 0; i < maxSteps; i++)
            {
                if (i >= currVersion.Length)
                    return false;
                if (i >= otherVersion.Length)
                    return true;

                int currVersionNum = -1;
                int otherVersionNum = -1;

                if (int.TryParse(currVersion[i], out currVersionNum) == false)
                    return false;
                if (int.TryParse(otherVersion[i], out otherVersionNum) == false)
                    return true;

                if (currVersionNum < otherVersionNum)
                    return false;
                if (otherVersionNum < currVersionNum)
                    return true;
            }

            return true;
        }
Esempio n. 2
0
        private static string GetDetails(HttpRequestMessage request, Package package)
        {
            entry entry = GetPackageEntry(package, request.RequestUri);

            XmlSerializer serializer = new XmlSerializer(typeof(entry));
            MemoryStream ms = new MemoryStream();
            serializer.Serialize(ms, entry);
            ms.Position = 0;
            string result = new StreamReader(ms).ReadToEnd();
            return result;
        }
        private static string GetDetailsResult(Package package, Uri uri)
        {
            entry entry = PackageDetails.GetPackageEntry(package, uri);

            XmlSerializer serializer = new XmlSerializer(typeof(entry));
            MemoryStream ms = new MemoryStream();
            serializer.Serialize(ms, entry);
            ms.Position = 0;
            string result = new StreamReader(ms).ReadToEnd();
            return result;
        }
Esempio n. 4
0
        public static entry GetPackageEntry(Package package, Uri uri)
        {
            if (package == null)
                return null;

            string baseUri = uri.Scheme + "://" + uri.Host + ":" + uri.Port;
            string apiUri = baseUri + "/api/v2/";

            string dependencies = package.Dependencies != null
                                      ? string.Join("|", package.Dependencies.Select(d => d.Id + ":" + d.Version))
                                      : "";
            
            entry entry = new entry
            {
                @base = apiUri,
                id = WebUtility.HtmlDecode(uri.ToString()),
                category = new entryCategory(),
                link = new[]
                {
                    new entryLink("edit", "Packages(Id='" + package.Title + "',Version='" + package.Version + "')"),
                    new entryLink("edit-media",
                                  "Packages(Id='" + package.Title + "',Version='" + package.Version + "')/$value")
                },
                title = new entryTitle(package.Title),
                summary = new entrySummary(package.Description),
                updated = package.DateUpdated.ToString("O"),
                author = new entryAuthor(package.Authors),
                content = new entryContent(apiUri + "package/" + package.Title + "/" + package.Version),
                properties = new properties
                {
                    Version = package.Version,
                    NormalizedVersion = package.Version,
                    Copyright = package.Copyright,
                    Created = new Created(package.DateCreated.ToString("o")),
                    Dependencies = dependencies,
                    Description = package.Description,
                    DownloadCount = new DownloadCount(1),
                    GalleryDetailsUrl = baseUri + "/packages/" + package.Title + "/" + package.Version,
                    IconUrl = package.IconUrl,
                    IsLatestVersion = new IsLatestVersion(package.LatestVersion),
                    IsAbsoluteLatestVersion = new IsAbsoluteLatestVersion(package.LatestVersion),
                    IsPrerelease = new IsPrerelease(package.IsPrerelease),
                    Language = package.Language,
                    Published = new Published(package.DateCreated.ToString("o")),
                    PackageHash = package.PackageHash,
                    PackageHashAlgorithm = "SHA512",
                    PackageSize = new PackageSize(Convert.ToUInt32(package.PackageSize)),
                    ProjectUrl = package.ProjectUrl,
                    ReportAbuseUrl = baseUri + "/package/ReportAbuse/" + package.Title + "/" + package.Version,
                    ReleaseNotes = package.ReleaseNotes,
                    RequireLicenseAcceptance = new RequireLicenseAcceptance(package.RequireLicenseAcceptance),
                    Tags = string.Join(" ", package.Tags),
                    Title = package.PackageTitle,
                    VersionDownloadCount = new VersionDownloadCount(0),
                    MinClientVersion = new MinClientVersion(),
                    LastEdited = new LastEdited(),
                    LicenseUrl = package.LicenseUrl,
                    LicenseNames = new LicenseNames(),
                    LicenseReportUrl = new LicenseReportUrl()
                }
            };

            return entry;
        }