Esempio n. 1
0
        private static XElement ToODataEntryXElement(ODataPackage package, Uri baseUri)
        {
            string     nsAtom        = "http://www.w3.org/2005/Atom";
            XNamespace nsDataService = "http://schemas.microsoft.com/ado/2007/08/dataservices";
            string     nsMetadata    = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";
            string     downloadUrl   = string.Format(
                CultureInfo.InvariantCulture,
                "{0}package/{1}/{2}", baseUri, package.Id, NuGetVersionUtility.NormalizeVersion(package.Version));
            string entryId = string.Format(
                CultureInfo.InvariantCulture,
                "{0}Packages(Id='{1}',Version='{2}')",
                baseUri, package.Id, NuGetVersionUtility.NormalizeVersion(package.Version));

            const string FeedDateTimeFormat = "yyyy-MM-ddTHH:mm:ss.FFF";

            var entry = new XElement(XName.Get("entry", nsAtom),
                                     new XAttribute(XNamespace.Xmlns + "d", nsDataService.ToString()),
                                     new XAttribute(XNamespace.Xmlns + "m", nsMetadata),
                                     new XElement(XName.Get("id", nsAtom), entryId),
                                     new XElement(XName.Get("title", nsAtom), package.Id),
                                     new XElement(XName.Get("content", nsAtom),
                                                  new XAttribute("type", "application/zip"),
                                                  new XAttribute("src", downloadUrl)),
                                     new XElement(XName.Get("properties", nsMetadata),
                                                  new XElement(nsDataService + "Id", package.Id),
                                                  new XElement(nsDataService + "NormalizedVersion", package.Version),
                                                  new XElement(nsDataService + "Version", package.Version),
                                                  new XElement(nsDataService + "PackageHash", "dummy"),
                                                  new XElement(nsDataService + "PackageHashAlgorithm", "dummy"),
                                                  new XElement(nsDataService + "Description", package.Description),
                                                  new XElement(nsDataService + "Listed", package.Listed),


                                                  new XElement(nsDataService + "Created", package.Created.ToString(FeedDateTimeFormat)),
                                                  new XElement(nsDataService + "LastEdited", package.LastEdited?.ToString(FeedDateTimeFormat)),
                                                  new XElement(nsDataService + "Published", package.Published.ToString(FeedDateTimeFormat)),
                                                  new XElement(nsDataService + "LicenseNames", package.LicenseNames),
                                                  new XElement(nsDataService + "LicenseReportUrl", package.LicenseReportUrl)));

            return(entry);
        }
        private static XElement ToODataEntryXElement(ODataPackage package, Uri baseUri)
        {
            string nsAtom = "http://www.w3.org/2005/Atom";
            XNamespace nsDataService = "http://schemas.microsoft.com/ado/2007/08/dataservices";
            string nsMetadata = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";
            string downloadUrl = string.Format(
                CultureInfo.InvariantCulture,
                "{0}package/{1}/{2}", baseUri, package.Id, package.Version);
            string entryId = string.Format(
                CultureInfo.InvariantCulture,
                "{0}Packages(Id='{1}',Version='{2}')",
                baseUri, package.Id, package.Version);

            var entry = new XElement(XName.Get("entry", nsAtom),
                new XAttribute(XNamespace.Xmlns + "d", nsDataService.ToString()),
                new XAttribute(XNamespace.Xmlns + "m", nsMetadata),
                new XElement(XName.Get("id", nsAtom), entryId),
                new XElement(XName.Get("title", nsAtom), package.Id),
                new XElement(XName.Get("content", nsAtom),
                    new XAttribute("type", "application/zip"),
                    new XAttribute("src", downloadUrl)),
                new XElement(XName.Get("properties", nsMetadata),
                    new XElement(nsDataService + "Version", package.Version),
                    new XElement(nsDataService + "PackageHash", "dummy"),
                    new XElement(nsDataService + "PackageHashAlgorithm", "dummy"),
                    new XElement(nsDataService + "Description", package.Description),
                    new XElement(nsDataService + "Listed", package.Listed),


                    new XElement(nsDataService + "Created", package.Created),
                    new XElement(nsDataService + "LastEdited", package.LastEdited),
                    new XElement(nsDataService + "Published", package.Published),
                    new XElement(nsDataService + "LicenseNames", package.LicenseNames),
                    new XElement(nsDataService + "LicenseReportUrl", package.LicenseReportUrl)));

            return entry;
        }
 public static string ToOData(ODataPackage package, Uri baseUri)
 {
     XDocument doc = new XDocument(ToODataEntryXElement(package, baseUri));
     return doc.ToString();
 }
Esempio n. 4
0
        public static string ToOData(ODataPackage package, Uri baseUri)
        {
            XDocument doc = new XDocument(ToODataEntryXElement(package, baseUri));

            return(doc.ToString());
        }