Created IMigrationEntryService and affiliated models, etc.... also updates the IServerRegistration stuff to be interfaced.
This commit is contained in:
11
src/Umbraco.Core/Models/IMigrationEntry.cs
Normal file
11
src/Umbraco.Core/Models/IMigrationEntry.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
public interface IMigrationEntry : IAggregateRoot, IRememberBeingDirty
|
||||
{
|
||||
string MigrationName { get; set; }
|
||||
Version Version { get; set; }
|
||||
}
|
||||
}
|
||||
31
src/Umbraco.Core/Models/IServerRegistration.cs
Normal file
31
src/Umbraco.Core/Models/IServerRegistration.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Sync;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
public interface IServerRegistration : IServerAddress, IAggregateRoot, IRememberBeingDirty
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the server unique identity.
|
||||
/// </summary>
|
||||
string ServerIdentity { get; set; }
|
||||
|
||||
new string ServerAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the server is active.
|
||||
/// </summary>
|
||||
bool IsActive { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time the registration was created.
|
||||
/// </summary>
|
||||
DateTime Registered { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time the registration was last accessed.
|
||||
/// </summary>
|
||||
DateTime Accessed { get; set; }
|
||||
}
|
||||
}
|
||||
52
src/Umbraco.Core/Models/MigrationEntry.cs
Normal file
52
src/Umbraco.Core/Models/MigrationEntry.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
public class MigrationEntry : Entity, IMigrationEntry
|
||||
{
|
||||
public MigrationEntry()
|
||||
{
|
||||
}
|
||||
|
||||
public MigrationEntry(int id, DateTime createDate, string migrationName, Version version)
|
||||
{
|
||||
Id = id;
|
||||
CreateDate = createDate;
|
||||
_migrationName = migrationName;
|
||||
_version = version;
|
||||
}
|
||||
|
||||
private static readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<MigrationEntry, string>(x => x.MigrationName);
|
||||
private static readonly PropertyInfo VersionSelector = ExpressionHelper.GetPropertyInfo<MigrationEntry, Version>(x => x.Version);
|
||||
private string _migrationName;
|
||||
private Version _version;
|
||||
|
||||
public string MigrationName
|
||||
{
|
||||
get { return _migrationName; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_migrationName = value;
|
||||
return _migrationName;
|
||||
}, _migrationName, NameSelector);
|
||||
}
|
||||
}
|
||||
|
||||
public Version Version
|
||||
{
|
||||
get { return _version; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_version = value;
|
||||
return _version;
|
||||
}, _version, VersionSelector);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
src/Umbraco.Core/Models/Rdbms/MigrationDto.cs
Normal file
29
src/Umbraco.Core/Models/Rdbms/MigrationDto.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.DatabaseAnnotations;
|
||||
|
||||
namespace Umbraco.Core.Models.Rdbms
|
||||
{
|
||||
[TableName("umbracoMigration")]
|
||||
[PrimaryKey("id")]
|
||||
[ExplicitColumns]
|
||||
internal class MigrationDto
|
||||
{
|
||||
[Column("id")]
|
||||
[PrimaryKeyColumn(AutoIncrement = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("name")]
|
||||
[Length(255)]
|
||||
[Index(IndexTypes.UniqueNonClustered, ForColumns = "name,version", Name = "IX_umbracoMigration")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column("createDate")]
|
||||
[Constraint(Default = "getdate()")]
|
||||
public DateTime CreateDate { get; set; }
|
||||
|
||||
[Column("version")]
|
||||
[Length(50)]
|
||||
public string Version { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Represents a registered server in a multiple-servers environment.
|
||||
/// </summary>
|
||||
public class ServerRegistration : Entity, IServerAddress, IAggregateRoot
|
||||
public class ServerRegistration : Entity, IServerRegistration
|
||||
{
|
||||
private string _serverAddress;
|
||||
private string _serverIdentity;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal class MigrationEntryFactory
|
||||
{
|
||||
public MigrationEntry BuildEntity(MigrationDto dto)
|
||||
{
|
||||
var model = new MigrationEntry(dto.Id, dto.CreateDate, dto.Name, Version.Parse(dto.Version));
|
||||
//on initial construction we don't want to have dirty properties tracked
|
||||
// http://issues.umbraco.org/issue/U4-1946
|
||||
model.ResetDirtyProperties(false);
|
||||
return model;
|
||||
}
|
||||
|
||||
public MigrationDto BuildDto(IMigrationEntry entity)
|
||||
{
|
||||
var dto = new MigrationDto
|
||||
{
|
||||
CreateDate = entity.CreateDate,
|
||||
Name = entity.MigrationName,
|
||||
Version = entity.Version.ToString()
|
||||
};
|
||||
|
||||
if (entity.HasIdentity)
|
||||
dto.Id = entity.Id;
|
||||
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,6 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal class ServerRegistrationFactory
|
||||
{
|
||||
#region Implementation of IEntityFactory<Language,LanguageDto>
|
||||
|
||||
public ServerRegistration BuildEntity(ServerRegistrationDto dto)
|
||||
{
|
||||
var model = new ServerRegistration(dto.Id, dto.ServerAddress, dto.ServerIdentity, dto.DateRegistered, dto.DateAccessed, dto.IsActive);
|
||||
@@ -16,23 +14,21 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
return model;
|
||||
}
|
||||
|
||||
public ServerRegistrationDto BuildDto(ServerRegistration entity)
|
||||
public ServerRegistrationDto BuildDto(IServerRegistration entity)
|
||||
{
|
||||
var dto = new ServerRegistrationDto
|
||||
{
|
||||
ServerAddress = entity.ServerAddress,
|
||||
DateRegistered = entity.CreateDate,
|
||||
IsActive = entity.IsActive,
|
||||
DateAccessed = entity.UpdateDate,
|
||||
ServerIdentity = entity.ServerIdentity
|
||||
};
|
||||
{
|
||||
ServerAddress = entity.ServerAddress,
|
||||
DateRegistered = entity.CreateDate,
|
||||
IsActive = entity.IsActive,
|
||||
DateAccessed = entity.UpdateDate,
|
||||
ServerIdentity = entity.ServerIdentity
|
||||
};
|
||||
|
||||
if (entity.HasIdentity)
|
||||
dto.Id = entity.Id;
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
38
src/Umbraco.Core/Persistence/Mappers/MigrationEntryMapper.cs
Normal file
38
src/Umbraco.Core/Persistence/Mappers/MigrationEntryMapper.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Collections.Concurrent;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Mappers
|
||||
{
|
||||
[MapperFor(typeof(MigrationEntry))]
|
||||
[MapperFor(typeof(IMigrationEntry))]
|
||||
internal sealed class MigrationEntryMapper : BaseMapper
|
||||
{
|
||||
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
|
||||
|
||||
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
|
||||
// otherwise that would fail because there is no public constructor.
|
||||
public MigrationEntryMapper()
|
||||
{
|
||||
BuildMap();
|
||||
}
|
||||
|
||||
#region Overrides of BaseMapper
|
||||
|
||||
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
|
||||
{
|
||||
get { return PropertyInfoCacheInstance; }
|
||||
}
|
||||
|
||||
internal override void BuildMap()
|
||||
{
|
||||
CacheMap<MigrationEntry, MigrationDto>(src => src.Id, dto => dto.Id);
|
||||
CacheMap<MigrationEntry, MigrationDto>(src => src.CreateDate, dto => dto.CreateDate);
|
||||
CacheMap<MigrationEntry, MigrationDto>(src => src.UpdateDate, dto => dto.CreateDate);
|
||||
CacheMap<MigrationEntry, MigrationDto>(src => src.Version, dto => dto.Version);
|
||||
CacheMap<MigrationEntry, MigrationDto>(src => src.MigrationName, dto => dto.Name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using Umbraco.Core.Models.Rdbms;
|
||||
namespace Umbraco.Core.Persistence.Mappers
|
||||
{
|
||||
[MapperFor(typeof(ServerRegistration))]
|
||||
[MapperFor(typeof(IServerRegistration))]
|
||||
internal sealed class ServerRegistrationMapper : BaseMapper
|
||||
{
|
||||
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
public interface IMigrationEntryRepository : IRepositoryQueryable<int, IMigrationEntry>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
public interface IServerRegistrationRepository : IRepositoryQueryable<int, IServerRegistration>
|
||||
{
|
||||
void DeactiveStaleServers(TimeSpan staleTimeout);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence.Factories;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
internal class MigrationEntryRepository : PetaPocoRepositoryBase<int, IMigrationEntry>, IMigrationEntryRepository
|
||||
{
|
||||
public MigrationEntryRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax)
|
||||
: base(work, cache, logger, sqlSyntax)
|
||||
{
|
||||
}
|
||||
|
||||
protected override IMigrationEntry PerformGet(int id)
|
||||
{
|
||||
var sql = GetBaseQuery(false);
|
||||
sql.Where(GetBaseWhereClause(), new { Id = id });
|
||||
|
||||
var dto = Database.First<MigrationDto>(sql);
|
||||
if (dto == null)
|
||||
return null;
|
||||
|
||||
var factory = new MigrationEntryFactory();
|
||||
var entity = factory.BuildEntity(dto);
|
||||
|
||||
//on initial construction we don't want to have dirty properties tracked
|
||||
// http://issues.umbraco.org/issue/U4-1946
|
||||
entity.ResetDirtyProperties(false);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
protected override IEnumerable<IMigrationEntry> PerformGetAll(params int[] ids)
|
||||
{
|
||||
var factory = new MigrationEntryFactory();
|
||||
|
||||
if (ids.Any())
|
||||
{
|
||||
return Database.Fetch<MigrationDto>("WHERE id in (@ids)", new { ids = ids })
|
||||
.Select(x => factory.BuildEntity(x));
|
||||
}
|
||||
|
||||
return Database.Fetch<MigrationDto>("WHERE id > 0")
|
||||
.Select(x => factory.BuildEntity(x));
|
||||
}
|
||||
|
||||
protected override IEnumerable<IMigrationEntry> PerformGetByQuery(IQuery<IMigrationEntry> query)
|
||||
{
|
||||
var factory = new MigrationEntryFactory();
|
||||
var sqlClause = GetBaseQuery(false);
|
||||
var translator = new SqlTranslator<IMigrationEntry>(sqlClause, query);
|
||||
var sql = translator.Translate();
|
||||
|
||||
return Database.Fetch<MigrationDto>(sql).Select(x => factory.BuildEntity(x));
|
||||
}
|
||||
|
||||
protected override Sql GetBaseQuery(bool isCount)
|
||||
{
|
||||
var sql = new Sql();
|
||||
sql.Select(isCount ? "COUNT(*)" : "*")
|
||||
.From<MigrationDto>(SqlSyntax);
|
||||
return sql;
|
||||
}
|
||||
|
||||
protected override string GetBaseWhereClause()
|
||||
{
|
||||
return "id = @Id";
|
||||
}
|
||||
|
||||
protected override IEnumerable<string> GetDeleteClauses()
|
||||
{
|
||||
var list = new List<string>
|
||||
{
|
||||
"DELETE FROM umbracoMigration WHERE id = @Id"
|
||||
};
|
||||
return list;
|
||||
}
|
||||
|
||||
protected override Guid NodeObjectTypeId
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
protected override void PersistNewItem(IMigrationEntry entity)
|
||||
{
|
||||
((MigrationEntry)entity).AddingEntity();
|
||||
|
||||
var factory = new MigrationEntryFactory();
|
||||
var dto = factory.BuildDto(entity);
|
||||
|
||||
var id = Convert.ToInt32(Database.Insert(dto));
|
||||
entity.Id = id;
|
||||
|
||||
entity.ResetDirtyProperties();
|
||||
}
|
||||
|
||||
protected override void PersistUpdatedItem(IMigrationEntry entity)
|
||||
{
|
||||
((MigrationEntry)entity).UpdatingEntity();
|
||||
|
||||
var factory = new MigrationEntryFactory();
|
||||
var dto = factory.BuildDto(entity);
|
||||
|
||||
Database.Update(dto);
|
||||
|
||||
entity.ResetDirtyProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,14 +13,14 @@ using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
internal class ServerRegistrationRepository : PetaPocoRepositoryBase<int, ServerRegistration>
|
||||
internal class ServerRegistrationRepository : PetaPocoRepositoryBase<int, IServerRegistration>, IServerRegistrationRepository
|
||||
{
|
||||
public ServerRegistrationRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax)
|
||||
: base(work, cache, logger, sqlSyntax)
|
||||
{
|
||||
}
|
||||
|
||||
protected override ServerRegistration PerformGet(int id)
|
||||
protected override IServerRegistration PerformGet(int id)
|
||||
{
|
||||
var sql = GetBaseQuery(false);
|
||||
sql.Where(GetBaseWhereClause(), new { Id = id });
|
||||
@@ -39,45 +39,35 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
return entity;
|
||||
}
|
||||
|
||||
protected override IEnumerable<ServerRegistration> PerformGetAll(params int[] ids)
|
||||
protected override IEnumerable<IServerRegistration> PerformGetAll(params int[] ids)
|
||||
{
|
||||
var factory = new ServerRegistrationFactory();
|
||||
|
||||
if (ids.Any())
|
||||
{
|
||||
foreach (var id in ids)
|
||||
{
|
||||
yield return Get(id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var serverDtos = Database.Fetch<ServerRegistrationDto>("WHERE id > 0");
|
||||
foreach (var serverDto in serverDtos)
|
||||
{
|
||||
yield return Get(serverDto.Id);
|
||||
}
|
||||
return Database.Fetch<ServerRegistrationDto>("WHERE id in (@ids)", new { ids = ids })
|
||||
.Select(x => factory.BuildEntity(x));
|
||||
}
|
||||
|
||||
return Database.Fetch<ServerRegistrationDto>("WHERE id > 0")
|
||||
.Select(x => factory.BuildEntity(x));
|
||||
}
|
||||
|
||||
protected override IEnumerable<ServerRegistration> PerformGetByQuery(IQuery<ServerRegistration> query)
|
||||
protected override IEnumerable<IServerRegistration> PerformGetByQuery(IQuery<IServerRegistration> query)
|
||||
{
|
||||
var factory = new ServerRegistrationFactory();
|
||||
var sqlClause = GetBaseQuery(false);
|
||||
var translator = new SqlTranslator<ServerRegistration>(sqlClause, query);
|
||||
var translator = new SqlTranslator<IServerRegistration>(sqlClause, query);
|
||||
var sql = translator.Translate();
|
||||
|
||||
var dtos = Database.Fetch<ServerRegistration>(sql);
|
||||
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
yield return Get(dto.Id);
|
||||
}
|
||||
|
||||
return Database.Fetch<ServerRegistrationDto>(sql).Select(x => factory.BuildEntity(x));
|
||||
}
|
||||
|
||||
protected override Sql GetBaseQuery(bool isCount)
|
||||
{
|
||||
var sql = new Sql();
|
||||
sql.Select(isCount ? "COUNT(*)" : "*")
|
||||
.From<ServerRegistrationDto>();
|
||||
.From<ServerRegistrationDto>(SqlSyntax);
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -100,9 +90,9 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
protected override void PersistNewItem(ServerRegistration entity)
|
||||
protected override void PersistNewItem(IServerRegistration entity)
|
||||
{
|
||||
entity.AddingEntity();
|
||||
((ServerRegistration)entity).AddingEntity();
|
||||
|
||||
var factory = new ServerRegistrationFactory();
|
||||
var dto = factory.BuildDto(entity);
|
||||
@@ -113,9 +103,9 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
entity.ResetDirtyProperties();
|
||||
}
|
||||
|
||||
protected override void PersistUpdatedItem(ServerRegistration entity)
|
||||
protected override void PersistUpdatedItem(IServerRegistration entity)
|
||||
{
|
||||
entity.UpdatingEntity();
|
||||
((ServerRegistration)entity).UpdatingEntity();
|
||||
|
||||
var factory = new ServerRegistrationFactory();
|
||||
var dto = factory.BuildDto(entity);
|
||||
@@ -129,7 +119,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
var timeoutDate = DateTime.UtcNow.Subtract(staleTimeout);
|
||||
|
||||
Database.Update<ServerRegistrationDto>("SET isActive=0 WHERE lastNotifiedDate < @timeoutDate", new {timeoutDate = timeoutDate});
|
||||
Database.Update<ServerRegistrationDto>("SET isActive=0 WHERE lastNotifiedDate < @timeoutDate", new { timeoutDate = timeoutDate });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -216,7 +216,15 @@ namespace Umbraco.Core.Persistence
|
||||
_settings.Templates);
|
||||
}
|
||||
|
||||
internal virtual ServerRegistrationRepository CreateServerRegistrationRepository(IDatabaseUnitOfWork uow)
|
||||
public virtual IMigrationEntryRepository CreateMigrationEntryRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return new MigrationEntryRepository(
|
||||
uow,
|
||||
CacheHelper.CreateDisabledCacheHelper(), //never cache
|
||||
_logger, _sqlSyntax);
|
||||
}
|
||||
|
||||
public virtual IServerRegistrationRepository CreateServerRegistrationRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return new ServerRegistrationRepository(
|
||||
uow,
|
||||
|
||||
32
src/Umbraco.Core/Services/IMigrationEntryService.cs
Normal file
32
src/Umbraco.Core/Services/IMigrationEntryService.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
public interface IMigrationEntryService
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a migration entry, will throw an exception if it already exists
|
||||
/// </summary>
|
||||
/// <param name="migrationName"></param>
|
||||
/// <param name="version"></param>
|
||||
/// <returns></returns>
|
||||
IMigrationEntry CreateEntry(string migrationName, Version version);
|
||||
|
||||
/// <summary>
|
||||
/// Finds a migration by name and version, returns null if not found
|
||||
/// </summary>
|
||||
/// <param name="migrationName"></param>
|
||||
/// <param name="version"></param>
|
||||
/// <returns></returns>
|
||||
IMigrationEntry FindEntry(string migrationName, Version version);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all entries for a given migration name
|
||||
/// </summary>
|
||||
/// <param name="migrationName"></param>
|
||||
/// <returns></returns>
|
||||
IEnumerable<IMigrationEntry> GetAll(string migrationName);
|
||||
}
|
||||
}
|
||||
35
src/Umbraco.Core/Services/IServerRegistrationService.cs
Normal file
35
src/Umbraco.Core/Services/IServerRegistrationService.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
public interface IServerRegistrationService
|
||||
{
|
||||
/// <summary>
|
||||
/// Touches a server to mark it as active; deactivate stale servers.
|
||||
/// </summary>
|
||||
/// <param name="serverAddress">The server url.</param>
|
||||
/// <param name="serverIdentity">The server unique identity.</param>
|
||||
/// <param name="staleTimeout">The time after which a server is considered stale.</param>
|
||||
void TouchServer(string serverAddress, string serverIdentity, TimeSpan staleTimeout);
|
||||
|
||||
/// <summary>
|
||||
/// Deactivates a server.
|
||||
/// </summary>
|
||||
/// <param name="serverIdentity">The server unique identity.</param>
|
||||
void DeactiveServer(string serverIdentity);
|
||||
|
||||
/// <summary>
|
||||
/// Deactivates stale servers.
|
||||
/// </summary>
|
||||
/// <param name="staleTimeout">The time after which a server is considered stale.</param>
|
||||
void DeactiveStaleServers(TimeSpan staleTimeout);
|
||||
|
||||
/// <summary>
|
||||
/// Return all active servers.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerable<IServerRegistration> GetActiveServers();
|
||||
}
|
||||
}
|
||||
80
src/Umbraco.Core/Services/MigrationEntryService.cs
Normal file
80
src/Umbraco.Core/Services/MigrationEntryService.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages migration entries in the database
|
||||
/// </summary>
|
||||
public sealed class MigrationEntryService : RepositoryService, IMigrationEntryService
|
||||
{
|
||||
public MigrationEntryService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger)
|
||||
: base(provider, repositoryFactory, logger)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a migration entry, will throw an exception if it already exists
|
||||
/// </summary>
|
||||
/// <param name="migrationName"></param>
|
||||
/// <param name="version"></param>
|
||||
/// <returns></returns>
|
||||
public IMigrationEntry CreateEntry(string migrationName, Version version)
|
||||
{
|
||||
var entry = new MigrationEntry
|
||||
{
|
||||
MigrationName = migrationName,
|
||||
Version = version
|
||||
};
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateMigrationEntryRepository(uow))
|
||||
{
|
||||
repo.AddOrUpdate(entry);
|
||||
uow.Commit();
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds a migration by name and version, returns null if not found
|
||||
/// </summary>
|
||||
/// <param name="migrationName"></param>
|
||||
/// <param name="version"></param>
|
||||
/// <returns></returns>
|
||||
public IMigrationEntry FindEntry(string migrationName, Version version)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateMigrationEntryRepository(uow))
|
||||
{
|
||||
var query = Query<IMigrationEntry>.Builder
|
||||
.Where(x => x.MigrationName.ToUpper() == migrationName.ToUpper() && x.Version == version);
|
||||
return repo.GetByQuery(query).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all entries for a given migration name
|
||||
/// </summary>
|
||||
/// <param name="migrationName"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<IMigrationEntry> GetAll(string migrationName)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateMigrationEntryRepository(uow))
|
||||
{
|
||||
var query = Query<IMigrationEntry>.Builder
|
||||
.Where(x => x.MigrationName.ToUpper() == migrationName.ToUpper());
|
||||
return repo.GetByQuery(query);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,10 @@ using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Manages server registrations in the database.
|
||||
/// </summary>
|
||||
public sealed class ServerRegistrationService : RepositoryService
|
||||
public sealed class ServerRegistrationService : RepositoryService, IServerRegistrationService
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ServerRegistrationService"/> class.
|
||||
@@ -36,14 +35,14 @@ namespace Umbraco.Core.Services
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateServerRegistrationRepository(uow))
|
||||
{
|
||||
var query = Query<ServerRegistration>.Builder.Where(x => x.ServerIdentity.ToUpper() == serverIdentity.ToUpper());
|
||||
var query = Query<IServerRegistration>.Builder.Where(x => x.ServerIdentity.ToUpper() == serverIdentity.ToUpper());
|
||||
var server = repo.GetByQuery(query).FirstOrDefault();
|
||||
if (server == null)
|
||||
{
|
||||
server = new ServerRegistration(serverAddress, serverIdentity, DateTime.UtcNow)
|
||||
{
|
||||
IsActive = true
|
||||
};
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -67,7 +66,7 @@ namespace Umbraco.Core.Services
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateServerRegistrationRepository(uow))
|
||||
{
|
||||
var query = Query<ServerRegistration>.Builder.Where(x => x.ServerIdentity.ToUpper() == serverIdentity.ToUpper());
|
||||
var query = Query<IServerRegistration>.Builder.Where(x => x.ServerIdentity.ToUpper() == serverIdentity.ToUpper());
|
||||
var server = repo.GetByQuery(query).FirstOrDefault();
|
||||
if (server != null)
|
||||
{
|
||||
@@ -95,12 +94,12 @@ namespace Umbraco.Core.Services
|
||||
/// Return all active servers.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<ServerRegistration> GetActiveServers()
|
||||
public IEnumerable<IServerRegistration> GetActiveServers()
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateServerRegistrationRepository(uow))
|
||||
{
|
||||
var query = Query<ServerRegistration>.Builder.Where(x => x.IsActive);
|
||||
var query = Query<IServerRegistration>.Builder.Where(x => x.IsActive);
|
||||
return repo.GetByQuery(query).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace Umbraco.Core.Services
|
||||
/// </summary>
|
||||
public class ServiceContext
|
||||
{
|
||||
private Lazy<IMigrationEntryService> _migrationEntryService;
|
||||
private Lazy<IPublicAccessService> _publicAccessService;
|
||||
private Lazy<ITaskService> _taskService;
|
||||
private Lazy<IDomainService> _domainService;
|
||||
@@ -33,7 +34,7 @@ namespace Umbraco.Core.Services
|
||||
private Lazy<IFileService> _fileService;
|
||||
private Lazy<ILocalizationService> _localizationService;
|
||||
private Lazy<IPackagingService> _packagingService;
|
||||
private Lazy<ServerRegistrationService> _serverRegistrationService;
|
||||
private Lazy<IServerRegistrationService> _serverRegistrationService;
|
||||
private Lazy<IEntityService> _entityService;
|
||||
private Lazy<IRelationService> _relationService;
|
||||
private Lazy<IApplicationTreeService> _treeService;
|
||||
@@ -70,6 +71,8 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="taskService"></param>
|
||||
/// <param name="macroService"></param>
|
||||
/// <param name="publicAccessService"></param>
|
||||
/// <param name="externalLoginService"></param>
|
||||
/// <param name="migrationEntryService"></param>
|
||||
public ServiceContext(
|
||||
IContentService contentService = null,
|
||||
IMediaService mediaService = null,
|
||||
@@ -94,8 +97,10 @@ namespace Umbraco.Core.Services
|
||||
ITaskService taskService = null,
|
||||
IMacroService macroService = null,
|
||||
IPublicAccessService publicAccessService = null,
|
||||
IExternalLoginService externalLoginService = null)
|
||||
IExternalLoginService externalLoginService = null,
|
||||
IMigrationEntryService migrationEntryService = null)
|
||||
{
|
||||
if (migrationEntryService != null) _migrationEntryService = new Lazy<IMigrationEntryService>(() => migrationEntryService);
|
||||
if (externalLoginService != null) _externalLoginService = new Lazy<IExternalLoginService>(() => externalLoginService);
|
||||
if (auditService != null) _auditService = new Lazy<IAuditService>(() => auditService);
|
||||
if (localizedTextService != null) _localizedTextService = new Lazy<ILocalizedTextService>(() => localizedTextService);
|
||||
@@ -149,6 +154,9 @@ namespace Umbraco.Core.Services
|
||||
var provider = dbUnitOfWorkProvider;
|
||||
var fileProvider = fileUnitOfWorkProvider;
|
||||
|
||||
if (_migrationEntryService == null)
|
||||
_migrationEntryService = new Lazy<IMigrationEntryService>(() => new MigrationEntryService(provider, repositoryFactory, logger));
|
||||
|
||||
if (_externalLoginService == null)
|
||||
_externalLoginService = new Lazy<IExternalLoginService>(() => new ExternalLoginService(provider, repositoryFactory, logger));
|
||||
|
||||
@@ -205,7 +213,7 @@ namespace Umbraco.Core.Services
|
||||
_notificationService = new Lazy<INotificationService>(() => new NotificationService(provider, _userService.Value, _contentService.Value, logger));
|
||||
|
||||
if (_serverRegistrationService == null)
|
||||
_serverRegistrationService = new Lazy<ServerRegistrationService>(() => new ServerRegistrationService(provider, repositoryFactory, logger));
|
||||
_serverRegistrationService = new Lazy<IServerRegistrationService>(() => new ServerRegistrationService(provider, repositoryFactory, logger));
|
||||
|
||||
if (_userService == null)
|
||||
_userService = new Lazy<IUserService>(() => new UserService(provider, repositoryFactory, logger));
|
||||
@@ -263,6 +271,14 @@ namespace Umbraco.Core.Services
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IMigrationEntryService"/>
|
||||
/// </summary>
|
||||
public IMigrationEntryService MigrationEntryService
|
||||
{
|
||||
get { return _migrationEntryService.Value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IPublicAccessService"/>
|
||||
/// </summary>
|
||||
@@ -314,7 +330,7 @@ namespace Umbraco.Core.Services
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ServerRegistrationService"/>
|
||||
/// </summary>
|
||||
public ServerRegistrationService ServerRegistrationService
|
||||
public IServerRegistrationService ServerRegistrationService
|
||||
{
|
||||
get { return _serverRegistrationService.Value; }
|
||||
}
|
||||
|
||||
@@ -340,6 +340,9 @@
|
||||
<Compile Include="Models\Identity\IdentityUserRole.cs" />
|
||||
<Compile Include="Models\Identity\BackOfficeIdentityUser.cs" />
|
||||
<Compile Include="Models\Identity\IIdentityUserLogin.cs" />
|
||||
<Compile Include="Models\IMigrationEntry.cs" />
|
||||
<Compile Include="Models\IServerRegistration.cs" />
|
||||
<Compile Include="Models\MigrationEntry.cs" />
|
||||
<Compile Include="Models\PublicAccessEntry.cs" />
|
||||
<Compile Include="Models\PublicAccessRule.cs" />
|
||||
<Compile Include="Models\Rdbms\AccessDto.cs" />
|
||||
@@ -358,15 +361,18 @@
|
||||
<Compile Include="Models\Rdbms\AccessRuleDto.cs" />
|
||||
<Compile Include="Models\Rdbms\DocumentPublishedReadOnlyDto.cs" />
|
||||
<Compile Include="Models\Rdbms\ExternalLoginDto.cs" />
|
||||
<Compile Include="Models\Rdbms\MigrationDto.cs" />
|
||||
<Compile Include="Models\UmbracoDomain.cs" />
|
||||
<Compile Include="Models\DoNotCloneAttribute.cs" />
|
||||
<Compile Include="Models\IDomain.cs" />
|
||||
<Compile Include="Persistence\Factories\ExternalLoginFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\MigrationEntryFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\PublicAccessEntryFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\TaskFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\TaskTypeFactory.cs" />
|
||||
<Compile Include="Persistence\Mappers\AccessMapper.cs" />
|
||||
<Compile Include="Persistence\Mappers\DomainMapper.cs" />
|
||||
<Compile Include="Persistence\Mappers\MigrationEntryMapper.cs" />
|
||||
<Compile Include="Persistence\Migrations\Upgrades\TargetVersionSevenThreeZero\AddExternalLoginsTable.cs" />
|
||||
<Compile Include="Persistence\Migrations\Upgrades\TargetVersionSevenThreeZero\AddPublicAccessTables.cs" />
|
||||
<Compile Include="Persistence\Migrations\Upgrades\TargetVersionSevenThreeZero\AddUserColumns.cs" />
|
||||
@@ -401,9 +407,12 @@
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IAuditRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IDomainRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IExternalLoginRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IMigrationEntryRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IPublicAccessRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IServerRegistrationRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\ITaskRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\ITaskTypeRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\MigrationEntryRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\PublicAccessRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\RepositoryCacheOptions.cs" />
|
||||
<Compile Include="Persistence\Repositories\TaskRepository.cs" />
|
||||
@@ -429,9 +438,12 @@
|
||||
<Compile Include="Services\IAuditService.cs" />
|
||||
<Compile Include="Services\IDomainService.cs" />
|
||||
<Compile Include="Services\IExternalLoginService.cs" />
|
||||
<Compile Include="Services\IMigrationEntryService.cs" />
|
||||
<Compile Include="Services\IPublicAccessService.cs" />
|
||||
<Compile Include="Services\IServerRegistrationService.cs" />
|
||||
<Compile Include="Services\ITaskService.cs" />
|
||||
<Compile Include="Services\LocalizedTextServiceSupplementaryFileSource.cs" />
|
||||
<Compile Include="Services\MigrationEntryService.cs" />
|
||||
<Compile Include="Services\PublicAccessService.cs" />
|
||||
<Compile Include="Services\PublicAccessServiceExtensions.cs" />
|
||||
<Compile Include="Services\RepositoryService.cs" />
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
using (var repository = CreateRepositor(unitOfWork))
|
||||
{
|
||||
// Act
|
||||
var query = Query<ServerRegistration>.Builder.Where(x => x.ServerIdentity.ToUpper() == "COMPUTER3");
|
||||
var query = Query<IServerRegistration>.Builder.Where(x => x.ServerIdentity.ToUpper() == "COMPUTER3");
|
||||
var result = repository.GetByQuery(query);
|
||||
|
||||
// Assert
|
||||
@@ -145,7 +145,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
using (var repository = CreateRepositor(unitOfWork))
|
||||
{
|
||||
// Act
|
||||
var query = Query<ServerRegistration>.Builder.Where(x => x.ServerAddress.StartsWith("http://"));
|
||||
var query = Query<IServerRegistration>.Builder.Where(x => x.ServerAddress.StartsWith("http://"));
|
||||
int count = repository.Count(query);
|
||||
|
||||
// Assert
|
||||
|
||||
Reference in New Issue
Block a user