/// <summary> /// Throw exception if entity depends on other entity that is missing. /// </summary> /// <param name="entity">entity to validate</param> /// <param name="config">Service Host configuration container</param> /// <exception cref="DependencyFailureException" /> public void CheckOtherServiceDependency(BaseServiceEntity entity, ServiceHostConfiguration config) { var attributes = entity.GetType().GetCustomAttributes(typeof (DependsOnServiceAttribute), false); if(attributes.Length < 1) { return; } foreach(var attribute in attributes.Cast<DependsOnServiceAttribute>().Where(attribute => config[attribute.ServiceType] == null)) { throw new DependencyFailureException(attribute.ServiceType, "Service dependency does not exist"); } }
public IConnectionValidator CreateValidator(BaseServiceEntity entity) { var entityType = entity.GetType(); if(!entityToValidatorTypeMappings.ContainsKey(entityType)) { throw new NotSupportedException("Wrong entity type"); } var validatorType = entityToValidatorTypeMappings[entityType]; var validator = (IConnectionValidator) Activator.CreateInstance(validatorType, new object[] { entity }); return validator; }
/// <summary> /// Throw exception if entity requires connection to V1 and actual connection is down. /// </summary> /// <param name="entity">entity to validate</param> /// <exception cref="V1ConnectionRequiredException"/> public void CheckVersionOneDependency(BaseServiceEntity entity) { if(entity.GetType().IsDefined(typeof(DependsOnVersionOneAttribute), false) && !facade.IsConnected) { throw new V1ConnectionRequiredException(); } }