public void GivenDifferentNameLengths_AlignEqualSigns_LeftAlignNamesAndValues() { NameValuePairs.Add("shortName", "parameterValue1"); NameValuePairs.Add("middleName", "parameterValue2"); NameValuePairs.Add("longestName", "parameterValue3"); AssertGivesParaFileText( "shortName = parameterValue1" + Environment.NewLine + "middleName = parameterValue2" + Environment.NewLine + "longestName = parameterValue3" + Environment.NewLine); }
public void SkipNullOrEmptyValues() { NameValuePairs.Add("parameterName1", "parameterValue1"); NameValuePairs.Add("parameterName3", ""); NameValuePairs.Add("parameterName4", null); NameValuePairs.Add("parameterName2", "parameterValue2"); AssertGivesParaFileText( "parameterName1 = parameterValue1" + Environment.NewLine + "parameterName2 = parameterValue2" + Environment.NewLine); }
public void GivenValidValues_FormNameValuePairs() { NameValuePairs.Add("parameterName1", "parameterValue1"); NameValuePairs.Add("parameterName2", "parameterValue2"); NameValuePairs.Add("parameterName3", "parameterValue3"); AssertGivesParaFileText( "parameterName1 = parameterValue1" + Environment.NewLine + "parameterName2 = parameterValue2" + Environment.NewLine + "parameterName3 = parameterValue3" + Environment.NewLine); }
/// <summary> /// Updates an application. /// </summary> /// <param name="appId">Application Id</param> /// <param name="frameworkType">FrameworkType (e.g. DETECT)</param> /// <param name="repositoryUrl">Repository URL</param> /// <returns></returns> public async Task <bool> SetApplicationParameters(int appId, FrameworkTypes frameworkType, string repositoryUrl) { NameValuePairs nvPairs = new NameValuePairs("frameworkType", frameworkType.ToString().ToUpper()); nvPairs.Add("repositoryUrl", repositoryUrl); JsonResponse response = await Post( String.Format("applications/{0}/setParameters", appId), nvPairs, typeof(Application)); return(response.Success); }
internal PayPalTransactionResponse(PayPalAccount usedAccount, NameValuePairs response) { RawResponse = response.ToString(); UsedAccount = usedAccount; Note = string.Empty; string refNo; response.TryGetValue("responseEnvelope.correlationId", out refNo); ReferenceNumber = refNo; string success = ""; bool isAck = response.TryGetValue("paymentExecStatus", out success); IsSuccess = isAck && String.Equals(success, "COMPLETED", StringComparison.OrdinalIgnoreCase); if (!IsSuccess) { string errorCode, message; if (!response.TryGetValue("error.errorId", out errorCode)) { response.TryGetValue("error(0).errorId", out errorCode); if (!response.TryGetValue("error(0).errorId", out errorCode)) { response.TryGetValue("L_ERRORCODE0", out errorCode); } } if (!response.TryGetValue("error.message", out message)) { response.TryGetValue("error(0).message", out message); if (!response.TryGetValue("error(0).message", out message)) { response.TryGetValue("L_LONGMESSAGE0", out message); } } Note = errorCode + ": " + message; } else { Note = Resources.U4000.MONEYSENT.Replace("%p%", "PayPal"); } }
/// <summary> /// Adds an application. /// </summary> /// <param name="teamId">Team Id</param> /// <param name="name">Name of the application</param> /// <param name="url">URL of the application</param> /// <returns>Id of the newly added application.</returns> public async Task <int> AddApplication(int teamId, string name, string url) { NameValuePairs nvPairs = new NameValuePairs("name", name); nvPairs.Add("url", url); JsonResponse response = await Post(String.Format("teams/{0}/applications/new", teamId), nvPairs, typeof(Application)); if (response.Success) { return(response.Object.Id); } else { return(response.Code); } }
public void HandlePayza(string ipnResponse) { var data = NameValuePairs.Parse(ipnResponse); string[] args = new string[] { data["apc_2"], data["apc_3"], data["apc_4"], data["apc_5"], data["apc_6"] }; if (AppSettings.Site.CurrencyCode.Equals(data["ap_currency"], StringComparison.OrdinalIgnoreCase) && "Success".Equals(data["ap_status"], StringComparison.OrdinalIgnoreCase)) { PaymentHandler.CheckIfNotDoneYet(PaymentProcessor.Payza, data["ap_referencenumber"]); handle(args, data["ap_referencenumber"], data["ap_totalamount"], "Payza"); } else { ErrorLogger.Log("Payza IPN: Problems with response: " + ipnResponse, LogType.Payza); } }
public void HandlePayPal(string ipnResponse) { var data = NameValuePairs.Parse(ipnResponse); string[] args = data["invoice"].Split(PayPalButtonGenerationStrategy.ArgsDelimeter); if (AppSettings.Site.CurrencyCode.Equals(data["mc_currency"], StringComparison.OrdinalIgnoreCase) && "Completed".Equals(data["payment_status"], StringComparison.OrdinalIgnoreCase)) { PaymentHandler.CheckIfNotDoneYet(PaymentProcessor.PayPal, data["txn_id"]); handle(args, data["txn_id"], data["mc_gross"], "PayPal"); } else { ErrorLogger.Log("PayPal IPN: Problems with response: " + ipnResponse, LogType.PayPal); } }
/// <summary> /// Adds a Web Application Firewall (WAF) /// </summary> /// <param name="name">Name</param> /// <param name="type">Type (e.g. mod_security)</param> /// <returns></returns> public async Task <int> AddWaf(string name, string type) { NameValuePairs nvPairs = new NameValuePairs("name", name); nvPairs.Add("type", type); JsonResponse response = await Post("wafs/new", nvPairs, typeof(Waf)); if (response.Success) { return(response.Object.Id); } else { return(response.Code); } }
public NameValuePairs ToNameValuePairs() { NameValuePairs nv = new NameValuePairs(); nv.Add("id", Id + ""); nv.Add("vulnType", vulnType); nv.Add("longDescription", longDescription); nv.Add("severity", severity + ""); nv.Add("isStatic", (isStatic) ? "1" : "0"); nv.Add("nativeId", nativeId + ""); nv.Add("parameter", parameter); nv.Add("filePath", filePath); nv.Add("column", column + ""); nv.Add("lineText", lineText); nv.Add("lineNumber", lineNumber + ""); nv.Add("fullUrl", fullUrl); nv.Add("path", path); return(nv); }
/// <summary> /// Uses the given path with the BaseUri and ApiKey (given in the constructor) to make a call /// to the ThreadFix REST API using HTTP verb GET. /// </summary> /// <param name="path">Path of the REST API to call (i.e. teams/3)</param> /// <param name="data">Data to include in the request (i.e. name=TEST123)</param> /// <returns>JsonResponse</returns> async Task <JsonResponse> Get(string path, Type objectType, NameValuePairs nvPairs = null) { path = "threadfix/" + REST + "/" + path; if (nvPairs != null) { path += "?" + nvPairs + "&"; } else { path += "?"; } path += String.Format("apiKey={0}", ApiKey); Uri endpoint = new Uri(BaseUri, path); Log.Debug(String.Format("Sending GET request to {0}", endpoint)); string json = await Client.GetStringAsync(endpoint); return(JsonResponse.GetInstance(json, objectType)); }
internal PayPalTransactionResponseForMassPay(PayPalAccount usedAccount, NameValuePairs response) { RawResponse = response.ToString(); UsedAccount = usedAccount; Note = string.Empty; string refNo; response.TryGetValue("CORRELATIONID", out refNo); ReferenceNumber = refNo; string success = ""; bool isAck = response.TryGetValue("ACK", out success); IsSuccess = isAck && String.Equals(success, "Success", StringComparison.OrdinalIgnoreCase); if (!IsSuccess) { string severity, errorCode, message; if ((!response.TryGetValue("error.severity", out severity)) || !response.TryGetValue("error(0).severity", out severity)) { response.TryGetValue("L_SHORTMESSAGE0", out severity); } if ((!response.TryGetValue("error.errorId", out errorCode)) || !response.TryGetValue("error(0).errorId", out errorCode)) { response.TryGetValue("L_ERRORCODE0", out errorCode); } if ((!response.TryGetValue("error.message", out message)) || !response.TryGetValue("error(0).message", out message)) { response.TryGetValue("L_LONGMESSAGE0", out message); } Note = severity + " " + errorCode + ": " + message; } else { Note = Resources.U4000.MONEYSENT.Replace("%p%", "PayPal"); } }
internal PayzaTransactionResponse(PayzaAccount usedAccount, NameValuePairs response) { RawResponse = response.ToString(); UsedAccount = usedAccount; try { string refNo; response.TryGetValue("REFERENCENUMBER", out refNo); ReferenceNumber = refNo; ReturnCode = Convert.ToInt32(response["RETURNCODE"]); Note = response["DESCRIPTION"]; IsTestMode = response["TESTMODE"] == "1"; } catch (Exception e) { ErrorLogger.Log(e); } IsSuccess = (ReturnCode == SuccessCode); }
private TransactionResponse CommitTransactionNormal(TransactionRequest request) { string dataToSend = buildTransactionRequestString(request); var req = (HttpWebRequest)WebRequest.Create(singlePaymentApi); req.Headers.Add("X-EgoPay-SECURITY-USERID", accountDetails.ApiUsername); req.Headers.Add("X-EgoPay-SECURITY-PASSWORD", accountDetails.ApiPassword); req.Headers.Add("X-EgoPay-SECURITY-SIGNATURE", accountDetails.ApiSignature); req.Headers.Add("X-EgoPay-APPLICATION-ID", accountDetails.AppId); req.Headers.Add("X-EgoPay-REQUEST-DATA-FORMAT", "NV"); req.Headers.Add("X-EgoPay-RESPONSE-DATA-FORMAT", "NV"); req.Headers.Add("X-EgoPay-DEVICE-IPADDRESS", ""); req.Headers.Add("X-EgoPay-REQUEST-SOURCE", "merchant-php-sdk-2.0.96"); //req.Headers.Add("X-EgoPay-SANDBOX-EMAIL-ADDRESS", "*****@*****.**"); req.Method = "POST"; req.ContentLength = dataToSend.Length; req.ContentType = "application/x-www-form-urlencoded"; var streamWriter = new StreamWriter(req.GetRequestStream(), Encoding.ASCII); streamWriter.Write(dataToSend); streamWriter.Close(); NameValuePairs content = null; using (var streamReader = new StreamReader(req.GetResponse().GetResponseStream())) { string result = streamReader.ReadToEnd(); content = NameValuePairs.Parse(result); } return(new EgoPayTransactionResponse(this, content)); }
internal EgoPayTransactionResponse(EgoPayAccount usedAccount, NameValuePairs response) { RawResponse = response.ToString(); UsedAccount = usedAccount; Note = string.Empty; string refNo; response.TryGetValue("responseEnvelope.correlationId", out refNo); ReferenceNumber = refNo; string success = ""; bool isAck = response.TryGetValue("paymentExecStatus", out success); IsSuccess = isAck && String.Equals(success, "COMPLETED", StringComparison.OrdinalIgnoreCase); if (!IsSuccess) { string severity, errorCode, message; if (!response.TryGetValue("error.severity", out severity)) { response.TryGetValue("error(0).severity", out severity); } if (!response.TryGetValue("error.errorId", out errorCode)) { response.TryGetValue("error(0).errorId", out errorCode); } if (!response.TryGetValue("error.message", out message)) { response.TryGetValue("error(0).message", out message); } Note = severity + " " + errorCode + ": " + message; } }
public HtmlReportModel( [NotNull] QualitySpecification qualitySpecification, [NotNull] IIssueStatistics statistics, [NotNull] XmlVerificationReport verificationReport, [NotNull] string outputDirectoryPath, [NotNull] string verificationReportName, [CanBeNull] string issueGeodatabasePath, [CanBeNull] IEnumerable <string> issueMapFilePaths, [NotNull] IEnumerable <string> htmlReportFileNames, [CanBeNull] IEnumerable <string> qualitySpecificationReportFilePaths, [NotNull] IHtmlDataQualityCategoryOptionsProvider categoryOptionsProvider) { Assert.ArgumentNotNull(qualitySpecification, nameof(qualitySpecification)); Assert.ArgumentNotNull(statistics, nameof(statistics)); Assert.ArgumentNotNull(verificationReport, nameof(verificationReport)); Assert.ArgumentNotNullOrEmpty(outputDirectoryPath, nameof(outputDirectoryPath)); Assert.ArgumentNotNullOrEmpty(verificationReportName, nameof(verificationReportName)); Assert.ArgumentNotNull(categoryOptionsProvider, nameof(categoryOptionsProvider)); _verificationReport = verificationReport; HtmlReportFiles = htmlReportFileNames.Select( fileName => new OutputFile( Path.Combine(outputDirectoryPath, fileName))) .ToList(); IssueMapFiles = issueMapFilePaths?.Select(path => new OutputFile(path)) .ToList() ?? new List <OutputFile>(); QualitySpecificationReportFiles = qualitySpecificationReportFilePaths?.Select(path => new OutputFile(path)) .ToList() ?? new List <OutputFile>(); Properties = new NameValuePairs(GetProperties(verificationReport.Properties)); QualitySpecification = qualitySpecification.Name; VerificationWasCancelled = verificationReport.Cancelled; HasVerificationExtent = verificationReport.TestExtent != null; if (verificationReport.TestExtent != null) { VerificationExtentString = HtmlReportUtils.FormatExtent( verificationReport.TestExtent); } if (verificationReport.AreaOfInterest != null) { AreaOfInterest = HtmlReportUtils.GetAreaOfInterest( verificationReport.AreaOfInterest); } OutputDirectoryPath = outputDirectoryPath; OutputDirectoryName = Assert.NotNull(Path.GetFileName(outputDirectoryPath)); OutputDirectoryRelativeUrl = HtmlReportUtils.GetRelativeUrl(string.Empty); OutputDirectoryAbsoluteUrl = outputDirectoryPath; VerificationReportName = verificationReportName; VerificationReportUrl = HtmlReportUtils.GetRelativeUrl(verificationReportName); if (IssueMapFiles.Count > 0) { OutputFile issueMapFile = IssueMapFiles[0]; MapDocumentName = issueMapFile.FileName; MapDocumentUrl = issueMapFile.Url; } IssueGeodatabaseName = Path.GetFileName(issueGeodatabasePath); List <HtmlReportDataQualityCategory> categories = HtmlReportUtils.GroupByCategories( statistics, new HtmlReportDataQualityCategoryComparer(), new HtmlReportQualityConditionComparer(), new HtmlReportIssueGroupComparer(), GetTestIdentifier, categoryOptionsProvider, out _issueGroups); CategoriesWithIssues = categories.Where(c => c.IssueGroups.Count > 0).ToList(); RootCategories = categories.Where(c => c.IsRoot).ToList(); HasWarnings = statistics.WarningCount > 0; HasErrors = statistics.ErrorCount > 0; HasIssues = !HasWarnings && !HasErrors; IssueCount = HtmlReportUtils.Format(statistics.WarningCount + statistics.ErrorCount); WarningCount = HtmlReportUtils.Format(statistics.WarningCount); ErrorCount = HtmlReportUtils.Format(statistics.ErrorCount); ExceptionCount = HtmlReportUtils.Format(statistics.ExceptionCount); TimeSpan t = TimeSpan.FromSeconds(verificationReport.ProcessingTimeSeconds); ProcessingTime = HtmlReportUtils.FormatTimeSpan(t); }
/// <summary> /// Tries to convert the string representation of the name or numeric value of one or more enumerated values to an equivalent enumerated object. /// In case of success the return value is <see langword="true"/> and parsed <see langword="enum"/> is returned in <paramref name="result"/> parameter. /// </summary> /// <param name="value">The <see cref="string">string</see> representation of the enumerated value or values to parse.</param> /// <param name="separator">In case of more values specifies the separator among the values. If <see langword="null"/> or is empty, then comma (<c>,</c>) separator is used.</param> /// <param name="ignoreCase">If <see langword="true"/>, ignores case; otherwise, regards case.</param> /// <param name="result">Returns the default value of <typeparamref name="TEnum"/>, if return value is <see langword="false"/>; otherwise, the parsed <see langword="enum"/> value.</param> /// <returns><see langword="false"/> if the <see cref="string">string</see> in <paramref name="value"/> parameter cannot be parsed as <typeparamref name="TEnum"/>; otherwise, <see langword="true"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="value"/> is <see langword="null"/>.</exception> public static bool TryParse(string value, string separator, bool ignoreCase, out TEnum result) { if (value == null) { Throw.ArgumentNullException(Argument.value); } // simple name match test (always case-sensitive) if (NameValuePairs.TryGetValue(value, out result)) { return(true); } var s = new StringSegmentInternal(value); s.Trim(); result = default(TEnum); if (s.Length == 0) { return(false); } // simple numeric value char c = s[0]; if (((c >= '0' && c <= '9') || c == '-' || c == '+') && s.TryParseIntQuick(underlyingInfo.IsSigned, underlyingInfo.MaxValue, out ulong numericValue)) { result = converter.ToEnum(numericValue); return(true); } // rest: flags enum or ignored case if (String.IsNullOrEmpty(separator)) { separator = EnumExtensions.DefaultParseSeparator; } ulong acc = 0UL; StringKeyedDictionary <ulong> dict = ignoreCase ? NameRawValuePairsIgnoreCase : NameRawValuePairs; while (s.TryGetNextSegment(separator, out StringSegmentInternal token)) { token.Trim(); if (token.Length == 0) { return(false); } // literal token found in dictionary if (dict.TryGetValue(token, out ulong tokens)) { acc |= tokens; continue; } // checking if is numeric token c = token[0]; if (((c >= '0' && c <= '9') || c == '-' || c == '+') && token.TryParseIntQuick(underlyingInfo.IsSigned, underlyingInfo.MaxValue, out numericValue)) { acc |= numericValue; continue; } // none of above return(false); } result = converter.ToEnum(acc); return(true); }