예제 #1
0
		public void GetFormatter ()
		{
			var v = new ServiceDocument ();
			var f = v.GetFormatter ();
			Assert.IsTrue (f is AtomPub10ServiceDocumentFormatter, "#1");
			Assert.IsTrue (f.Document == v, "#2");
		}
 public AtomPub10ServiceDocumentFormatter(ServiceDocument documentToWrite) : base(documentToWrite)
 {
     this.maxExtensionSize = 0x7fffffff;
     this.preserveAttributeExtensions = true;
     this.preserveElementExtensions = true;
     this.documentType = documentToWrite.GetType();
 }
        protected override Task<HttpResponseMessage> SendAsync(
            HttpRequestMessage request, 
            CancellationToken cancellationToken) {

            UrlHelper url = request.GetUrlHelper();
            ServiceDocument doc = new ServiceDocument();
            Workspace ws = new Workspace() {

                Title = new TextSyndicationContent("My Site"),
                BaseUri = new Uri(request.RequestUri.GetLeftPart(UriPartial.Authority))
            };

            ws.Collections.Add(GetPostsResourceCollectionInfo(url));
            ws.Collections.Add(GetMediaResourceCollectionInfo(url));
            doc.Workspaces.Add(ws);

            HttpResponseMessage response = request.CreateResponse(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 Task.FromResult(response);
        }
예제 #4
0
		public void Save ()
		{
			var v = new ServiceDocument ();
			var sw = new StringWriter ();
			using (var xw = XmlWriter.Create (sw, settings))
				v.Save (xw);
			Assert.AreEqual ("<app:service xmlns:a10=\"http://www.w3.org/2005/Atom\" xmlns:app=\"http://www.w3.org/2007/app\" />", sw.ToString ());
		}
 protected ServiceDocumentFormatter(ServiceDocument documentToWrite)
 {
     if (documentToWrite == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("documentToWrite");
     }
     this.document = documentToWrite;
 }
 protected static Workspace CreateWorkspace(ServiceDocument document)
 {
     if (document == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("document");
     }
     return document.CreateWorkspace();
 }
 public AtomPub10ServiceDocumentFormatter(ServiceDocument documentToWrite)
     : base(documentToWrite)
 {
     // No need to check that the parameter passed is valid - it is checked by the c'tor of the base class
     this.maxExtensionSize = int.MaxValue;
     preserveAttributeExtensions = true;
     preserveElementExtensions = true;
     this.documentType = documentToWrite.GetType();
 }
 internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, ServiceDocument document)
 {
     if (document == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("document");
     }
     Atom10FeedFormatter.CloseBuffer(buffer, writer);
     document.LoadElementExtensions(buffer);
 }
 public AtomServiceDocumentActionResult(ServiceDocument document, ContentType contentType) {
     if (document == null) {
         throw new ArgumentNullException("document");
     }
     if (contentType == null) {
         throw new ArgumentNullException("contentType");
     }
     this.document = document;
     this.contentType = contentType;
 }
		public void WriteTo ()
		{
			var s = new ServiceDocument ();
			var a = new AtomPub10ServiceDocumentFormatter (s);
			Assert.AreEqual ("http://www.w3.org/2007/app", a.Version, "#1");
			Assert.IsTrue (a.CanRead (XmlReader.Create (new StringReader (app1))), "#2");
			var sw = new StringWriter ();
			using (var xw = XmlWriter.Create (sw, settings))
				a.WriteTo (xw);
			Assert.AreEqual (app1, sw.ToString (), "#3");
		}
        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;
        }
예제 #12
0
		//=============== Workspace service

		internal static AtomPub10ServiceDocumentFormatter BuildWorkspace(string repositoryId)
		{
			//var xmlns = new XmlSerializerNamespaces();
			//xmlns.Add("app", Workspace.APPNAMESPACE);
			//xmlns.Add("atom", Workspace.ATOMNAMESPACE);
			//xmlns.Add("cmis", Workspace.CMISNAMESPACE);

			var baseUri = GetBaseUri();

			var workspace = new Workspace("Main Repository", GetResourceCollections(baseUri, repositoryId));
			var repInfo =  new RepositoryInfo
			{
				Id = repositoryId,
				Name = "MainRep",
				Relationship = enumRepositoryRelationship.self,
				Description = "Main Repository",
				VendorName = "Sense/Net Ltd.",
				ProductName = "SenseNet Content Repository Prototype",
				ProductVersion = "0.01",
				RootFolderId = "2",
				Capabilities = new RepositoryCapabilities
				{
					Multifiling = false,
					Unfiling = true,
					VersionSpecificFiling = false,
					PWCUpdateable = false,
					AllVersionsSearchable = false,
					Join = enumCapabilityJoin.nojoin,
					FullText = enumCapabilityFullText.none
				},
				CmisVersionsSupported = "0.5"
			};
			workspace.ElementExtensions.Add(repInfo, new XmlSerializer(typeof(RepositoryInfo)));

			var serviceDoc = new ServiceDocument(new Workspace[] { workspace });
			var formatter = new AtomPub10ServiceDocumentFormatter(serviceDoc);
			return formatter;
		}
        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())
            };
        }
