Hello,
I am developing a VAF2.3 application where I need to make an ODBC connection; So I want a configuration tab in the admin to write the connection string and then validate it. That's exactly the example here : Custom-Validation .
Here are the 2 class I made:
Configuration.cs :
using MFiles.VAF.Configuration; using System.Runtime.Serialization; using System.Collections.Generic; namespace mynamespace { [DataContract] public class Configuration : MFiles.VAF.Extensions.Configuration.ConfigurationBase { [DataMember] [JsonConfEditor(DefaultValue = "v_agents_responsables_h", Label = "Nom de la table", HelpText = "Nom de la table ou de la vue contenant le référentiel Agents")] public string tablename = ""; [DataMember] [JsonConfEditor(DefaultValue = "Driver={SQL Server};Server=mf-sql.mydomain.local;Database=REF AGENTS;Uid=sa;Pwd=Admin123;", Label = "Chaîne de connexion ODBC", HelpText = "La connectionString ODBC permettant de se connecter au référentiel Agents. Elle doit faire référence à la connexion TNS créée lors de l'installation du serveur")] public string ConnectionString = "Driver={SQL Server};Server=mf-sql.mydomain.local;Database=REF AGENTS;Uid=sa;Pwd=Admin123;"; [DataMember] public List<Mapping> mappings { get; set; } [DataContract] public class Mapping { [DataMember] public string colonneSQL { get; set; } [DataMember] [TextEditor(IsRequired = true)] public string mfilesProperty { get; set; } } } }
VaultApplication.cs:
using MFiles.VAF.Common; using MFiles.VAF.Configuration; using MFilesAPI; using System; using System.Collections; using System.Collections.Generic; using MFiles.VaultApplications.Logging; namespace mynamespace { /// <summary> /// The entry point for this Vault Application Framework application. /// </summary> /// <remarks>Examples and further information available on the developer portal: http://developer.m-files.com/. </remarks> public class VaultApplication : MFiles.VAF.Extensions.ConfigurableVaultApplicationBase<Configuration> { #region Overrides of ConfigurableVaultApplicationBase<Configuration> /// <inheritdoc /> protected override IEnumerable<ValidationFinding> CustomValidation(Vault vault, Configuration config) { return base.CustomValidation(vault, config); } private IEnumerable<ValidationFinding> CustomValidator(Configuration configuration) { ValidationFinding finding = null; try { // Connect to the database to test the connection is valid. using (var sqlConnection = new System.Data.SqlClient.SqlConnection(configuration.ConnectionString)) { // Connect to the database. sqlConnection.Open(); // If no exception then report okay. finding = new ValidationFinding( ValidationFindingType.Ok, nameof(Configuration.ConnectionString), "Connection successful"); // Disconnect. sqlConnection.Close(); } } catch (Exception e) { // Report an exception. finding = new ValidationFinding( ValidationFindingType.Error, nameof(Configuration.ConnectionString), $"Exception connecting to server: {e.Message}"); } // Return the finding. yield return finding; } #endregion // my custom code }}
In the admin interface, I can write anything but it will never be validated:
I don't really understand the example. Which code do I need to conserve in the 2.3 framework?
Thank you all for the help.
Amaury
NB : here are the librairies :