Exemplo n.º 1
0
 public static IEnumerable <Container> ParseFromXMLEnumerationResults(AzureBlobService abs, XmlDocument doc)
 {
     foreach (XmlNode n in doc.SelectNodes("EnumerationResults/Containers/Container"))
     {
         yield return(ParseFromXMLNode(abs, n));
     }
 }
Exemplo n.º 2
0
        public static void AddContainerACL(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString containerName,
            SqlString containerPublicReadAccess,
            SqlString accessPolicyId,
            SqlDateTime start, SqlDateTime expiry,
            SqlBoolean canRead,
            SqlBoolean canWrite,
            SqlBoolean canDeleteBlobs,
            SqlBoolean canListBlobs,
            SqlGuid LeaseId,
            SqlInt32 timeoutSeconds,
            SqlGuid xmsclientrequestId)
        {
            Enumerations.ContainerPublicReadAccess cpraNew;
            if(!Enum.TryParse<Enumerations.ContainerPublicReadAccess>(containerPublicReadAccess.Value, out cpraNew))
            {
                StringBuilder sb = new StringBuilder("\"" + containerPublicReadAccess.Value + "\" is an invalid ContainerPublicReadAccess value. Valid values are: ");
                foreach (string s in Enum.GetNames(typeof(Enumerations.ContainerPublicReadAccess)))
                    sb.Append("\"" + s + "\" ");
                throw new ArgumentException(sb.ToString());
            }

            AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            Container cont = abs.GetContainer(containerName.Value);

            Enumerations.ContainerPublicReadAccess cpra;
            SharedAccessSignature.SharedAccessSignatureACL sasACL = cont.GetACL(out cpra,
                LeaseId.IsNull ? (Guid?)null : LeaseId.Value,
                timeoutSeconds.IsNull ? 0 : timeoutSeconds.Value,
                xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);

            string strPermissions = "";
            if (canRead.IsTrue)
                strPermissions += "r";
            if (canWrite.IsTrue)
                strPermissions += "w";
            if (canDeleteBlobs.IsTrue)
                strPermissions += "d";
            if (canListBlobs.IsTrue)
                strPermissions += "l";

            SharedAccessSignature.AccessPolicy ap = new SharedAccessSignature.AccessPolicy()
            {
                Start = start.Value,
                Expiry = expiry.Value,
                Permission = strPermissions
            };

            sasACL.SignedIdentifier.Add(new SharedAccessSignature.SignedIdentifier()
                {
                    AccessPolicy = ap,
                    Id = accessPolicyId.Value
                });

            cont.UpdateContainerACL(cpraNew, sasACL,
                LeaseId.IsNull ? (Guid?)null : LeaseId.Value,
                timeoutSeconds.IsNull ? 0 : timeoutSeconds.Value,
                xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);
        }
Exemplo n.º 3
0
 public static IEnumerable<Container> ParseFromXMLEnumerationResults(AzureBlobService abs, XmlDocument doc)
 {
     foreach (XmlNode n in doc.SelectNodes("EnumerationResults/Containers/Container"))
     {
         yield return ParseFromXMLNode(abs, n);
     }
 }
Exemplo n.º 4
0
        public static Container ParseFromXMLNode(AzureBlobService abs, XmlNode node)
        {
            Container cont = new Container()
            {
                Name = node.SelectSingleNode("Name").InnerText,
                Url = new Uri(node.SelectSingleNode("Url").InnerText),
                LastModified = DateTime.Parse(node.SelectSingleNode("Properties/Last-Modified").InnerText),
                Etag = node.SelectSingleNode("Properties/Etag").InnerText,
                LeaseState = (Enumerations.LeaseState)Enum.Parse(typeof(Enumerations.LeaseState), node.SelectSingleNode("Properties/LeaseState").InnerText, true),
                LeaseStatus = (Enumerations.LeaseStatus)Enum.Parse(typeof(Enumerations.LeaseStatus), node.SelectSingleNode("Properties/LeaseStatus").InnerText, true),
                AzureBlobService = abs
            };

            XmlNode n = node.SelectSingleNode("Properties/LeaseDuration");
            if (n != null)
                cont.LeaseDuration = (Enumerations.LeaseDuration)Enum.Parse(typeof(Enumerations.LeaseDuration), n.InnerText, true);

            return cont;
        }
