/// <summary>
        /// Get the specified configuration name
        /// </summary>
        /// <param name="name">The configuratio name</param>
        /// <returns>The matching configuration</returns>
        public IRecordMatchingConfiguration GetConfiguration(string name)
        {
            if (this.m_configurationCache.TryGetValue(name, out IRecordMatchingConfiguration retVal))
            {
                var solutions = ApplicationServiceContext.Current.GetService <IAppletSolutionManagerService>()?.Solutions.Select(o => o.Meta.Id).ToList();
                solutions.Add(String.Empty); // Include the default solution

                // Solution
                foreach (var sln in solutions)
                {
                    var amgr = ApplicationServiceContext.Current.GetService <IAppletSolutionManagerService>()?.GetApplets(sln).SelectMany(a => a.Assets).Where(o => o.Name == $"matching/{name}.xml").FirstOrDefault();

                    try
                    {
                        this.m_tracer.TraceInfo("Will load {0}..", amgr.ToString());

                        using (var ms = new MemoryStream(amgr.Content as byte[]))
                            retVal = MatchConfiguration.Load(ms);

                        lock (this.m_configurationCache)
                            if (!this.m_configurationCache.ContainsKey(name))
                            {
                                this.m_configurationCache.Add(name, retVal);
                            }
                    }
                    catch (Exception e)
                    {
                        this.m_tracer.TraceError("Error loading match config {0} : {1}", name, e.ToString());
                        throw;
                    }
                }
            }
            return(retVal);
        }
 /// <summary>
 /// Dummy match configuration provider
 /// </summary>
 public DummyMatchConfigurationProvider()
 {
     foreach (var n in typeof(DummyMatchConfigurationProvider).Assembly.GetManifestResourceNames().Where(o => o.Contains(".xml")))
     {
         try
         {
             this.m_configs.Add(MatchConfiguration.Load(typeof(DummyMatchConfigurationProvider).Assembly.GetManifestResourceStream(n)));
         }
         catch { }
     }
 }
        public void ShouldLoadConfiguration()
        {
            var loaded = MatchConfiguration.Load(typeof(MatchConfigurationTest).Assembly.GetManifestResourceStream("SanteDB.Matcher.Test.Resources.DateOfBirthGenderIdClassified.xml"));

            Assert.IsNotNull(loaded);
            Assert.AreEqual(2, loaded.Scoring.Count);
            Assert.IsNotNull(loaded.Scoring.First().Assertion);
            Assert.AreEqual(1, loaded.Blocking.Count);
            Assert.AreEqual(3, loaded.Blocking.First().Filter.Count);
            Assert.AreEqual(typeof(Patient), loaded.Target.First().ResourceType);
            Assert.AreNotEqual(0.0d, loaded.Scoring.First().MatchWeight);
        }
 /// <summary>
 /// Add not supported
 /// </summary>
 public object Add(Type scopingType, object scopingKey, object item)
 {
     if (item is Stream stream)
     {
         var configuration = MatchConfiguration.Load(stream);
         RestOperationContext.Current.OutgoingResponse.StatusCode = 201;
         return(this.m_matchConfiguration.SaveConfiguration(configuration));
     }
     else
     {
         throw new InvalidOperationException("Cannot process this request");
     }
 }
        /// <summary>
        /// CTOR will load configuration
        /// </summary>
        public AssemblyMatchConfigurationProvider()
        {
            var config = ApplicationServiceContext.Current.GetService <IConfigurationManager>().GetSection <AssemblyMatchConfigurationSection>();

            try
            {
                foreach (var asmRef in config.Assemblies)
                {
                    this.m_tracer.TraceInfo("Loading configurations from {0}", asmRef);
                    var asm = Assembly.Load(new AssemblyName(asmRef));
                    if (asm == null)
                    {
                        throw new FileNotFoundException($"Assembly {asmRef} could not be found");
                    }
                    // Get embedded resource names
                    foreach (var name in asm.GetManifestResourceNames().Where(o => o.EndsWith(".xml")))
                    {
                        this.m_tracer.TraceVerbose("Attempting load of {0}...", name);
                        using (var s = asm.GetManifestResourceStream(name))
                        {
                            try
                            {
                                var conf = MatchConfigurationCollection.Load(s);
                                this.m_configurations.Add(conf);
                                this.m_tracer.TraceInfo("Loaded match configuration collection {0}", conf.Id);
                            }
                            catch
                            {
                                try
                                {
                                    var conf = MatchConfiguration.Load(s);
                                    this.m_configurations.Add(conf);
                                    this.m_tracer.TraceInfo("Loaded match configuration {0}", conf.Id);
                                }
                                catch { }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                this.m_tracer.TraceError("Error starting file configuration match provider: {0}", e);
                throw;
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Get the specified configuration
 /// </summary>
 /// <param name="name">The name of the configuration</param>
 /// <returns>The loaded configuration</returns>
 public IRecordMatchingConfiguration GetConfiguration(string name)
 {
     if (this.m_matchConfigurations.TryGetValue(name, out ConfigCacheObject configData))
     {
         if (this.m_configuration.CacheFiles)
         {
             return(configData.Configuration as IRecordMatchingConfiguration);
         }
         else
         {
             using (var fs = System.IO.File.OpenRead(configData.OriginalFilePath))
                 return(MatchConfiguration.Load(fs));
         }
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 7
0
        /// <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);
                }
            };
        }