protected override EventCacheWriteObject LoadObject(AccountCacheRequest request, AccountDbContext accountDbContext) { var eventRepository = accountDbContext.GetEventRepository(); var eventObj = eventRepository.GetByIdOrNull(request.ObjectId); return(EventCacheWriteObject.CreateForUpdate(eventObj, request.AccountId)); }
protected override UnitTestCacheWriteObject LoadObject(AccountCacheRequest request, AccountDbContext accountDbContext) { var repository = accountDbContext.GetUnitTestRepository(); var data = repository.GetByIdOrNull(request.ObjectId); return(UnitTestCacheWriteObject.Create(data, request.AccountId)); }
protected override BulbCacheWriteObject LoadObject(AccountCacheRequest request, AccountDbContext accountDbContext) { var repository = accountDbContext.GetStatusDataRepository(); var statusData = repository.GetByIdOrNull(request.ObjectId); return(BulbCacheWriteObject.Create(statusData, request.AccountId)); }
protected override MetricTypeCacheWriteObject LoadObject(AccountCacheRequest request, AccountDbContext accountDbContext) { var repository = accountDbContext.GetMetricTypeRepository(); var metricType = repository.GetByIdOrNull(request.ObjectId); return(MetricTypeCacheWriteObject.Create(metricType, request.AccountId)); }
public TReadObject Read(Guid id) { var request = new AccountCacheRequest() { AccountId = AccountId, ObjectId = id }; return(Storage.Read(request)); }
public TWriteObject Write(Guid id) { var request = new AccountCacheRequest() { AccountId = AccountId, ObjectId = id }; return(Storage.Write(request)); }
public void Unload(Guid id) { var request = new AccountCacheRequest() { AccountId = AccountId, ObjectId = id }; Storage.Unload(request); }
public bool ExistsInCache(Guid id) { var request = new AccountCacheRequest() { AccountId = AccountId, ObjectId = id }; return(Storage.ExistsInCache(request)); }
public IEventCacheReadObject GetForRead(Event eventObj, Guid accountId) { if (eventObj == null) { throw new ArgumentNullException("eventObj"); } var request = new AccountCacheRequest() { AccountId = accountId, ObjectId = eventObj.Id }; return(Find(request)); }
public bool ExistsInStorage(IEventCacheReadObject eventObj) { if (eventObj == null) { throw new ArgumentNullException("eventObj"); } var request = new AccountCacheRequest() { AccountId = eventObj.AccountId, ObjectId = eventObj.Id }; return(ExistsInStorage(request)); }
protected override ComponentCacheWriteObject LoadObject(AccountCacheRequest request, AccountDbContext accountDbContext) { if (request == null) { throw new ArgumentNullException("request"); } if (accountDbContext == null) { throw new ArgumentNullException("accountDbContext"); } var repository = accountDbContext.GetComponentRepository(); var component = repository.GetByIdOrNull(request.ObjectId); return(ComponentCacheWriteObject.Create(component, request.AccountId)); }
protected override TWriteObject LoadObject(AccountCacheRequest request) { if (request == null) { throw new ArgumentNullException("request"); } if (request.AccountId == Guid.Empty) { throw new Exception("request.AccountId == Guid.Empty"); } using (var accountDbContext = AccountDbContext.CreateFromAccountIdLocalCache(request.AccountId)) { return(LoadObject(request, accountDbContext)); } }
public override TReadObject Find(AccountCacheRequest request) { var result = base.Find(request); if (result == null) { return(null); } if (result.AccountId != request.AccountId) { return(null); } return(result); }
protected override void ValidateChanges(MetricCacheWriteObject oldObj, MetricCacheWriteObject newObj) { if (newObj.AccountId == Guid.Empty) { throw new Exception("newObj.AccountId == Guid.Empty"); } if (newObj.ComponentId == Guid.Empty) { throw new Exception("newObj.ComponentId == Guid.Empty"); } if (newObj.CreateDate == DateTime.MinValue) { throw new Exception("newObj.CreateDate == DateTime.MinValue"); } if (newObj.StatusDataId == Guid.Empty) { throw new Exception("newObj.StatusDataId == Guid.Empty"); } if (oldObj.AccountId != newObj.AccountId) { throw new Exception("oldObj.AccountId != newObj.AccountId"); } if (StringHelper.GetLength(newObj.DisableComment) > 1000) { throw new UserFriendlyException("Длина DisableComment макимум 1000 символов"); } var newComponentRequest = new AccountCacheRequest() { AccountId = newObj.AccountId, ObjectId = newObj.ComponentId }; // если удалена if (newObj.IsDeleted) { // получим нового родителя using (var newComponent = AllCaches.Components.Write(newComponentRequest)) { newComponent.WriteMetrics.Delete(newObj.Id); newComponent.BeginSave(); } } // если изменился родитель else if (oldObj.ComponentId != newObj.ComponentId) { // получим нового родителя using (var newComponent = AllCaches.Components.Write(newComponentRequest)) { // проверим, что у нового родителя нет ребенка с таким же именем var child = newComponent.Metrics.FindByMetricTypeId(newObj.MetricTypeId); if (child != null) { throw new Exception("У нового компонента уже есть метрика с таким именем"); } // получим старого родителя var oldComponentRequest = new AccountCacheRequest() { AccountId = newObj.AccountId, ObjectId = oldObj.ComponentId }; using (var oldComponent = AllCaches.Components.Write(oldComponentRequest)) { var reference = new CacheObjectReference(newObj.Id, newObj.MetricTypeId.ToString()); newComponent.WriteMetrics.Add(reference); oldComponent.WriteMetrics.Delete(newObj.Id); oldComponent.BeginSave(); } newComponent.BeginSave(); } } // если изменилось только системное имя else if (oldObj.MetricTypeId != newObj.MetricTypeId) { // проверим что у компонента нет проверки с таким MetricTypeId using (var component = AllCaches.Components.Write(newComponentRequest)) { var child = component.Metrics.FindByMetricTypeId(newObj.MetricTypeId); if (child != null) { throw new Exception("У компонента уже есть метрика с таким именем"); } component.WriteMetrics.Rename(oldObj.MetricTypeId.ToString(), newObj.MetricTypeId.ToString()); component.BeginSave(); } } }
protected abstract TWriteObject LoadObject(AccountCacheRequest request, AccountDbContext accountDbContext);
protected override void ValidateChanges(ComponentCacheWriteObject oldComponent, ComponentCacheWriteObject newComponent) { if (oldComponent == null) { throw new ArgumentNullException("oldComponent"); } if (newComponent == null) { throw new ArgumentNullException("newComponent"); } if (oldComponent.AccountId != newComponent.AccountId) { throw new ArgumentNullException("Нельзя изменять AccountId"); } if (newComponent.AccountId == Guid.Empty) { throw new ArgumentNullException("AccountId is Empty"); } if (newComponent.ParentId == null) { if (newComponent.IsRoot == false) { throw new ArgumentException("Не указан ParentId"); } } if (newComponent.SystemName == null) { throw new ArgumentException("Не указан SystemName"); } if (StringHelper.GetLength(newComponent.DisplayName) > 255) { throw new Exception("StringHelper.GetLength(newComponent.DisplayName) > 255"); } if (StringHelper.GetLength(newComponent.SystemName) > 255) { throw new Exception("StringHelper.GetLength(newComponent.SystemName) > 255"); } if (StringHelper.GetLength(newComponent.DisableComment) > 1000) { throw new Exception("StringHelper.GetLength(newComponent.DisableComment) > 1000"); } var accountId = newComponent.AccountId; // если объект удалили if (newComponent.IsDeleted) { using (var parent = AllCaches.Components.Write(new AccountCacheRequest() { AccountId = newComponent.AccountId, ObjectId = newComponent.ParentId.Value })) { parent.WriteChilds.Delete(newComponent.Id); parent.BeginSave(); }; } // если изменился родитель if (newComponent.ParentId != oldComponent.ParentId) { // проверим наличие нового родителя var parentRequest = new AccountCacheRequest() { AccountId = accountId, ObjectId = newComponent.ParentId.Value }; using (var parent = AllCaches.Components.Write(parentRequest)) { // проверим, что у нового родителя нет детей с таким же именем var child = parent.Childs.FindByName(newComponent.SystemName); if (child != null) { throw new ParameterErrorException("Системное имя должно быть уникальным"); } // родителу можно добавить нового ребенка var newReference = new CacheObjectReference(newComponent.Id, newComponent.SystemName); parent.WriteChilds.Add(newReference); // удлалим ссылку в старом родителе if (oldComponent.ParentId.HasValue) { var oldParentRequest = new AccountCacheRequest() { AccountId = accountId, ObjectId = oldComponent.ParentId.Value }; using (var oldParent = AllCaches.Components.Write(oldParentRequest)) { oldParent.WriteChilds.Delete(newComponent.Id); oldParent.BeginSave(); } } parent.BeginSave(); } } // если родитель НЕ изменился, но изменилось системное имя else if (string.Equals(oldComponent.SystemName, newComponent.SystemName, StringComparison.InvariantCultureIgnoreCase) == false) { // проверим, что у родителя нет ребенка с таким же именем var parentRequest = new AccountCacheRequest() { AccountId = accountId, ObjectId = newComponent.ParentId.Value }; using (var parent = AllCaches.Components.Write(parentRequest)) { // проверим, что у нового родителя нет детей с таким же именем var child = parent.Childs.FindByName(newComponent.SystemName); if (child != null) { throw new ParameterErrorException("SystemName должен быть уникальным"); } // родителю можно добавить нового ребенка parent.WriteChilds.Rename(oldComponent.SystemName, newComponent.SystemName); parent.BeginSave(); } } }
protected override Exception CreateNotFoundException(AccountCacheRequest request) { return(new UnknownUnitTestIdException(request.ObjectId)); }
protected override Exception CreateNotFoundException(AccountCacheRequest request) { return(new UserFriendlyException("Не удалось найти тип метрики с ID " + request.ObjectId)); }
protected override void ValidateChanges(UnitTestCacheWriteObject oldObj, UnitTestCacheWriteObject newObj) { if (newObj.AccountId == Guid.Empty) { throw new Exception("unitTest.AccountId == Guid.Empty"); } if (newObj.ComponentId == Guid.Empty) { throw new Exception("unitTest.ComponentId == Guid.Empty"); } if (newObj.CreateDate == DateTime.MinValue) { throw new Exception("unitTest.CreateDate == DateTime.MinValue"); } if (newObj.StatusDataId == Guid.Empty) { throw new Exception("unitTest.StatusDataId == Guid.Empty"); } if (oldObj.AccountId != newObj.AccountId) { throw new Exception("oldObj.AccountId != newObj.AccountId"); } if (StringHelper.GetLength(newObj.DisplayName) > 255) { throw new Exception("StringHelper.GetLength(newObj.DisplayName) > 255"); } if (StringHelper.GetLength(newObj.SystemName) > 255) { throw new Exception("StringHelper.GetLength(newObj.SystemName) > 255"); } if (StringHelper.GetLength(newObj.DisableComment) > 1000) { throw new Exception("StringHelper.GetLength(newObj.DisableComment) > 1000"); } var newComponentRequest = new AccountCacheRequest() { AccountId = newObj.AccountId, ObjectId = newObj.ComponentId }; // если изменился родитель if (oldObj.ComponentId != newObj.ComponentId) { // получим нового родителя using (var newComponent = AllCaches.Components.Write(newComponentRequest)) { // проверим, что у нового родителя нет ребенка с таким же именем var child = newComponent.UnitTests.FindByName(newObj.SystemName); if (child != null) { throw new Exception("У нового компонента уже есть проверка с таким именем"); } // получим старого родителя var oldComponentRequest = new AccountCacheRequest() { AccountId = newObj.AccountId, ObjectId = oldObj.ComponentId }; using (var oldComponent = AllCaches.Components.Write(oldComponentRequest)) { var reference = new CacheObjectReference(newObj.Id, newObj.SystemName); newComponent.WriteUnitTests.Add(reference); oldComponent.WriteUnitTests.Delete(newObj.Id); oldComponent.BeginSave(); } newComponent.BeginSave(); } } // если изменилось только системное имя else if (string.Equals(oldObj.SystemName, newObj.SystemName, StringComparison.InvariantCultureIgnoreCase) == false) { // проверим что у компонента нет проверки с таким SystemName using (var component = AllCaches.Components.Write(newComponentRequest)) { var child = component.UnitTests.FindByName(newObj.SystemName); if (child != null) { throw new Exception("У компонента уже есть проверка с таким SystemName"); } component.WriteUnitTests.Rename(oldObj.SystemName, newObj.SystemName); component.BeginSave(); } } }