Пример #1
0
        public Guid RegisterOrUpdate(string monitorType, string address, string group, string name, string[] tags)
        {
            if (!_healthMonitorTypeRegistry.GetMonitorTypes().Contains(monitorType))
            {
                throw new UnsupportedMonitorException(monitorType);
            }
            var newIdentifier = new EndpointIdentity(Guid.NewGuid(), monitorType, address);
            var endpoint      = _endpoints.AddOrUpdate(newIdentifier.GetNaturalKey(), new Endpoint(newIdentifier, new EndpointMetadata(name, group, tags)), (k, e) => e.UpdateMetadata(group, name, tags));

            _endpointsByGuid[endpoint.Identity.Id] = endpoint;
            _endpointConfigurationRepository.SaveEndpoint(endpoint);
            return(endpoint.Identity.Id);
        }
        public Guid RegisterOrUpdate(string monitorType, string address, string group, string name, string[] tags, string password = null)
        {
            if (!_healthMonitorTypeRegistry.GetMonitorTypes().Contains(monitorType))
            {
                throw new UnsupportedMonitorException(monitorType);
            }
            var encryptedPassword = password?.ToSha256Hash();
            var newIdentifier     = new EndpointIdentity(Guid.NewGuid(), monitorType, address);
            var endpoint          = _endpoints.AddOrUpdate(newIdentifier.GetNaturalKey(),
                                                           new Endpoint(_timeCoordinator, newIdentifier, new EndpointMetadata(name, group, tags), encryptedPassword),
                                                           (k, e) => e.UpdateEndpoint(group, name, tags, encryptedPassword));

            _endpointsByGuid[endpoint.Identity.Id] = endpoint;
            _endpointConfigurationRepository.SaveEndpoint(endpoint);

            if (endpoint.Identity == newIdentifier)
            {
                EndpointAdded?.Invoke(endpoint);
            }
            return(endpoint.Identity.Id);
        }