public void SetBlobContentWithProperties(StorageBlob.BlobType blobType) { string filePath = FileUtil.GenerateOneTempTestFile(); CloudBlobContainer container = blobUtil.CreateContainer(); Hashtable properties = new Hashtable(); properties.Add("CacheControl", Utility.GenNameString(string.Empty)); properties.Add("ContentEncoding", Utility.GenNameString(string.Empty)); properties.Add("ContentLanguage", Utility.GenNameString(string.Empty)); properties.Add("ContentType", Utility.GenNameString(string.Empty)); try { Test.Assert(CommandAgent.SetAzureStorageBlobContent(filePath, container.Name, blobType, string.Empty, true, -1, properties), "set blob content with property should succeed"); CloudBlob blob = StorageExtensions.GetBlobReferenceFromServer(container, Path.GetFileName(filePath)); blob.FetchAttributes(); ExpectEqual(properties["CacheControl"].ToString(), blob.Properties.CacheControl, "Cache control"); ExpectEqual(properties["ContentEncoding"].ToString(), blob.Properties.ContentEncoding, "Content Encoding"); ExpectEqual(properties["ContentLanguage"].ToString(), blob.Properties.ContentLanguage, "Content Language"); ExpectEqual(properties["ContentType"].ToString(), blob.Properties.ContentType, "Content Type"); } finally { blobUtil.RemoveContainer(container.Name); FileUtil.RemoveFile(filePath); } }
public void GetCopyStateFromCrossAccountCopyTest() { CloudStorageAccount secondaryAccount = TestBase.GetCloudStorageAccountFromConfig("Secondary"); object destContext; if (lang == Language.PowerShell) { destContext = PowerShellAgent.GetStorageContext(secondaryAccount.ToString(true)); } else { destContext = secondaryAccount; } CloudBlobUtil destBlobUtil = new CloudBlobUtil(secondaryAccount); string destContainerName = Utility.GenNameString("secondary"); CloudBlobContainer destContainer = destBlobUtil.CreateContainer(destContainerName); if (lang == Language.PowerShell) { blobUtil.SetupTestContainerAndBlob(); } else { blobUtil.SetupTestContainerAndBlob(blobNamePrefix: "blob"); } //remove the same name container in source storage account, so we could avoid some conflicts. if (!blobUtil.Blob.ServiceClient.BaseUri.Host.Equals(destContainer.ServiceClient.BaseUri.Host)) { blobUtil.RemoveContainer(destContainer.Name); } try { Test.Assert(CommandAgent.StartAzureStorageBlobCopy(blobUtil.Blob, destContainer.Name, string.Empty, destContext), "Start cross account copy should succeed"); int expectedBlobCount = 1; Test.Assert(CommandAgent.Output.Count == expectedBlobCount, String.Format("Expected get {0} copy blob, and actually it's {1}", expectedBlobCount, CommandAgent.Output.Count)); CloudBlob destBlob; object context; if (lang == Language.PowerShell) { destBlob = (CloudBlob)CommandAgent.Output[0]["ICloudBlob"]; //make sure this context is different from the PowerShell.Context context = CommandAgent.Output[0]["Context"]; Test.Assert(PowerShellAgent.Context != context, "make sure you are using different context for cross account copy"); } else { destBlob = StorageExtensions.GetBlobReferenceFromServer(destContainer, (string)CommandAgent.Output[0]["name"]); context = destContext; } Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(destBlob, context, true), "Get copy state in dest container should succeed."); AssertFinishedCopyState(blobUtil.Blob.Uri); } finally { blobUtil.CleanupTestContainerAndBlob(); destBlobUtil.RemoveContainer(destContainer.Name); } }
public async Task <object?> CreateAsync(IStorageFile item, IServiceProvider services) { StorageFolder?parentFolder = await(item as IStorageItem2)?.GetParentAsync(); if (parentFolder is null) { return(null); } StorageFile?projectFile = await parentFolder.GetFileWithExtensionInHierarchyAsync("proj"); if (projectFile is null) { throw new FileNotFoundException("No project file could be found."); } StorageFolder projectFolder = await projectFile.GetParentAsync(); await LoadAssemblyAsync(projectFolder, Path.GetFileNameWithoutExtension(projectFile.Name)); string scenePath = StorageExtensions.GetRelativePath(projectFolder.Path, item.Path); scenePath = Path.Combine(Path.GetDirectoryName(scenePath), Path.GetFileNameWithoutExtension(scenePath)); return(new SceneEditorViewModel(projectFolder, scenePath, services.GetRequiredService <IPropertyManager>())); }
/// <summary> /// Expect sas token has the Append permission for the specified container. /// </summary> internal void ValidateContainerAppendableWithSasToken(CloudBlobContainer container, string sastoken) { Test.Info("Verify container Append permission"); CloudStorageAccount sasAccount = TestBase.GetStorageAccountWithSasToken(container.ServiceClient.Credentials.AccountName, sastoken); CloudBlobClient sasBlobClient = sasAccount.CreateCloudBlobClient(); CloudBlobContainer sasContainer = sasBlobClient.GetContainerReference(container.Name); string blobName = Utility.GenNameString("sasAppendblob"); CloudAppendBlob appendblob = sasContainer.GetAppendBlobReference(blobName); container.GetAppendBlobReference(blobName).CreateOrReplace(); long buffSize = 1024 * 1024; byte[] buffer = new byte[buffSize]; random.NextBytes(buffer); MemoryStream ms = new MemoryStream(buffer); appendblob.AppendBlock(ms); CloudBlob retrievedBlob = StorageExtensions.GetBlobReferenceFromServer(container, blobName); Test.Assert(retrievedBlob != null, "Append blob should exist on server"); TestBase.ExpectEqual(StorageBlobType.AppendBlob.ToString(), retrievedBlob.BlobType.ToString(), "blob type"); TestBase.ExpectEqual(buffSize, retrievedBlob.Properties.Length, "blob size"); }
protected override void OnApplicationStarted() { RegisterRoutes(); StorageExtensions.Setup(); // Always call this method before starting any EPCIS application // Start the Subscription Runner. _subscriptionRunner = _kernel.Get <ISubscriptionRunner>(); _subscriptionRunner.Start(); }
protected void Application_Start() { StorageExtensions.Setup(); // Always call this method before starting any EPCIS application (web/desktop) GlobalConfiguration.Configuration.Formatters.Clear(); GlobalConfiguration.Configuration.Formatters.Add(new CustomXmlFormatter()); GlobalConfiguration.Configure(WebApiConfig.Register); NinjectHttpContainer.RegisterModules(NinjectHttpModules.Modules); }
protected override async Task AppendInternal(bool async, CancellationToken cancellationToken) { if (_buffer.Length > 0) { _buffer.Position = 0; string blockId = StorageExtensions.GenerateBlockId(_position); await _blockBlobClient.StageBlockInternal( base64BlockId : blockId, content : _buffer, transactionalContentHash : default,
public void AddsTimeoutToQuery() { // Arrange var client = new BlobServiceClient(_endpoint, _credentials, _clientOptions); // Act using (StorageExtensions.CreateServiceTimeoutScope(ServerTimeout)) { Assert.ThrowsAsync <RequestFailedException>(async() => await client.GetPropertiesAsync()); } // Assert StringAssert.Contains($"timeout={ServerTimeoutSeconds}", _transport.SingleRequest.Uri.ToString()); }
public async Task AppendsTimeoutToUriWithNonEmptyQuery() { // Arrange var transport = new MockTransport(r => new MockResponse(200)); // Act using (StorageExtensions.CreateServiceTimeoutScope(ServerTimeout)) { await SendGetRequest(transport, StorageServerTimeoutPolicy.Shared, uri : new Uri("http://foo.com/?bar=baz")); } // Assert Assert.AreEqual($"http://foo.com/?bar=baz&timeout={ServerTimeoutSeconds}", transport.SingleRequest.Uri.ToString()); }
public async Task DoesNotOverrideAlreadyPresentTimeout() { // Arrange var transport = new MockTransport(r => new MockResponse(200)); // Act using (StorageExtensions.CreateServiceTimeoutScope(ServerTimeout)) { await SendGetRequest(transport, StorageServerTimeoutPolicy.Shared, uri : new Uri("http://foo.com/?timeout=25")); } // Assert Assert.AreEqual("http://foo.com/?timeout=25", transport.SingleRequest.Uri.ToString()); }
public void SetBlobContentWithMetadata(StorageBlob.BlobType blobType) { string filePath = FileUtil.GenerateOneTempTestFile(); CloudBlobContainer container = blobUtil.CreateContainer(); Hashtable metadata = new Hashtable(); int metaCount = Utility.GetRandomTestCount(); for (int i = 0; i < metaCount; i++) { string key = Utility.GenRandomAlphabetString(); string value = Utility.GenNameString(string.Empty); if (!metadata.ContainsKey(key)) { Test.Info(string.Format("Add meta key: {0} value : {1}", key, value)); metadata.Add(key, value); } } try { Test.Assert(CommandAgent.SetAzureStorageBlobContent(filePath, container.Name, blobType, string.Empty, true, -1, null, metadata), "set blob content with meta should succeed"); CloudBlob blob = StorageExtensions.GetBlobReferenceFromServer(container, Path.GetFileName(filePath)); blob.FetchAttributes(); ExpectEqual(metadata.Count, blob.Metadata.Count, "meta data count"); foreach (string key in metadata.Keys) { if (blob.Metadata.ContainsKey(key)) { ExpectEqual(metadata[key].ToString(), blob.Metadata[key], "Meta data key " + key); } else if (blob.Metadata.ContainsKey(key.ToLower())) { // NodeJS stores key in lower case ExpectEqual(metadata[key].ToString().ToLower(), blob.Metadata[key.ToLower()], "Meta data key " + key); } else { Test.AssertFail("Could not find meta data key " + key + " in blob entity"); } } } finally { blobUtil.RemoveContainer(container.Name); FileUtil.RemoveFile(filePath); } }
public async Task NestedScopeWins() { // Arrange var transport = new MockTransport(r => new MockResponse(200)); // Act using (StorageExtensions.CreateServiceTimeoutScope(ServerTimeout)) { using (StorageExtensions.CreateServiceTimeoutScope(ServerTimeout.Add(TimeSpan.FromSeconds(1)))) { await SendGetRequest(transport, StorageServerTimeoutPolicy.Shared, uri : new Uri("http://foo.com/")); } } // Assert Assert.AreEqual($"http://foo.com/?timeout={ServerTimeout.TotalSeconds + 1}", transport.SingleRequest.Uri.ToString()); }
public async Task CanUnsetTheTimeout() { // Arrange var transport = new MockTransport(r => new MockResponse(200)); // Act using (StorageExtensions.CreateServiceTimeoutScope(ServerTimeout)) { using (StorageExtensions.CreateServiceTimeoutScope(null)) { await SendGetRequest(transport, StorageServerTimeoutPolicy.Shared, uri : new Uri("http://foo.com/")); } } // Assert Assert.AreEqual("http://foo.com/", transport.SingleRequest.Uri.ToString()); }
/// <summary> /// Expect sas token has the read permission for the specified container. /// </summary> internal void ValidateContainerReadableWithSasToken(CloudBlobContainer container, string sastoken) { Test.Info("Verify container read permission"); List <CloudBlob> randomBlobs = CreateRandomBlob(container); CloudBlob blob = randomBlobs[0]; CloudStorageAccount sasAccount = TestBase.GetStorageAccountWithSasToken(container.ServiceClient.Credentials.AccountName, sastoken); CloudBlobClient sasBlobClient = sasAccount.CreateCloudBlobClient(); CloudBlobContainer sasContainer = sasBlobClient.GetContainerReference(container.Name); CloudBlob retrievedBlob = StorageExtensions.GetBlobReferenceFromServer(sasContainer, blob.Name); long buffSize = retrievedBlob.Properties.Length; byte[] buffer = new byte[buffSize]; MemoryStream ms = new MemoryStream(buffer); retrievedBlob.DownloadRangeToStream(ms, 0, buffSize); string md5 = Utility.GetBufferMD5(buffer); TestBase.ExpectEqual(blob.Properties.ContentMD5, md5, "content md5"); }
public void ApplyServerTimeout() { // Get a connection string to our Azure Storage account. string connectionString = ConnectionString; // Create our client options and customize our retries BlobClientOptions options = new BlobClientOptions(); options.Retry.MaxRetries = 5; // Create our client and make a simple request #region Snippet:Sample_StorageServerTimeout BlobServiceClient client = new BlobServiceClient(connectionString, options); using (StorageExtensions.CreateServiceTimeoutScope(TimeSpan.FromSeconds(10))) { client.GetProperties(); } #endregion }
public BlobAsyncCopyController( TransferScheduler transferScheduler, TransferJob transferJob, CancellationToken cancellationToken) : base(transferScheduler, transferJob, cancellationToken) { this.destLocation = transferJob.Destination as AzureBlobLocation; CloudBlob transferDestBlob = this.destLocation.Blob; if (null == transferDestBlob) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, Resources.ParameterCannotBeNullException, "Dest.Blob"), "transferJob"); } if (transferDestBlob.IsSnapshot) { throw new ArgumentException(Resources.DestinationMustBeBaseBlob, "transferJob"); } AzureBlobLocation sourceBlobLocation = transferJob.Source as AzureBlobLocation; if (sourceBlobLocation != null) { if (sourceBlobLocation.Blob.BlobType != transferDestBlob.BlobType) { throw new ArgumentException(Resources.SourceAndDestinationBlobTypeDifferent, "transferJob"); } if (StorageExtensions.Equals(sourceBlobLocation.Blob, transferDestBlob)) { throw new InvalidOperationException(Resources.SourceAndDestinationLocationCannotBeEqualException); } } this.destBlob = transferDestBlob; }
/// <summary> /// Expect sas token has the Create permission for the specified container. /// </summary> internal void ValidateContainerCreateableWithSasToken(CloudBlobContainer container, string sastoken) { Test.Info("Verify container Create permission"); CloudStorageAccount sasAccount = TestBase.GetStorageAccountWithSasToken(container.ServiceClient.Credentials.AccountName, sastoken); CloudBlobClient sasBlobClient = sasAccount.CreateCloudBlobClient(); CloudBlobContainer sasContainer = sasBlobClient.GetContainerReference(container.Name); if (!container.Exists()) { sasContainer.Create(); Test.Assert(sasContainer.Exists(), "The container should exist after Creating with sas token"); } string blobName = Utility.GenNameString("saspageblob"); CloudPageBlob pageblob = sasContainer.GetPageBlobReference(blobName); long blobSize = 1024 * 1024; pageblob.Create(blobSize); CloudBlob retrievedBlob = StorageExtensions.GetBlobReferenceFromServer(container, blobName); Test.Assert(retrievedBlob != null, "Page blob should exist on server"); TestBase.ExpectEqual(StorageBlobType.PageBlob.ToString(), retrievedBlob.BlobType.ToString(), "blob type"); TestBase.ExpectEqual(blobSize, retrievedBlob.Properties.Length, "blob size"); }