Exemplo n.º 1
0
 private void SerializeAttachment(XRoadAttachment attachment, string boundaryMarker)
 {
     writer.Write(NEW_LINE);
     writer.Write("--{0}", boundaryMarker);
     writer.Write(NEW_LINE);
     writer.Write("Content-Disposition: attachment; filename=notAnswering");
     writer.Write(NEW_LINE);
     writer.Write("Content-Type: application/octet-stream");
     writer.Write(NEW_LINE);
     writer.Write("Content-Transfer-Encoding: base64");
     writer.Write(NEW_LINE);
     writer.Write("Content-ID: <{0}>", attachment.ContentID.Trim('<', '>', ' '));
     writer.Write(NEW_LINE);
     writer.Write(NEW_LINE);
     attachment.WriteAsBase64(writer);
 }
Exemplo n.º 2
0
        private void SerializeXopAttachment(XRoadAttachment attachment, string boundaryMarker)
        {
            writer.Write(NEW_LINE);
            writer.Write("--{0}", boundaryMarker);
            writer.Write(NEW_LINE);
            writer.Write("Content-Type: application/octet-stream");
            writer.Write(NEW_LINE);
            writer.Write("Content-Transfer-Encoding: binary");
            writer.Write(NEW_LINE);
            writer.Write("Content-ID: <{0}>", attachment.ContentID.Trim('<', '>', ' '));
            writer.Write(NEW_LINE);
            writer.Write(NEW_LINE);
            writer.Flush();

            attachment.ContentStream.Position = 0;
            attachment.ContentStream.CopyTo(outputStream);
            outputStream.Flush();
        }
Exemplo n.º 3
0
        private bool ReadMessageParts(XRoadMessage target)
        {
            if (!IsMultipartMsg(contentTypeHeader))
            {
                ReadNextPart(target.ContentStream, GetByteDecoder(null), target.ContentEncoding, null);
                target.ContentLength = streamPosition;
                return(false);
            }

            target.MultipartContentType = GetMultipartContentType();
            var multipartStartContentID = GetMultipartStartContentID();
            var multipartBoundary       = GetMultipartBoundary();
            var multipartBoundaryMarker = target.ContentEncoding.GetBytes("--" + multipartBoundary);
            var multipartEndMarker      = target.ContentEncoding.GetBytes("--" + multipartBoundary + "--");

            byte[] lastLine = null;

            do
            {
                if (!BufferStartsWith(lastLine, multipartBoundaryMarker))
                {
                    lastLine = ReadLine();
                    continue;
                }

                string partID, partTransferEncoding;
                ExtractMultipartHeader(target.ContentEncoding, out partID, out partTransferEncoding);

                var targetStream = target.ContentStream;
                if (targetStream.Length > 0 || (!string.IsNullOrEmpty(multipartStartContentID) && !multipartStartContentID.Contains(partID)))
                {
                    var attachment = new XRoadAttachment(partID, Path.Combine(storagePath, Path.GetRandomFileName()));
                    target.AllAttachments.Add(attachment);
                    targetStream = attachment.ContentStream;
                }

                lastLine = ReadNextPart(targetStream, GetByteDecoder(partTransferEncoding), target.ContentEncoding, multipartBoundaryMarker);
            } while (PeekByte() != -1 && !BufferStartsWith(lastLine, multipartEndMarker));

            target.ContentLength = streamPosition;

            return(true);
        }