本文整理汇总了C#中System.Xml.XmlWriter.WriteElementStringIfNotNull方法的典型用法代码示例。如果您正苦于以下问题:C# XmlWriter.WriteElementStringIfNotNull方法的具体用法?C# XmlWriter.WriteElementStringIfNotNull怎么用?C# XmlWriter.WriteElementStringIfNotNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlWriter
的用法示例。
在下文中一共展示了XmlWriter.WriteElementStringIfNotNull方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeBlobListing
static void SerializeBlobListing(XmlWriter writer, BlobListHandler.BlobListResults results)
{
var uri = new UriBuilder(results.ServiceEndpoint);
writer.WriteStartElement("EnumerationResults");
if (results.RequestVersion >= StorageServiceVersions.Version_2013_08_15)
{
writer.WriteAttributeString("ServiceEndpoint", results.ServiceEndpoint);
writer.WriteAttributeString("ContainerName", results.ContainerName);
}
else
{
uri = uri.AddPathSegment(results.ContainerName);
writer.WriteAttributeString("ContainerName", uri.Uri.ToString());
}
writer.WriteElementStringIfNotNull("Prefix", results.Prefix);
writer.WriteElementStringIfNotNull("Marker", results.Marker);
writer.WriteElementStringIfNotNull("MaxResults", results.IndicatedMaxResults);
writer.WriteElementStringIfNotNull("Delimiter", results.Delimiter);
writer.WriteStartElement("Blobs");
IListBlobItem nextBlob = null;
int blobCount = 0;
foreach (var blob in results.Blobs)
{
if (++blobCount > results.MaxResults)
{
nextBlob = blob;
break;
}
else if (blob is ICloudBlob)
{
var realBlob = (ICloudBlob)blob;
writer.WriteStartElement("Blob");
writer.WriteElementString("Name", realBlob.Name);
if (results.RequestVersion < StorageServiceVersions.Version_2013_08_15)
{
writer.WriteElementString("Url", uri.AddPathSegment(realBlob.Name).Uri.ToString());
}
if (realBlob.IsSnapshot && results.IncludeDetails.IsFlagSet(BlobListingDetails.Snapshots))
{
writer.WriteElementString("Snapshot", realBlob.SnapshotTime, true);
}
writer.WriteStartElement("Properties");
writer.WriteElementString("Last-Modified", realBlob.Properties.LastModified);
writer.WriteElementString("Etag", realBlob.Properties.ETag);
writer.WriteElementString("Content-Length", realBlob.Properties.Length.ToString());
writer.WriteElementString("Content-Type", realBlob.Properties.ContentType);
writer.WriteElementString("Content-Encoding", realBlob.Properties.ContentEncoding);
writer.WriteElementString("Content-Language", realBlob.Properties.ContentLanguage);
writer.WriteElementString("Content-MD5", realBlob.Properties.ContentMD5);
writer.WriteElementString("Cache-Control", realBlob.Properties.CacheControl);
writer.WriteElementString("Content-Disposition", realBlob.Properties.ContentDisposition);
writer.WriteElementStringIfNotNull("x-ms-blob-sequence-number", realBlob.Properties.PageBlobSequenceNumber);
writer.WriteElementStringIfNotEnumValue("BlobType", realBlob.Properties.BlobType, BlobType.Unspecified, false);
if (results.RequestVersion >= StorageServiceVersions.Version_2012_02_12)
{
writer.WriteElementStringIfNotEnumValue("LeaseStatus", realBlob.Properties.LeaseStatus, LeaseStatus.Unspecified);
writer.WriteElementStringIfNotEnumValue("LeaseState", realBlob.Properties.LeaseState, LeaseState.Unspecified);
writer.WriteElementStringIfNotEnumValue("LeaseDuration", realBlob.Properties.LeaseDuration, LeaseDuration.Unspecified);
}
if (results.IncludeDetails.IsFlagSet(BlobListingDetails.Copy) && realBlob.CopyState != null)
{
writer.WriteElementStringIfNotNull("CopyId", realBlob.CopyState.CopyId);
writer.WriteElementStringIfNotEnumValue("CopyStatus", realBlob.CopyState.Status, CopyStatus.Invalid);
writer.WriteElementStringIfNotNull("CopySource", realBlob.CopyState.Source.ToString());
writer.WriteElementString("CopyProgress", String.Format("{0}/{1}", realBlob.CopyState.BytesCopied, realBlob.CopyState.TotalBytes));
writer.WriteElementStringIfNotNull("CopyCompletionTime", realBlob.CopyState.CompletionTime);
writer.WriteElementStringIfNotNull("CopyStatusDescription", realBlob.CopyState.StatusDescription);
}
writer.WriteEndElement(); // Properties
if (results.IncludeDetails.IsFlagSet(BlobListingDetails.Metadata))
{
writer.WriteStartElement("Metadata");
foreach (var metadataItem in realBlob.Metadata)
{
writer.WriteElementString(metadataItem.Key, metadataItem.Value);
}
writer.WriteEndElement(); // Metadata
}
writer.WriteEndElement(); // Blob
}
else if (blob is CloudBlobDirectory)
{
writer.WriteStartElement("BlobPrefix");
writer.WriteElementString("Name", ((CloudBlobDirectory)blob).Prefix);
writer.WriteEndElement();
}
else
{
System.Diagnostics.Debug.Assert(false, "Unexpected blob listing item");
}
}
writer.WriteEndElement(); // Blobs
if (nextBlob != null)
{
writer.WriteElementString("NextMarker", BlobListHandler.GetMarkerForBlob(nextBlob));
}
writer.WriteEndElement(); // EnumerationResults
}
示例2: SerializeContainerListing
static void SerializeContainerListing(XmlWriter writer, ContainerListResults results)
{
writer.WriteStartElement("EnumerationResults");
var uri = new UriBuilder(results.ServiceEndpoint);
if (results.RequestVersion >= StorageServiceVersions.Version_2013_08_15)
{
writer.WriteAttributeString("ServiceEndpoint", results.ServiceEndpoint);
}
else
{
writer.WriteAttributeString("AccountName", results.ServiceEndpoint);
}
writer.WriteElementStringIfNotNull("Prefix", results.Prefix);
writer.WriteElementStringIfNotNull("Marker", results.Marker);
writer.WriteElementStringIfNotNull("MaxResults", results.MaxResults);
writer.WriteStartElement("Containers");
foreach (var container in results.Containers.Results)
{
writer.WriteStartElement("Container");
writer.WriteElementString("Name", container.Name);
if (results.RequestVersion < StorageServiceVersions.Version_2013_08_15)
{
writer.WriteElementString("Url", uri.AddPathSegment(container.Name).Uri.ToString());
}
writer.WriteStartElement("Properties");
writer.WriteElementString("Last-Modified", container.Properties.LastModified);
writer.WriteElementString("Etag", container.Properties.ETag);
if (results.RequestVersion >= StorageServiceVersions.Version_2012_02_12)
{
writer.WriteElementStringIfNotEnumValue("LeaseStatus", container.Properties.LeaseStatus, LeaseStatus.Unspecified);
writer.WriteElementStringIfNotEnumValue("LeaseState", container.Properties.LeaseState, LeaseState.Unspecified);
writer.WriteElementStringIfNotEnumValue("LeaseDuration", container.Properties.LeaseDuration, LeaseDuration.Unspecified);
}
writer.WriteEndElement(); // Properties
if (results.IncludeDetails.IsFlagSet(ContainerListingDetails.Metadata))
{
writer.WriteStartElement("Metadata");
foreach (var metadataItem in container.Metadata)
{
writer.WriteElementString(metadataItem.Key, metadataItem.Value);
}
writer.WriteEndElement(); // Metadata
}
writer.WriteEndElement(); // Container
}
writer.WriteEndElement(); // Containers
if (results.Containers.ContinuationToken != null)
{
writer.WriteElementStringIfNotNull("NextMarker", results.Containers.ContinuationToken.NextMarker);
}
writer.WriteEndElement(); // EnumerationResults
}
示例3: SerializeServiceProperties
static void SerializeServiceProperties(XmlWriter writer, RequestServiceProperites results)
{
writer.WriteStartElement("StorageServiceProperties");
writer.WriteStartElement("Logging");
writer.WriteElementStringIfNotNull("Version", results.Properties.Logging.Version);
// TODO: These values are hard-coded until we implement logging & metrics
writer.WriteElementString("Delete", "false");
writer.WriteElementString("Read", "false");
writer.WriteElementString("Write", "false");
SerializeRetentionPolicy(writer);
writer.WriteEndElement(); // Logging
if (results.RequestVersion <= StorageServiceVersions.Version_2012_02_12)
{
// TODO: These values are hard-coded until we implement logging & metrics
writer.WriteStartElement("Metrics");
writer.WriteElementStringIfNotNull("Version", results.Properties.HourMetrics.Version);
writer.WriteElementString("Enabled", "false");
writer.WriteElementString("IncludeAPIs", "false");
SerializeRetentionPolicy(writer);
writer.WriteEndElement(); // Metrics
}
else
{
// TODO: These values are hard-coded until we implement logging & metrics
writer.WriteStartElement("HourMetrics");
writer.WriteElementStringIfNotNull("Version", results.Properties.HourMetrics.Version);
writer.WriteElementString("Enabled", "false");
writer.WriteElementString("IncludeAPIs", "false");
SerializeRetentionPolicy(writer);
writer.WriteEndElement(); // HourMetrics
// TODO: These values are hard-coded until we implement logging & metrics
writer.WriteStartElement("MinuteMetrics");
writer.WriteElementStringIfNotNull("Version", results.Properties.MinuteMetrics.Version);
writer.WriteElementString("Enabled", "false");
writer.WriteElementString("IncludeAPIs", "false");
SerializeRetentionPolicy(writer);
writer.WriteEndElement(); // MinuteMetrics
writer.WriteStartElement("Cors");
foreach (var corsRule in results.Properties.Cors.CorsRules)
{
writer.WriteStartElement("CorsRule");
writer.WriteElementString("AllowedOrigins", String.Join(",", corsRule.AllowedOrigins));
writer.WriteElementString("AllowedMethods", corsRule.AllowedMethods.ToString());
writer.WriteElementString("MaxAgeInSeconds", corsRule.MaxAgeInSeconds.ToString());
writer.WriteElementString("ExposedHeaders", String.Join(",", corsRule.ExposedHeaders));
writer.WriteElementString("AllowedHeaders", String.Join(",", corsRule.AllowedHeaders));
writer.WriteEndElement(); // CorsRule
}
writer.WriteEndElement(); // Cors
}
writer.WriteElementStringIfNotNull("DefaultServiceVersion", results.Properties.DefaultServiceVersion);
writer.WriteEndElement(); // StorageServiceProperties
}
示例4: WriteContentsTo
/// <summary>
/// Writes the contents of this <see cref="T:System.ServiceModel.Syndication.SyndicationContent"/> object to the specified <see cref="T:System.Xml.XmlWriter"/>.
/// </summary>
/// <param name="writer">The <see cref="T:System.Xml.XmlWriter"/> to write to.</param>
protected override void WriteContentsTo(XmlWriter writer)
{
writer.WriteStartElement("Contact", Constants.XmlNamespace);
{
if (Contact.Id != null)
{
writer.WriteAttributeString("id", Contact.Id.ToString());
}
writer.WriteElementStringIfNotNull("EmailAddress", Contact.EmailAddress);
writer.WriteElementStringIfNotNull("EmailType", Contact.EmailType.ToString());
writer.WriteElementStringIfNotNull("FirstName", Contact.FirstName);
writer.WriteElementStringIfNotNull("MiddleName", Contact.MiddleName);
writer.WriteElementStringIfNotNull("LastName", Contact.LastName);
writer.WriteElementStringIfNotNull("JobTitle", Contact.JobTitle);
writer.WriteElementStringIfNotNull("CompanyName", Contact.CompanyName);
writer.WriteElementStringIfNotNull("HomePhone", Contact.HomePhone);
writer.WriteElementStringIfNotNull("WorkPhone", Contact.WorkPhone);
writer.WriteElementStringIfNotNull("Addr1", Contact.Addr1);
writer.WriteElementStringIfNotNull("Addr2", Contact.Addr2);
writer.WriteElementStringIfNotNull("Addr3", Contact.Addr3);
writer.WriteElementStringIfNotNull("City", Contact.City);
writer.WriteElementStringIfNotNull("StateCode", Contact.StateCode);
writer.WriteElementStringIfNotNull("StateName", Contact.StateName);
writer.WriteElementStringIfNotNull("CountryCode", Contact.CountryCode);
writer.WriteElementStringIfNotNull("CountryName", Contact.CountryName);
writer.WriteElementStringIfNotNull("PostalCode", Contact.PostalCode);
writer.WriteElementStringIfNotNull("SubPostalCode", Contact.SubPostalCode);
writer.WriteElementStringIfNotNull("Note", Contact.Note);
for (int i = Contact.CustomField.GetLowerBound(0); i <= Contact.CustomField.GetUpperBound(0); i++)
{
writer.WriteElementStringIfNotNull(String.Format("CustomField{0}", i),
Contact.CustomField[i]);
}
writer.WriteElementString("OptInTime", Contact.OptInTime.ToString("O"));
writer.WriteElementString("OptInSource", Contact.OptInSource.ToString());
writer.WriteElementString("Confirmed", Contact.Confirmed.ToString());
writer.WriteElementString("InsertTime", Contact.InsertTime.ToString("O"));
writer.WriteElementString("LastUpdateTime", Contact.LastUpdateTime.ToString("O"));
writer.WriteStartElement("ContactLists");
foreach (ContactList list in Contact.Lists)
{
writer.WriteStartElement("ContactList");
writer.WriteAttributeString("id", list.Link);
writer.WriteStartElement("link");
writer.WriteAttributeString("href", list.Link);
writer.WriteAttributeString("rel", "self");
writer.WriteEndElement(); // link
writer.WriteElementString("OptInSource", list.OptInSource.ToString());
writer.WriteElementString("OptInTime", list.OptInTime.ToString("O"));
writer.WriteEndElement(); // ContactList
}
writer.WriteEndElement(); // ContactLists
}
writer.WriteEndElement(); // Contact
}