protected void btnTransHistory_Click(object sender, EventArgs e) { try { string OrgID = Session["OrgID"].ToString(); //get CDX username, password, and CDX destination URL CDXCredentials cred = WQXSubmit.GetCDXSubmitCredentials2(OrgID); //*******AUTHENTICATE*********************************** string token = WQXSubmit.AuthHelper(cred.userID, cred.credential, "Password", "default", cred.NodeURL); //*******QUERY***************************************** if (token.Length > 0) { List<net.epacdxnode.test.ParameterType> pars = new List<net.epacdxnode.test.ParameterType>(); net.epacdxnode.test.ParameterType p = new net.epacdxnode.test.ParameterType(); p.parameterName = "organizationIdentifier"; p.Value = OrgID; pars.Add(p); p.parameterName = "transactionDateBegin"; p.Value = "2015-01-04"; p.parameterType = new System.Xml.XmlQualifiedName("DateTime", "http://www.w3.org/2001/XMLSchema"); pars.Add(p); net.epacdxnode.test.ResultSetType queryResp = WQXSubmit.QueryHelper(cred.NodeURL, token, "WQX", "WQX.GetTransactionHistoryByParameters_v2.1", null, null, pars); } else { //lblMsg.Text = "Unable to authenticate to EPA-WQX server."; } } catch { return; } }
internal static StatusResponseType SolicitHelper(string NodeURL, string secToken, string dataFlow, string request, int? rowID, int? maxRows, List<ParameterType> pars) { try { NetworkNode2 nn = new NetworkNode2(); nn.Url = NodeURL; nn.SoapVersion = SoapProtocolVersion.Soap12; Solicit s1 = new Solicit(); s1.securityToken = secToken; s1.dataflow = dataFlow; s1.request = request; ParameterType[] ps = new ParameterType[pars.Count]; int i = 0; System.Xml.XmlQualifiedName parType = new System.Xml.XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); foreach (ParameterType par in pars) { if (par.parameterEncoding == null) par.parameterEncoding = EncodingType.None; ps[i] = par; i++; } s1.parameters = ps; return nn.Solicit(s1); } catch (SoapException sExept) { db_Ref.InsertT_OE_SYS_LOG("WQX", sExept.Message.SubStringPlus(0, 1999)); return null; } }
internal static ResultSetType QueryHelper(string NodeURL, string secToken, string dataFlow, string request, int? rowID, int? maxRows, List<ParameterType> pars) { try { NetworkNode2 nn = new NetworkNode2(); nn.Url = NodeURL; nn.SoapVersion = SoapProtocolVersion.Soap12; Query q1 = new Query(); q1.securityToken = secToken; q1.dataflow = dataFlow; q1.request = request; q1.rowId = (rowID ?? 0).ToString(); q1.maxRows = (maxRows ?? -1).ToString(); ParameterType[] ps = new ParameterType[pars.Count]; int i = 0; System.Xml.XmlQualifiedName parType = new System.Xml.XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); foreach (ParameterType par in pars) { if (par.parameterEncoding == null) par.parameterEncoding = EncodingType.None; ps[i] = par; i++; } q1.parameters = ps; return nn.Query(q1); } catch (SoapException sExept) { db_Ref.InsertT_OE_SYS_LOG("ERROR", sExept.Message.SubStringPlus(0, 1999)); //logging an authentication failure //special handling of an unauthorized if (sExept.Message.SubStringPlus(0, 9) == "ORA-20997") { ResultSetType rs = new ResultSetType(); rs.rowId = "-99"; return rs; } return null; } }
private bool WQXImport_Proj(string OrgID) { //first delete any previous temp import data int SuccID = db_WQX.DeleteT_WQX_IMPORT_TEMP_PROJECT(User.Identity.Name); if (SuccID == 0) { lblMsg.Text = "Unable to proceed with import."; return false; } try { //get CDX username, password, and CDX destination URL CDXCredentials cred = WQXSubmit.GetCDXSubmitCredentials2(OrgID); //*******AUTHENTICATE*********************************** string token = WQXSubmit.AuthHelper(cred.userID, cred.credential, "Password", "default", cred.NodeURL); //*******QUERY***************************************** if (token.Length > 0) { List<net.epacdxnode.test.ParameterType> pars = new List<net.epacdxnode.test.ParameterType>(); net.epacdxnode.test.ParameterType p = new net.epacdxnode.test.ParameterType(); p.parameterName = "organizationIdentifier"; p.Value = OrgID; pars.Add(p); net.epacdxnode.test.ResultSetType queryResp = WQXSubmit.QueryHelper(cred.NodeURL, token, "WQX", "WQX.GetProjectByParameters_v2.1", null, null, pars); XDocument xdoc = XDocument.Parse(queryResp.results.Any[0].InnerXml); var projects = (from project in xdoc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}Project") select new { ID = (string)project.Element("{http://www.exchangenetwork.net/schema/wqx/2}ProjectIdentifier") ?? String.Empty, Name = (string)project.Element("{http://www.exchangenetwork.net/schema/wqx/2}ProjectName") ?? String.Empty, Desc = (string)project.Element("{http://www.exchangenetwork.net/schema/wqx/2}ProjectDescriptionText") ?? String.Empty, SamplingDesignType = (string)project.Element("{http://www.exchangenetwork.net/schema/wqx/2}SamplingDesignTypeCode") ?? String.Empty, QAPPInd = (string)project.Element("{http://www.exchangenetwork.net/schema/wqx/2}QAPPApprovedIndicator") ?? String.Empty, QAPPAgency = (string)project.Element("{http://www.exchangenetwork.net/schema/wqx/2}QAPPApprovalAgencyName") ?? String.Empty, }); //loop through retrieved data and insert into temp table if (projects != null) { foreach (var project in projects) { int Succ = db_WQX.InsertOrUpdateWQX_IMPORT_TEMP_PROJECT(null, User.Identity.Name, null, OrgID, project.ID, project.Name, project.Desc, project.SamplingDesignType, project.QAPPInd.ConvertOrDefault<Boolean?>(), project.QAPPAgency, "P", ""); } } Response.Redirect("~/App_Pages/Secure/WQXImportProject.aspx?e=1"); return true; } else { lblMsg.Text = "Unable to authenticate to EPA-WQX server."; return false; } } catch { return false; } }
private bool WQXImport_MonLoc(string OrgID, string UserID) { int SuccID = db_WQX.DeleteT_WQX_IMPORT_TEMP_MONLOC(UserID); if (SuccID == 0) { lblMsg.Text = "Unable to proceed with import."; return false; } try { //get CDX username, password, and CDX destination URL CDXCredentials cred = WQXSubmit.GetCDXSubmitCredentials2(OrgID); //*******AUTHENTICATE*********************************** string token = WQXSubmit.AuthHelper(cred.userID, cred.credential, "Password", "default", cred.NodeURL); //*******QUERY***************************************** if (token.Length > 0) { List<net.epacdxnode.test.ParameterType> pars = new List<net.epacdxnode.test.ParameterType>(); net.epacdxnode.test.ParameterType p = new net.epacdxnode.test.ParameterType(); p.parameterName = "organizationIdentifier"; p.Value = OrgID;//txtOrgTest.Text pars.Add(p); net.epacdxnode.test.ParameterType p2 = new net.epacdxnode.test.ParameterType(); p2.parameterName = "monitoringLocationIdentifier"; p2.Value = ""; pars.Add(p2); net.epacdxnode.test.ResultSetType queryResp = WQXSubmit.QueryHelper(cred.NodeURL, token, "WQX", "WQX.GetMonitoringLocationByParameters_v2.1", null, null, pars); //handle no response if (queryResp == null) { lblMsg.Text = "No monitoring locations found at EPA for this organization."; return true; } XDocument xdoc = XDocument.Parse(queryResp.results.Any[0].InnerXml); var mlocs = (from mloc in xdoc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocation") select new { ID = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationIdentity").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationIdentifier") ?? String.Empty, Name = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationIdentity").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationName") ?? String.Empty, MonLocType = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationIdentity").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationTypeName") ?? String.Empty, Desc = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationIdentity").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationDescriptionText") ?? String.Empty, HUC8 = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationIdentity").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}HUCEightDigitCode") ?? String.Empty, HUC12 = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationIdentity").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}HUCTwelveDigitCode") ?? String.Empty, TribeLandInd = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationIdentity").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}TribalLandIndicator") ?? String.Empty, TribeLandName = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationIdentity").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}TribalLandName") ?? String.Empty, Lat = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationGeospatial").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}LatitudeMeasure") ?? String.Empty, Long = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationGeospatial").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}LongitudeMeasure") ?? String.Empty, SourceMapScale = (int?)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationGeospatial").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}SourceMapScaleNumeric").ConvertOrDefault<int?>(), HorizontalAccuracyMeasure = mloc.Element("{http://www.exchangenetwork.net/schema/wqx/2}HorizontalAccuracyMeasure") != null ? (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}HorizontalAccuracyMeasure").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}MeasureValue") ?? String.Empty : "", HorizontalAccuracyMeasureUnit = mloc.Element("{http://www.exchangenetwork.net/schema/wqx/2}HorizontalAccuracyMeasure") != null ? (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}HorizontalAccuracyMeasure").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}MeasureUnitCode") ?? String.Empty : "", HorizontalCollectionMethodName = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationGeospatial").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}HorizontalCollectionMethodName") ?? String.Empty, HorizontalCoordinateReferenceSystemDatumName = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationGeospatial").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}HorizontalCoordinateReferenceSystemDatumName") ?? String.Empty, VerticalMeasure = mloc.Element("{http://www.exchangenetwork.net/schema/wqx/2}VerticalMeasure") != null ? (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}VerticalMeasure").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}MeasureValue") ?? String.Empty : "", VerticalMeasureUnit = mloc.Element("{http://www.exchangenetwork.net/schema/wqx/2}VerticalMeasure") != null ? (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}VerticalMeasure").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}MeasureUnitCode") ?? String.Empty : "", VerticalCollectionMethodName = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationGeospatial").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}VerticalCollectionMethodName") ?? String.Empty, VerticalCoordinateReferenceSystemDatumName = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationGeospatial").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}VerticalCoordinateReferenceSystemDatumName") ?? String.Empty, CountryCode = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationGeospatial").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}CountryCode") ?? String.Empty, StateCode = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationGeospatial").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}StateCode") ?? String.Empty, CountyCode = (string)mloc.Descendants("{http://www.exchangenetwork.net/schema/wqx/2}MonitoringLocationGeospatial").FirstOrDefault().Element("{http://www.exchangenetwork.net/schema/wqx/2}CountyCode") ?? String.Empty }); //loop through retrieved data and insert into temp table if (mlocs != null) { foreach (var mloc in mlocs) { int Succ = db_WQX.InsertOrUpdateWQX_IMPORT_TEMP_MONLOC(null, UserID, null, OrgID, mloc.ID, mloc.Name, mloc.MonLocType, mloc.Desc, mloc.HUC8, mloc.HUC12, mloc.TribeLandInd, mloc.TribeLandName, mloc.Lat, mloc.Long, mloc.SourceMapScale, mloc.HorizontalAccuracyMeasure, mloc.HorizontalAccuracyMeasureUnit, mloc.HorizontalCollectionMethodName, mloc.HorizontalCoordinateReferenceSystemDatumName, mloc.VerticalMeasure, mloc.VerticalMeasureUnit, mloc.VerticalCollectionMethodName, mloc.VerticalCoordinateReferenceSystemDatumName, mloc.CountryCode, mloc.StateCode, mloc.CountyCode, null, null, null, null, null, "P", ""); } } Response.Redirect("~/App_Pages/Secure/WQXImportMonLoc.aspx?e=1"); return true; } else { lblMsg.Text = "Unable to authenticate to EPA-WQX server."; return false; } } catch { return false; } }
private void ConnectTest(string typ) { try { //AUTHENTICATION TEST********************************************* CDXCredentials cred = WQXSubmit.GetCDXSubmitCredentials2(Session["OrgID"].ToString()); string token = WQXSubmit.AuthHelper(cred.userID, cred.credential, "Password", "default", cred.NodeURL); if (token.Length > 0) { spnAuth.Attributes["class"] = "signup_header_check"; lblAuthResult.Text = "Authentication passed."; lblCDXSubmitInd.CssClass = "fldPass"; lblCDXSubmitInd.Text = "This Organization is able to submit to EPA."; //SUBMIT TEST********************************************* List<net.epacdxnode.test.ParameterType> pars = new List<net.epacdxnode.test.ParameterType>(); net.epacdxnode.test.ParameterType p = new net.epacdxnode.test.ParameterType(); p.parameterName = "organizationIdentifier"; p.Value = Session["OrgID"].ToString(); pars.Add(p); net.epacdxnode.test.ParameterType p2 = new net.epacdxnode.test.ParameterType(); p2.parameterName = "monitoringLocationIdentifier"; p2.Value = ""; pars.Add(p2); OpenEnvironment.net.epacdxnode.test.ResultSetType rs = WQXSubmit.QueryHelper(cred.NodeURL, token, "WQX", "WQX.GetMonitoringLocationByParameters_v2.1", null, null, pars); if (rs.rowId == "-99") { //THE NAAS ACCOUNT DOES NOT HAVE RIGHTS TO SUBMIT FOR THIS ORGANIZATION********************************************* spnSubmit.Attributes["class"] = "signup_header_cross"; if (typ == "LOCAL") lblSubmitResult.Text = "The NAAS account you supplied is not authorized to submit for this organization. Please contact the STORET Helpdesk to request access."; else lblSubmitResult.Text = "Open Waters is not authorized to submit for your organization. Please contact the STORET Helpdesk to request access."; lblCDXSubmitInd.CssClass = "fldErr"; lblCDXSubmitInd.Text = "This Organization is unable to submit to EPA. Please correct this below."; db_WQX.InsertOrUpdateT_WQX_ORGANIZATION(Session["OrgID"].ToString(), null, null, null, null, null, null, null, null, null, null, false, null, User.Identity.Name); } else { spnSubmit.Attributes["class"] = "signup_header_check"; lblSubmitResult.Text = "Submit test passed."; lblCDXSubmitInd.CssClass = "fldPass"; lblCDXSubmitInd.Text = "This Organization is able to submit to EPA."; //BOTH AUTHENTICATION AND SUBMIT PASSES - UPDATE ORG SUBMIT IND********************************************* db_WQX.InsertOrUpdateT_WQX_ORGANIZATION(Session["OrgID"].ToString(), null, null, null, null, null, null, null, null, null, null, true, null, User.Identity.Name); } } else //failed authentication { spnAuth.Attributes["class"] = "signup_header_cross"; lblAuthResult.Text = "Unable to authenticate to EPA-CDX. Please double-check your username and password."; spnSubmit.Attributes["class"] = "signup_header_crossbw"; lblSubmitResult.Text = "Cannot test until authentication is resolved."; lblCDXSubmitInd.CssClass = "fldErr"; lblCDXSubmitInd.Text = "This Organization is unable to submit to EPA. Please correct this below."; db_WQX.InsertOrUpdateT_WQX_ORGANIZATION(Session["OrgID"].ToString(), null, null, null, null, null, null, null, null, null, null, false, null, User.Identity.Name); } pnlCDXResults.Visible = true; } catch (Exception ex) { lblMsg.Text = ex.Message; } }