public void BinaryAttachment_ToString_1()
        {
            string name = "Name";

            byte[]           content    = { 1, 2, 3 };
            BinaryAttachment attachment = new BinaryAttachment(name, content);

            Assert.AreEqual("Name: 3 bytes", attachment.ToString());
        }
        public void BinaryAttachment_Construction_1()
        {
            string name = "Name";

            byte[]           content    = { 1, 2, 3 };
            BinaryAttachment attachment = new BinaryAttachment(name, content);

            Assert.AreSame(name, attachment.Name);
            Assert.AreSame(content, attachment.Content);
        }
Esempio n. 3
0
 public void ToAttachmentData_Binary()
 {
     byte[] bytes = new byte[] { 1, 2, 3 };
     var attachment = new BinaryAttachment("name", MimeTypes.Binary, bytes);
     AttachmentData attachmentData = attachment.ToAttachmentData();
     Assert.AreEqual("name", attachmentData.Name);
     Assert.AreEqual(MimeTypes.Binary, attachmentData.ContentType);
     Assert.AreEqual(bytes, attachmentData.GetBytes());
     Assert.AreEqual(AttachmentContentDisposition.Inline, attachmentData.ContentDisposition);
     Assert.AreEqual(AttachmentType.Binary, attachmentData.Type);
 }
Esempio n. 4
0
        public void ToAttachmentData_Binary()
        {
            byte[]         bytes          = new byte[] { 1, 2, 3 };
            var            attachment     = new BinaryAttachment("name", MimeTypes.Binary, bytes);
            AttachmentData attachmentData = attachment.ToAttachmentData();

            Assert.AreEqual("name", attachmentData.Name);
            Assert.AreEqual(MimeTypes.Binary, attachmentData.ContentType);
            Assert.AreEqual(bytes, attachmentData.GetBytes());
            Assert.AreEqual(AttachmentContentDisposition.Inline, attachmentData.ContentDisposition);
            Assert.AreEqual(AttachmentType.Binary, attachmentData.Type);
        }
Esempio n. 5
0
        public void Factuare_To_Pdf()
        {
            var fe32 = Factuare_Create_Simple_Invoice_And_validate();

            var logoPath = "https://a248.e.akamai.net/assets.github.com/images/modules/header/logov6-hover.png";

            var unedoc = fe32.ToPdf(logoPath);

            Assert.IsNotNull(unedoc);

            var attachmentData = new BinaryAttachment("invoice.pdf", "application/pdf", unedoc.ToArray());

            TestLog.Attach(attachmentData);
        }
Esempio n. 6
0
        public void ArsMagnaException_Attach_1()
        {
            ArsMagnaException exception  = new ArsMagnaException();
            BinaryAttachment  attachment = new BinaryAttachment
                                           (
                "first",
                new byte[] { 1, 2, 3 }
                                           );

            exception.Attach(attachment);
            BinaryAttachment[] attachments = exception.ListAttachments();
            Assert.AreEqual(1, attachments.Length);
            Assert.AreSame(attachment, attachments[0]);
            Assert.AreEqual("first", attachments[0].Name);
            Assert.AreEqual(3, attachments[0].Content.Length);
        }
        private static Attachment GetBinaryAttachment(UriDataAttachment vstsAttachment, string fileEx)
        {
            var mem = new MemoryStream();
            var f   = new FileStream(vstsAttachment.Uri.LocalPath, FileMode.Open, FileAccess.Read);

            mem.SetLength(f.Length);

            f.Read(mem.GetBuffer(), 0, (int)f.Length - 1);

            var mime = MimeTypes.GetMimeTypeByExtension(fileEx) ?? MimeTypes.Binary;

            var binaryAttachment = new BinaryAttachment(vstsAttachment.Description, mime, mem.ToArray());

            f.Close();
            mem.Close();

            return(binaryAttachment);
        }