Exemplo n.º 5
0
        public static void AcquireBlobInfiniteLease(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString containerName,
            SqlString blobName,
            SqlGuid proposedLeaseId,
            SqlInt32 timeoutSeconds,
            SqlGuid xmsclientrequestId)
        {
            AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            Container cont = abs.GetContainer(containerName.Value);
            Blob blob = cont.GetBlob(blobName.Value);

            Responses.LeaseBlobResponse lbr = blob.AcquireInfiniteLease(
                proposedLeaseId.IsNull ? (Guid?)null : proposedLeaseId.Value,
                timeoutSeconds.IsNull ? 0 : timeoutSeconds.Value,
                xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);

            PushLeaseBlobResponse(lbr);
        }
Exemplo n.º 6
0
        public static Container ParseFromXMLNode(AzureBlobService abs, XmlNode node)
        {
            Container cont = new Container()
            {
                Name             = node.SelectSingleNode("Name").InnerText,
                Url              = new Uri(node.SelectSingleNode("Url").InnerText),
                LastModified     = DateTime.Parse(node.SelectSingleNode("Properties/Last-Modified").InnerText),
                Etag             = node.SelectSingleNode("Properties/Etag").InnerText,
                LeaseState       = (Enumerations.LeaseState)Enum.Parse(typeof(Enumerations.LeaseState), node.SelectSingleNode("Properties/LeaseState").InnerText, true),
                LeaseStatus      = (Enumerations.LeaseStatus)Enum.Parse(typeof(Enumerations.LeaseStatus), node.SelectSingleNode("Properties/LeaseStatus").InnerText, true),
                AzureBlobService = abs
            };

            XmlNode n = node.SelectSingleNode("Properties/LeaseDuration");

            if (n != null)
            {
                cont.LeaseDuration = (Enumerations.LeaseDuration)Enum.Parse(typeof(Enumerations.LeaseDuration), n.InnerText, true);
            }

            return(cont);
        }
Exemplo n.º 7
0
        public static void BreakBlobLeaseWithGracePeriod(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString containerName,
            SqlString blobName,
            SqlInt32 leaseBreakPeriod,
            SqlInt32 timeoutSeconds,
            SqlGuid xmsclientrequestId)
        {
            AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            Container cont = abs.GetContainer(containerName.Value);
            Blob blob = cont.GetBlob(blobName.Value);

            Responses.LeaseBlobResponse lbr = blob.BreakLeaseWithGracePeriod(
                leaseBreakPeriod.IsNull ? 0 : leaseBreakPeriod.Value,
                timeoutSeconds.IsNull ? 0 : timeoutSeconds.Value,
                xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);

            PushLeaseBlobResponse(lbr);
        }
Exemplo n.º 8
0
        public static void RemoveContainerACL(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString containerName,            
            SqlString accessPolicyId,            
            SqlGuid LeaseId,
            SqlInt32 timeoutSeconds,
            SqlGuid xmsclientrequestId)
        {
            AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            Container cont = abs.GetContainer(containerName.Value);

            Enumerations.ContainerPublicReadAccess cpra;
            SharedAccessSignature.SharedAccessSignatureACL sasACL = cont.GetACL(out cpra,
                LeaseId.IsNull ? (Guid?)null : LeaseId.Value,
                timeoutSeconds.IsNull ? 0 : timeoutSeconds.Value,
                xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);

            int idx = sasACL.SignedIdentifier.FindIndex(item => item.Id == accessPolicyId.Value);
            if (idx == -1)
                throw new ArgumentException("No shared access policy with Id=" + accessPolicyId.Value + " found on container " + containerName.Value + ".");

            sasACL.SignedIdentifier.RemoveAt(idx);

            cont.UpdateContainerACL(cpra, sasACL,
                LeaseId.IsNull ? (Guid?)null : LeaseId.Value,
                timeoutSeconds.IsNull ? 0 : timeoutSeconds.Value,
                xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);
        }
