Beispiel #1
0
        /// <summary>
        /// Creates the transport document attachment.
        /// </summary>
        /// <returns>Task.</returns>
        public async Task CreateTransportDocumentAttachment()
        {
            long?id = ConsoleApp.AskId("Enter the Id of the CMR for which to upload the attachment");

            if (id.HasValue)
            {
                var    externalId = ConsoleApp.AskStringValue("ExternalId");
                string path       = ConsoleApp.AskStringValue("Enter the file name to the attachment to upload");
                if (!File.Exists(path))
                {
                    Console.WriteLine("File {0} does not exist", path);

                    return;
                }

                byte[] buffer  = File.ReadAllBytes(path);
                string content = Convert.ToBase64String(buffer);

                var attachment = new TransportDocumentAttachment
                {
                    ExternalId  = externalId,
                    DisplayName = Path.GetFileNameWithoutExtension(path),
                    Filename    = Path.GetFileName(path),
                    Content     = content,
                    MimeType    = System.Web.MimeMapping.GetMimeMapping(path),
                    Type        = "Delivery Note"
                };

                var response = await this.client.PostJsonAsync <TransportDocumentReturnState>(
                    new Uri($"{this.oauthSettings.BaseUrl}/api/v2/transportdocuments/{id.Value}/attachments"),
                    attachment);

                Console.WriteLine("Attachment created with id: {0}", response.Id);
            }
        }
        /// <summary>
        /// Gets the transport document as PDF.
        /// </summary>
        /// <returns>Task.</returns>
        public async Task GetTransportDocumentAsPdf()
        {
            long?id = ConsoleApp.AskId("Enter the Id of the CMR to retrieve");

            if (id.HasValue)
            {
                TransportDocumentAttachment transportDocumentPdf = await this.soapClient.GetTransportDocumentAsPdfAsync(id.Value);

                if (transportDocumentPdf != null)
                {
                    Console.WriteLine();
                    Console.WriteLine("CMR with ID " + transportDocumentPdf.Id.ToString() + " succesfully retrieved as pdf!");
                    Console.WriteLine();
                    Console.WriteLine();

                    byte[] content = Convert.FromBase64String(transportDocumentPdf.Content);
                    if (content != null)
                    {
                        string path = System.IO.Path.GetTempFileName() + ".pdf";
                        File.WriteAllBytes(path, content);
                        Process.Start(path);
                    }
                }
                else
                {
                    Console.WriteLine("CMR with ID {0} not found!", id);
                }
            }
        }