internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, ResourceCollectionInfo collection)
 {
     if (collection == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("collection");
     }
     SyndicationFeedFormatter.CloseBuffer(buffer, writer);
     collection.LoadElementExtensions(buffer);
 }
Exemplo n.º 2
0
		//-- Workspace service tools
		private static List<ResourceCollectionInfo> GetResourceCollections(string baseUri, string repositoryId)
		{
			List<ResourceCollectionInfo> collections = new List<ResourceCollectionInfo>();
			var collectionTitle = "root collection";
			var collectionUri = new Uri(GetRootActionUri(baseUri, repositoryId, "getRoot"));
			var collection = new ResourceCollectionInfo(collectionTitle, collectionUri);
			collection.AttributeExtensions.Add(new XmlQualifiedName("collectionType", CmisService.CmisNamespace), "root-children");
			collections.Add(collection);
			return collections;
		}
        // http://atompub-mulitpart-spec.googlecode.com/svn/trunk/draft-gregorio-atompub-multipart-03.html
        // https://tools.ietf.org/html/rfc5023#section-9.6
        // http://msdn.microsoft.com/en-us/magazine/dd569753.aspx
        private ResourceCollectionInfo GetMediaResourceCollectionInfo(UrlHelper url) {

            ResourceCollectionInfo pics = new ResourceCollectionInfo("Pictures",
                new Uri(url.Link("DefaultApi", new { controller = "media" })));

            pics.Accepts.Add("image/png");
            pics.Accepts.Add("image/jpeg");
            pics.Accepts.Add("image/gif");

            return pics;
        }
        private ResourceCollectionInfo GetPostsResourceCollectionInfo(UrlHelper url) {

            ResourceCollectionInfo posts = new ResourceCollectionInfo("Blog",
                new Uri(url.Link("DefaultApi", new { controller = "posts" })));

            posts.Accepts.Add("application/atom+xml;type=entry");

            // For WLW to work we need to include format in the categories URI.
            // Hoping to provide a better solution than this.
            var categoriesUri = new Uri(url.Link("DefaultApi", new { controller = "tags", format = "atomcat" }));
            ReferencedCategoriesDocument categories = new ReferencedCategoriesDocument(categoriesUri);
            posts.Categories.Add(categories);

            return posts;
        }
        public HttpResponseMessage Get()
        {
            var doc = new ServiceDocument();
            var ws = new Workspace
            {
                Title = new TextSyndicationContent("My Site"),
                BaseUri = new Uri(Request.RequestUri.GetLeftPart(UriPartial.Authority))
            };

            var posts = new ResourceCollectionInfo("Blog",
                new Uri(Url.Link("DefaultApi", new { controller = "posts" })));

            posts.Accepts.Add("application/atom+xml;type=entry");

            // For WLW to work we need to include format in the categories URI.
            // Hoping to provide a better solution than this.
            var categoriesUri = new Uri(Url.Link("DefaultApi", new { controller = "tags", format = "atomcat" }));
            var categories = new ReferencedCategoriesDocument(categoriesUri);
            posts.Categories.Add(categories);

            ws.Collections.Add(posts);

            doc.Workspaces.Add(ws);

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            var formatter = new AtomPub10ServiceDocumentFormatter(doc);

            var stream = new MemoryStream();
            using (var writer = XmlWriter.Create(stream))
            {
                formatter.WriteTo(writer);
            }

            stream.Position = 0;
            var content = new StreamContent(stream);
            response.Content = content;
            response.Content.Headers.ContentType =
                new MediaTypeHeaderValue("application/atomsvc+xml");

            return response;
        }
        public HttpResponseMessage GetServiceDoc(HttpRequestMessage request)
        {
            string baseUrl = request.BaseUrl("servicedoc");

            ServiceDocument doc = new ServiceDocument();
            var postCollection = new ResourceCollectionInfo()
            {
                Title = new TextSyndicationContent("Posts"),
                Link = new Uri(string.Format("{0}/posts", baseUrl))
            };
            postCollection.Accepts.Add("application/atom+xml;type=entry");

            var wspace = new Workspace() { Title = new TextSyndicationContent("The Blog") };
            wspace.Collections.Add(postCollection);

            doc.Workspaces.Add(wspace);

            return new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content = new ObjectContent(typeof(AtomPub10ServiceDocumentFormatter), doc.GetFormatter())
            };
        }
        public HttpResponseMessage<ServiceDocument> ServiceDocumentation()
        {

            //TODO: change this to specific
            var serviceDocument = new ServiceDocument()
                                      {
                                          BaseUri = new Uri(this.ServiceURI + "/blogs")
                                      };

            var collection = new List<ResourceCollectionInfo>();

            foreach (var blog in _blogService.GetAll())
            {
                var resourceCollectionInfo = new ResourceCollectionInfo(blog.Title,
                                                                    new Uri(this.ServiceURI + "/blogs/" + blog.Id + "/posts"));

                resourceCollectionInfo.Accepts.Add("application/atom+xml;type=entry");
                collection.Add(resourceCollectionInfo);
            }

            var workspace = new Workspace("Feed", collection);
            serviceDocument.Workspaces.Add(workspace);

            return new HttpResponseMessage<ServiceDocument>(serviceDocument, HttpStatusCode.OK);
        }
 protected static void LoadElementExtensions(XmlReader reader, ResourceCollectionInfo collection, int maxExtensionSize)
 {
     if (collection == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("collection");
     }
     collection.LoadElementExtensions(reader, maxExtensionSize);
 }
    protected static ReferencedCategoriesDocument CreateReferencedCategories(ResourceCollectionInfo collection)
    {
      Contract.Requires(collection != null);

      return default(ReferencedCategoriesDocument);
    }
 protected static void LoadElementExtensions(System.Xml.XmlReader reader, ResourceCollectionInfo collection, int maxExtensionSize)
 {
 }
 protected static ReferencedCategoriesDocument CreateReferencedCategories(ResourceCollectionInfo collection)
 {
     return collection.CreateReferencedCategoriesDocument ();
 }
        private async Task <ResourceCollectionInfo> ReadCollectionAsync(XmlReader reader, Workspace workspace)
        {
            ResourceCollectionInfo result = CreateCollection(workspace);

            result.BaseUri = workspace.BaseUri;
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        result.BaseUri = FeedUtils.CombineXmlBase(result.BaseUri, await reader.GetValueAsync());
                    }
                    else if (reader.LocalName == App10Constants.Href && reader.NamespaceURI == string.Empty)
                    {
                        result.Link = new Uri(await reader.GetValueAsync(), UriKind.RelativeOrAbsolute);
                    }
                    else
                    {
                        string ns   = reader.NamespaceURI;
                        string name = reader.LocalName;
                        if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns))
                        {
                            continue;
                        }

                        string val = await reader.GetValueAsync();

                        if (!TryParseAttribute(name, ns, val, result, Version))
                        {
                            if (_preserveAttributeExtensions)
                            {
                                result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), val);
                            }
                        }
                    }
                }
            }

            XmlBuffer           buffer    = null;
            XmlDictionaryWriter extWriter = null;

            reader.ReadStartElement();
            try
            {
                while (await reader.IsStartElementAsync())
                {
                    if (await reader.IsStartElementAsync(Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace))
                    {
                        result.Title = await new Atom10FeedFormatter().ReadTextContentFromAsync(reader, "//app:service/app:workspace/app:collection/atom:title[@type]", _preserveAttributeExtensions);
                    }
                    else if (await reader.IsStartElementAsync(App10Constants.Categories, App10Constants.Namespace))
                    {
                        result.Categories.Add(await ReadCategories(reader,
                                                                   result.BaseUri,
                                                                   delegate()
                        {
                            return(CreateInlineCategories(result));
                        },

                                                                   delegate()
                        {
                            return(CreateReferencedCategories(result));
                        },
                                                                   Version,
                                                                   _preserveElementExtensions,
                                                                   _preserveAttributeExtensions,
                                                                   _maxExtensionSize));
                    }
                    else if (await reader.IsStartElementAsync(App10Constants.Accept, App10Constants.Namespace))
                    {
                        result.Accepts.Add(reader.ReadElementString());
                    }
                    else if (!TryParseElement(reader, result, Version))
                    {
                        if (_preserveElementExtensions)
                        {
                            var tuple = await SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNodeAsync(buffer, extWriter, reader, _maxExtensionSize);

                            buffer    = tuple.Item1;
                            extWriter = tuple.Item2;
                        }
                        else
                        {
                            reader.Skip();
                        }
                    }
                }

                LoadElementExtensions(buffer, extWriter, result);
            }
            finally
            {
                if (extWriter != null)
                {
                    extWriter.Close();
                }
            }

            reader.ReadEndElement();
            return(result);
        }
 protected static bool TryParseAttribute(string name, string ns, string value, ResourceCollectionInfo collection, string version)
 {
     return collection.TryParseAttribute (name, ns, value, version);
 }