Exemplo n.º 9
0
        public static void UpdateBlobMetadata(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString containerName,
            SqlString blobName,
            SqlXml AttributeList,
            SqlGuid leaseId,
            SqlInt32 timeoutSeconds,
            SqlGuid xmsclientrequestId)
        {
            AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            Container cont = abs.GetContainer(containerName.Value);
            Blob blob = cont.GetBlob(blobName.Value);

            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.LoadXml(AttributeList.Value);

            if (doc.FirstChild.ChildNodes.Count == 1)
            {
                // single row, multiple attribs...  FOR XML RAW?
                foreach (System.Xml.XmlAttribute attrib in doc.FirstChild.FirstChild.Attributes)
                {
                    blob.Metadata[attrib.Name] = attrib.Value;
                }
            }
            else
            {
                foreach (System.Xml.XmlNode nAttrib in doc.FirstChild.ChildNodes)
                {
                    if (!(string.IsNullOrEmpty(nAttrib.InnerText)))
                        blob.Metadata[nAttrib.Name] = nAttrib.InnerText;
                    else if (((nAttrib.Attributes != null) && (nAttrib.Attributes.Count > 0)))
                    {
                        blob.Metadata[nAttrib.Name] = nAttrib.Attributes[0].Value;
                    }
                }
            }

            blob.SaveMetadata(
                leaseId.IsNull ? (Guid?)null : leaseId.Value,
                timeoutSeconds.IsNull ? 0 : timeoutSeconds.Value,
                xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);
        }
Exemplo n.º 10
0
        public static void PutPage(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString containerName, SqlString blobName,
            SqlBytes binaryBuffer,
            SqlInt64 startPositionBytes, SqlInt32 bytesToUpload,
            SqlGuid leaseId, SqlString contentMD5,
            SqlInt32 timeoutSeconds, SqlGuid xmsclientrequestId)
        {
            AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            Container cont = abs.GetContainer(containerName.Value);
            PageBlob pb = cont.GetPageBlob(blobName.Value);

            if (binaryBuffer.IsNull)
            {
                // clear
                pb.ClearPage(
                     startPositionBytes.Value,
                     bytesToUpload.Value,
                     leaseId.IsNull ? (Guid?)null : leaseId.Value,
                     timeoutSeconds.IsNull ? 0 : timeoutSeconds.Value,
                     xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);
            }
            else
            {
                pb.UpdatePage(
                    startPositionBytes.Value,
                    binaryBuffer.Stream,
                    bytesToUpload.IsNull ? (long?)null : bytesToUpload.Value,
                    contentMD5.IsNull ? (null) : contentMD5.Value,
                    leaseId.IsNull ? (Guid?)null : leaseId.Value,
                    timeoutSeconds.IsNull ? 0 : timeoutSeconds.Value,
                    xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);
            }
        }
Exemplo n.º 11
0
        public static void ChangeContainerPublicAccessMethod(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString containerName,
            SqlString containerPublicReadAccess,            
            SqlGuid LeaseId,
            SqlInt32 timeoutSeconds,
            SqlGuid xmsclientrequestId)
        {
            Enumerations.ContainerPublicReadAccess cpraNew;
            if (!Enum.TryParse<Enumerations.ContainerPublicReadAccess>(containerPublicReadAccess.Value, out cpraNew))
            {
                StringBuilder sb = new StringBuilder("\"" + containerPublicReadAccess.Value + "\" is an invalid ContainerPublicReadAccess value. Valid values are: ");
                foreach (string s in Enum.GetNames(typeof(Enumerations.ContainerPublicReadAccess)))
                    sb.Append("\"" + s + "\" ");
                throw new ArgumentException(sb.ToString());
            }

            AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            Container cont = abs.GetContainer(containerName.Value);

            Enumerations.ContainerPublicReadAccess cpra;
            SharedAccessSignature.SharedAccessSignatureACL sasACL = cont.GetACL(out cpra,
                LeaseId.IsNull ? (Guid?)null : LeaseId.Value,
                timeoutSeconds.IsNull ? 0 : timeoutSeconds.Value,
                xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);

            cont.UpdateContainerACL(cpraNew, sasACL,
                LeaseId.IsNull ? (Guid?)null : LeaseId.Value,
                timeoutSeconds.IsNull ? 0 : timeoutSeconds.Value,
                xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);
        }
