/// <summary> /// Uses Levenshtein Distance to determine the closest string. Outputs the string and the distance /// </summary> /// <param name="context"></param> protected override void Execute(NativeActivityContext context) { LevenshteinEngine engine = new LevenshteinEngine(BaseString.Get(context)); Boolean first = true; foreach (String possible in Possibles.Get(context)) { int currentDistance = engine.Distance(possible); if (currentDistance < Distance.Get(context) || first) { Distance.Set(context, currentDistance); SelectedString.Set(context, possible); } first = false; } }
/// <summary> /// Inicializa el diálogo. /// </summary> public override void Initialize() { base.Initialize(); this.Items = new ObservableCollection <IKeyValueItem>(this.queryFunction.Invoke()); if (this.AllowEmptyResult) { // Agregar a la lista de clientes asociados el cliente "vacío" (para permitir la desociación de clientes). this.Items.Insert(0, new BaseKeyValueItem(0, string.Empty, true)); } if (this.SelectedString != null) { string[] words = SelectedString.Split(','); foreach (IKeyValueItem item in Items) { foreach (string w in words) { if (item.Id.Trim() == w.Trim()) { item.IsSelected = true; } } } } // Quitar de la lista de clientes asociados el cliente actual (no se puede relacionar así mismo). if (this.IdCliente != 0) { var cliente = this.Items.FirstOrDefault(c => c.Id == this.IdCliente.ToString()); if (cliente != null) { this.Items.Remove(cliente); } } } // Initialize
private void ChangeSelection(bool down) { if (down) { switch (selection) { case SelectedString.userName: userNameEntry.StopPulsing(); selection = SelectedString.hostName; selectionChecker.Position = new Vector2(selectionChecker.Position.X, selectionChecker.Position.Y + oneLineSize); hostNameEntry.PulseColors(pulse1, pulse2, pulsePeriod); break; case SelectedString.hostName: hostNameEntry.StopPulsing(); selection = SelectedString.port; selectionChecker.Position = new Vector2(selectionChecker.Position.X, selectionChecker.Position.Y + oneLineSize); portEntry.PulseColors(pulse1, pulse2, pulsePeriod); break; case SelectedString.port: portEntry.StopPulsing(); selection = SelectedString.userName; selectionChecker.Position = new Vector2(selectionChecker.Position.X, selectionChecker.Position.Y - 2 * oneLineSize); userNameEntry.PulseColors(pulse1, pulse2, pulsePeriod); break; } } else { switch (selection) { case SelectedString.userName: userNameEntry.StopPulsing(); selection = SelectedString.port; selectionChecker.Position = new Vector2(selectionChecker.Position.X, selectionChecker.Position.Y + 2 * oneLineSize); portEntry.PulseColors(pulse1, pulse2, pulsePeriod); break; case SelectedString.hostName: hostNameEntry.StopPulsing(); selection = SelectedString.userName; selectionChecker.Position = new Vector2(selectionChecker.Position.X, selectionChecker.Position.Y - oneLineSize); userNameEntry.PulseColors(pulse1, pulse2, pulsePeriod); break; case SelectedString.port: portEntry.StopPulsing(); selection = SelectedString.hostName; selectionChecker.Position = new Vector2(selectionChecker.Position.X, selectionChecker.Position.Y - oneLineSize); hostNameEntry.PulseColors(pulse1, pulse2, pulsePeriod); break; } } }