/// <summary>
        /// Query the current status of the feature
        /// </summary>
        public FeatureInstallState QueryState(SanteDBConfiguration configuration)
        {
            // Configuration of features
            var config = new GenericFeatureConfiguration();

            config.Options.Add("Configuration", () => ConfigurationOptionType.Object);
            config.Values.Add("Configuration", configuration.GetSection(typeof(SecurityConfigurationSection)) ?? new SecurityConfigurationSection());

            // Add options for password encrypting and such
            config.Options.Add("PasswordHasher", () => ApplicationServiceContext.Current.GetService <IServiceManager>().GetAllTypes().Where(t => !t.IsInterface && !t.IsAbstract && typeof(IPasswordHashingService).IsAssignableFrom(t)));
            config.Options.Add("PolicyDecisionProvider", () => ApplicationServiceContext.Current.GetService <IServiceManager>().GetAllTypes().Where(t => !t.IsInterface && !t.IsAbstract && typeof(IPolicyDecisionService).IsAssignableFrom(t)));
            config.Options.Add("PolicyInformationProvider", () => ApplicationServiceContext.Current.GetService <IServiceManager>().GetAllTypes().Where(t => !t.IsInterface && !t.IsAbstract && typeof(IPolicyInformationService).IsAssignableFrom(t)));
            config.Options.Add("PasswordValidator", () => ApplicationServiceContext.Current.GetService <IServiceManager>().GetAllTypes().Where(t => !t.IsInterface && !t.IsAbstract && typeof(IPasswordValidatorService).IsAssignableFrom(t)));

            var appServices = configuration.GetSection <ApplicationServiceContextConfigurationSection>().ServiceProviders;

            Type validator = appServices.FirstOrDefault(t => typeof(IPasswordValidatorService).IsAssignableFrom(t.Type))?.Type,
                 hasher    = appServices.FirstOrDefault(t => typeof(IPasswordHashingService).IsAssignableFrom(t.Type))?.Type,
                 pip       = appServices.FirstOrDefault(t => typeof(IPolicyInformationService).IsAssignableFrom(t.Type))?.Type,
                 pdp       = appServices.FirstOrDefault(t => typeof(IPolicyDecisionService).IsAssignableFrom(t.Type))?.Type;

            config.Values.Add("PasswordHasher", hasher ?? typeof(SHA256PasswordHashingService));
            config.Values.Add("PasswordValidator", validator ?? typeof(DefaultPasswordValidationService));
            config.Values.Add("PolicyDecisionProvider", pdp ?? typeof(DefaultPolicyDecisionService));
            config.Values.Add("PolicyInformationProvider", pip ?? (config.Options["PolicyInformationProvider"]() as IEnumerable <Type>).FirstOrDefault());

            if (this.Configuration == null)
            {
                this.Configuration = config;
            }

            return(hasher != null && validator != null && pdp != null && pip != null ? FeatureInstallState.Installed : FeatureInstallState.PartiallyInstalled);
        }
        /// <inheritdoc/>
        public FeatureInstallState QueryState(SanteDBConfiguration configuration)
        {
            // Configuration is not known?
            var config = configuration.GetSection <DiagnosticsConfigurationSection>();

            if (config == null)
            {
                config = new DiagnosticsConfigurationSection();
            }

            // Configuration for trace sources missing?
            var configFeature = new GenericFeatureConfiguration();

            // Configuration features
            var asms = AppDomain.CurrentDomain.GetAllTypes()
                       .Select(t => t.Assembly)
                       .Distinct();

            foreach (var source in asms.SelectMany(a => a.GetCustomAttributes <PluginTraceSourceAttribute>()).Select(o => o.TraceSourceName).Distinct())
            {
                configFeature.Options.Add(source, () => Enum.GetValues(typeof(EventLevel)));
                var src = config.Sources.FirstOrDefault(
                    s => s.SourceName == source);
                if (configFeature.Values.ContainsKey(source))
                {
                    continue;
                }
                if (src != null)
                {
                    configFeature.Values.Add(source, src.Filter);
                }
                else
                {
                    configFeature.Values.Add(source, EventLevel.Warning);
                }
            }

            configFeature.Categories.Add("Sources", configFeature.Options.Keys.ToArray());

            // Writers?
            var tw = AppDomain.CurrentDomain.GetAllTypes()
                     .Where(t => typeof(TraceWriter).IsAssignableFrom(t) && !t.IsAbstract)
                     .Distinct();

            configFeature.Options.Add("writer", () => tw);
            configFeature.Options.Add("filter", () => Enum.GetValues(typeof(EventLevel)));

            configFeature.Options.Add("initializationData", () => ConfigurationOptionType.FileName);
            configFeature.Categories.Add("Writers", new[] { "writer", "initializationData", "filter" });
            configFeature.Values.Add("writer", config.TraceWriter.FirstOrDefault()?.TraceWriter ?? tw.FirstOrDefault());
            configFeature.Values.Add("initializationData", config.TraceWriter.FirstOrDefault()?.InitializationData ?? "santedb.log");
            configFeature.Values.Add("filter", config.TraceWriter.FirstOrDefault()?.Filter);
            this.Configuration = configFeature;
            return(FeatureInstallState.Installed);
        }
        /// <inheritdoc/>
        public FeatureInstallState QueryState(SanteDBConfiguration configuration)
        {
            // First ensure the data retention service is present
            if (this.Configuration == null)
            {
                this.Configuration = this.m_configuration = new GenericFeatureConfiguration();

                this.m_configuration.Options.Add("Retention Policies", () => ConfigurationOptionType.Object);
                var retentionConfig = configuration.GetSection <DataRetentionConfigurationSection>();
                if (retentionConfig == null)
                {
                    this.m_configuration.Values.Add("Retention Policies", new DataRetentionConfigurationSection());
                }
                else
                {
                    this.m_configuration.Values.Add("Retention Policies", retentionConfig);
                }

                // Next the timer job
                var jobSection = configuration.GetSection <JobConfigurationSection>();
                var jobConfig  = jobSection?.Jobs.Find(o => o.Type == typeof(DataRetentionJob));
                this.m_configuration.Options.Add("Job Status", () => new String[] { "Enabled", "Disabled" });
                this.m_configuration.Values.Add("Job Status", jobConfig == null ? "Disabled" : "Enabled");
                this.m_configuration.Options.Add("Schedule", () => ConfigurationOptionType.Object);
                this.m_configuration.Values.Add("Schedule", jobConfig?.Schedule?.FirstOrDefault() ?? new JobItemSchedule());

                return(retentionConfig == null && jobConfig == null ? FeatureInstallState.NotInstalled :
                       retentionConfig != null || jobConfig != null || jobConfig.StartType == JobStartType.Never ? FeatureInstallState.PartiallyInstalled :
                       FeatureInstallState.Installed);
            }
            else
            {
                var jobSection      = configuration.GetSection <JobConfigurationSection>();
                var jobConfig       = jobSection.Jobs.Find(o => o.Type == typeof(DataRetentionJob));
                var retentionConfig = configuration.GetSection <DataRetentionConfigurationSection>();

                this.m_configuration = this.Configuration as GenericFeatureConfiguration;
                return(retentionConfig == null && jobConfig == null ? FeatureInstallState.NotInstalled :
                       retentionConfig != null || jobConfig != null || jobConfig.StartType == JobStartType.Never ? FeatureInstallState.PartiallyInstalled :
                       FeatureInstallState.Installed);
            }
        }