Exemplo n.º 12
0
        public static void CreateContainer(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString containerName,
            SqlString containerPublicReadAccess,
            SqlString xmsclientrequestId)
        {
            AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);

            Enumerations.ContainerPublicReadAccess cpra;

            if (!Enum.TryParse<Enumerations.ContainerPublicReadAccess>(containerPublicReadAccess.Value, out cpra))
            {
                StringBuilder sb = new StringBuilder("\"" + containerPublicReadAccess.Value + "\" is an invalid ContainerPublicReadAccess value. Valid values are: ");
                foreach (string s in Enum.GetNames(typeof(Enumerations.ContainerPublicReadAccess)))
                    sb.Append("\"" + s + "\" ");
                throw new ArgumentException(sb.ToString());
            }

            abs.CreateContainer(containerName.Value,
                cpra,
                xmsclientrequestId: xmsclientrequestId != null ? xmsclientrequestId.Value : null);
        }
Exemplo n.º 13
0
 public static System.Collections.IEnumerable ListContainers(
     SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
     SqlGuid xmsclientrequestId)
 {
     AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
     return abs.ListContainers(null, true, 0,
         xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);
 }
Exemplo n.º 14
0
        public static System.Collections.IEnumerable GetBlobProperties(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString containerName, SqlString blobName,
            SqlDateTime snapshotDateTime,
            SqlString xmsclientrequestId)
        {
            AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            Container cont = abs.GetContainer(containerName.Value);
            List<Responses.GetBlobPropertyResponse> lResps = new List<Responses.GetBlobPropertyResponse>();

            lResps.Add(cont.GetBlob(blobName.Value).GetProperties(
                snapshotDateTime: snapshotDateTime.IsNull ? (DateTime?)null : snapshotDateTime.Value));

            return lResps;
        }
Exemplo n.º 15
0
        public static System.Collections.IEnumerable GetContainerACL(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString containerName,
            SqlGuid leaseId,
            SqlInt32 timeoutSeconds,
            SqlGuid xmsclientrequestId)
        {
            AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            Container cont = abs.GetContainer(containerName.Value);

            Enumerations.ContainerPublicReadAccess cpr;
            SharedAccessSignature.SharedAccessSignatureACL sasACL = cont.GetACL(out cpr,
                leaseId.IsNull ? (Guid?)null : leaseId.Value,
                timeoutSeconds.IsNull ? 0 : timeoutSeconds.Value,
                xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);

            List<CallbackSupport.SignedIdentifierWithContainerPublicReadAccess> lItems = new List<CallbackSupport.SignedIdentifierWithContainerPublicReadAccess>();
            foreach (SharedAccessSignature.SignedIdentifier si in sasACL.SignedIdentifier)
                lItems.Add(new CallbackSupport.SignedIdentifierWithContainerPublicReadAccess()
                {
                    SignedIdentifier = si,
                    ContainerPublicReadAccess = cpr
                });

            if (lItems.Count == 0) // add empty to expose ContainerPublicReadAccess
                lItems.Add(new CallbackSupport.SignedIdentifierWithContainerPublicReadAccess()
                    {
                        SignedIdentifier = null,
                        ContainerPublicReadAccess = cpr
                    });

            return lItems;
        }
Exemplo n.º 16
0
 public static void DeleteContainer(
     SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
     SqlString containerName,
     SqlGuid leaseId,
     SqlString xmsclientrequestId)
 {
     AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
     abs.GetContainer(containerName.Value).Delete(
         leaseID: leaseId.IsNull ? (Guid?)null : leaseId.Value,
         xmsclientrequestId: xmsclientrequestId.IsNull ? null : xmsclientrequestId.Value);
 }