예제 #14
0
 public static void LoadElementExtensionsEntryPoint(XmlReader reader, ServiceDocument document, int maxExtensionSize) => LoadElementExtensions(reader, document, maxExtensionSize);
예제 #15
0
        public void Workspaces_AddNullItem_ThrowsArgumentNullException()
        {
            Collection <Workspace> collection = new ServiceDocument().Workspaces;

            AssertExtensions.Throws <ArgumentNullException>("item", () => collection.Add(null));
        }
 protected static void WriteElementExtensions(XmlWriter writer, ServiceDocument document, string version)
 {
     document.WriteElementExtensions (writer, version);
 }
 protected static bool TryParseAttribute(string name, string ns, string value, ServiceDocument document, string version)
 {
     return document.TryParseAttribute (name, ns, value, version);
 }
 protected static Workspace CreateWorkspace(ServiceDocument document)
 {
     return document.CreateWorkspace ();
 }
 private Workspace ReadWorkspace(XmlReader reader, ServiceDocument document)
 {
     Workspace workspace = ServiceDocumentFormatter.CreateWorkspace(document);
     workspace.BaseUri = document.BaseUri;
     if (reader.HasAttributes)
     {
         while (reader.MoveToNextAttribute())
         {
             if ((reader.LocalName == "base") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace"))
             {
                 workspace.BaseUri = FeedUtils.CombineXmlBase(workspace.BaseUri, reader.Value);
             }
             else
             {
                 string namespaceURI = reader.NamespaceURI;
                 string localName = reader.LocalName;
                 if (!FeedUtils.IsXmlns(localName, namespaceURI) && !FeedUtils.IsXmlSchemaType(localName, namespaceURI))
                 {
                     string str3 = reader.Value;
                     if (!ServiceDocumentFormatter.TryParseAttribute(localName, namespaceURI, str3, workspace, this.Version))
                     {
                         if (this.preserveAttributeExtensions)
                         {
                             workspace.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                             continue;
                         }
                         SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader);
                     }
                 }
             }
         }
     }
     XmlBuffer buffer = null;
     XmlDictionaryWriter extWriter = null;
     reader.ReadStartElement();
     try
     {
         while (reader.IsStartElement())
         {
             if (reader.IsStartElement("title", "http://www.w3.org/2005/Atom"))
             {
                 workspace.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/atom:title[@type]", this.preserveAttributeExtensions);
             }
             else
             {
                 if (reader.IsStartElement("collection", "http://www.w3.org/2007/app"))
                 {
                     workspace.Collections.Add(this.ReadCollection(reader, workspace));
                     continue;
                 }
                 if (!ServiceDocumentFormatter.TryParseElement(reader, workspace, this.Version))
                 {
                     if (this.preserveElementExtensions)
                     {
                         SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, this.maxExtensionSize);
                         continue;
                     }
                     SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader);
                     reader.Skip();
                 }
             }
         }
         ServiceDocumentFormatter.LoadElementExtensions(buffer, extWriter, workspace);
     }
     finally
     {
         if (extWriter != null)
         {
             extWriter.Close();
         }
     }
     reader.ReadEndElement();
     return workspace;
 }
예제 #20
0
 public static Workspace CreateWorkspaceEntryPoint(ServiceDocument document) => CreateWorkspace(document);
예제 #21
0
 public void SetDocumentEntryPoint(ServiceDocument document) => SetDocument(document);
예제 #22
0
 public static bool TryParseAttributeEntryPoint(string name, string ns, string value, ServiceDocument document, string version)
 {
     return(TryParseAttribute(name, ns, value, document, version));
 }
