public static Blob ParseFromXMLNode(Container container, XmlNode node) { Enumerations.BlobType blobType = (Enumerations.BlobType)Enum.Parse( typeof(Enumerations.BlobType), node.SelectSingleNode("Properties/BlobType").InnerText, true); Blob blob = null; switch (blobType) { case Enumerations.BlobType.BlockBlob: blob = new BlockBlob(container); break; case Enumerations.BlobType.PageBlob: blob = new PageBlob(container); break; default: throw new ArgumentException("BlobType of type " + blobType.ToString() + " is not supported."); } blob.Name = node.SelectSingleNode("Name").InnerText; blob.Url = new Uri(node.SelectSingleNode("Url").InnerText); blob.LeaseState = (Enumerations.LeaseState)Enum.Parse(typeof(Enumerations.LeaseState), node.SelectSingleNode("Properties/LeaseState").InnerText, true); blob.LeaseStatus = (Enumerations.LeaseStatus)Enum.Parse(typeof(Enumerations.LeaseStatus), node.SelectSingleNode("Properties/LeaseStatus").InnerText, true); blob.ContentLength = long.Parse(node.SelectSingleNode("Properties/Content-Length").InnerText); blob.BlobType = blobType; System.Xml.XmlNode nMeta = node.SelectSingleNode("Metadata"); if (nMeta != null) { foreach (System.Xml.XmlNode nMetaElem in nMeta.ChildNodes) { blob.Metadata[nMetaElem.Name] = nMetaElem.InnerText; } } XmlNode n = node.SelectSingleNode("Properties/LeaseDuration"); if (n != null) { blob.LeaseDuration = (Enumerations.LeaseDuration)Enum.Parse(typeof(Enumerations.LeaseDuration), n.InnerText, true); } n = node.SelectSingleNode("Properties/Last-Modified"); if (n != null) { blob.LastModified = DateTime.Parse(n.InnerText); } n = node.SelectSingleNode("Properties/Etag"); if (n != null) { blob.Etag = n.InnerText; } n = node.SelectSingleNode("Properties/Content-Type"); if (n != null) { blob.ContentType = n.InnerText; } n = node.SelectSingleNode("Properties/Content-Encoding"); if (n != null) { blob.ContentEncoding = n.InnerText; } n = node.SelectSingleNode("Properties/Content-Language"); if (n != null) { blob.ContentLanguage = n.InnerText; } n = node.SelectSingleNode("Properties/Content-MD5"); if (n != null) { blob.ContentMD5 = n.InnerText; } n = node.SelectSingleNode("Properties/CopyId"); if (n != null) { blob.CopyAttributes = new CopyAttributes() { CopyId = Guid.Parse(node.SelectSingleNode("Properties/CopyId").InnerText), CopySource = new Uri(node.SelectSingleNode("Properties/CopySource").InnerText), CopyStatus = node.SelectSingleNode("Properties/CopyStatus").InnerText }; n = node.SelectSingleNode("Properties/CopyCompletionTime"); if (n != null) { blob.CopyAttributes.CopyCompletionTime = DateTime.Parse(n.InnerText); } n = node.SelectSingleNode("Properties/CopyProgress"); if (n != null) { string[] tokens = n.InnerText.Split(new char[] { '/' }); blob.CopyAttributes.CopyCurrentPosition = long.Parse(tokens[0]); blob.CopyAttributes.CopyTotalLength = long.Parse(tokens[1]); } } return(blob); }
public static SqlBinary DownloadPageBlob( SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS, SqlString containerName, SqlString blobName, SqlGuid leaseId, SqlInt64 startPosition, SqlInt32 length, SqlGuid xmsclientrequestId) { AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value); Container cont = abs.GetContainer(containerName.Value); ITPCfSQL.Azure.PageBlob blob = new ITPCfSQL.Azure.PageBlob(cont, blobName.Value); byte[] bBuffer = new byte[1024]; using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { int iDownloaded = 0; using (System.IO.Stream s = blob.Download( leaseId.IsNull ? (Guid?)null : leaseId.Value, (DateTime?)null, startPosition.IsNull ? (long?)null : startPosition.Value, length.IsNull ? (long?)null : length.Value, xmsclientrequestId: xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value)) { while ((iDownloaded = s.Read(bBuffer, 0, bBuffer.Length)) > 0) { ms.Write(bBuffer, 0, iDownloaded); } } return new SqlBinary(ms.ToArray()); } }
public static Blob ParseFromXMLNode(Container container, XmlNode node) { Enumerations.BlobType blobType = (Enumerations.BlobType)Enum.Parse( typeof(Enumerations.BlobType), node.SelectSingleNode("Properties/BlobType").InnerText, true); Blob blob = null; switch (blobType) { case Enumerations.BlobType.BlockBlob: blob = new BlockBlob(container); break; case Enumerations.BlobType.PageBlob: blob = new PageBlob(container); break; default: throw new ArgumentException("BlobType of type " + blobType.ToString() + " is not supported."); } blob.Name = node.SelectSingleNode("Name").InnerText; blob.Url = new Uri(node.SelectSingleNode("Url").InnerText); blob.LeaseState = (Enumerations.LeaseState)Enum.Parse(typeof(Enumerations.LeaseState), node.SelectSingleNode("Properties/LeaseState").InnerText, true); blob.LeaseStatus = (Enumerations.LeaseStatus)Enum.Parse(typeof(Enumerations.LeaseStatus), node.SelectSingleNode("Properties/LeaseStatus").InnerText, true); blob.ContentLength = long.Parse(node.SelectSingleNode("Properties/Content-Length").InnerText); blob.BlobType = blobType; System.Xml.XmlNode nMeta = node.SelectSingleNode("Metadata"); if (nMeta != null) { foreach (System.Xml.XmlNode nMetaElem in nMeta.ChildNodes) { blob.Metadata[nMetaElem.Name] = nMetaElem.InnerText; } } XmlNode n = node.SelectSingleNode("Properties/LeaseDuration"); if (n != null) blob.LeaseDuration = (Enumerations.LeaseDuration)Enum.Parse(typeof(Enumerations.LeaseDuration), n.InnerText, true); n = node.SelectSingleNode("Properties/Last-Modified"); if (n != null) blob.LastModified = DateTime.Parse(n.InnerText); n = node.SelectSingleNode("Properties/Etag"); if (n != null) blob.Etag = n.InnerText; n = node.SelectSingleNode("Properties/Content-Type"); if (n != null) blob.ContentType = n.InnerText; n = node.SelectSingleNode("Properties/Content-Encoding"); if (n != null) blob.ContentEncoding = n.InnerText; n = node.SelectSingleNode("Properties/Content-Language"); if (n != null) blob.ContentLanguage = n.InnerText; n = node.SelectSingleNode("Properties/Content-MD5"); if (n != null) blob.ContentMD5 = n.InnerText; n = node.SelectSingleNode("Properties/CopyId"); if (n != null) { blob.CopyAttributes = new CopyAttributes() { CopyId = Guid.Parse(node.SelectSingleNode("Properties/CopyId").InnerText), CopySource = new Uri(node.SelectSingleNode("Properties/CopySource").InnerText), CopyStatus = node.SelectSingleNode("Properties/CopyStatus").InnerText }; n = node.SelectSingleNode("Properties/CopyCompletionTime"); if (n != null) blob.CopyAttributes.CopyCompletionTime = DateTime.Parse(n.InnerText); n = node.SelectSingleNode("Properties/CopyProgress"); if (n != null) { string[] tokens = n.InnerText.Split(new char[] { '/' }); blob.CopyAttributes.CopyCurrentPosition = long.Parse(tokens[0]); blob.CopyAttributes.CopyTotalLength = long.Parse(tokens[1]); } } return blob; }