Esempio n. 8
0
        public void ArsMagnaException_ToString_3()
        {
            ArsMagnaException exception = new ArsMagnaException("Something went wrong");

            byte[] array = new byte[100];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = (byte)i;
            }
            BinaryAttachment attachment = new BinaryAttachment
                                          (
                "first",
                array
                                          );

            exception.Attach(attachment);
            Assert.AreEqual("AM.ArsMagnaException: Something went wrong\n\nAttachment: first\n0000: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n0010: 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F\n0020: 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n0030: 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F\n0040: 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n0050: 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F\n0060: 60 61 62 63\n", exception.ToString().DosToUnix());
        }
Esempio n. 9
0
        public void ArsMagnaException_ToString_2()
        {
            ArsMagnaException exception   = new ArsMagnaException("Something went wrong");
            BinaryAttachment  attachment1 = new BinaryAttachment
                                            (
                "first",
                new byte[] { 1, 2, 3 }
                                            );

            exception.Attach(attachment1);
            BinaryAttachment attachment2 = new BinaryAttachment
                                           (
                "second",
                new byte[] { 3, 2, 1 }
                                           );

            exception.Attach(attachment2);
            Assert.AreEqual("AM.ArsMagnaException: Something went wrong\n\nAttachment: first\n0000: 01 02 03\n\nAttachment: second\n0000: 03 02 01\n", exception.ToString().DosToUnix());
        }
Esempio n. 10
0
        public void ArsMagnaException_Attach_2()
        {
            ArsMagnaException exception   = new ArsMagnaException();
            BinaryAttachment  attachment1 = new BinaryAttachment
                                            (
                "first",
                new byte[] { 1, 2, 3 }
                                            );

            exception.Attach(attachment1);
            BinaryAttachment attachment2 = new BinaryAttachment
                                           (
                "second",
                new byte[] { 3, 2, 1 }
                                           );

            exception.Attach(attachment2);
            BinaryAttachment[] attachments = exception.ListAttachments();
            Assert.AreEqual(2, attachments.Length);
            Assert.AreSame(attachment1, attachments[0]);
            Assert.AreSame(attachment2, attachments[1]);
        }