Exemplo n.º 14
0
 protected static ReferencedCategoriesDocument CreateReferencedCategories(ResourceCollectionInfo collection)
 {
     return(collection.CreateReferencedCategoriesDocument());
 }
 protected static void WriteElementExtensions(XmlWriter writer, ResourceCollectionInfo collection, string version)
 {
     if (collection == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("collection");
     }
     collection.WriteElementExtensions(writer, version);
 }
 private void WriteCollection(XmlWriter writer, ResourceCollectionInfo collection, Uri baseUri)
 {
     writer.WriteStartElement("app", "collection", "http://www.w3.org/2007/app");
     Uri baseUriToWrite = FeedUtils.GetBaseUriToWrite(baseUri, collection.BaseUri);
     if (baseUriToWrite != null)
     {
         baseUri = collection.BaseUri;
         WriteXmlBase(writer, baseUriToWrite);
     }
     if (collection.Link != null)
     {
         writer.WriteAttributeString("href", FeedUtils.GetUriString(collection.Link));
     }
     ServiceDocumentFormatter.WriteAttributeExtensions(writer, collection, this.Version);
     if (collection.Title != null)
     {
         collection.Title.WriteTo(writer, "title", "http://www.w3.org/2005/Atom");
     }
     for (int i = 0; i < collection.Accepts.Count; i++)
     {
         writer.WriteElementString("app", "accept", "http://www.w3.org/2007/app", collection.Accepts[i]);
     }
     for (int j = 0; j < collection.Categories.Count; j++)
     {
         WriteCategories(writer, collection.Categories[j], baseUri, this.Version);
     }
     ServiceDocumentFormatter.WriteElementExtensions(writer, collection, this.Version);
     writer.WriteEndElement();
 }
        private ResourceCollectionInfo ReadCollection(XmlReader reader, Workspace workspace)
        {
            ResourceCollectionInfo result = CreateCollection(workspace);

            result.BaseUri = workspace.BaseUri;
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        result.BaseUri = FeedUtils.CombineXmlBase(result.BaseUri, reader.Value);
                    }
                    else if (reader.LocalName == App10Constants.Href && reader.NamespaceURI == string.Empty)
                    {
                        result.Link = new Uri(reader.Value, UriKind.RelativeOrAbsolute);
                    }
                    else
                    {
                        string ns   = reader.NamespaceURI;
                        string name = reader.LocalName;
                        if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns))
                        {
                            continue;
                        }

                        string val = reader.Value;
                        if (!TryParseAttribute(name, ns, val, result, Version))
                        {
                            result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                        }
                    }
                }
            }

            XmlBuffer           buffer    = null;
            XmlDictionaryWriter extWriter = null;

            reader.ReadStartElement();
            try
            {
                while (reader.IsStartElement())
                {
                    if (reader.IsStartElement(Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace))
                    {
                        result.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/app:collection/atom:title[@type]", preserveAttributeExtensions: true);
                    }
                    else if (reader.IsStartElement(App10Constants.Categories, App10Constants.Namespace))
                    {
                        result.Categories.Add(ReadCategories(reader,
                                                             result.BaseUri,
                                                             () => CreateInlineCategories(result),
                                                             () => CreateReferencedCategories(result),
                                                             Version,
                                                             _maxExtensionSize));
                    }
                    else if (reader.IsStartElement(App10Constants.Accept, App10Constants.Namespace))
                    {
                        result.Accepts.Add(reader.ReadElementString());
                    }
                    else if (!TryParseElement(reader, result, Version))
                    {
                        SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize);
                    }
                }
                LoadElementExtensions(buffer, extWriter, result);
            }
            finally
            {
                extWriter?.Close();
            }

            reader.ReadEndElement();
            return(result);
        }
