当前位置: 首页>>代码示例>>C#>>正文


C# XDocument.GetDocumentAsString方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:hitesh97,项目名称:C1-CMS,代码行数:92,代码来源:FormData.cs

示例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;
        }
开发者ID:RuneAndersen,项目名称:C1-CMS,代码行数:69,代码来源:PackageServerFacadeLocalMock.cs


注:本文中的System.Xml.Linq.XDocument.GetDocumentAsString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。