GetBlobReference() public method

Returns a reference to a CloudBlob with the specified address.
public GetBlobReference ( string blobAddress ) : CloudBlob
blobAddress string The absolute URI to the blob, or a relative URI beginning with the container name.
return CloudBlob
Ejemplo n.º 1
0
		public static void DeletePackageFromBlob(IServiceManagement channel, string storageName, string subscriptionId, Uri packageUri)
		{
			StorageService storageKeys = channel.GetStorageKeys(subscriptionId, storageName);
			string primary = storageKeys.StorageServiceKeys.Primary;
			storageKeys = channel.GetStorageService(subscriptionId, storageName);
			EndpointList endpoints = storageKeys.StorageServiceProperties.Endpoints;
			string str = ((List<string>)endpoints).Find((string p) => p.Contains(".blob."));
			StorageCredentialsAccountAndKey storageCredentialsAccountAndKey = new StorageCredentialsAccountAndKey(storageName, primary);
			CloudBlobClient cloudBlobClient = new CloudBlobClient(str, storageCredentialsAccountAndKey);
			CloudBlob blobReference = cloudBlobClient.GetBlobReference(packageUri.AbsoluteUri);
			blobReference.DeleteIfExists();
		}
Ejemplo n.º 2
0
		public static void RemoveVHD(IServiceManagement channel, string subscriptionId, Uri mediaLink)
		{
			StorageService storageKeys;
			char[] chrArray = new char[1];
			chrArray[0] = '.';
			string str = mediaLink.Host.Split(chrArray)[0];
			string components = mediaLink.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
			using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)channel))
			{
				storageKeys = channel.GetStorageKeys(subscriptionId, str);
			}
			StorageCredentialsAccountAndKey storageCredentialsAccountAndKey = new StorageCredentialsAccountAndKey(str, storageKeys.StorageServiceKeys.Primary);
			CloudBlobClient cloudBlobClient = new CloudBlobClient(components, storageCredentialsAccountAndKey);
			CloudBlob blobReference = cloudBlobClient.GetBlobReference(mediaLink.AbsoluteUri);
			blobReference.DeleteIfExists();
		}
 private static void ProcessDynamicRegisterRequest(HttpRequest request, HttpResponse response)
 {
     CloudBlobClient publicClient = new CloudBlobClient("http://theball.blob.core.windows.net/");
     string blobPath = GetBlobPath(request);
     CloudBlob blob = publicClient.GetBlobReference(blobPath);
     response.Clear();
     try
     {
         string template = blob.DownloadText();
         string returnUrl = request.Params["ReturnUrl"];
         TBRegisterContainer registerContainer = GetRegistrationInfo(returnUrl, request.Url.DnsSafeHost);
         string responseContent = RenderWebSupport.RenderTemplateWithContent(template, registerContainer);
         response.ContentType = blob.Properties.ContentType;
         response.Write(responseContent);
     } catch(StorageClientException scEx)
     {
         response.Write(scEx.ToString());
         response.StatusCode = (int)scEx.StatusCode;
     } finally
     {
         response.End();
     }
 }
 private void ProcessAnonymousRequest(HttpRequest request, HttpResponse response)
 {
     CloudBlobClient publicClient = new CloudBlobClient("http://theball.blob.core.windows.net/");
     string blobPath = GetBlobPath(request);
     CloudBlob blob = publicClient.GetBlobReference(blobPath);
     response.Clear();
     try
     {
         blob.FetchAttributes();
         response.ContentType = blob.Properties.ContentType;
         blob.DownloadToStream(response.OutputStream);
     } catch(StorageClientException scEx)
     {
         if (scEx.ErrorCode == StorageErrorCode.BlobNotFound || scEx.ErrorCode == StorageErrorCode.ResourceNotFound || scEx.ErrorCode == StorageErrorCode.BadRequest)
         {
             response.Write("Blob not found or bad request: " + blob.Name + " (original path: " + request.Path + ")");
             response.StatusCode = (int)scEx.StatusCode;
         }
         else
         {
             response.Write("Errorcode: " + scEx.ErrorCode.ToString() + Environment.NewLine);
             response.Write(scEx.ToString());
             response.StatusCode = (int) scEx.StatusCode;
         }
     } finally
     {
         response.End();
     }
 }
