public IResult RegisterMicroservice(string microserviceName, IEnumerable <string> servicesNames) { if (string.IsNullOrEmpty(microserviceName) || string.IsNullOrWhiteSpace(microserviceName)) { var failureMessage = Messages.MicroserviceNameCanNotBeNullOrEmptyOrWhitespace(); _logger.Error(failureMessage); return(Result.Failure(failureMessage)); } if (servicesNames == null || !servicesNames.Any()) { var failureMessage = Messages.CanNotRegisterMicroserviceWithoutServices(microserviceName); _logger.Error(failureMessage); return(Result.Failure(failureMessage)); } var microservice = new Microservice(microserviceName, servicesNames); if (!_microservices.TryAdd(microserviceName, microservice)) { var failureMessage = Messages.MicroserviceHasBeenAlreadyRegisteredMessage(microserviceName); _logger.Error(failureMessage); return(Result.Failure(failureMessage)); } var message = servicesNames .Where(serviceName => !_servicesOwners.TryAdd(serviceName, microservice)) .Aggregate(string.Empty, (current, serviceName) => current + Messages.ServiceHasBeenAlreadyRegisteredMessage(serviceName)); var result = string.IsNullOrEmpty(message) ? Result.Success(Messages.MicroserviceHasBeenRegistered(microserviceName)) : Result.Failure(message); _logger.LogResult(result); return(result); }
public void AddProto(IFileInfo proto) { IResult result; var textReaderCreationResult = _textReaderFactory.Create(proto.FullName); if (textReaderCreationResult.IsSuccess) { using var protoStream = textReaderCreationResult.Value; result = _microserviceDescriptor.Read(proto.Name, protoStream); } else { result = textReaderCreationResult; } _logger.LogResult(result); }