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:
Daniel Stolt
2014-11-17 00:01:44 +01:00
parent ffe6a733ea
commit 9855914af2
7 changed files with 45 additions and 61 deletions

View File

@@ -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();
}

View File

@@ -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>

View File

@@ -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;
}
}

View File

@@ -3,44 +3,42 @@ 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;
public TaskLeaseService(
IRepository<TaskLeaseRecord> repository,
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;
}