Beispiel #4
0
        /// <inheritdoc/>
        public FeatureInstallState QueryState(SanteDBConfiguration configuration)
        {
            // Get the configuratoin
            switch (configuration.GetSection <ApplicationServiceContextConfigurationSection>().ServiceProviders.Count(
                        s => s.Type == typeof(SimplePatchService) || s.Type == typeof(SimpleCarePlanService)
                        ))
            {
            case 2:
                var sp     = configuration.GetSection <ApplicationServiceContextConfigurationSection>().ServiceProviders;
                var types  = AppDomain.CurrentDomain.GetAllTypes();
                var config = new GenericFeatureConfiguration();
                // Map configuration over to the features section
                foreach (var pvd in types.Where(t => t.IsInterface && typeof(IServiceImplementation).IsAssignableFrom(t)).ToArray())
                {
                    if (pvd.Name == "IDaemonService")
                    {
                        var daemons     = types.Where(t => pvd.IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface && !t.ContainsGenericParameters);
                        var daemonNames = daemons.Select(o => o.GetCustomAttribute <ServiceProviderAttribute>()?.Name ?? o.Name);
                        config.Categories.Add("Daemons", daemonNames.ToArray());
                        foreach (var itm in daemons)
                        {
                            config.Options.Add(itm.GetCustomAttribute <ServiceProviderAttribute>()?.Name ?? itm.Name, () => new String[] { "Active", "Disabled" });
                            config.Values.Add(itm.GetCustomAttribute <ServiceProviderAttribute>()?.Name ?? itm.Name, sp.Any(t => t.Type == itm) ? "Active" : "Disabled");
                        }
                        continue;
                    }
                    else
                    {
                        var optionName = pvd.GetCustomAttribute <DescriptionAttribute>()?.Description ?? pvd.Name;
                        config.Options.Add(optionName, () => types.Where(t => !t.IsInterface && !t.IsAbstract && !t.ContainsGenericParameters && pvd.IsAssignableFrom(t)));
                        config.Values.Add(optionName, sp.FirstOrDefault(o => pvd.IsAssignableFrom(o.Type))?.Type);
                    }
                }

                var removeOptions = new List <string>();
                foreach (var o in config.Options)
                {
                    if ((o.Value() as IEnumerable)?.OfType <object>().Count() == 0)
                    {
                        removeOptions.Add(o.Key);
                    }
                }

                foreach (var itm in removeOptions)
                {
                    config.Options.Remove(itm);
                    config.Values.Remove(itm);
                }

                if (this.Configuration == null)
                {
                    this.Configuration = config;
                }

                return(FeatureInstallState.Installed);

            case 1:
                return(FeatureInstallState.PartiallyInstalled);

            case 0:
            default:
                return(FeatureInstallState.NotInstalled);
            }
        }
 /// <summary>
 /// Creates a new retnetion policy configuration task
 /// </summary>
 public ConfigureRetentionJobTask(IFeature feature, GenericFeatureConfiguration configuration)
 {
     this.m_configuration = configuration;
     this.Feature         = feature;
 }