Skip to content
This repository was archived by the owner on Nov 10, 2017. It is now read-only.

Commit 7cf303c

Browse files
authored
Merge pull request #8 from olegburov/Issue-#4
Fixed issue #4.
2 parents c539203 + 140872b commit 7cf303c

3 files changed

Lines changed: 34 additions & 38 deletions

File tree

src/Sitecore.Azure.Diagnostics/Sitecore.Azure.Diagnostics.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@
6060
<HintPath>..\packages\Microsoft.Data.Services.Client.5.7.0\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
6161
<Private>True</Private>
6262
</Reference>
63-
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
64-
<HintPath>..\packages\Microsoft.WindowsAzure.ConfigurationManager.3.2.1\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
65-
<Private>True</Private>
66-
</Reference>
67-
<Reference Include="Microsoft.WindowsAzure.ServiceRuntime, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
6863
<Reference Include="Microsoft.WindowsAzure.Storage, Version=7.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6964
<HintPath>..\packages\WindowsAzure.Storage.7.1.2\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
7065
<Private>True</Private>

src/Sitecore.Azure.Diagnostics/Storage/AzureBlobStorageProvider.cs

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
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;
27
using System.Collections.Specialized;
8+
using System.Configuration;
39
using System.Configuration.Provider;
410
using System.Linq;
511
using 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

1313
namespace 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;

src/Sitecore.Azure.Diagnostics/packages.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<package id="Microsoft.Data.Edm" version="5.7.0" targetFramework="net45" />
55
<package id="Microsoft.Data.OData" version="5.7.0" targetFramework="net45" />
66
<package id="Microsoft.Data.Services.Client" version="5.7.0" targetFramework="net45" />
7-
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.1" targetFramework="net45" />
87
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
98
<package id="SC.Sitecore.Client" version="8.1.3.160519" targetFramework="net45" />
109
<package id="SC.Sitecore.Kernel" version="8.1.3.160519" targetFramework="net45" />

0 commit comments

Comments
 (0)