Example #1
0
 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
 }
Example #2
0
 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 
 }