/// <summary>
 /// DI constructor
 /// </summary>
 public HtmlReportRenderer(IConfigurationManager configurationManager)
 {
     this.m_configuration = configurationManager.GetSection <BiConfigurationSection>();
 }
 /// <summary>
 /// DI constructor
 /// </summary>
 public XsltReportRendererBase(IConfigurationManager configurationManager)
 {
     this.m_configuration = configurationManager.GetSection <BiConfigurationSection>();
 }
Example #3
0
        /// <summary>
        /// Configure the feature
        /// </summary>
        public void Configure(SanteDBConfiguration configuration, IDictionary <string, string> settings)
        {
            var restConfiguration = configuration.GetSection <SanteDB.Rest.Common.Configuration.RestConfigurationSection>();

            if (restConfiguration == null)
            {
                throw new ConfigurationException("Error retrieving REST configuration", configuration);
            }

            var hdsiRestConfiguration = restConfiguration.Services.FirstOrDefault(o => o.ServiceType == typeof(IBisServiceContract));

            if (hdsiRestConfiguration == null) // add fhir rest config
            {
                hdsiRestConfiguration = new Rest.Common.Configuration.RestServiceConfiguration()
                {
                    Behaviors = new List <Rest.Common.Configuration.RestServiceBehaviorConfiguration>()
                    {
                        new Rest.Common.Configuration.RestServiceBehaviorConfiguration(typeof(TokenAuthorizationAccessBehavior))
                    },
                    Name      = "BIS",
                    Endpoints = new List <Rest.Common.Configuration.RestEndpointConfiguration>()
                    {
                        this.CreateEndpoint("http://0.0.0.0:8080/bis")
                    }
                };
                restConfiguration.Services.Add(hdsiRestConfiguration);
            }


            // Listen address
            if (settings.TryGetValue(ListenUriSetting, out string listen))
            {
                if (!Uri.TryCreate(listen, UriKind.Absolute, out Uri listenUri))
                {
                    throw new ArgumentOutOfRangeException($"{listen} is not a valid URL");
                }

                // Setup the endpoint
                hdsiRestConfiguration.Endpoints.Clear();
                hdsiRestConfiguration.Endpoints.Add(this.CreateEndpoint(listen));
            }

            // Authentication
            if (settings.TryGetValue(AuthenticationSetting, out string auth))
            {
                if (!this.authSettings.TryGetValue(auth.ToUpperInvariant(), out Type authType))
                {
                    throw new ArgumentOutOfRangeException($"Don't understand auth option {auth} allowed values {String.Join(",", this.authSettings.Keys)}");
                }

                // Add behavior
                if (authType != null)
                {
                    hdsiRestConfiguration.Behaviors.Add(new RestServiceBehaviorConfiguration()
                    {
                        Type = authType
                    });
                }
                else
                {
                    hdsiRestConfiguration.Behaviors.RemoveAll(o => this.authSettings.Values.Any(v => v == o.Type));
                }
            }

            // Has the user set CORS?
            if (settings.TryGetValue(CorsSetting, out string cors))
            {
                if (!Boolean.TryParse(cors, out bool enabled))
                {
                    throw new ArgumentOutOfRangeException($"{cors} is not a valid boolean value");
                }

                // Cors is disabled?
                if (!enabled)
                {
                    hdsiRestConfiguration.Endpoints.ForEach(ep => ep.Behaviors.RemoveAll(o => o.Type == typeof(CorsEndpointBehavior)));
                }
                else
                {
                    hdsiRestConfiguration.Endpoints.ForEach(ep => ep.Behaviors.RemoveAll(o => o.Type == typeof(CorsEndpointBehavior)));
                    hdsiRestConfiguration.Endpoints.ForEach(ep => ep.Behaviors.Add(new RestEndpointBehaviorConfiguration()
                    {
                        Type = typeof(CorsEndpointBehavior)
                    }));
                }
            }

            if (settings.TryGetValue(MaxResultsSetting, out var maxResults))
            {
                var biConfig = configuration.GetSection <BiConfigurationSection>();
                if (biConfig == null)
                {
                    biConfig = new BiConfigurationSection();
                    configuration.AddSection(biConfig);
                }
                biConfig.MaxBiResultSetSize = Int32.Parse(maxResults);
            }

            var serviceTypes = new Type[]
            {
                typeof(BisMessageHandler),
                typeof(AppletBiRepository),
                typeof(InMemoryPivotProvider),
                typeof(LocalBiRenderService)
            };
            var serviceConfiguration = configuration.GetSection <ApplicationServiceContextConfigurationSection>().ServiceProviders;

            serviceConfiguration.AddRange(serviceTypes.Where(t => !serviceConfiguration.Any(c => c.Type == t)).Select(t => new TypeReferenceConfiguration(t)));
        }