Ejemplo n.º 5
0
        public IEnumerable<CloudBlob> Translate(IExpression expression, CloudBlobClient blobClient, MediaFolder mediaFolder)
        {
            this.Visite(expression);

            if (!string.IsNullOrEmpty(fileName))
            {
                var blob = blobClient.GetBlobReference(mediaFolder.GetMediaFolderItemPath(fileName));
                blob.FetchAttributes();
                return new[] { blob };
            }
            else
            {
                var maxResult = 100;
                if (Take.HasValue)
                {
                    maxResult = Take.Value;
                }
                var take = maxResult;

                var skip = 0;
                if (Skip.HasValue)
                {
                    skip = Skip.Value;
                    maxResult = +skip;
                }
                var blobPrefix = mediaFolder.GetMediaFolderItemPath(prefix);

                if (string.IsNullOrEmpty(prefix))
                {
                    blobPrefix += "/";
                }

                return blobClient.ListBlobsWithPrefixSegmented(blobPrefix, maxResult, null, new BlobRequestOptions() { BlobListingDetails = Microsoft.WindowsAzure.StorageClient.BlobListingDetails.Metadata, UseFlatBlobListing = false })
                    .Results.Skip(skip).Select(it => it as CloudBlob).Take(take);
            }
        }
        private static void CreateStorageCrossDomainPolicy(CloudBlobClient blobClient)
        {
            blobClient.GetContainerReference("$root").CreateIfNotExist();
            blobClient.GetContainerReference("$root").SetPermissions(
                new BlobContainerPermissions()
                {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                });

            var blob = blobClient.GetBlobReference("clientaccesspolicy.xml");
            blob.Properties.ContentType = "text/xml";
            blob.UploadText(@"<?xml version=""1.0"" encoding=""utf-8""?>
            <access-policy>
              <cross-domain-access>
                <policy>
                  <allow-from http-methods=""*"" http-request-headers=""*"">
                    <domain uri=""*"" />
                    <domain uri=""http://*"" />
                  </allow-from>
                  <grant-to>
                    <resource path=""/"" include-subpaths=""true"" />
                  </grant-to>
                </policy>
              </cross-domain-access>
            </access-policy>");
        }
Ejemplo n.º 7
0
 private void CopyDirectoryToBlob(CloudBlobClient blobClient, string path)
 {
     var files = Directory.EnumerateFiles(path);
     var rootPath = HostingEnvironment.MapPath("~/");
     foreach (var file in files) {
         var container = file.Substring(rootPath.Length, file.Length - rootPath.Length);
         var blobReference = blobClient.GetBlobReference(container);
         try {
             blobReference.FetchAttributes();
         } catch (StorageClientException e) {
             if (e.ErrorCode == StorageErrorCode.ResourceNotFound) {
                 var content = File.ReadAllText(file);
                 blobReference.UploadText(content);
             }
         }
     }
     var directories = Directory.EnumerateDirectories(path);
     foreach (var directory in directories) {
         CopyDirectoryToBlob(blobClient, directory);
     }
 }
Ejemplo n.º 8
0
		public void DownloadJava(IPaths paths, CloudStorageAccount storageAccount)
		{
			try
			{
				var localJavaZipPath = paths.LocalJavaZip;

				if (File.Exists(localJavaZipPath))
				{
					File.Delete(localJavaZipPath);
					//return;
				}

				Trace.TraceInformation("Downloading Java.");

				var blobClient = new CloudBlobClient(storageAccount.BlobEndpoint, storageAccount.Credentials);

				string blobStoragePath = storageAccount.BlobEndpoint.AbsoluteUri;
				string jBlobRelativePath = RoleEnvironment.GetConfigurationSettingValue(ConfigSettings.JavaBlobNameSetting);

				string javaBlobAddress = blobStoragePath.CombineUris(jBlobRelativePath);

				var blob = blobClient.GetBlobReference(javaBlobAddress);
                
                var option = new BlobRequestOptions();
                option.Timeout = new TimeSpan(0, 15, 0);
				blob.DownloadToFile(localJavaZipPath, option);

				Trace.TraceInformation("Java downloaded.");
			}
			catch (Exception e)
			{
				Trace.Fail(string.Format("Error downloading Java: type <{0}> message <{1}> stack trace <{2}>.", e.GetType().FullName, e.Message, e.StackTrace));
				throw;
			}
		}