Exemplo n.º 17
0
        public static void Do()
        {
            string accountName = "enosg";
            string sharedKey = "oooo+ps!";
            bool useHTTPS = true;

            string contName = "testsas";

            SharedAccessSignatureACL queueACL = new SharedAccessSignatureACL();
            queueACL.SignedIdentifier = new List<SignedIdentifier>();

            queueACL.SignedIdentifier.Add(new SignedIdentifier()
            {
                Id = "sisisisisisisvvv",
                AccessPolicy = new AccessPolicy()
                {
                    Start = DateTime.Now.AddYears(-1),
                    Expiry = DateTime.Now.AddYears(1),
                    Permission = "rwd"
                }
            });

            queueACL.SignedIdentifier.Add(new SignedIdentifier()
            {
                Id = "secondsigid",
                AccessPolicy = new AccessPolicy()
                {
                    Start = DateTime.Now.AddYears(-10),
                    Expiry = DateTime.Now.AddYears(10),
                    Permission = "rwdl"
                }
            });

            System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(queueACL.GetType());

            // use this two lines to get rid of those useless namespaces :).
            System.Xml.Serialization.XmlSerializerNamespaces namespaces = new System.Xml.Serialization.XmlSerializerNamespaces();
            namespaces.Add(string.Empty, string.Empty);

            using (System.IO.FileStream fs = new System.IO.FileStream("C:\\temp\\QueueACL.xml", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read))
            {
                ser.Serialize(fs, queueACL, namespaces);
            }

            using (System.IO.FileStream fs = new System.IO.FileStream("C:\\temp\\QueueACL.xml", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
            {
                queueACL = (SharedAccessSignatureACL)ser.Deserialize(fs);
            }

            var result = InternalMethods.SetContainerACL(accountName, sharedKey, useHTTPS, contName, null, queueACL, ITPCfSQL.Azure.Enumerations.ContainerPublicReadAccess.Blob);

            //return;

            AzureBlobService abs = new AzureBlobService(accountName, sharedKey, useHTTPS);

            List<Container> lConts = abs.ListContainers();
            if (lConts.FirstOrDefault(item => item.Name == contName) == null)
            {
                abs.CreateContainer("testsas", ITPCfSQL.Azure.Enumerations.ContainerPublicReadAccess.Blob);
                lConts = abs.ListContainers();
            }

            Container cTest = lConts.First(item => item.Name == contName);

            ContainerPublicReadAccess containerPublicAccess;
            var output = InternalMethods.GetContainerACL(accountName, sharedKey, useHTTPS, contName, out containerPublicAccess);
        }
Exemplo n.º 18
0
        public static void DeleteBlob(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString containerName, SqlString blobName,
            SqlString blobDeletionMethod,
            SqlGuid leaseID,
            SqlDateTime snapshotDateTimeToDelete,
            SqlString xmsclientrequestId)
        {
            AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            Container cont = abs.GetContainer(containerName.Value);
            ITPCfSQL.Azure.Blob bb = new Azure.Blob(cont, blobName.Value);

            Enumerations.BlobDeletionMethod bbm;

            if (!Enum.TryParse<Enumerations.BlobDeletionMethod>(blobDeletionMethod.Value, out bbm))
            {
                StringBuilder sb = new StringBuilder("\"" + blobDeletionMethod.Value + "\" is an invalid blobDeletionMethod value. Valid values are: ");
                foreach (string s in Enum.GetNames(typeof(Enumerations.BlobDeletionMethod)))
                    sb.Append("\"" + s + "\" ");
                throw new ArgumentException(sb.ToString());
            }

            bb.Delete(bbm,
                leaseID.IsNull ? (Guid?)null : leaseID.Value,
                snapshotDateTimeToDelete.IsNull ? (DateTime?)null : snapshotDateTimeToDelete.Value,
                0,
                xmsclientrequestId != null ? xmsclientrequestId.Value : null);
        }
Exemplo n.º 19
0
 public static void CreateOrReplacePageBlob(
     SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
     SqlString containerName, SqlString blobName, SqlInt64 maximumSize,
     SqlGuid leaseId,
     SqlString contentType, SqlString contentEncoding, SqlString contentLanguage,
     SqlInt32 timeoutSeconds, SqlGuid xmsclientrequestId)
 {
     AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
     Container cont = abs.GetContainer(containerName.Value);
     cont.CreatePageBlob(blobName.Value, maximumSize.Value,
         leaseId.IsNull ? (Guid?)null : leaseId.Value,
         contentType.IsNull ? "application/octet-stream" : contentType.Value,
         contentEncoding.IsNull ? null : contentEncoding.Value,
         contentLanguage.IsNull ? null : contentLanguage.Value,
         timeoutSeconds.IsNull ? 0 : timeoutSeconds.Value,
         xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);
 }
Exemplo n.º 20
0
 public static void CreateOrReplaceBlockBlob(
     SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
     SqlString containerName, SqlString blobName,
     SqlBytes binaryBuffer, SqlString contentType, SqlString contentEncoding,
     SqlString contentMD5,
     SqlGuid xmsclientrequestId)
 {
     AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
     Container cont = abs.GetContainer(containerName.Value);
     cont.CreateBlockBlob(blobName.Value, binaryBuffer.Stream,
         null,
         contentType.IsNull ? "application/octet-stream" : contentType.Value,
         contentEncoding.IsNull ? null : contentEncoding.Value,
         null,
         contentMD5.IsNull ? (null) : contentMD5.Value,
         0,
         xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);
 }
Exemplo n.º 21
0
        public static void RenewContainerLease(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString containerName,
            SqlGuid leaseId,
            SqlInt32 timeoutSeconds,
            SqlGuid xmsclientrequestId)
        {
            AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            Container cont = abs.GetContainer(containerName.Value);

            Responses.LeaseBlobResponse lbr = cont.RenewLease(
                leaseId.IsNull ? Guid.Empty : leaseId.Value,
                timeoutSeconds.IsNull ? 0 : timeoutSeconds.Value,
                xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);

            PushLeaseBlobResponse(lbr);
        }
Exemplo n.º 22
0
        public static System.Collections.IEnumerable ListBlobs(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString containerName,
            SqlBoolean includeSnapshots,
            SqlBoolean includeMetadata,
            SqlBoolean includeCopy,
            SqlBoolean includeUncommittedBlobs,
            SqlString xmsclientrequestId)
        {
            AzureBlobService abs = new AzureBlobService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            Container cont = abs.GetContainer(containerName.Value);

            return cont.ListBlobs(null,
                includeSnapshots.Value, includeMetadata.Value, includeCopy.Value, includeUncommittedBlobs.Value, 0,
                xmsclientrequestId != null ? xmsclientrequestId.Value : null);
        }
Exemplo n.º 23
0
        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());
            }
        }
