本文整理汇总了C#中XDoc.ToPrettyString方法的典型用法代码示例。如果您正苦于以下问题:C# XDoc.ToPrettyString方法的具体用法?C# XDoc.ToPrettyString怎么用?C# XDoc.ToPrettyString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XDoc
的用法示例。
在下文中一共展示了XDoc.ToPrettyString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: XmlNullChar_in_xml_element_ToPrettyString
public void XmlNullChar_in_xml_element_ToPrettyString()
{
var doc = new XDoc("root").Value("foo\0bar");
Assert.AreEqual("<root>foobar</root>", doc.ToPrettyString());
}
示例2: WriteErrorRequest
private void WriteErrorRequest(XDoc request)
{
WriteLineToLog("Request deoc: " + request.ToPrettyString());
}
示例3: PutPagePropertiesXml
public void PutPagePropertiesXml() {
Plug p = Utils.BuildPlugForAdmin();
string id = null;
string path = null;
DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path);
var propertyContent = new XDoc("foo").Start("someelement").Attr("justanattribute", true).End();
var propXml = new XDoc("properties")
.Start("property").Attr("name", "foo")
.Start("contents").Attr("type", MimeType.XML.ToString())
.Value(propertyContent) // the xml content is not escaped!
.End()
.Elem("description", "whattup")
.End();
msg = p.At("pages", id, "properties").PutAsync(DreamMessage.Ok(propXml)).Wait();
Assert.AreEqual(DreamStatus.Ok, msg.Status);
msg = p.At("pages", id, "properties", "foo").GetAsync().Wait();
Assert.AreEqual(DreamStatus.Ok, msg.Status);
Assert.AreEqual(propertyContent.ToPrettyString(), msg.ToDocument().ToPrettyString(), "Contents don't match!");
PageUtils.DeletePageByID(p, id, true);
}
示例4: XmlNullChar_in_xml_attribute_ToPrettyString
public void XmlNullChar_in_xml_attribute_ToPrettyString()
{
var doc = new XDoc("root").Attr("name", "foo\0bar");
Assert.AreEqual("<root name=\"foobar\" />", doc.ToPrettyString());
}
示例5: DeleteAndOverwritePageProperty
public void DeleteAndOverwritePageProperty() {
//Set a property foo with content c1
//Delete the property foo
//Validate that foo doesn't exist
//Set property to content c2
//Validate property content of c2
string C1 = "C1";
string C2 = "C2";
Plug p = Utils.BuildPlugForAdmin();
string id = null;
string path = null;
XDoc content = null;
DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path);
//Set foo with c1
content = new XDoc("deltest").Start("somevalue").Value(C1).End();
msg = p.At("pages", id, "properties").WithHeader("Slug", XUri.Encode("foo")).PostAsync(DreamMessage.Ok(content)).Wait();
Assert.AreEqual(DreamStatus.Ok, msg.Status, "put property returned non 200 status: " + msg.ToString());
msg = p.At("pages", id, "properties", "foo", "info").GetAsync().Wait();
Assert.AreEqual(DreamStatus.Ok, msg.Status, "get property returned non 200 status: " + msg.ToString());
msg = p.At("pages", id, "properties", "foo").GetAsync().Wait();
Assert.AreEqual(DreamStatus.Ok, msg.Status, "get property contents returned non 200 status: " + msg.ToString());
Assert.AreEqual(content.ToPrettyString(), msg.ToDocument().ToPrettyString(), "Contents don't match!");
//Delete foo
msg = p.At("pages", id, "properties", "foo").DeleteAsync(DreamMessage.Ok()).Wait();
Assert.AreEqual(DreamStatus.Ok, msg.Status, "delete property returned non 200 status: " + msg.ToString());
//Validate that foo doesn't exist
msg = p.At("pages", id, "properties", "foo", "info").GetAsync(DreamMessage.Ok()).Wait();
Assert.AreEqual(DreamStatus.NotFound, msg.Status, "get deleted property returned non 404 status: " + msg.ToString());
//Set property to content c2
content = new XDoc("deltest").Start("somevalue").Value(C2).End();
msg = p.At("pages", id, "properties").WithHeader("Slug", XUri.Encode("foo")).PostAsync(DreamMessage.Ok(content)).Wait();
Assert.AreEqual(DreamStatus.Ok, msg.Status, "put property returned non 200 status: " + msg.ToString());
msg = p.At("pages", id, "properties", "foo", "info").GetAsync().Wait();
Assert.AreEqual(DreamStatus.Ok, msg.Status, "get property returned non 200 status: " + msg.ToString());
//Validate property content of c2
msg = p.At("pages", id, "properties", "foo").GetAsync().Wait();
Assert.AreEqual(DreamStatus.Ok, msg.Status, "get property contents returned non 200 status: " + msg.ToString());
Assert.AreEqual(content.ToPrettyString(), msg.ToDocument().ToPrettyString(), "Contents don't match!");
}
示例6: MultiplePropertiesInPage
public void MultiplePropertiesInPage() {
//Save multiple properties in a page
//Retrieve them
Plug p = Utils.BuildPlugForAdmin();
string id = null;
string path = null;
int NUMPROPS = 5;
DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path);
for(int i = 1; i <= NUMPROPS; i++) {
string propname = string.Format("testprop_{0}", i);
XDoc content = new XDoc("proptest");
content.Start("name").Value(propname).End();
msg = p.At("pages", id, "properties").WithHeader("Slug", XUri.Encode(propname)).PostAsync(DreamMessage.Ok(content)).Wait();
Assert.AreEqual(DreamStatus.Ok, msg.Status, "put property returned non 200 status: " + msg.ToString());
msg = p.At("pages", id, "properties", propname, "info").GetAsync().Wait();
Assert.AreEqual(DreamStatus.Ok, msg.Status, "get property returned non 200 status: " + msg.ToString());
Assert.AreEqual(MimeType.XML.ToString(), MimeType.New(msg.ToDocument()["/property[@name='" + propname + "']/contents/@type"].AsText).ToString(), "Content types dont match");
msg = p.At("pages", id, "properties", propname).GetAsync().Wait();
Assert.AreEqual(DreamStatus.Ok, msg.Status, "get property content returned non 200 status: " + msg.ToString());
Assert.AreEqual(content.ToPrettyString(), msg.ToDocument().ToPrettyString(), "Contents don't match!");
//revisions not yet supported.
//Assert.AreEqual((msg.ToDocument()["/property[@name= '" + propname + "']/revisions/@count"].AsInt ?? 0), 1);
}
msg = p.At("pages", id, "properties").GetAsync(DreamMessage.Ok()).Wait();
Assert.AreEqual(DreamStatus.Ok, msg.Status, "get properties returned non 200 status: " + msg.ToString());
Assert.AreEqual(msg.ToDocument()["/properties/@count"].AsInt, NUMPROPS, "Wrong property count!");
}
示例7: RevisionPageProperty
public void RevisionPageProperty() {
//Create n revisions.
//Validate number of revisions created and content at head revisions
//Validate content of each revision
//TODO: description tests
int REVS = 10;
Plug p = Utils.BuildPlugForAdmin();
string id = null;
string path = null;
DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path);
for (int i = 1; i <= REVS; i++) {
XDoc content = new XDoc("revtest");
content.Start("revision").Value(i).End();
string etag = string.Empty;
msg = p.At("pages", id, "properties", "foo").WithHeader(DreamHeaders.ETAG, etag).PutAsync(DreamMessage.Ok(content)).Wait();
Assert.IsTrue(msg.Status == DreamStatus.Ok, "put property returned non 200 status: " + msg.ToString());
etag = msg.ToDocument()["/property/@etag"].AsText;
msg = p.At("pages", id, "properties", "foo", "info").GetAsync().Wait();
Assert.IsTrue(msg.Status == DreamStatus.Ok, "get property returned non 200 status: " + msg.ToString());
string c = XDocFactory.From(msg.ToDocument()["/property[@name= 'foo']/contents"].AsText, MimeType.New(msg.ToDocument()["/property[@name='foo']/contents/@type"].AsText)).ToPrettyString();
Assert.IsTrue(msg.Status == DreamStatus.Ok, "get property returned non 200 status: " + msg.ToString());
Assert.AreEqual(content.ToPrettyString(), c, "Contents don't match!");
Assert.AreEqual((msg.ToDocument()["/property[@name= 'foo']/revisions/@count"].AsInt ?? 0), i);
}
msg = p.At("pages", id, "properties", "foo", "revisions").GetAsync().Wait();
Assert.IsTrue(msg.Status == DreamStatus.Ok, "get property revisions returned non 200 status: " + msg.ToString());
Assert.AreEqual((msg.ToDocument()["/properties/@count"].AsInt ?? 0), REVS);
for (int i = 1; i <= REVS; i++) {
XDoc content = new XDoc("revtest");
content.Start("revision").Value(i).End();
msg = p.At("pages", id, "properties", "foo", "info").With("revision", i).GetAsync().Wait();
Assert.IsTrue(msg.Status == DreamStatus.Ok, "get property returned non 200 status: " + msg.ToString());
string c = XDocFactory.From(msg.ToDocument()["/property[@name= 'foo']/contents"].AsText, MimeType.New(msg.ToDocument()["/property[@name='foo']/contents/@type"].AsText)).ToPrettyString();
Assert.IsTrue(msg.Status == DreamStatus.Ok, "get property returned non 200 status: " + msg.ToString());
Assert.AreEqual(content.ToPrettyString(), c, "Contents don't match!");
Assert.AreEqual((msg.ToDocument()["/property[@name= 'foo']/revisions/@count"].AsInt ?? 0), REVS);
}
}
示例8: FromXmlRpcToDekiScript
private static DekiScriptLiteral FromXmlRpcToDekiScript(XDoc xdoc) {
if(xdoc.HasName("html")) {
return new DekiScriptList().Add(new DekiScriptXml(xdoc));
}
if(xdoc.HasName("methodResponse")) {
if(!xdoc["fault"].IsEmpty) {
string errorMessage = xdoc["fault/value/struct/member[name='faultString']/value/string"].AsText;
throw new DekiScriptXmlRpcException(errorMessage ?? xdoc.ToPrettyString());
}
if(!xdoc["params"].IsEmpty) {
DekiScriptList result = new DekiScriptList();
foreach(XDoc param in xdoc["params/param/value"]) {
result.Add(ToDekiScriptRecurse(param));
}
return result;
} else {
// NOTE: unexpected result, treat it as a nil result
DekiScriptList result = new DekiScriptList();
result.Add(DekiScriptNil.Value);
return result;
}
}
throw new DekiScriptUnsupportedTypeException(Location.None, string.Format("<{0}>", xdoc.Name));
}
示例9: Save
private void Save(XDoc html, string title, string href, string path, string assembly) {
html.EndAll(); // xdocs div
var filepath = Path.Combine("relative", path);
_fileMap.Start("item").Attr("dataid", _currentDataId).Attr("path", filepath).End();
_manifest.Start("page")
.Attr("dataid", _currentDataId);
if(!string.IsNullOrEmpty(title)) {
_manifest.Elem("title", title);
}
_manifest
.Elem("path", href)
.Start("contents").Attr("type", "application/x.deki0805+xml").End()
.End();
filepath = Path.Combine(_outputPath, filepath);
Directory.CreateDirectory(Path.GetDirectoryName(filepath));
using(var stream = File.Create(filepath)) {
using(var writer = new StreamWriter(stream)) {
writer.Write(html.ToPrettyString());
writer.Close();
}
stream.Close();
}
_currentDataId++;
if(string.IsNullOrEmpty(assembly)) {
return;
}
// add assembly tag to file
var assemblyString = "assembly:" + assembly;
var tagDoc = new XDoc("tags")
.Attr("count", 1)
.Start("tag")
.Attr("value", assemblyString)
.Elem("type", "text")
.Elem("title", assemblyString)
.End();
filepath = Path.Combine("relative", Path.GetFileNameWithoutExtension(path) + ".tags");
_fileMap.Start("item").Attr("dataid", _currentDataId).Attr("path", filepath).End();
_manifest.Start("tags")
.Attr("dataid", _currentDataId)
.Elem("path", href)
.End();
filepath = Path.Combine(_outputPath, filepath);
using(var stream = File.Create(filepath)) {
using(var writer = new StreamWriter(stream)) {
writer.Write(tagDoc.ToPrettyString());
writer.Close();
}
stream.Close();
}
_currentDataId++;
}
示例10: BuildDocumenationPackage
//--- Methods ---
public void BuildDocumenationPackage(string outputPath, params string[] namespaces) {
_types = GetTypes();
InitNamespaces(namespaces);
_outputPath = outputPath;
_currentDataId = 0;
var package = new XDoc("package").Elem("manifest").Elem("map");
_manifest = package["manifest"];
_fileMap = package["map"];
var root = NewHtmlDocument("", false).Start("div").Attr("class", "doctree").Value("{{wiki.tree()}}").End();
Save(root, "", "//", "root.xml", null);
foreach(var type in _types.OrderBy(x => x.LongDisplayName).Where(IsTypeInDocumentation)) {
EnsureNamespaceRootDocument(type.Namespace);
var sig = type.Signature;
var xmlDoc = GetDoc(sig);
var title = type.DisplayName;
if(type.IsStatic) {
title += " Static";
}
switch(type.Kind) {
case TypeKind.Enum:
title += " Enumeration";
break;
case TypeKind.Interface:
title += " Interface";
break;
case TypeKind.Struct:
title += " Struct";
break;
default:
title += " Class";
break;
}
var html = NewHtmlDocument(title, true);
html.StartSection("docheader")
.CSharpBlock(type.CodeSignature)
.NameValueLine("namespace", "Namespace", type.Namespace)
.NameValueLine("assembly", "Assembly", type.Assembly);
BuildInheritanceChain(html, type);
BuildInterfaceBlock(html, type);
html
.Div("summary", xmlDoc["summary"])
.EndSection() // header section
.Section(1, "remarks", "Remarks", xmlDoc["remarks"]);
if(type.Kind == TypeKind.Enum) {
BuildEnumFields(html, type.Fields);
} else {
BuildGenericParameterSection(1, html, xmlDoc, type.GenericParameters.Where(x => !x.IsInherited));
if(!type.IsDelegate) {
AddMemberTables(html, type);
BuildConstructorHtml(type.Constructors);
BuildFieldHtml(type.Fields);
BuildPropertyHtml(type.Properties.Where(x => !x.IsInherited));
BuildMethodHtml(type.Methods.Where(x => !x.IsInherited));
BuildEventHtml(type.Events.Where(x => !x.IsInherited));
}
}
AddExceptionSection(html, xmlDoc);
Save(html, title, type.UriPath, type.FilePath, type.Assembly);
}
var packagePath = Path.Combine(_outputPath, "package.xml");
Directory.CreateDirectory(Path.GetDirectoryName(packagePath));
using(var stream = File.Create(packagePath)) {
using(var writer = new StreamWriter(stream)) {
writer.Write(package.ToPrettyString());
}
}
}
示例11: Pages_filtered_for_user_preserve_order_in_verbose_mode
public void Pages_filtered_for_user_preserve_order_in_verbose_mode() {
// Build ADMIN plug
var p = Utils.BuildPlugForAdmin();
// Create a random contributor
string id;
string name;
UserUtils.CreateRandomContributor(p, out id, out name);
// Create a random page
string id1;
PageUtils.CreateRandomPage(p, out id1);
string id2;
PageUtils.CreateRandomPage(p, out id2);
string id3;
PageUtils.CreateRandomPage(p, out id3);
// XML document with a list of pages to run against the 'allowed' feature
var pagesDoc = new XDoc("pages")
.Start("page").Attr("id", id2).End()
.Start("page").Attr("id", id3).End()
.Start("page").Attr("id", id1).End();
var msg = p.At("users", id, "allowed")
.With("operations", "READ")
.Post(pagesDoc, new Result<DreamMessage>()).Wait();
Assert.AreEqual(DreamStatus.Ok, msg.Status, "Allowed retrieval failed");
var filtered = msg.ToDocument();
_log.DebugFormat("------------ submitted page doc\r\n{0}", pagesDoc.ToPrettyString());
_log.DebugFormat("------------ received page doc\r\n{0}", filtered.ToPrettyString());
Assert.AreEqual(new[] { id2, id3, id1 }, filtered["page/@id"].Select(x => x.Contents).ToArray(), "wrong page id's returned");
}