mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Removed IDependency from AzureBlobShellSettingsManager and AzureMachineNameProvider to prevent them from being registered as part of the default feature of the Orchard.Azure module. IShellSettingsManager and IMachineNameProvider implementations should always be registered using Host.config.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
<autofac defaultAssembly="Orchard.Framework">
|
||||
<components>
|
||||
<component instance-scope="single-instance" type="Orchard.Localization.Services.CultureDateTimeFormatProvider, Orchard.Framework" service="Orchard.Localization.Services.IDateTimeFormatProvider"></component>
|
||||
<component instance-scope="single-instance" type="Orchard.TaskLease.Services.MachineNameProvider, Orchard.TaskLease" service="Orchard.TaskLease.Services.IMachineNameProvider, Orchard.TaskLease"></component>
|
||||
</components>
|
||||
</autofac>
|
||||
|
||||
|
@@ -14,12 +14,7 @@ namespace Orchard.Azure.Services.Environment.Configuration {
|
||||
/// Provides an IShellSettingsManager implementation that uses Microsoft Azure Blob Storage as the
|
||||
/// underlying storage system.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Additionally, this class handles role configuration change events when running in a Microsoft Azure Cloud
|
||||
/// Service to ensure all Orchard tenents are notified whenever a role configuration setting is changed
|
||||
/// through the management portal or API.
|
||||
/// </remarks>
|
||||
public class AzureBlobShellSettingsManager : Component, IShellSettingsManager {
|
||||
public class AzureBlobShellSettingsManager : IShellSettingsManager {
|
||||
|
||||
private readonly AzureFileSystem _fileSystem;
|
||||
private readonly IShellSettingsManagerEventHandler _events;
|
||||
@@ -27,8 +22,11 @@ namespace Orchard.Azure.Services.Environment.Configuration {
|
||||
public AzureBlobShellSettingsManager(IMimeTypeProvider mimeTypeProvider, IShellSettingsManagerEventHandler events) {
|
||||
_fileSystem = new AzureFileSystem(CloudConfigurationManager.GetSetting(Constants.ShellSettingsStorageConnectionStringSettingName), Constants.ShellSettingsContainerName, String.Empty, true, mimeTypeProvider);
|
||||
_events = events;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public virtual IEnumerable<ShellSettings> LoadSettings() {
|
||||
Logger.Debug("Reading ShellSettings...");
|
||||
var settingsList = LoadSettingsInternal().ToArray();
|
||||
|
@@ -2,15 +2,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.WindowsAzure.ServiceRuntime;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.TaskLease.Services;
|
||||
|
||||
namespace Orchard.Azure.Services.TaskLease
|
||||
{
|
||||
public class AzureMachineNameProvider : IMachineNameProvider
|
||||
{
|
||||
public string GetMachineName()
|
||||
{
|
||||
return RoleEnvironment.CurrentRoleInstance.Id;
|
||||
}
|
||||
}
|
||||
namespace Orchard.Azure.Services.TaskLease {
|
||||
public class AzureMachineNameProvider : IMachineNameProvider {
|
||||
public string GetMachineName() {
|
||||
return RoleEnvironment.CurrentRoleInstance.Id;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,15 +1,12 @@
|
||||
namespace Orchard.TaskLease.Services
|
||||
{
|
||||
namespace Orchard.TaskLease.Services {
|
||||
|
||||
/// <summary>
|
||||
/// Describes a service which returns a name for the machine running the application.
|
||||
/// Describes a service which the name of the machine running the application.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Should be delocalized to IHostEnvironment in a leter version
|
||||
/// </remarks>
|
||||
public interface IMachineNameProvider : IDependency
|
||||
{
|
||||
public interface IMachineNameProvider {
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current machine's name
|
||||
/// Returns the name of the machine running the application.
|
||||
/// </summary>
|
||||
string GetMachineName();
|
||||
}
|
||||
|
@@ -1,14 +1,14 @@
|
||||
using System;
|
||||
using Orchard.TaskLease.Models;
|
||||
|
||||
namespace Orchard.TaskLease.Services
|
||||
{
|
||||
namespace Orchard.TaskLease.Services {
|
||||
|
||||
/// <summary>
|
||||
/// Describes a service to save and acquire task leases. A task lease can't be acquired by two different machines,
|
||||
/// for a specific amount of time. Optionnally a State can be saved along with the lease.
|
||||
/// </summary>
|
||||
public interface ITaskLeaseService : IDependency
|
||||
{
|
||||
public interface ITaskLeaseService : IDependency {
|
||||
|
||||
/// <summary>
|
||||
/// Acquires a lease for the specified task name, and amount of time.
|
||||
/// </summary>
|
||||
|
@@ -1,9 +1,6 @@
|
||||
namespace Orchard.TaskLease.Services
|
||||
{
|
||||
public class MachineNameProvider : IMachineNameProvider
|
||||
{
|
||||
public string GetMachineName()
|
||||
{
|
||||
namespace Orchard.TaskLease.Services {
|
||||
public class MachineNameProvider : IMachineNameProvider {
|
||||
public string GetMachineName() {
|
||||
return System.Environment.MachineName;
|
||||
}
|
||||
}
|
||||
|
@@ -3,13 +3,13 @@ using Orchard.Data;
|
||||
using Orchard.Services;
|
||||
using Orchard.TaskLease.Models;
|
||||
|
||||
namespace Orchard.TaskLease.Services
|
||||
{
|
||||
namespace Orchard.TaskLease.Services {
|
||||
|
||||
/// <summary>
|
||||
/// Provides a database driven implementation of <see cref="ITaskLeaseService" />
|
||||
/// </summary>
|
||||
public class TaskLeaseService : ITaskLeaseService
|
||||
{
|
||||
public class TaskLeaseService : ITaskLeaseService {
|
||||
|
||||
private readonly IRepository<TaskLeaseRecord> _repository;
|
||||
private readonly IClock _clock;
|
||||
private readonly IMachineNameProvider _machineNameProvider;
|
||||
@@ -17,30 +17,28 @@ namespace Orchard.TaskLease.Services
|
||||
public TaskLeaseService(
|
||||
IRepository<TaskLeaseRecord> repository,
|
||||
IClock clock,
|
||||
IMachineNameProvider machineNameProvider)
|
||||
{
|
||||
IMachineNameProvider machineNameProvider) {
|
||||
|
||||
_repository = repository;
|
||||
_clock = clock;
|
||||
_machineNameProvider = machineNameProvider;
|
||||
}
|
||||
|
||||
public string Acquire(string taskName, DateTime expiredUtc)
|
||||
{
|
||||
public string Acquire(string taskName, DateTime expiredUtc) {
|
||||
var machineName = _machineNameProvider.GetMachineName();
|
||||
|
||||
// retrieve current lease for the specified task
|
||||
var taskLease = _repository.Get(x => x.TaskName == taskName);
|
||||
|
||||
// create a new lease if there is no current lease for this task
|
||||
if (taskLease == null)
|
||||
{
|
||||
if (taskLease == null) {
|
||||
taskLease = new TaskLeaseRecord {
|
||||
TaskName = taskName,
|
||||
MachineName = machineName,
|
||||
State = String.Empty,
|
||||
UpdatedUtc = _clock.UtcNow,
|
||||
ExpiredUtc = expiredUtc
|
||||
};
|
||||
TaskName = taskName,
|
||||
MachineName = machineName,
|
||||
State = String.Empty,
|
||||
UpdatedUtc = _clock.UtcNow,
|
||||
ExpiredUtc = expiredUtc
|
||||
};
|
||||
|
||||
_repository.Create(taskLease);
|
||||
_repository.Flush();
|
||||
@@ -49,8 +47,7 @@ namespace Orchard.TaskLease.Services
|
||||
}
|
||||
|
||||
// lease can't be aquired only if for a different machine and it has not expired
|
||||
if (taskLease.MachineName != machineName && taskLease.ExpiredUtc >= _clock.UtcNow)
|
||||
{
|
||||
if (taskLease.MachineName != machineName && taskLease.ExpiredUtc >= _clock.UtcNow) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -64,15 +61,13 @@ namespace Orchard.TaskLease.Services
|
||||
return taskLease.State;
|
||||
}
|
||||
|
||||
public void Update(string taskName, string state)
|
||||
{
|
||||
public void Update(string taskName, string state) {
|
||||
var machineName = _machineNameProvider.GetMachineName();
|
||||
|
||||
// retrieve current lease for the specified task
|
||||
var taskLease = _repository.Get(x => x.TaskName == taskName && x.MachineName == machineName);
|
||||
|
||||
if(taskLease == null)
|
||||
{
|
||||
if (taskLease == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -80,15 +75,13 @@ namespace Orchard.TaskLease.Services
|
||||
_repository.Flush();
|
||||
}
|
||||
|
||||
public void Update(string taskName, string state, DateTime expiredUtc)
|
||||
{
|
||||
public void Update(string taskName, string state, DateTime expiredUtc) {
|
||||
var machineName = _machineNameProvider.GetMachineName();
|
||||
|
||||
// retrieve current lease for the specified task
|
||||
var taskLease = _repository.Get(x => x.TaskName == taskName && x.MachineName == machineName);
|
||||
|
||||
if (taskLease == null)
|
||||
{
|
||||
if (taskLease == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user