public override ConnectorPropertyValidationResult ValidateProperties(IEnumerable <ConnectorProperty> properties) { foreach (ConnectorProperty property in properties) { switch (property.Key) { case SampleConnectorDefinition.UriProperty: Uri uri; if (!Uri.TryCreate(((ConnectorStringProperty)property).Value, UriKind.Absolute, out uri)) { return(ConnectorPropertyValidationResult.CreateInvalidResult(property.Key, Resources.InvalidURI)); } break; case SampleConnectorDefinition.PasswordProperty: string password = ((ConnectorPasswordProperty)property).Value; if (!password.Any(c => Char.IsLetter(c)) || !password.Any(c => Char.IsDigit(c))) { return(ConnectorPropertyValidationResult.CreateInvalidResult(property.Key, Resources.InvalidPassword)); } break; } } return(ConnectorPropertyValidationResult.ValidResult); }
public override ConnectorPropertyValidationResult ValidateProperties(IEnumerable <ConnectorProperty> properties) { var settings = properties.ToList(); var newPort = settings.Single(p => p.Key == nameof(Resources.LocalPort)) as ConnectorIntegerProperty; if (newPort == null) { return(ConnectorPropertyValidationResult.CreateInvalidResult(nameof(Resources.LocalPort), $"Property not found: {Resources.LocalPort}")); } var portInUse = PortRegistry.Where(pair => pair.Key != _instanceId && pair.Value == newPort.Value).ToList(); if (portInUse.Count != 0) { Util.Log( true, $"{GetType().FullName}.{System.Reflection.MethodBase.GetCurrentMethod().Name} [{_instanceId}]", $"Port {newPort} in use by instance {portInUse.First().Key}"); return(ConnectorPropertyValidationResult.CreateInvalidResult( nameof(Resources.LocalPort), string.Format(Resources.LocalPortInUse, newPort))); } var networkInterface = settings.Single(s => s.Key == nameof(Resources.Interface)) as ConnectorStringProperty; var ipAddress = Cascadia.Net.Util.GetIpAddressByString(networkInterface.Value); if (networkInterface.Value != "*" && ipAddress == null) { return(ConnectorPropertyValidationResult.CreateInvalidResult( nameof(Resources.Interface), $"Local IP Address '{networkInterface.Value}' not found")); } return(ConnectorPropertyValidationResult.ValidResult); }