public override string ToString() { var result = $@"Path: {Path} Parameters: {Parameters?.Aggregate("", (curr, next) => curr + (curr.Length > 0 ? ", " : "") + next)} "; if (Delete != null) { result += $@"Delete: {Delete} "; } if (Get != null) { result += $@"Get: {Get} "; } if (Head != null) { result += $@"Head: {Head} "; } if (Options != null) { result += $@"Options: {Options} "; } if (Patch != null) { result += $@"Patch: {Patch} "; } if (Post != null) { result += $@"Post: {Post} "; } if (Put != null) { result += $@"Put: {Put} "; } return(result); }
internal string GetRequestBody() { switch (ContentType) { case ContentTypes.FormUrlEncoded: var parameters = Parameters.Aggregate("", (s, pair) => s + string.Format("{0}{1}={2}", s.Length > 0 ? "&" : "", Uri.EscapeDataString(pair.Key), Uri.EscapeDataString(pair.Value.ToString()))); return(parameters); case ContentTypes.Xml: throw new NotImplementedException("Sending XML is not yet supported, but will be added in a future release."); default: return(Parameters.Count > 0 ? JsonConvert.SerializeObject(Parameters[0].Value) : ""); } }
/// <summary> /// /// </summary> /// <returns></returns> internal string GetRequestBody() { switch (ContentType) { case ContentTypes.FormUrlEncoded: var parameters = Parameters.Aggregate(new StringBuilder(), (current, next) => current.Append(string.Format("{0}{1}={2}", current.Length > 0 ? "&" : "", Uri.EscapeDataString(next.Key), next.GetEncodedValue()))); return(parameters.ToString()); case ContentTypes.Xml: var result = ""; if (Parameters.Count == 0) { return(result); } var type = Parameters[0].Value.GetType(); var serializer = new DataContractSerializer(type); using (var stream = new MemoryStream()) { serializer.WriteObject(stream, Parameters[0].Value); result = Encoding.UTF8.GetString(stream.ToArray(), 0, (int)stream.Length); } if (IgnoreXmlAttributes || string.IsNullOrWhiteSpace(result)) { return(result); } var doc = XElement.Parse(result); //Clean all of the DataContract namespaces from the payload. doc.Attributes().Remove(); Transform(IgnoreRootElement ? doc.Descendants().First() : doc, Parameters[0].Value.GetType()); return(doc.ToString()); default: return(Parameters.Count > 0 ? JsonConvert.SerializeObject(Parameters[0].Value, JsonSerializerSettings) : ""); } }
private long CalculateContentLength() { if (RequestBodyBytes == null) { if (HasFiles || AlwaysMultipartFormData) { long num = 0L; foreach (HttpFile file in Files) { num += Encoding.GetByteCount(GetMultipartFileHeader(file)); num += file.ContentLength; num += Encoding.GetByteCount("\r\n"); } num = Parameters.Aggregate(num, (long current, HttpParameter param) => current + Encoding.GetByteCount(GetMultipartFormData(param))); return(num + Encoding.GetByteCount(GetMultipartFooter())); } return(encoding.GetByteCount(RequestBody)); } return(RequestBodyBytes.Length); }
public override List <PriceRecord> GetPriceRecords(DateTime lastDateTime) { if (!IsAvailable) { return(new List <PriceRecord>()); } var priceRecords = new List <PriceRecord>(); var tickerUrl = Properties.Settings.Default.RavaUrl + "?"; tickerUrl = Parameters.Aggregate(tickerUrl, (current, parameter) => current + (parameter.Key + "=" + parameter.Value + "&")); tickerUrl = tickerUrl.TrimEnd(new [] { '&' }); var client = new WebClient(); var input = client.DownloadString(tickerUrl); var matchSymbolValues = Regex.Matches(input, @"<td>(\d{2})\/(\d{2})\/(\d{2})<\/td><td>(\d[\d.,]+)<\/td><td>(\d[\d.,]+)<\/td><td>(\d[\d.,]+)<\/td><td>(\d[\d.,]+)<\/td><td>(\d[\d.,]+)", RegexOptions.Singleline); foreach (Match match in matchSymbolValues) { var date = new DateTime(Int32.Parse("20" + match.Groups[3].Value), Int32.Parse(match.Groups[2].Value), Int32.Parse(match.Groups[1].Value)); if (date <= lastDateTime) { break; } var pr = new PriceRecord(new MetaLibDate(date), float.Parse(match.Groups[4].Value), float.Parse(match.Groups[5].Value), float.Parse(match.Groups[6].Value), float.Parse(match.Groups[7].Value), float.Parse(match.Groups[8].Value)); priceRecords.Add(pr); } priceRecords = priceRecords.OrderBy(x => x.Date.Date).ToList(); return(priceRecords); }
public string GetParametersString() { string paramString = Parameters.Aggregate("", (x, y) => { if (y.VarArgs) { x += $", params {y.Type.ManagedType}[] {y.Name}"; } else { x += $", {y.Type.ManagedType} {y.Name}"; } if (string.IsNullOrEmpty(y.DefaultValue)) { return(x); } if (y.DefaultValue.Contains("::")) { x += " = null"; } else if (y.Type.DataType == DataType.Struct) { x += " = null"; } else if (y.Type.ManagedType.Equals("float") && !y.DefaultValue.EndsWith("f")) { x += " = " + y.DefaultValue + "f"; } else { x += " = " + y.DefaultValue; } return(x); }); if (paramString.Length > 0) { paramString = paramString.Substring(2); } return(paramString); }
public string GetNativeArgsString() { if (IsStringlyTyped != null && IsStringlyTyped.Value) { return("argc, argv"); } string argString = Parameters.Aggregate("", (x, y) => { if (y.VarArgs) { return($"{x}, {y.Name}_c, {y.Name}_v"); } return($"{x}, {y.Name}"); }); if (argString.Length > 0) { argString = argString.Substring(2); } return(argString); }
public override int GetHashCode() { return(Parameters.Aggregate(0, (seed, next) => seed ^ next)); }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public override int GetHashCode() { var hash = MemberName.GetHashCode(); return(Parameters.Aggregate(hash, (a, b) => a ^ b.GetHashCode())); }
private void compileRequestParams(Configuration configuration) { HttpWebRequest request; if (configuration.Method == "POST") { request = (HttpWebRequest)WebRequest.Create(RequestUri); request.Method = configuration.Method; request.Headers.Add(Configuration.Headers["AppKey"], configuration.AppKey); request.Headers.Add(Configuration.Headers["AppId"], configuration.AppId); request.UserAgent = configuration.UserAgent; var postData = Parameters.Aggregate("", (memo, pair) => "&" + pair.First().Key + "=" + Uri.EscapeDataString(pair.First().Value) + memo ).Substring(1); var data = Encoding.UTF8.GetBytes(postData); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; using (var stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); stream.Close(); } } else if (configuration.Method == "GET") { var query = Parameters.Aggregate("", (memo, pair) => "&" + pair.First().Key + "=" + Uri.EscapeDataString(pair.First().Value) + memo ); if (query != null && query.Length > 2) { query = query.Substring(1); } if (Parameters.Count > 0) { request = (HttpWebRequest)WebRequest.Create(RequestUri + "?" + query); } else { request = (HttpWebRequest)WebRequest.Create(RequestUri); } request.Method = configuration.Method; request.Headers.Add(Configuration.Headers["AppKey"], configuration.AppKey); request.Headers.Add(Configuration.Headers["AppId"], configuration.AppId); request.UserAgent = configuration.UserAgent; } else { throw new ArgumentException("Method should be GET or POST."); } Request = request; }
public override string ToString() => $"{Modifier} {Name}(" + Parameters.Aggregate("", (a, b) => a + ", " + b.Name + ":" + b.Type).TrimStart(", ".ToCharArray()) + ")" + (string.IsNullOrWhiteSpace(ReturnType) ? "" : " : " + ReturnType);
public override int GetHashCode() => Parameters.Aggregate(ReturnType.GetHashCode(), (p1, p2) => p1.GetHashCode() ^ p2.GetHashCode()) ^ CallingConvention.GetHashCode() ^ ExceptionSpecType.GetHashCode();
public override string ToString() { return($"{Name}({Parameters.Aggregate("", (x, y) => x.ToString() + ", " + y.ToString())})"); }