private void initializeConfiguration() { IIdentity user = HttpContext.Current.User.Identity; WindowsIdentity wi = (WindowsIdentity)user; WindowsImpersonationContext impersonater = wi.Impersonate(); try { MdwsConfiguration mdwsConfig = new MdwsConfiguration(); } catch (Exception exc) { // problem writing values while impersonating labelMessage.Text = "MDWS encountered an error while configuring your default settings. This is usually " + "because the host machine is not configured to enable impersonation by IIS. You can fix this by editing " + "your local security policy to allow the IUSR, IWAM and ASPNET user objects to impersonate. Go to Start > " + "Settings > Control Panel > Administrative Tools > Local Security Policies > Expand Local Policies > " + "User Rights Assignment > locate the 'Impersonate a Client After Authentication' setting > Open and add the " + "user objects listed above to the group. Restart IIS and launch this page again. <br />(" + exc.Message + ")"; } finally { impersonater.Undo(); } }
void setForm() { MdwsConfiguration mdwsConfig = new MdwsConfiguration(dropdownFacadeName.SelectedValue); radioButtonMdwsProduction.SelectedValue = mdwsConfig.IsProduction.ToString().ToLower(); radioMdwsSessionsLogging.SelectedValue = mdwsConfig.ApplicationSessionsLogging.ToString().ToLower(); radioMdwsSessionsLogLevel.SelectedValue = Enum.GetName(typeof(ApplicationSessionsLogLevel), mdwsConfig.ApplicationSessionsLogLevel); if (mdwsConfig.SqlConfiguration != null) { textboxSqlServerPath.Text = mdwsConfig.SqlConfiguration.Hostname; textboxSqlDatabase.Text = mdwsConfig.SqlConfiguration.Database; textboxSqlUsername.Text = mdwsConfig.SqlConfiguration.Username; textboxSqlPassword.Text = mdwsConfig.SqlConfiguration.Password; } if (mdwsConfig.FacadeConfiguration != null) { textboxFacadeSitesFileName.Text = mdwsConfig.FacadeConfiguration.SitesFileName; radioFacadeIsProduction.SelectedValue = mdwsConfig.FacadeConfiguration.IsProduction.ToString().ToLower(); try { Object currentFacade = Activator.CreateInstance(Type.GetType("gov.va.medora.mdws." + dropdownFacadeName.SelectedValue)); string facadeVersion = (string)Type.GetType("gov.va.medora.mdws." + dropdownFacadeName.SelectedValue). GetField("VERSION").GetValue(dropdownFacadeName.SelectedValue); textboxFacadeVersion.Text = facadeVersion; } catch (Exception) { textboxFacadeVersion.Text = "0.0.0"; } } }
public void testFacadeNameConstructor() { MdwsConfiguration config = new MdwsConfiguration("EmrSvc"); Assert.IsNotNull(config); Assert.IsNotNull(config.FacadeConfiguration); Assert.IsNotNull(config.AllConfigs); Assert.IsFalse(String.IsNullOrEmpty(config.ResourcesPath)); }
//public ILog log; public MySession() { _mdwsConfig = new MdwsConfiguration(); _defaultVisitMethod = _mdwsConfig.AllConfigs[MdwsConfigConstants.MDWS_CONFIG_SECTION][MdwsConfigConstants.DEFAULT_VISIT_METHOD]; _defaultPermissionString = _mdwsConfig.AllConfigs[MdwsConfigConstants.MDWS_CONFIG_SECTION][MdwsConfigConstants.DEFAULT_CONTEXT]; try { _siteTable = new mdo.SiteTable(_mdwsConfig.ResourcesPath + "xml\\" + _mdwsConfig.FacadeConfiguration.SitesFileName); } catch (Exception) { /* SiteTable is going to be null - how do we let the user know?? */ } }
/// <summary> /// Every client application requesting a MDWS session (invokes a function with EnableSession = True attribute) passes /// through this point. Fetches facade configuration settings and sets up session for subsequent calls /// </summary> /// <param name="facadeName">The facade name being invoked (e.g. EmrSvc)</param> /// <exception cref="System.Configuration.ConfigurationErrorsException" /> public MySession(string facadeName) { this._facadeName = facadeName; _mdwsConfig = new MdwsConfiguration(facadeName); _defaultVisitMethod = _mdwsConfig.AllConfigs[MdwsConfigConstants.MDWS_CONFIG_SECTION][MdwsConfigConstants.DEFAULT_VISIT_METHOD]; _defaultPermissionString = _mdwsConfig.AllConfigs[MdwsConfigConstants.MDWS_CONFIG_SECTION][MdwsConfigConstants.DEFAULT_CONTEXT]; _excludeSite200 = String.Equals("true", _mdwsConfig.AllConfigs[MdwsConfigConstants.MDWS_CONFIG_SECTION][MdwsConfigConstants.EXCLUDE_SITE_200], StringComparison.CurrentCultureIgnoreCase); try { _siteTable = new mdo.SiteTable(_mdwsConfig.ResourcesPath + "xml\\" + _mdwsConfig.FacadeConfiguration.SitesFileName); watchSitesFile(_mdwsConfig.ResourcesPath + "xml\\"); } catch (Exception) { /* SiteTable is going to be null - how do we let the user know?? */ } }
protected void DownloadSitesFile_Click(object sender, EventArgs e) { MdwsConfiguration config = new MdwsConfiguration(dropdownFacadeName.SelectedValue); string connectionString = ""; if (config != null && config.AllConfigs != null && config.AllConfigs.ContainsKey(MdwsConfigConstants.MDWS_CONFIG_SECTION) && config.AllConfigs[MdwsConfigConstants.MDWS_CONFIG_SECTION].ContainsKey("UpdaterConnectionString")) { connectionString = config.AllConfigs[MdwsConfigConstants.MDWS_CONFIG_SECTION]["UpdaterConnectionString"]; } else { labelMessage.Text = "No updater connection information found in your config file!"; return; } MdwsToolsDao dao = new MdwsToolsDao(connectionString); try { byte[] file = dao.getLatestSitesFile(); if (file == null || file.Length == 0) { labelMessage.Text = "Doesn't look to be a active sites file in the updater database. Please check back later."; } else { Response.AddHeader("Content-Disposition", "attachment;filename=VhaSites.xml"); Response.ContentType = "application/octet-stream"; Response.BinaryWrite(file); Response.Flush(); Response.End(); } } catch (Exception exc) { labelMessage.Text = "Awww, snap. I couldn't get that for you. Maybe this will help figure out why:</p>" + exc.Message + "</p>"; } }
public ApplicationSessions() { _logLevel = ApplicationSessionsLogLevel.info; _sessions = new Dictionary <string, ApplicationSession>(); _configurationSettings = new MdwsConfiguration(); }
protected void SubmitChangesClick(object sender, EventArgs e) { IIdentity user = HttpContext.Current.User.Identity; WindowsIdentity wi = (WindowsIdentity)user; WindowsImpersonationContext impersonater = wi.Impersonate(); try { Dictionary <string, Dictionary <string, string> > newSettings = new Dictionary <string, Dictionary <string, string> >(); MdwsConfiguration mdwsConfig = new MdwsConfiguration(); Dictionary <string, Dictionary <string, string> > oldSettings = mdwsConfig.AllConfigs; newSettings.Add(MdwsConfigConstants.MDWS_CONFIG_SECTION, new Dictionary <string, string>()); newSettings.Add(MdwsConfigConstants.SQL_CONFIG_SECTION, new Dictionary <string, string>()); newSettings.Add(dropdownFacadeName.Text, new Dictionary <string, string>()); newSettings[MdwsConfigConstants.MDWS_CONFIG_SECTION].Add(MdwsConfigConstants.SESSIONS_LOG_LEVEL, radioMdwsSessionsLogLevel.SelectedValue); newSettings[MdwsConfigConstants.MDWS_CONFIG_SECTION].Add(MdwsConfigConstants.SESSIONS_LOGGING, radioMdwsSessionsLogging.SelectedValue); newSettings[MdwsConfigConstants.MDWS_CONFIG_SECTION].Add(MdwsConfigConstants.MDWS_PRODUCTION, radioButtonMdwsProduction.SelectedValue); newSettings[MdwsConfigConstants.SQL_CONFIG_SECTION].Add(MdwsConfigConstants.SQL_HOSTNAME, textboxSqlServerPath.Text); newSettings[MdwsConfigConstants.SQL_CONFIG_SECTION].Add(MdwsConfigConstants.SQL_DB, textboxSqlDatabase.Text); newSettings[MdwsConfigConstants.SQL_CONFIG_SECTION].Add(MdwsConfigConstants.SQL_USERNAME, textboxSqlUsername.Text); newSettings[MdwsConfigConstants.SQL_CONFIG_SECTION].Add(MdwsConfigConstants.SQL_PASSWORD, textboxSqlPassword.Text); newSettings[dropdownFacadeName.Text].Add(MdwsConfigConstants.FACADE_PRODUCTION, radioFacadeIsProduction.SelectedValue); if (String.IsNullOrEmpty(textboxFacadeSitesFileName.Text)) { newSettings[dropdownFacadeName.Text].Add(MdwsConfigConstants.FACADE_SITES_FILE, MdwsConstants.DEFAULT_SITES_FILE_NAME); } else { newSettings[dropdownFacadeName.Text].Add(MdwsConfigConstants.FACADE_SITES_FILE, textboxFacadeSitesFileName.Text); } foreach (string key in newSettings.Keys) { // if old settings doesn't have facade config, add it if (!oldSettings.ContainsKey(key)) { oldSettings.Add(key, new Dictionary <string, string>()); } foreach (string settingKey in newSettings[key].Keys) { if (oldSettings[key].ContainsKey(settingKey)) { oldSettings[key][settingKey] = newSettings[key][settingKey]; } else { oldSettings[key].Add(settingKey, newSettings[key][settingKey]); } } } gov.va.medora.mdo.dao.file.ConfigFileDao fileDao = new mdo.dao.file.ConfigFileDao(mdwsConfig.ConfigFilePath); fileDao.writeToFile(oldSettings); // not really old settings any more } catch (Exception exc) { labelMessage.Text = exc.ToString(); } finally { impersonater.Undo(); } setForm(); }