本文整理汇总了C#中System.Xml.Linq.XDocument.GetDocumentAsString方法的典型用法代码示例。如果您正苦于以下问题:C# XDocument.GetDocumentAsString方法的具体用法?C# XDocument.GetDocumentAsString怎么用?C# XDocument.GetDocumentAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XDocument
的用法示例。
在下文中一共展示了XDocument.GetDocumentAsString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
/// <exclude />
public XElement Serialize()
{
using (var cultureInvariant = new ThreadCultureScope(CultureInfo.InvariantCulture))
{
IXmlSerializer xmlSerializer = new XmlSerializer(new IValueXmlSerializer[] {
new SystemPrimitivValueXmlSerializer(),
new SystemCollectionValueXmlSerializer(),
new SystemTypesValueXmlSerializer(),
new CompositeCollectionValueXmlSerializer(),
new DataFieldDescriptorValueXmlSerializer(),
new DataTypeDescriptorValueXmlSerializer(),
new NamedFunctionCallValueXmlSerializer(),
new SerializerHandlerValueXmlSerializer(),
new SystemSerializableValueXmlSerializer() });
XElement containerLabelElement = new XElement("ContainerLabel");
if (this.ContainerLabel != null)
{
containerLabelElement.Add(new XAttribute("value", this.ContainerLabel));
}
XElement formDefinitionElement = new XElement("FormDefinition");
if (this.FormDefinition != null)
{
formDefinitionElement.Add(new XAttribute("value", this.FormDefinition));
}
else
{
using (XmlReader xmlReader = this.FormMarkupProvider.GetReader())
{
xmlReader.MoveToContent();
XElement element = (XElement)XDocument.ReadFrom(xmlReader);
XDocument document = new XDocument(element);
string content = document.GetDocumentAsString();
formDefinitionElement.Add(new XAttribute("value", content));
}
}
XElement customToolbarDefinitionElement = new XElement("CustomToolbarDefinition");
if (this.CustomToolbarDefinition != null)
{
customToolbarDefinitionElement.Add(new XAttribute("value", this.CustomToolbarDefinition));
}
else if (this.CustomToolbarMarkupProvider != null)
{
using (XmlReader xmlReader = this.CustomToolbarMarkupProvider.GetReader())
{
xmlReader.MoveToContent();
XElement element = (XElement)XDocument.ReadFrom(xmlReader);
XDocument document = new XDocument(element);
string content = document.GetDocumentAsString();
customToolbarDefinitionElement.Add(new XAttribute("value", content));
}
}
XElement containerTypeElement = xmlSerializer.Serialize(typeof(IFlowUiContainerType), this.ContainerType);
Dictionary<string, object> selectedBindings =
(from kvp in this.Bindings
where (kvp.Value != null &&
kvp.Value.GetType() != typeof(System.EventHandler)) ||
kvp.Value == null
select kvp).ToDictionary(f => f.Key, f => f.Value);
XElement bindingsElement = xmlSerializer.Serialize(typeof(Dictionary<string, object>), selectedBindings);
XElement bindingsValidationRulesElement = xmlSerializer.Serialize(typeof(Dictionary<string, List<ClientValidationRule>>), this.BindingsValidationRules);
XElement excludedEventsElement = xmlSerializer.Serialize(typeof(List<string>), ExcludedEvents);
XElement formDataElement = new XElement("FormData");
formDataElement.Add(containerLabelElement);
formDataElement.Add(formDefinitionElement);
formDataElement.Add(customToolbarDefinitionElement);
formDataElement.Add(new XElement("ContainerType", containerTypeElement));
formDataElement.Add(new XElement("Bindings", bindingsElement));
formDataElement.Add(new XElement("BindingsValidationRules", bindingsValidationRulesElement));
if (excludedEventsElement != null) formDataElement.Add(new XElement("ExcludedEvents", excludedEventsElement));
if (this.EventHandleFilterType != null)
{
formDataElement.Add(new XElement("EventHandleFilterType", new XAttribute("type", TypeManager.SerializeType(this.EventHandleFilterType))));
}
return formDataElement;
}
}
示例2: GetInstallFileStream
public Stream GetInstallFileStream(string packageFileDownloadUrl)
{
Initialize();
PackageDescription packageDescription = null;
ExtraInfo extraInfo = null;
foreach (List<KeyValuePair<PackageDescription, ExtraInfo>> packageDescriptions in _packageDescriptions.Values)
{
KeyValuePair<PackageDescription, ExtraInfo>? q =
(from desc in packageDescriptions
where desc.Key.PackageFileDownloadUrl == packageFileDownloadUrl
select desc).FirstOrDefault();
if (q != null)
{
packageDescription = q.Value.Key;
extraInfo = q.Value.Value;
break;
}
}
XElement rootElement =
new XElement(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageInstallerElementName),
new XElement(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageRequirementsElementName),
new XAttribute(PackageSystemSettings.MinimumCompositeVersionAttributeName, packageDescription.MinCompositeVersionSupported),
new XAttribute(PackageSystemSettings.MaximumCompositeVersionAttributeName, packageDescription.MaxCompositeVersionSupported)
),
new XElement(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageInformationElementName),
new XAttribute(PackageSystemSettings.IdAttributeName, packageDescription.Id),
new XAttribute(PackageSystemSettings.NameAttributeName, packageDescription.Name),
new XAttribute(PackageSystemSettings.GroupNameAttributeName, packageDescription.GroupName),
new XAttribute(PackageSystemSettings.AuthorAttributeName, packageDescription.Vendor),
new XAttribute(PackageSystemSettings.WebsiteAttributeName, packageDescription.ReadMoreUrl),
new XAttribute(PackageSystemSettings.VersionAttributeName, packageDescription.PackageVersion),
new XAttribute(PackageSystemSettings.CanBeUninstalledAttributeName, extraInfo.CanBeUninstalled),
new XAttribute(PackageSystemSettings.SystemLockingAttributeName, extraInfo.SystemLockingType.Serialize()),
new XAttribute(PackageSystemSettings.FlushOnCompletionAttributeName, extraInfo.FlushOnCompletion),
new XAttribute(PackageSystemSettings.ReloadConsoleOnCompletionAttributeName, extraInfo.ReloadConsoleOnCompletion),
packageDescription.Description
),
new XElement(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageFragmentInstallersElementName))
);
XDocument doc = new XDocument(rootElement);
string content = doc.GetDocumentAsString();
UTF8Encoding encoding = new UTF8Encoding();
byte[] buffer = encoding.GetBytes(content);
MemoryStream outputStream = new MemoryStream();
ZipOutputStream zipStream = new ZipOutputStream(outputStream);
Crc32 crc = new Crc32();
crc.Update(buffer);
ZipEntry zipEntry = new ZipEntry("install.xml");
zipEntry.Size = buffer.Length;
zipEntry.Crc = crc.Value;
zipEntry.DateTime = DateTime.Now;
zipStream.PutNextEntry(zipEntry);
zipStream.Write(buffer, 0, buffer.Length);
zipStream.Finish();
outputStream.Seek(0, SeekOrigin.Begin);
return outputStream;
}