当前位置: 首页>>代码示例>>C#>>正文


C# Queue.Cast方法代码示例

本文整理汇总了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.");
        }
开发者ID:kenny-evitt,项目名称:FogBugz-XML-API-Client,代码行数:67,代码来源:FogBugzClient.cs


注:本文中的System.Collections.Queue.Cast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。