/// <summary> /// Loads an instance of the monahrq settings configuration if not already loaded. /// </summary> private void Load() { if (_monahrqConfigurationSettings == null) { _monahrqConfigurationSettings = MonahrqConfiguration.SettingsGroup.MonahrqSettings(); } }
/// <summary> /// Saves the specified settings. /// </summary> /// <param name="settings">The settings.</param> public static void Save(IMonahrqSettings settings) { try { //wha??? lock (_objLock) { ConfigDebugLog("Save", String.Format("States: {0}", settings.HospitalRegion.DefaultStateCount)); settings.HospitalRegion.SyncDefaultStatesToConfig(); _userSettingsConfig = null; _monahrqConfigurationSection = null; var config = UserSettingsConfig; var group = config.GetMonahrqSectionGroup(); var temp = ConnectionStringSettingsElement.Default; temp.ConnectionString = settings.EntityConnectionSettings.ConnectionString; group.MonahrqSettings().EntityConnectionSettings = temp; var temp2 = ConnectionStringSettingsElement.WinQiDefault; temp2.ConnectionString = settings.WinQiConnectionSettings.ConnectionString; group.MonahrqSettings().WinQiConnectionSettings = temp2; group.MonahrqSettings().HospitalRegion.SelectedRegionType = settings.HospitalRegion.SelectedRegionType; group.MonahrqSettings().HospitalRegion.DefaultStates = settings.HospitalRegion.DefaultStates; group.MonahrqSettings().NamedConnections = settings.NamedConnections; group.MonahrqSettings().ShortTimeout = settings.ShortTimeout; group.MonahrqSettings().LongTimeout = settings.LongTimeout; group.MonahrqSettings().LastFolder = settings.LastFolder; group.MonahrqSettings().BatchSize = settings.BatchSize; group.MonahrqSettings().DebugSql = settings.DebugSql; group.MonahrqSettings().RebuildDatabase = settings.RebuildDatabase; group.MonahrqSettings().UseApiForPhysicians = settings.UseApiForPhysicians; group.MonahrqSettings().DataAccessComponentsInstalled = settings.DataAccessComponentsInstalled; group.MonahrqSettings().UpdateScriptToRunAtStartup = settings.UpdateScriptToRunAtStartup; group.MonahrqSettings().IsFirstRun = settings.IsFirstRun; config.Save(ConfigurationSaveMode.Modified); } Thread.Sleep(300); } catch (Exception ex) { ex.GetType(); } _reset = true; }
/// <summary> /// Gets the monahrq section group. /// </summary> /// <param name="config">The configuration.</param> /// <returns></returns> public static ConfigurationSectionGroup GetMonahrqSectionGroup(this System.Configuration.Configuration config) { var group = config.GetSectionGroup("MonahrqConfigurationSectionGroup"); if (group == null) { group = new ConfigurationSectionGroup(); config.SectionGroups.Add("MonahrqConfigurationSectionGroup", group); var section = new MonahrqConfigurationSection(); section.SectionInformation.AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToLocalUser; group.Sections.Add(MonahrqConfigurationSection.MonahrqConfigurationSectionSectionName, section); config.Save(ConfigurationSaveMode.Minimal); } return(group); }
public void ForceRefresh() { _monahrqConfigurationSettings = null; Load(); }
/// <summary> /// Transforms to new configuration. /// </summary> /// <param name="oldConfigFilePath">The old configuration file path.</param> /// <param name="monahrqConfigurationFilePath">The monahrq configuration file path.</param> /// <param name="monahrqConfiguration">The monahrq configuration.</param> /// <exception cref="ArgumentNullException"> /// oldConfigFilePath;oldConfigFilePath can not be null. /// or /// monahrqConfigurationFilePath;monahrqConfigurationFilePath can not be null. /// </exception> private static void TransformToNewConfig(string oldConfigFilePath, string monahrqConfigurationFilePath, ref MonahrqConfigurationSection monahrqConfiguration) { if (string.IsNullOrEmpty(oldConfigFilePath)) { throw new ArgumentNullException("oldConfigFilePath", @"oldConfigFilePath can not be null."); } if (string.IsNullOrEmpty(monahrqConfigurationFilePath)) { throw new ArgumentNullException("monahrqConfigurationFilePath", @"monahrqConfigurationFilePath can not be null."); } if (monahrqConfiguration == null) { monahrqConfiguration = new MonahrqConfigurationSection(); } if (monahrqConfiguration.SectionInformation.AllowExeDefinition != ConfigurationAllowExeDefinition.MachineToLocalUser) { monahrqConfiguration.SectionInformation.AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToLocalUser; } var configDoc = XDocument.Load(oldConfigFilePath); var rootElement = configDoc.Element("configuration"); if (rootElement != null) { var monahrqConfigSectionElement = rootElement.Descendants(XName.Get("MonahrqConfigurationSection")).First(); if (monahrqConfigSectionElement != null) { monahrqConfiguration.RebuildDatabase = bool.Parse(monahrqConfigSectionElement.Attribute("rebuildDatabase").Value); monahrqConfiguration.LongTimeout = TimeSpan.Parse(monahrqConfigSectionElement.Attribute("longTimeout").Value); monahrqConfiguration.ShortTimeout = TimeSpan.Parse(monahrqConfigSectionElement.Attribute("shortTimeout").Value); monahrqConfiguration.LastFolder = monahrqConfigSectionElement.Attribute("lastFolder").Value; monahrqConfiguration.BatchSize = int.Parse(monahrqConfigSectionElement.Attribute("batchSize").Value); monahrqConfiguration.DebugSql = bool.Parse(monahrqConfigSectionElement.Attribute("debugSql").Value); monahrqConfiguration.DataAccessComponentsInstalled = bool.Parse(monahrqConfigSectionElement.Attribute("dataAccessComponentsInstalled").Value); monahrqConfiguration.UseApiForPhysicians = bool.Parse(monahrqConfigSectionElement.Attribute("useApiForPhysicians").Value); monahrqConfiguration.UpdateScriptToRunAtStartup = monahrqConfigSectionElement.Attribute("updateScriptToRunAtStartup").Value; if (monahrqConfigSectionElement.HasElements) { if (monahrqConfiguration.EntityConnectionSettings == null) { monahrqConfiguration.EntityConnectionSettings = new ConnectionStringSettingsElement(); } var entityDbSettings = monahrqConfigSectionElement.Element("entityConnectionSettings"); if (entityDbSettings != null) { monahrqConfiguration.EntityConnectionSettings.ConnectionString = entityDbSettings.Attribute("connectionString").Value; monahrqConfiguration.EntityConnectionSettings.ProviderName = entityDbSettings.Attribute("providerName").Value; } if (monahrqConfiguration.WinQiConnectionSettings == null) { monahrqConfiguration.WinQiConnectionSettings = new ConnectionStringSettingsElement(); } var winQIDbSettings = monahrqConfigSectionElement.Element("winQiConnectionSettings"); if (winQIDbSettings != null) { monahrqConfiguration.WinQiConnectionSettings.ConnectionString = winQIDbSettings.Attribute("connectionString").Value; monahrqConfiguration.WinQiConnectionSettings.ProviderName = winQIDbSettings.Attribute("providerName").Value; } } } var hospitalRegionElement = rootElement.Descendants(XName.Get("Monahrq.Sdk.Modules.Settings.HospitalRegion")).First(); if (hospitalRegionElement != null && hospitalRegionElement.HasElements) { if (monahrqConfiguration.HospitalRegion == null) { monahrqConfiguration.HospitalRegion = new HospitalRegionElement(); } var regionTypeSetting = hospitalRegionElement.Elements() .FirstOrDefault(e => e.Attribute("name").Value == "DefaultRegionTypeName"); if (regionTypeSetting != null) { monahrqConfiguration.HospitalRegion.SelectedRegionType = Type.GetType(regionTypeSetting.Value); } var defaultStatesSetting = hospitalRegionElement.Elements().FirstOrDefault(e => e.Attribute("name").Value == "DefaultStates"); if (defaultStatesSetting != null && !string.IsNullOrEmpty(defaultStatesSetting.Element("value").Value)) { var statesXmlDoc = new XmlDocument(); statesXmlDoc.LoadXml(defaultStatesSetting.Element("value").Element("ArrayOfString").ToString()); var states = XmlHelper.Deserialize <List <string> >(statesXmlDoc).ToArray(); monahrqConfiguration.HospitalRegion.DefaultStates = new StringCollection(); monahrqConfiguration.HospitalRegion.DefaultStates.AddRange(states); } else { monahrqConfiguration.HospitalRegion.DefaultStates = new StringCollection(); } } } //return monahrqConfiguration; }