예제 #23
0
 public static bool TryParseElementEntryPoint(XmlReader reader, ServiceDocument document, string version)
 {
     return(TryParseElement(reader, document, version));
 }
 protected static bool TryParseElement(XmlReader reader, ServiceDocument document, string version)
 {
     if (document == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("document");
     }
     return document.TryParseElement(reader, version);
 }
 protected static void WriteElementExtensions(XmlWriter writer, ServiceDocument document, string version)
 {
     if (document == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("document");
     }
     document.WriteElementExtensions(writer, version);
 }
 protected ServiceDocumentFormatter(ServiceDocument documentToWrite)
 {
     SetDocument (documentToWrite);
 }
예제 #27
0
 public Formatter(ServiceDocument document) : base(document)
 {
 }
 /// <summary>
 /// The content type defaults to application/atomsvc+xml
 /// </summary>
 /// <param name="document"></param>
 public AtomServiceDocumentActionResult(ServiceDocument document)
     : this(document, new ContentType("application/atomsvc+xml")) {
 }
예제 #29
0
		public string Join (string s1, string s2)
		{
			try {
				// ServiceDocument
				var woc = WebOperationContext.Current;
				var sd = new ServiceDocument ();
				var msg = woc.CreateAtom10Response (sd);
				var xml = "<service xmlns:a10='http://www.w3.org/2005/Atom' xmlns='http://www.w3.org/2007/app' />";
			
				Assert.AreEqual (xml.Replace ('\'', '"'), GetXml (msg), "#1");
				// Feed
				var uid = new UniqueId ().ToString ();
				var updatedTime = DateTime.SpecifyKind (new DateTime (2011, 4, 8, 11, 46, 12), DateTimeKind.Utc);
				var feed = new SyndicationFeed () { Id = uid, LastUpdatedTime = updatedTime };
				msg = woc.CreateAtom10Response (feed);
				xml = @"<feed xmlns='http://www.w3.org/2005/Atom'><title type='text'></title><id>" + uid + @"</id><updated>2011-04-08T11:46:12Z</updated></feed>";
				Assert.AreEqual (xml.Replace ('\'', '"'), GetXml (msg), "#2");

				// Item
				var item = new SyndicationItem () { Id = uid, LastUpdatedTime = updatedTime };
				msg = woc.CreateAtom10Response (item);
				xml = @"<entry xmlns='http://www.w3.org/2005/Atom'><id>" + uid + "</id><title type='text'></title><updated>2011-04-08T11:46:12Z</updated></entry>";
				Assert.AreEqual (xml.Replace ('\'', '"'), GetXml (msg), "#2");
			} catch (Exception ex) {
				Console.Error.WriteLine (ex);
				throw;
			}
			return s1 + s2;
		}
예제 #30
0
 public Message CreateAtom10Response(ServiceDocument document)
 {
     return(CreateAtom10Response <AtomPub10ServiceDocumentFormatter> (new AtomPub10ServiceDocumentFormatter(document), ref document_serializer));
 }
 //[MonoTODO ("Use maxExtensionSize somewhere")]
 protected static void LoadElementExtensions(XmlReader reader, ServiceDocument document, int maxExtensionSize)
 {
     document.ElementExtensions.Add (reader);
 }
 protected virtual void SetDocument(ServiceDocument document)
 {
     this.document = document;
 }
 protected static bool TryParseElement(XmlReader reader, ServiceDocument document, string version)
 {
     return document.TryParseElement (reader, version);
 }
 protected static bool TryParseAttribute(string name, string ns, string value, ServiceDocument document, string version)
 {
     if (document == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("document");
     }
     return document.TryParseAttribute(name, ns, value, version);
 }
 protected virtual void SetDocument(ServiceDocument document)
 {
     if (document == null)
         throw new ArgumentNullException ("document");
     Document = document;
 }
예제 #36
0
 public static void WriteElementExtensionsEntryPoint(XmlWriter writer, ServiceDocument document, string version)
 {
     WriteElementExtensions(writer, document, version);
 }
		public AtomPub10ServiceDocumentFormatter (ServiceDocument documentToWrite)
			: base (documentToWrite)
		{
		}
        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, ServiceDocument document, int maxExtensionSize)
 {
     if (document == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("document");
     }
     document.LoadElementExtensions(reader, maxExtensionSize);
 }
예제 #40
0
 /// <summary>
 /// The content type defaults to application/atomsvc+xml
 /// </summary>
 /// <param name="document"></param>
 public AtomServiceDocumentActionResult(ServiceDocument document)
     : this(document, new ContentType("application/atomsvc+xml"))
 {
 }