Exemplo n.º 24
0
        public static void CopyBlob(
            SqlString destinationAccount, SqlString destinationSharedKey, SqlBoolean useHTTPS,
            SqlString sourceAccountName,
            SqlString sourceContainerName, SqlString sourceBlobName,
            SqlGuid sourceLeaseId, SqlGuid destinationLeaseId,
            SqlString destinationContainerName, SqlString destinationBlobName,
            SqlString xmsclientrequestId)
        {
            AzureBlobService absDest = new AzureBlobService(destinationAccount.Value, destinationSharedKey.Value, useHTTPS.Value);
            Container contDest = absDest.GetContainer(destinationContainerName.Value);
            ITPCfSQL.Azure.Blob bbDest = new Azure.Blob(contDest, destinationBlobName.Value);

            AzureBlobService absSrc = new AzureBlobService(sourceAccountName.Value, "", useHTTPS.Value);
            Container contSrc = absSrc.GetContainer(sourceContainerName.Value);
            ITPCfSQL.Azure.Blob bbSrc = new Azure.Blob(contSrc, sourceBlobName.Value);

            Responses.CopyBlobResponse resp = bbSrc.Copy(bbDest,
                sourceLeaseID: sourceLeaseId.IsNull ? (Guid?)null : sourceLeaseId.Value,
                destinationLeaseID: destinationLeaseId.IsNull ? (Guid?)null : destinationLeaseId.Value,
                xmsclientrequestId: xmsclientrequestId.IsNull ? null : xmsclientrequestId.Value);

            SqlDataRecord record = new SqlDataRecord(
                new SqlMetaData[]
                {
                    new SqlMetaData("BlobCopyStatus", System.Data.SqlDbType.NVarChar, 255),
                    new SqlMetaData("CopyId", System.Data.SqlDbType.NVarChar, 255),
                    new SqlMetaData("Date", System.Data.SqlDbType.DateTime),
                    new SqlMetaData("ETag", System.Data.SqlDbType.NVarChar, 255),
                    new SqlMetaData("LastModified", System.Data.SqlDbType.DateTime),
                    new SqlMetaData("RequestID", System.Data.SqlDbType.UniqueIdentifier),
                    new SqlMetaData("Version", System.Data.SqlDbType.NVarChar, 255)
                });

            SqlContext.Pipe.SendResultsStart(record);

            record.SetString(0, resp.BlobCopyStatus.ToString());
            record.SetString(1, resp.CopyId);
            record.SetDateTime(2, resp.Date);
            record.SetString(3, resp.ETag);
            record.SetDateTime(4, resp.LastModified);
            record.SetGuid(5, resp.RequestID);
            record.SetString(6, resp.Version);

            SqlContext.Pipe.SendResultsRow(record);
            SqlContext.Pipe.SendResultsEnd();
        }