Exemplo n.º 18
0
        public HttpResponseMessage GetServiceDoc(HttpRequestMessage request)
        {
            ServiceDocument doc = new ServiceDocument { BaseUri = new Uri(this.serviceURI) };
            List<ResourceCollectionInfo> resources = new List<ResourceCollectionInfo>();

            ResourceCollectionInfo blogsCollection = new ResourceCollectionInfo("Blogs", new Uri(String.Format("{0}/blogs", this.serviceURI)));
            blogsCollection.Accepts.Add("application/atom+xml;type=feed");
            resources.Add(blogsCollection);

            Workspace main = new Workspace("RESTBlogsService", resources);
            doc.Workspaces.Add(main);

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
                                               {
                                                   Content = new ObjectContent(typeof(AtomPub10ServiceDocumentFormatter), doc.GetFormatter())
                                               };

            return response;
        }
Exemplo n.º 19
0
 protected static InlineCategoriesDocument CreateInlineCategories(ResourceCollectionInfo collection)
 {
     return(collection.CreateInlineCategoriesDocument());
 }
 protected static bool TryParseAttribute(string name, string ns, string value, ResourceCollectionInfo collection, string version)
 {
     if (collection == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("collection");
     }
     return collection.TryParseAttribute(name, ns, value, version);
 }
 protected static void WriteElementExtensions(XmlWriter writer, ResourceCollectionInfo collection, string version)
 {
     collection.WriteElementExtensions (writer, version);
 }
 protected static bool TryParseElement(XmlReader reader, ResourceCollectionInfo collection, string version)
 {
     if (collection == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("collection");
     }
     return collection.TryParseElement(reader, version);
 }
