isotonicq

Untitled

Jan 8th, 2021 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using BST.ExternalDataImport.AttachmentServicer;
  6.  
  7. namespace BST.ExternalDataImport
  8. {
  9.     public sealed class AttachmentUploader
  10.     {
  11.         //WSDL directory: http://10.48.86.222:89/Methods/Attachments.asmx?wsdl
  12.        
  13.         //Private
  14.         private readonly AttachmentsSoapClient _client;
  15.         private readonly NetworkCredential _credentials;
  16.        
  17.         //CTOR
  18.         public AttachmentUploader()
  19.         {
  20.             _client = new AttachmentsSoapClient();
  21.             _credentials = new NetworkCredential();
  22.         }
  23.  
  24.         public async Task AddAttachment(string path, string productCode)
  25.         {
  26.             //Check if exist
  27.             if (!File.Exists(path)) throw new Exception($"File not exist: {path}");
  28.            
  29.             //Prepare value
  30.             FileInfo info = new FileInfo(path);
  31.            
  32.             AttachmentModel attachment = new AttachmentModel
  33.             {
  34.                 Barcode = productCode,
  35.                 Category = "Attachment",
  36.                 Extension = info.Extension,
  37.                 Name = info.Name,
  38.                 NamePl = "Nazwa PL",
  39.                 NameCz = "České jméno",
  40.                 NameEn = "Name ENG",
  41.                 Binary = Convert.ToBase64String(File.ReadAllBytes(path))
  42.             };
  43.            
  44.             //Send value
  45.             await _client.AddAttachmentAsync(_credentials, attachment, "PL");
  46.         }
  47.     }
  48. }
Add Comment
Please, Sign In to add comment