本文整理汇总了C#中System.Collections.Queue.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Cast方法的具体用法?C# Queue.Cast怎么用?C# Queue.Cast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Queue
的用法示例。
在下文中一共展示了Queue.Cast方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CallRestApi
private static string CallRestApi(IEnumerable<KeyValuePair<string, string>> arguments, IEnumerable<IDictionary<string, byte[]>> attachments)
{
const string newLine = "\r\n";
const string bounds = "--------------------------------";
const string bounds2 = "--" + bounds;
var encoding = new ASCIIEncoding();
var utf8Encoding = new UTF8Encoding();
var http = (HttpWebRequest)WebRequest.Create(_url);
http.Method = "POST";
http.AllowWriteStreamBuffering = true;
http.ContentType = "multipart/form-data; boundary=" + bounds;
var parts = new Queue();
foreach (var argument in arguments)
{
parts.Enqueue(encoding.GetBytes(bounds2 + newLine));
parts.Enqueue(encoding.GetBytes("Content-Type: text/plain; charset=\"utf-8\"" + newLine));
parts.Enqueue(encoding.GetBytes(String.Format("Content-Disposition: form-data; name=\"{0}\"{1}{1}", argument.Key, newLine)));
parts.Enqueue(utf8Encoding.GetBytes(argument.Value));
parts.Enqueue(encoding.GetBytes(newLine));
}
if (attachments != null)
{
foreach (Dictionary<string, byte[]> attachment in attachments)
{
parts.Enqueue(encoding.GetBytes(bounds2 + newLine));
parts.Enqueue(encoding.GetBytes("Content-Disposition: form-data; name=\""));
parts.Enqueue(attachment["name"]);
parts.Enqueue(encoding.GetBytes("\"; filename=\""));
parts.Enqueue(attachment["filename"]);
parts.Enqueue(encoding.GetBytes("\"" + newLine));
parts.Enqueue(encoding.GetBytes("Content-Transfer-Encoding: base64" + newLine));
parts.Enqueue(encoding.GetBytes("Content-Type: "));
parts.Enqueue(attachment["contenttype"]);
parts.Enqueue(encoding.GetBytes(newLine + newLine));
parts.Enqueue(attachment["data"]);
parts.Enqueue(encoding.GetBytes(newLine));
}
}
parts.Enqueue(encoding.GetBytes(bounds2 + "--"));
var nContentLength = parts.Cast<byte[]>().Sum(part => part.Length);
http.ContentLength = nContentLength;
var stream = http.GetRequestStream();
foreach (Byte[] part in parts)
stream.Write(part, 0, part.Length);
stream.Close();
var r = http.GetResponse().GetResponseStream();
if (r != null)
{
var reader = new StreamReader(r);
var retValue = reader.ReadToEnd();
reader.Close();
return retValue;
}
throw new Exception("HTTP response stream is null.");
}