Esempio n. 11
0
        /// <summary>
        /// Throw <see cref="IrbisNetworkException"/>
        /// if the record is empty.
        /// </summary>
        private static void _ThrowIfEmptyRecord
        (
            [NotNull] MarcRecord record,
            [NotNull] string line
        )
        {
            Sure.NotNull(record, "record");
            Sure.NotNull(line, "line");

            if (ThrowOnEmptyRecord &&
                record.Fields.Count == 0
                )
            {
                Log.Error
                (
                    "BatchAccessor::ThrowIfEmptyRecord: "
                    + "empty record detected"
                );

                byte[] bytes   = Encoding.UTF8.GetBytes(line);
                string dump    = IrbisNetworkUtility.DumpBytes(bytes);
                string message = string.Format
                                 (
                    "Empty record in BatchAccessor:{0}{1}",
                    Environment.NewLine,
                    dump
                                 );

                IrbisNetworkException exception  = new IrbisNetworkException(message);
                BinaryAttachment      attachment = new BinaryAttachment
                                                   (
                    "response",
                    bytes
                                                   );
                exception.Attach(attachment);
                throw exception;
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Throw <see cref="IrbisNetworkException"/>
        /// if the record is empty.
        /// </summary>
        public static void ThrowIfEmptyRecord
        (
            [NotNull] MarcRecord record,
            [NotNull] ServerResponse response
        )
        {
            Sure.NotNull(record, nameof(record));
            Sure.NotNull(response, nameof(response));

            if (record.Fields.Count == 0)
            {
                byte[] bytes   = response.GetAnswerCopy();
                string dump    = DumpBytes(bytes);
                string message = string.Format
                                 (
                    "Empty record detected:{0}{1}",
                    Environment.NewLine,
                    dump
                                 );

                Log.Error
                (
                    "IrbisNetworkUtility::ThrowIfEmptyRecord: "
                    + "empty record detected"
                );

                IrbisNetworkException exception
                    = new IrbisNetworkException(message);
                BinaryAttachment attachment = new BinaryAttachment
                                              (
                    "response",
                    bytes
                                              );
                exception.Attach(attachment);
                throw exception;
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Exception occurs.
        /// </summary>
        protected void OnException
        (
            [NotNull] ExecutionContext context
        )
        {
            Sure.NotNull(context, nameof(context));
            Log.Trace(nameof(AbstractEngine) + "::" + nameof(OnException));

            // TODO Implement properly!

            if (context.Exception is ArsMagnaException exception &&
                context.Connection is IrbisConnection connection)
            {
                if (!ReferenceEquals(connection.RawClientRequest, null))
                {
                    BinaryAttachment request = new BinaryAttachment
                                               (
                        "request",
                        connection.RawClientRequest
                                               );
                    exception.Attach(request);
                }

                if (!ReferenceEquals(connection.RawServerResponse, null))
                {
                    BinaryAttachment response = new BinaryAttachment
                                                (
                        "response",
                        connection.RawServerResponse
                                                );
                    exception.Attach(response);
                }
            }

            ExceptionOccurs?.Invoke(this, new ExecutionEventArgs(context));
        }
Esempio n. 14
0
        public string GetUtfString()
        {
            using (MemoryStream memory = Connection.Executive
                                         .GetMemoryStream(GetType()))
            {
                _savedPosition = _stream.Position;
                while (true)
                {
                    int code = _stream.ReadByte();
                    if (code < 0)
                    {
                        return(null);
                    }
                    if (code == 0x0D)
                    {
                        code = _stream.ReadByte();
                        if (code == 0x0A)
                        {
                            break;
                        }
                        memory.WriteByte(0x0D);
                    }
                    memory.WriteByte((byte)code);
                }

                string result;
                byte[] buffer = memory.ToArray();
                Connection.Executive.ReportMemoryUsage
                (
                    GetType(),
                    buffer.Length
                );
                try
                {
                    result = IrbisEncoding.Utf8.GetString
                             (
                        buffer,
                        0,
                        buffer.Length
                             );
                }
                catch (Exception inner)
                {
                    Log.TraceException
                    (
                        "ServerResponse::GetUtfString",
                        inner
                    );

                    IrbisException outer = new IrbisException
                                           (
                        "ServerResponse::GetUtfString failed",
                        inner
                                           );
                    BinaryAttachment attachment = new BinaryAttachment
                                                  (
                        "problem line",
                        GetDump()
                                                  );
                    outer.Attach(attachment);
                    throw outer;
                }

                return(result);
            }
        }
        private static Attachment GetBinaryAttachment(UriDataAttachment vstsAttachment, string fileEx)
        {
            var mem = new MemoryStream();
            var f = new FileStream(vstsAttachment.Uri.LocalPath, FileMode.Open, FileAccess.Read);
            mem.SetLength(f.Length);

            f.Read(mem.GetBuffer(), 0, (int)f.Length -1);

            var mime = MimeTypes.GetMimeTypeByExtension(fileEx) ?? MimeTypes.Binary;

            var binaryAttachment = new BinaryAttachment(vstsAttachment.Description, mime, mem.ToArray());

            f.Close();
            mem.Close();

            return binaryAttachment;
          
        }
Esempio n. 16
0
        public void Factuare_To_Pdf()
        {
            var fe32 = Factuare_Create_Simple_Invoice_And_validate();

            var logoPath = "https://a248.e.akamai.net/assets.github.com/images/modules/header/logov6-hover.png";

            var unedoc = fe32.ToPdf(logoPath);

            Assert.IsNotNull(unedoc);

            var attachmentData = new BinaryAttachment("invoice.pdf", "application/pdf",unedoc.ToArray());

            TestLog.Attach(attachmentData);
        }