asafgb

Untitled

Jan 5th, 2021
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. [FunctionName("'")]
  2.         public static void Run([EventGridTrigger]EventGridEvent eventGridEvent, ILogger log)
  3.         {
  4.             Logger.instace.Init(log);
  5.             log.LogInformation(eventGridEvent.Data.ToString());
  6.             JsonApi jsonApi = Newtonsoft.Json.JsonConvert.DeserializeObject<JsonApi>(eventGridEvent.Data.ToString());
  7.  
  8.             if(jsonApi.contentType == "text/xml")
  9.                 TakeCareFile(jsonApi);
  10.  
  11.         }
  12.  
  13.         public static async void TakeCareFile(JsonApi jsonApi)
  14.         {
  15.             string connectionString = Static.AccessKey;//Environment.GetEnvironmentVariable();
  16.             string destinationFile = jsonApi.url.Split('/')[4];
  17.             CloudStorageAccount storageAccount;
  18.  
  19.             if (CloudStorageAccount.TryParse(connectionString, out storageAccount))
  20.             {
  21.                 CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
  22.                 CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("ids");
  23.                 await cloudBlobContainer.CreateIfNotExistsAsync();
  24.  
  25.                 CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(destinationFile);
  26.  
  27.                 Console.WriteLine("Downloading blob to {0}", destinationFile);
  28.                 Stream Read = await cloudBlockBlob.OpenReadAsync();
  29.                 //await cloudBlockBlob.DownloadToFileAsync(destinationFile, FileMode.Create);
  30.  
  31.                 using var sr = new StreamReader(Read, Encoding.UTF8);
  32.                 string line = String.Empty;
  33.                 string XMLdata=sr.ReadToEnd();
  34.  
  35.                 await cloudBlockBlob.DeleteIfExistsAsync();
  36.  
  37.  
  38.  
  39.             }
  40.         }
Advertisement
Add Comment
Please, Sign In to add comment