/// <summary> /// Install the specified extension /// </summary> public bool Install() { // Connected to sync var syncMode = ApplicationContext.Current.Configuration.GetSection <SynchronizationConfigurationSection>()?.Mode; if (!syncMode.HasValue || syncMode == SynchronizationMode.Online) { ApplicationContext.Current.RemoveServiceProvider(typeof(SimpleRecordMatchingService), true); ApplicationContext.Current.RemoveServiceProvider(typeof(FileMatchConfigurationProvider), true); ApplicationContext.Current.AddServiceProvider(typeof(RemoteRecordMatchConfigurationService), true); } else // user central server for checkout { ApplicationContext.Current.RemoveServiceProvider(typeof(RemoteRecordMatchConfigurationService), true); ApplicationContext.Current.AddServiceProvider(typeof(SimpleRecordMatchingService), true); ApplicationContext.Current.AddServiceProvider(typeof(FileMatchConfigurationProvider), true); // Setup the match configurations var fileConfig = ApplicationContext.Current.Configuration.GetSection <FileMatchConfigurationSection>(); if (fileConfig == null) { fileConfig = new FileMatchConfigurationSection { FilePath = new List <FilePathConfiguration> { new FilePathConfiguration { Path = Path.Combine(ApplicationContext.Current.ConfigurationPersister.ApplicationDataDirectory, "matching"), ReadOnly = false } } }; ApplicationContext.Current.Configuration.AddSection(fileConfig); } } // Setup the approx configuration var approxConfig = ApplicationContext.Current.Configuration.GetSection <ApproximateMatchingConfigurationSection>(); if (approxConfig == null) { approxConfig = new ApproximateMatchingConfigurationSection { ApproxSearchOptions = new List <ApproxSearchOption>() }; // Add pattern approxConfig.ApproxSearchOptions.Add(new ApproxPatternOption { Enabled = true, IgnoreCase = true }); // Add soundex as preferred approxConfig.ApproxSearchOptions.Add(new ApproxPhoneticOption { Enabled = true, Algorithm = ApproxPhoneticOption.PhoneticAlgorithmType.Auto, MinSimilarity = 1.0f, MinSimilaritySpecified = true }); // Add levenshtein approxConfig.ApproxSearchOptions.Add(new ApproxDifferenceOption { Enabled = true, MaxDifference = 1 }); ApplicationContext.Current.Configuration.AddSection(approxConfig); } return(true); }
/// <summary> /// Process the file directory /// </summary> public FileMatchConfigurationProvider(IConfigurationManager configurationManager, IPolicyEnforcementService pepService, ILocalizationService localizationService) { this.m_pepService = pepService; this.m_configuration = configurationManager.GetSection <FileMatchConfigurationSection>(); this.m_localizationService = localizationService; // When application has started ApplicationServiceContext.Current.Started += (o, e) => { try { if (this.m_configuration == null) { this.m_matchConfigurations = new ConcurrentDictionary <string, ConfigCacheObject>(); return; } this.m_matchConfigurations = new ConcurrentDictionary <string, ConfigCacheObject>(); this.m_tracer.TraceInfo("Loading match configurations..."); foreach (var configDir in this.m_configuration.FilePath) { if (!Path.IsPathRooted(configDir.Path)) { configDir.Path = Path.Combine(Path.GetDirectoryName(this.GetType().Assembly.Location), configDir.Path); } if (!Directory.Exists(configDir.Path)) { this.m_tracer.TraceWarning("Skipping {0} because it doesn't exist!", configDir.Path); } else { foreach (var fileName in Directory.GetFiles(configDir.Path, "*.xml")) { this.m_tracer.TraceInfo("Attempting load of {0}", fileName); try { MatchConfiguration config = null; using (var fs = System.IO.File.OpenRead(fileName)) { config = MatchConfiguration.Load(fs); } var originalPath = fileName; if (!Guid.TryParse(Path.GetFileNameWithoutExtension(fileName), out Guid uuid) || uuid != config.Uuid) // Migrate the config { originalPath = Path.Combine(configDir.Path, $"{config.Uuid}.xml"); File.Move(fileName, originalPath); using (var fs = File.Create(originalPath)) { config.Save(fs); } } this.m_matchConfigurations.TryAdd(config.Id, new ConfigCacheObject() { OriginalFilePath = originalPath, Configuration = config }); } catch (Exception ex) { this.m_tracer.TraceWarning("Could not load {0} - SKIPPING - {1}", fileName, ex.Message); } } } } } catch (Exception ex) { this.m_tracer.TraceError("Could not fully load configuration for matching : {0}", ex); } }; }