/// <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); } } }
/// <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) { string url = $"{this.oauthSettings.BaseUrl}api/v2/transportdocuments/{id.Value.ToString()}"; await this.client.SetTokenAsync(); this.client.DefaultRequestHeaders.Accept.Clear(); this.client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/pdf")); HttpResponseMessage response = await this.client.GetAsync(url); if (response.StatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine(); Console.WriteLine($"CMR with ID {id.ToString()} succesfully retrieved as pdf!"); Console.WriteLine(); Console.WriteLine(); byte[] content = await response.Content.ReadAsByteArrayAsync(); if (content != null) { System.IO.File.WriteAllBytes("c:\\ecmr.pdf", content); Process.Start("c:\\ecmr.pdf"); } } else { Console.WriteLine($"CMR with ID {id} not found!"); } } }
/// <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> /// Prints the transport document. /// </summary> /// <returns>Task.</returns> public Task PrintTransportDocument() { long?id = ConsoleApp.AskId("Enter the Id of the CMR to print."); if (id.HasValue) { // TBD } return(Task.FromResult(0)); }
/// <summary> /// Issues the transport document. /// </summary> /// <returns>Task.</returns> public async Task IssueTransportDocument() { long?id = ConsoleApp.AskId("Enter the Id of the CMR to issue."); if (id.HasValue) { var state = await this.client.PostJsonAsync <TransportDocumentReturnState>(new Uri($"{this.oauthSettings.BaseUrl}/api/v2/transportdocuments/{id.Value}/issue"), null); DumpReturnState(state); } }
/// <summary> /// Gets the transport document states. /// </summary> /// <returns>Task.</returns> public async Task GetTransportDocumentStates() { long?id = ConsoleApp.AskId("Enter the Id of the CMR for which to retrieve the state"); if (id.HasValue) { var states = await this.client.GetAsync <TransportDocumentReturnState[]>($"{this.oauthSettings.BaseUrl}/api/v2/transportdocuments/states?ids={id.Value}"); DumpStates(states); } }
/// <summary> /// Issues if necessary and sends a print request to the Xynaps Agent. /// </summary> /// <returns>Task.</returns> public async Task PrintTransportDocument() { long?id = ConsoleApp.AskId("Enter the Id of the CMR to print."); if (id.HasValue) { var document = await this.soapClient.PrintTransportDocumentAsync(id.Value, "Microsoft XPS Document Writer"); DumpReturnState(document); } }
/// <summary> /// Gets the transport document states. /// </summary> /// <returns>Task.</returns> public async Task GetTransportDocumentStates() { long?id = ConsoleApp.AskId("Enter the Id of the CMR for which to retrieve the state"); if (id.HasValue) { var states = await this.soapClient.GetTransportDocumentStateByIdsAsync(new long[] { id.Value }, 1, 10); DumpStates(states); } }
/// <summary> /// Gets the transport document attachments. /// </summary> /// <returns>Task.</returns> public async Task GetTransportDocumentAttachments() { long?id = ConsoleApp.AskId("Enter the Id of the CMR for which to retrieve the attachments"); if (id.HasValue) { var attachments = await this.client.GetAsync <TransportDocumentAttachment[]>($"{this.oauthSettings.BaseUrl}/api/v2/transportdocuments/{id.Value}/attachments"); foreach (var attachment in attachments) { Console.WriteLine("{0} - {1}: {2}", attachment.Id, attachment.DisplayName, attachment.Uri); } } }
/// <summary> /// Issues the transport document. /// </summary> /// <returns>Task.</returns> public async Task IssueTransportDocument() { long?id = ConsoleApp.AskId("Enter the Id of the CMR to issue."); if (id.HasValue) { var document = await this.soapClient.GetTransportDocumentByIdAsync(id.Value); document.State = State.Issued; var state = await this.soapClient.UpdateTransportDocumentAsync(document); DumpReturnState(state); } }
/// <summary> /// Gets the transport document attachments. /// </summary> /// <returns>Task.</returns> public async Task GetTransportDocumentAttachments() { long?id = ConsoleApp.AskId("Enter the Id of the CMR for which to retrieve the attachments"); if (id.HasValue) { var attachments = await this.soapClient.GetTransportDocumentAttachmentsAsync(id.Value); foreach (var attachment in attachments) { Console.WriteLine("{0} - {1}: {2}", attachment.Id, attachment.DisplayName, attachment.Uri); } } }
/// <summary> /// Gets the transport document. /// </summary> /// <returns>Task.</returns> public async Task GetTransportDocument() { long?id = ConsoleApp.AskId("Enter the Id of the CMR to retrieve"); if (id.HasValue) { TransportDocument transportDocument = await this.GetTransportDocument(id.Value); if (transportDocument != null) { Console.WriteLine(); Console.WriteLine("CMR with ID " + transportDocument.Id.ToString() + " succesfully retrieved!"); Console.WriteLine(); Console.WriteLine(); } else { Console.WriteLine("CMR with ID {0} not found!", id); } } }
/// <summary> /// Updates the transport document. /// </summary> /// <returns>Task.</returns> public async Task UpdateTransportDocument() { var id = ConsoleApp.AskId("Enter the Id of the CMR to update"); TransportDocument newDocument = new TransportDocument { Id = id, TransportExecutions = new TransportExecution[] { new TransportExecution { Driver = new Driver { Name = "John Doe 3", ExternalId = "JOHNDOE_12" }, Truck = new Vehicle { ExternalId = "123459", LicensePlate = "5-JNK-716" }, Trailer = new Vehicle { ExternalId = "678990", LicensePlate = "5-TRV-388" }, } } }; var state = await this.client.PostJsonAsync <TransportDocumentReturnState>(new Uri(this.oauthSettings.BaseUrl + "/api/v2/transportdocuments"), newDocument); if (state != null) { Console.WriteLine("CMR succesfully created!"); DumpReturnState(state); } }
/// <summary> /// Updates the transport document. /// </summary> /// <returns>Task.</returns> public async Task UpdateTransportDocument() { var id = ConsoleApp.AskId("Enter the Id of the CMR to update"); TransportDocument newDocument = new TransportDocument { Id = id, TransportExecutions = new TransportExecution[] { new TransportExecution { Driver = new Driver { Name = "John Doe 3", ExternalId = "JOHNDOE_12" }, Truck = new Vehicle { ExternalId = "123459", LicensePlate = "5-JNK-716" }, Trailer = new Vehicle { ExternalId = "678990", LicensePlate = "5-TRV-388" }, } } }; TransportDocumentReturnState state = await this.soapClient.CreateTransportDocumentAsync(newDocument); if (state != null) { Console.WriteLine("CMR succesfully created!"); DumpReturnState(state); } }