Ejemplo n.º 1
0
        void NetworkReadCallback(IAsyncResult ar)
        {
            var count = 0;

            try
            {
                count = AsyncData.Stream.EndRead(ar);
                if (count > 0)
                {
                    ResultStream.Write(_buffer, 0, count);
                }
            }
            catch (Exception exception)
            {
                AsyncData.Exception = exception;
                CompleteCallback();

                return;
            }

            if (count == 0)
            {
                ProcessFinalResponse();
                ResultStream.Seek(0, SeekOrigin.Begin);
                CompleteCallback();
            }
            else
            {
                AsyncData.Stream.BeginRead(_buffer, 0, _buffer.Length, NetworkReadCallback, this);
            }
        }
Ejemplo n.º 2
0
 public Stream AsStream()
 {
     if (ResultStream.CanSeek)
     {
         ResultStream.Seek(0, SeekOrigin.Begin);
     }
     return(ResultStream);
 }
Ejemplo n.º 3
0
        public string AsString()
        {
            if (ResultStream.CanSeek)
            {
                ResultStream.Seek(0, SeekOrigin.Begin);
            }
            var retv = Fi.StandardEncoding.GetString(AsBuffer());

            return(retv);
        }
Ejemplo n.º 4
0
 public MemoryStream AsSeekableStream()
 {
     if (ResultStream.CanSeek)
     {
         ResultStream.Seek(0, SeekOrigin.Begin);
     }
     using (ResultStream) {
         var ms = new MemoryStream();
         ResultStream.CopyTo(ms);
         ResultStream.Flush();
         return(ms);
     }
 }
Ejemplo n.º 5
0
        public void SubmitToStream(BuiltinReportDescriptor descriptor)
        {
            /* load the master template */
            var raw = LoadTemplate("builtinreport.ent", descriptor.m);

            /* do we need the JS libraries of amline? */
            if (NeedsAMJSLines)
            {
                var flashscript = LoadTemplate("am_embed_js.html", descriptor.m);
                raw.Set("flashscript", flashscript.ToString());
            }
            else
            {
                raw.Set("flashscript", String.Empty); /* added [dlatikay 20120202] */
            }
            /* perform the replacements */
            raw.Set("title", descriptor.ReportPageTitle);
            raw.Set("dqp", descriptor.DQP);                                                                          /* added [dlatikay 20120209] */
            raw.Set("onloadaction", descriptor.Outputformat == FileType.ft_html ? "window.print();" : String.Empty); /* added [dlatikay 20120209] */
            raw.Set("header", header == null ? String.Empty : header.ToString());
            raw.Set("meta", meta == null ? String.Empty : meta.ToString());
            var compositecontent = new StringBuilder();
            var partcounter      = 0;

            foreach (var part in parts)
            {
                compositecontent.AppendFormat("{1}{0}{2}", part.ToString(), (((++partcounter) <= 1) ? String.Empty : "<!-- section ruler -->"), Environment.NewLine);
            }
            raw.Set("rendition", compositecontent.ToString());
            raw.Set("footer", String.Format("<span id=\"builtinreport_footer\">{0}</span>", HttpUtility.HtmlEncode(String.Format(descriptor.m(3252), descriptor.Systemname, descriptor.Systemversion, descriptor.ReportCreationTimestamp)))); /* Created using en-software SHERM v2.1 */
            raw.Set("onafterprint", descriptor.Outputformat == dal.business.FileType.ft_pdf ? "JavaScript:window.location.href='about:blank';" : String.Empty);                                                                               /* when we are rendering a pdf, we will print it to the postscript printer. therefore we need this to allow the silent host browser to detect when printing has finished */

            /* [dlatikay 20111202] if we want html, we get html;
             * stream it out: */
            if (descriptor.Outputformat == dal.business.FileType.ft_html)
            {
                byte[] html = System.Text.UTF8Encoding.UTF8.GetBytes(raw.ToString());
                ResultStream.Write(html, 0, html.Length);
            }
            /* reset if can */
            if (ResultStream.CanSeek)
            {
                ResultStream.Seek(0, SeekOrigin.Begin);
            }
        }
Ejemplo n.º 6
0
        //public Stream AsRawStream() {
        //    var rawStream = new MemoryStream();
        //    using (var writer = new StreamWriter(rawStream, new UTF8Encoding(), 8192, true)) {
        //        writer.WriteLine($"HTTP/1.1 {StatusCode} {StatusDescription}");
        //        lock (this.Headers) {
        //            this.Headers.ForEach(header => {
        //                writer.WriteLine();
        //            });
        //        }
        //        writer.WriteLine();
        //    }
        //    ResultStream.CopyTo(rawStream);
        //    rawStream.Seek(0, SeekOrigin.Begin);
        //    return rawStream;
        //}

        public byte[] AsBuffer()
        {
            if (ResultStream.CanSeek)
            {
                ResultStream.Seek(0, SeekOrigin.Begin);
            }
            byte[] bytes;
            if (ResultStream is MemoryStream rsms)
            {
                bytes = rsms.ToArray();
            }
            else
            {
                using (var ms = new MemoryStream()) {
                    ResultStream.CopyTo(ms);
                    ms.Seek(0, SeekOrigin.Begin);
                    bytes = ms.ToArray();
                }
            }
            return(bytes);
        }
Ejemplo n.º 7
0
 public async Task SaveToFile(IFileSystem fs, string fileName)
 {
     ResultStream.Seek(0, SeekOrigin.Begin);
     await fs.Write(fileName, async stream => await ResultStream.CopyToAsync(stream));
 }
Ejemplo n.º 8
0
 public byte[] AsDecodedBuffer(IEncryptionMethod method)
 {
     ResultStream.Seek(0, SeekOrigin.Begin);
     return(method.Decrypt(AsBuffer()));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 请求处理最后的内容
 /// </summary>
 protected virtual void ProcessFinalResponse()
 {
     ResultStream.Seek(0, SeekOrigin.Begin);
 }