1- using System . Collections . Generic ;
1+ using Microsoft . WindowsAzure . Storage ;
2+ using Microsoft . WindowsAzure . Storage . Blob ;
3+ using Sitecore . Azure . Diagnostics . Storage . RetryPolicies ;
4+ using Sitecore . Diagnostics ;
5+ using System ;
6+ using System . Collections . Generic ;
27using System . Collections . Specialized ;
8+ using System . Configuration ;
39using System . Configuration . Provider ;
410using System . Linq ;
511using System . Text ;
6- using Microsoft . Azure ;
7- using Microsoft . WindowsAzure . ServiceRuntime ;
8- using Microsoft . WindowsAzure . Storage ;
9- using Microsoft . WindowsAzure . Storage . Blob ;
10- using Sitecore . Azure . Diagnostics . Storage . RetryPolicies ;
11- using Sitecore . Diagnostics ;
1212
1313namespace Sitecore . Azure . Diagnostics . Storage
1414{
@@ -29,6 +29,16 @@ public class AzureBlobStorageProvider : ProviderBase
2929 /// </summary>
3030 private const string AppSettingName = "Azure.Storage.ConnectionString.AppSettingName" ;
3131
32+ /// <summary>
33+ /// The web apps environment variables that contains the name of the site.
34+ /// </summary>
35+ private const string WebsiteNameEnvVar = "WEBSITE_SITE_NAME" ;
36+
37+ /// <summary>
38+ /// The web apps environment variables that contains the VM's id where the site is running on.
39+ /// </summary>
40+ private const string WebsiteInstanceIdEnvVar = "WEBSITE_INSTANCE_ID " ;
41+
3242 /// <summary>
3343 /// The cloud BLOB client.
3444 /// </summary>
@@ -38,7 +48,7 @@ public class AzureBlobStorageProvider : ProviderBase
3848 /// The cloud blob container name
3949 /// </summary>
4050 public string CloudBlobContainerName { get ; protected set ; }
41-
51+
4252 /// <summary>
4353 /// The BLOB container public access type
4454 /// </summary>
@@ -69,7 +79,7 @@ public class AzureBlobStorageProvider : ProviderBase
6979 public AzureBlobStorageProvider ( )
7080 {
7181 string appSetting = Configuration . Settings . GetSetting ( AppSettingName ) ;
72- string storageConnectionString = CloudConfigurationManager . GetSetting ( appSetting ) ;
82+ string storageConnectionString = ConfigurationManager . AppSettings [ appSetting ] ;
7383
7484 // Retrieve storage account from connection string.
7585 this . StorageAccount = CloudStorageAccount . Parse ( storageConnectionString ) ;
@@ -187,7 +197,7 @@ protected string Encoding
187197 }
188198 }
189199 }
190-
200+
191201 #endregion
192202
193203 #region Public Methods
@@ -224,9 +234,9 @@ public virtual CloudBlobContainer GetContainer(string containerName)
224234 {
225235 RetryPolicy = new ContainerBeingDeletedRetryPolicy ( ) ,
226236 } ;
227-
237+
228238 container . CreateIfNotExists ( this . PublicAccessType , options ) ;
229-
239+
230240 return container ;
231241 }
232242
@@ -239,13 +249,13 @@ public virtual ICloudBlob CreateBlob(string blobName)
239249 {
240250 Assert . ArgumentNotNull ( blobName , "blobName" ) ;
241251
242- string webRoleRelativeAddress = this . GetWebRoleRelativeAddress ( ) ;
252+ string webRoleRelativeAddress = this . GetWebsiteRelativeAddress ( ) ;
243253
244254 // Build blob name for a Role Environment using the following format: {DeploymentId}/{RoleInstanceId}/{BlobName}.
245255 blobName = string . IsNullOrEmpty ( webRoleRelativeAddress ) ? blobName : string . Format ( "{0}/{1}" , webRoleRelativeAddress , blobName ) ;
246-
247- ICloudBlob blob = this . CloudBlobContainer . Exists ( ) ?
248- this . CloudBlobContainer . GetAppendBlobReference ( blobName ) :
256+
257+ ICloudBlob blob = this . CloudBlobContainer . Exists ( ) ?
258+ this . CloudBlobContainer . GetAppendBlobReference ( blobName ) :
249259 this . GetContainer ( this . ContainerName ) . GetAppendBlobReference ( blobName ) ;
250260
251261 return blob ;
@@ -261,8 +271,8 @@ public virtual ICloudBlob GetBlob(string blobName)
261271 {
262272 Assert . ArgumentNotNull ( blobName , "blobName" ) ;
263273
264- ICloudBlob blob = this . CloudBlobContainer . Exists ( ) ?
265- this . CloudBlobContainer . GetBlobReferenceFromServer ( blobName ) :
274+ ICloudBlob blob = this . CloudBlobContainer . Exists ( ) ?
275+ this . CloudBlobContainer . GetBlobReferenceFromServer ( blobName ) :
266276 this . GetContainer ( this . ContainerName ) . GetBlobReferenceFromServer ( blobName ) ;
267277
268278 return blob ;
@@ -321,7 +331,7 @@ public virtual ICollection<ICloudBlob> ListBlobs(CloudBlobContainer container, s
321331 Assert . ArgumentNotNull ( container , "container" ) ;
322332 Assert . ArgumentNotNull ( searchPattern , "searchPattern" ) ;
323333
324- string webRoleRelativeAddress = this . GetWebRoleRelativeAddress ( ) ;
334+ string webRoleRelativeAddress = this . GetWebsiteRelativeAddress ( ) ;
325335 var blobList = container . ListBlobs ( webRoleRelativeAddress , true ) . Cast < ICloudBlob > ( ) . ToList ( ) ;
326336
327337 var filteredBlobList = new List < ICloudBlob > ( ) ;
@@ -342,29 +352,21 @@ public virtual ICollection<ICloudBlob> ListBlobs(CloudBlobContainer container, s
342352
343353 #region Protected Methods
344354
345- /// <summary>
346- /// Gets the deployment relative address.
347- /// </summary>
348- /// <returns>The deployment address that includes {DeploymentId}.</returns>
349- protected virtual string GetDeploymentRelativeAddress ( )
350- {
351- return RoleEnvironment . IsAvailable ? RoleEnvironment . DeploymentId : string . Empty ;
352- }
353-
354355 /// <summary>
355356 /// Gets the WebRole relative address.
356357 /// </summary>
357358 /// <returns>
358359 /// The WebRole address that includes {DeploymentId}/{RoleInstanceId}.
359360 /// </returns>
360- protected virtual string GetWebRoleRelativeAddress ( )
361+ protected virtual string GetWebsiteRelativeAddress ( )
361362 {
362363 string webRoleRelativeAddress = string . Empty ;
363- string deploymentRelativeAddress = this . GetDeploymentRelativeAddress ( ) ;
364+ var websiteName = Environment . GetEnvironmentVariable ( WebsiteNameEnvVar ) ;
364365
365- if ( ! string . IsNullOrEmpty ( deploymentRelativeAddress ) )
366+ if ( ! string . IsNullOrEmpty ( websiteName ) )
366367 {
367- webRoleRelativeAddress = string . Format ( "{0}/{1}" , deploymentRelativeAddress , RoleEnvironment . CurrentRoleInstance . Id ) ;
368+ var websiteInstanceId = Environment . GetEnvironmentVariable ( WebsiteInstanceIdEnvVar ) ;
369+ webRoleRelativeAddress = $ "{ websiteName } /{ websiteInstanceId } ";
368370 }
369371
370372 return webRoleRelativeAddress ;
0 commit comments