/// <summary> /// Continue with configuration /// </summary> private void btnContinue_Click(object sender, EventArgs e) { ConfigurationContext.Current.ConfigurationTasks.Clear(); this.Hide(); // Create a default configuration with minimal sections if (cbxTemplate.SelectedItem != null) { try { var fileName = Path.ChangeExtension(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "config", "template", cbxTemplate.SelectedItem.ToString()), "xml"); using (var s = File.OpenRead(fileName)) { ConfigurationContext.Current.Configuration = SanteDBConfiguration.Load(s); } } catch (Exception ex) { MessageBox.Show($"Error loading template: {ex.Message}"); } } else { ConfigurationContext.Current.Configuration = new SanteDBConfiguration() { Sections = new List <object>() { new DataConfigurationSection(), new DiagnosticsConfigurationSection(), new ApplicationServiceContextConfigurationSection() { ThreadPoolSize = Environment.ProcessorCount * 16 } } }; } ConfigurationContext.Current.Configuration.RemoveSection <OrmLite.Configuration.OrmConfigurationSection>(); ConfigurationContext.Current.Configuration.AddSection(new OrmLite.Configuration.OrmConfigurationSection() { Providers = ConfigurationContext.Current.DataProviders.Select(o => new OrmLite.Configuration.ProviderRegistrationConfiguration(o.Invariant, o.DbProviderType)).ToList(), AdoProvider = ConfigurationContext.Current.GetAllTypes().Where(t => typeof(DbProviderFactory).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface).Select(t => new ProviderRegistrationConfiguration(t.Namespace.StartsWith("System") ? t.Name : t.Namespace.Split('.')[0], t)).ToList(), }); // Push the initial configuration features onto the service if (rdoEasy.Checked) { // Create feature dbSelector.ConnectionString.Name = "main"; var dataSection = ConfigurationContext.Current.Configuration.GetSection <DataConfigurationSection>(); if (dataSection == null) { dataSection = new DataConfigurationSection(); ConfigurationContext.Current.Configuration.AddSection(dataSection); } dataSection.ConnectionString.Clear(); dataSection.ConnectionString.Add(dbSelector.ConnectionString); ConfigurationContext.Current.Configuration.Sections.OfType <OrmConfigurationBase>().ToList().ForEach(o => { o.ReadonlyConnectionString = o.ReadWriteConnectionString = "main"; o.ProviderType = dbSelector.Provider.Invariant; }); // Configuration of windows service parameters ConfigurationContext.Current.Features.OfType <WindowsServiceFeature>().FirstOrDefault().Configuration = new WindowsServiceFeature.Options() { ServiceName = txtInstance.Text, StartBehavior = ServiceTools.ServiceBootFlag.AutoStart }; // Set all data connections var autoFeatures = ConfigurationContext.Current.Features.Where(o => o.Flags.HasFlag(FeatureFlags.AutoSetup) && o.QueryState(ConfigurationContext.Current.Configuration) != FeatureInstallState.Installed); foreach (var ftr in autoFeatures) { var ormConfig = (ftr.Configuration as OrmLite.Configuration.OrmConfigurationBase); if (ormConfig != null) { ormConfig.ReadWriteConnectionString = ormConfig.ReadonlyConnectionString = dbSelector.ConnectionString.Name; ormConfig.ProviderType = dbSelector.Provider.Invariant; ormConfig.TraceSql = false; } // Add configuration foreach (var tsk in ftr.CreateInstallTasks().Where(o => o.VerifyState(ConfigurationContext.Current.Configuration))) { ConfigurationContext.Current.ConfigurationTasks.Add(tsk); } } ConfigurationContext.Current.Apply(this); } this.DialogResult = DialogResult.OK; this.Close(); }
/// <summary> /// Get a bare bones configuration /// </summary> public static OpenIZConfiguration GetDefaultConfiguration() { // TODO: Bring up initial settings dialog and utility var retVal = new OpenIZConfiguration(); // Inital data source DataConfigurationSection dataSection = new DataConfigurationSection() { MainDataSourceConnectionStringName = "openIzData", MessageQueueConnectionStringName = "openIzQueue", ConnectionString = new System.Collections.Generic.List <ConnectionString>() { new ConnectionString() { Name = "openIzData", Value = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MINIMS", "OpenIZ.sqlite") }, new ConnectionString() { Name = "openIzSearch", Value = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MINIMS", "OpenIZ.ftsearch.sqlite") }, new ConnectionString() { Name = "openIzQueue", Value = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MINIMS", "MessageQueue.sqlite") }, new ConnectionString() { Name = "openIzWarehouse", Value = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MINIMS", "OpenIZ.warehouse.sqlite") }, new ConnectionString() { Name = "openIzAudit", Value = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MINIMS", "OpenIZ.audit.sqlite") } } }; // Initial Applet configuration AppletConfigurationSection appletSection = new AppletConfigurationSection() { AppletDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MINIMS", "applets"), AppletGroupOrder = new System.Collections.Generic.List <string>() { "Patient Management", "Encounter Management", "Stock Management", "Administration" }, StartupAsset = "org.openiz.core", Security = new AppletSecurityConfiguration() { TrustedPublishers = new List <string>() { "84BD51F0584A1F708D604CF0B8074A68D3BEB973" } } }; // Initial applet style ApplicationConfigurationSection appSection = new ApplicationConfigurationSection() { Style = StyleSchemeType.Dark, UserPrefDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MINIMS", "userpref"), ServiceTypes = new List <string>() { typeof(LocalPolicyDecisionService).AssemblyQualifiedName, typeof(LocalPolicyInformationService).AssemblyQualifiedName, typeof(LocalPatientService).AssemblyQualifiedName, typeof(LocalPlaceService).AssemblyQualifiedName, typeof(LocalAlertService).AssemblyQualifiedName, typeof(LocalConceptService).AssemblyQualifiedName, typeof(LocalEntityRepositoryService).AssemblyQualifiedName, typeof(LocalOrganizationService).AssemblyQualifiedName, typeof(LocalRoleProviderService).AssemblyQualifiedName, typeof(LocalSecurityService).AssemblyQualifiedName, typeof(LocalMaterialService).AssemblyQualifiedName, typeof(LocalBatchService).AssemblyQualifiedName, typeof(LocalActService).AssemblyQualifiedName, typeof(SQLiteDatawarehouse).AssemblyQualifiedName, typeof(LocalProviderService).AssemblyQualifiedName, typeof(NetworkInformationService).AssemblyQualifiedName, typeof(CarePlanManagerService).AssemblyQualifiedName, typeof(BusinessRulesDaemonService).AssemblyQualifiedName, typeof(LocalEntitySource).AssemblyQualifiedName, typeof(MiniImsServer).AssemblyQualifiedName, typeof(MemoryCacheService).AssemblyQualifiedName, typeof(OpenIZThreadPool).AssemblyQualifiedName, typeof(SimpleCarePlanService).AssemblyQualifiedName, typeof(MemorySessionManagerService).AssemblyQualifiedName, typeof(AmiUpdateManager).AssemblyQualifiedName, typeof(AppletClinicalProtocolRepository).AssemblyQualifiedName, typeof(MemoryQueryPersistenceService).AssemblyQualifiedName, typeof(SimpleQueueFileProvider).AssemblyQualifiedName, typeof(SimplePatchService).AssemblyQualifiedName, typeof(SQLite.Net.Platform.Generic.SQLitePlatformGeneric).AssemblyQualifiedName, typeof(SearchIndexService).AssemblyQualifiedName, typeof(MiniAppletManagerService).AssemblyQualifiedName, typeof(MemoryTickleService).AssemblyQualifiedName, typeof(LocalTagPersistenceService).AssemblyQualifiedName, typeof(SQLiteReportDatasource).AssemblyQualifiedName, typeof(ReportExecutor).AssemblyQualifiedName, typeof(XamarinBackupService).AssemblyQualifiedName, typeof(AppletReportRepository).AssemblyQualifiedName }, Cache = new CacheConfiguration() { MaxAge = new TimeSpan(0, 5, 0).Ticks, MaxSize = 1000, MaxDirtyAge = new TimeSpan(0, 20, 0).Ticks, MaxPressureAge = new TimeSpan(0, 2, 0).Ticks } }; // Security configuration var wlan = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault(o => o.NetworkInterfaceType == NetworkInterfaceType.Ethernet && o.Description.StartsWith("wlan")); String macAddress = Guid.NewGuid().ToString(); if (wlan != null) { macAddress = wlan.GetPhysicalAddress().ToString(); } //else SecurityConfigurationSection secSection = new SecurityConfigurationSection() { DeviceName = String.Format("MINI-IMS-{0}", macAddress).Replace(" ", ""), AuditRetention = new TimeSpan(30, 0, 0, 0, 0) }; // Device key var certificate = X509CertificateUtils.FindCertificate(X509FindType.FindBySubjectName, StoreLocation.LocalMachine, StoreName.My, String.Format("DN={0}.mobile.openiz.org", macAddress)); secSection.DeviceSecret = certificate?.Thumbprint; // Rest Client Configuration ServiceClientConfigurationSection serviceSection = new ServiceClientConfigurationSection() { RestClientType = typeof(RestClient) }; // Trace writer #if DEBUG DiagnosticsConfigurationSection diagSection = new DiagnosticsConfigurationSection() { TraceWriter = new System.Collections.Generic.List <TraceWriterConfiguration>() { new TraceWriterConfiguration() { Filter = System.Diagnostics.Tracing.EventLevel.LogAlways, InitializationData = "OpenIZ", TraceWriter = new LogTraceWriter(System.Diagnostics.Tracing.EventLevel.LogAlways, "OpenIZ") }, new TraceWriterConfiguration() { Filter = System.Diagnostics.Tracing.EventLevel.LogAlways, InitializationData = "OpenIZ", TraceWriter = new FileTraceWriter(System.Diagnostics.Tracing.EventLevel.LogAlways, "OpenIZ") }, new TraceWriterConfiguration() { Filter = System.Diagnostics.Tracing.EventLevel.LogAlways, InitializationData = "OpenIZ", TraceWriter = new ConsoleTraceWriter(System.Diagnostics.Tracing.EventLevel.LogAlways, "OpenIZ") } } }; #else DiagnosticsConfigurationSection diagSection = new DiagnosticsConfigurationSection() { TraceWriter = new List <TraceWriterConfiguration>() { new TraceWriterConfiguration() { Filter = System.Diagnostics.Tracing.EventLevel.LogAlways, InitializationData = "OpenIZ", TraceWriter = new FileTraceWriter(System.Diagnostics.Tracing.EventLevel.LogAlways, "OpenIZ") } } }; #endif retVal.Sections.Add(appletSection); retVal.Sections.Add(dataSection); retVal.Sections.Add(diagSection); retVal.Sections.Add(appSection); retVal.Sections.Add(secSection); retVal.Sections.Add(serviceSection); retVal.Sections.Add(new SynchronizationConfigurationSection() { PollInterval = new TimeSpan(0, 5, 0) }); return(retVal); }
/// <summary> /// Load the configuration file /// </summary> public void Load() { if (!String.IsNullOrEmpty(this.m_configPath)) { using (var fs = File.OpenRead(this.m_configPath)) { this.m_configuration = OpenIZConfiguration.Load(fs); } } else { this.m_configuration = new OpenIZConfiguration(); // Inital data source DataConfigurationSection dataSection = new DataConfigurationSection() { MainDataSourceConnectionStringName = "openIzData", MessageQueueConnectionStringName = "openIzData", ConnectionString = new System.Collections.Generic.List <ConnectionString>() { new ConnectionString() { Name = "openIzData", Value = String.IsNullOrEmpty(this.m_dataPath) ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Minims", "OpenIZ.sqlite") : this.m_dataPath } } }; // Initial Applet configuration AppletConfigurationSection appletSection = new AppletConfigurationSection() { Security = new AppletSecurityConfiguration() { AllowUnsignedApplets = true, TrustedPublishers = new List <string>() { "84BD51F0584A1F708D604CF0B8074A68D3BEB973" } } }; // Initial applet style ApplicationConfigurationSection appSection = new ApplicationConfigurationSection() { Style = StyleSchemeType.Dark, UserPrefDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "OizDebug", "userpref"), ServiceTypes = new List <string>() { typeof(LocalPolicyDecisionService).AssemblyQualifiedName, typeof(LocalPolicyInformationService).AssemblyQualifiedName, typeof(LocalPatientService).AssemblyQualifiedName, typeof(LocalPlaceService).AssemblyQualifiedName, //typeof(LocalAlertService).AssemblyQualifiedName, typeof(LocalConceptService).AssemblyQualifiedName, typeof(LocalEntityRepositoryService).AssemblyQualifiedName, typeof(LocalOrganizationService).AssemblyQualifiedName, typeof(LocalRoleProviderService).AssemblyQualifiedName, typeof(LocalSecurityService).AssemblyQualifiedName, typeof(LocalMaterialService).AssemblyQualifiedName, typeof(LocalBatchService).AssemblyQualifiedName, typeof(LocalActService).AssemblyQualifiedName, typeof(LocalProviderService).AssemblyQualifiedName, typeof(LocalTagPersistenceService).AssemblyQualifiedName, typeof(NetworkInformationService).AssemblyQualifiedName, typeof(BusinessRulesDaemonService).AssemblyQualifiedName, typeof(LocalEntitySource).AssemblyQualifiedName, typeof(MemoryCacheService).AssemblyQualifiedName, typeof(OpenIZThreadPool).AssemblyQualifiedName, typeof(MemorySessionManagerService).AssemblyQualifiedName, typeof(AmiUpdateManager).AssemblyQualifiedName, typeof(AppletClinicalProtocolRepository).AssemblyQualifiedName, typeof(MemoryQueryPersistenceService).AssemblyQualifiedName, typeof(SimpleQueueFileProvider).AssemblyQualifiedName, typeof(SimpleCarePlanService).AssemblyQualifiedName, typeof(SimplePatchService).AssemblyQualifiedName, typeof(DebugAppletManagerService).AssemblyQualifiedName, typeof(SQLiteConnectionManager).AssemblyQualifiedName, typeof(LocalPersistenceService).AssemblyQualifiedName }, Cache = new CacheConfiguration() { MaxAge = new TimeSpan(0, 5, 0).Ticks, MaxSize = 1000, MaxDirtyAge = new TimeSpan(0, 20, 0).Ticks, MaxPressureAge = new TimeSpan(0, 2, 0).Ticks } }; appSection.ServiceTypes.Add(typeof(SQLite.Net.Platform.Generic.SQLitePlatformGeneric).AssemblyQualifiedName); // Security configuration SecurityConfigurationSection secSection = new SecurityConfigurationSection() { DeviceName = Environment.MachineName, AuditRetention = new TimeSpan(30, 0, 0, 0, 0) }; // Device key //var certificate = X509CertificateUtils.FindCertificate(X509FindType.FindBySubjectName, StoreLocation.LocalMachine, StoreName.My, String.Format("DN={0}.mobile.openiz.org", macAddress)); //secSection.DeviceSecret = certificate?.Thumbprint; // Rest Client Configuration ServiceClientConfigurationSection serviceSection = new ServiceClientConfigurationSection() { RestClientType = typeof(RestClient) }; // Trace writer DiagnosticsConfigurationSection diagSection = new DiagnosticsConfigurationSection() { TraceWriter = new System.Collections.Generic.List <TraceWriterConfiguration>() { new TraceWriterConfiguration() { Filter = System.Diagnostics.Tracing.EventLevel.Error, InitializationData = "OpenIZ", TraceWriter = new ConsoleTraceWriter(System.Diagnostics.Tracing.EventLevel.Warning, "OpenIZ") }, new TraceWriterConfiguration() { Filter = System.Diagnostics.Tracing.EventLevel.LogAlways, InitializationData = "OpenIZ", TraceWriter = new FileTraceWriter(System.Diagnostics.Tracing.EventLevel.Warning, "OpenIZ") } } }; this.m_configuration.Sections.Add(appletSection); this.m_configuration.Sections.Add(dataSection); this.m_configuration.Sections.Add(diagSection); this.m_configuration.Sections.Add(appSection); this.m_configuration.Sections.Add(secSection); this.m_configuration.Sections.Add(serviceSection); this.m_configuration.Sections.Add(new SynchronizationConfigurationSection() { PollInterval = new TimeSpan(0, 5, 0) }); } }