Exemplo n.º 23
0
        protected static bool TryParseAttribute(string name, string ns, string value, ResourceCollectionInfo collection, string version)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            return(collection.TryParseAttribute(name, ns, value, version));
        }
		public void WriteTo2 ()
		{
			var s = new ServiceDocument ();
			var ws = new Workspace ("test title", null);
			var rc = new ResourceCollectionInfo ("test resource", new Uri ("urn:foo"));
			rc.Accepts.Add ("application/atom+xml;type=entry");
			ws.Collections.Add (rc);
			s.Workspaces.Add (ws);
			var a = new AtomPub10ServiceDocumentFormatter (s);
			Assert.AreEqual ("http://www.w3.org/2007/app", a.Version, "#1");
			Assert.IsTrue (a.CanRead (XmlReader.Create (new StringReader (app2))), "#2");
			var sw = new StringWriter ();
			using (var xw = XmlWriter.Create (sw, settings))
				a.WriteTo (xw);
			Assert.AreEqual (app2, sw.ToString (), "#3");
		}
 protected static bool TryParseAttribute(string name, string ns, string value, ResourceCollectionInfo collection, string version)
 {
   return default(bool);
 }
 //[MonoTODO ("Use maxExtensionSize somewhere")]
 protected static void LoadElementExtensions(XmlReader reader,ResourceCollectionInfo collection, int maxExtensionSize)
 {
     collection.ElementExtensions.Add (reader);
 }
 protected static bool TryParseElement(System.Xml.XmlReader reader, ResourceCollectionInfo collection, string version)
 {
   return default(bool);
 }
 protected static bool TryParseElement(XmlReader reader, ResourceCollectionInfo collection, string version)
 {
     return collection.TryParseElement (reader, version);
 }
 protected static void WriteElementExtensions(System.Xml.XmlWriter writer, ResourceCollectionInfo collection, string version)
 {
 }
 protected static InlineCategoriesDocument CreateInlineCategories(ResourceCollectionInfo collection)
 {
     return collection.CreateInlineCategoriesDocument ();
 }
    protected static InlineCategoriesDocument CreateInlineCategories(ResourceCollectionInfo collection)
    {
      Contract.Requires(collection != null);

      return default(InlineCategoriesDocument);
    }
Exemplo n.º 32
0
        protected internal virtual bool TryParseElement(XmlReader reader, string version)
        {
            if (reader == null)
                throw new ArgumentNullException ("reader");

            reader.MoveToContent ();
            if (reader.LocalName != "workspace" || reader.NamespaceURI != version)
                return false;

            bool isEmpty = reader.IsEmptyElement;

            reader.ReadStartElement ();
            if (isEmpty)
                return true;

            for (reader.MoveToContent (); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent ()) {
                if (reader.LocalName == "title" && reader.NamespaceURI == Namespaces.Atom10) {
                    Title = Atom10FeedFormatter.ReadTextSyndicationContent (reader);
                    continue;
                } else if (reader.LocalName == "collection" && reader.NamespaceURI == version) {
                    var rc = new ResourceCollectionInfo ();
                    if (rc.TryParseElement (reader, version)) {
                        Collections.Add (rc);
                        continue;
                    }
                }
                ElementExtensions.Add (new SyndicationElementExtension (reader));
            }
            return true;
        }
 void WriteCollection(XmlWriter writer, ResourceCollectionInfo collection, Uri baseUri)
 {
     writer.WriteStartElement(App10Constants.Prefix, App10Constants.Collection, App10Constants.Namespace);
     Uri baseUriToWrite = FeedUtils.GetBaseUriToWrite(baseUri, collection.BaseUri);
     if (baseUriToWrite != null)
     {
         baseUri = collection.BaseUri;
         WriteXmlBase(writer, baseUriToWrite);
     }
     if (collection.Link != null)
     {
         writer.WriteAttributeString(App10Constants.Href, FeedUtils.GetUriString(collection.Link));
     }
     WriteAttributeExtensions(writer, collection, this.Version);
     if (collection.Title != null)
     {
         collection.Title.WriteTo(writer, Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace);
     }
     for (int i = 0; i < collection.Accepts.Count; ++i)
     {
         writer.WriteElementString(App10Constants.Prefix, App10Constants.Accept, App10Constants.Namespace, collection.Accepts[i]);
     }
     for (int i = 0; i < collection.Categories.Count; ++i)
     {
         WriteCategories(writer, collection.Categories[i], baseUri, this.Version);
     }
     WriteElementExtensions(writer, collection, this.Version);
     writer.WriteEndElement();
 }