public static async Task FnCompareFiles( [QueueTrigger("nextazureipfile", Connection = "FileStorAcc")] string fileName, ILogger log) { var containerName = Environment.GetEnvironmentVariable("region"); var storage = new StorageProvider(); // in case of multiple runs check so see if there's already a delta - set to run as singleton , so this is belt and brace var existingDelta = await storage.FileExistsBlobStorageAsync(containerName, $"{fileName}.delta"); if (existingDelta) { log.LogInformation($"Existing Delta found for {fileName}, duplicate run for the same file?"); return; } // check for a previous change number var currentFileStream = await storage.ReadFileFromBlobToStorageAsync(containerName, fileName); var currentFile = DeserializeFile(StreamToString(currentFileStream)); if (currentFile == null) { throw new Exception($"No valid file named {fileName} for container {containerName}"); } if (currentFile.Values == null || currentFile.Values.Count == 0) { // empty file , remove (this can happen?) log.LogInformation("empty current file found, removing."); await storage.DeleteFileFromBlobStorageAsync(containerName, fileName); return; } var previousFile = await GetPreviousFileAsync(storage, containerName, fileName); var delta = CompareFiles(currentFile, previousFile); if (null != delta) { var newFileName = $"{fileName}.delta"; var newFile = new ServiceTagFile() { Values = delta }; var stream = StringToStream(SerializeFile(newFile)); // AEG event will be raised for next func await storage.WriteStreamAsBlobToStorageAsync(stream, containerName, newFileName); // enqueue reference to delta for function to write access restrictions log.LogInformation($"C# function processed: {fileName} and wrote delta {newFileName}"); } log.LogInformation($"C# function processed: {fileName}. No delta."); }
public static async Task FnActionDelta( [EventGridTrigger] EventGridEvent eventGridEvent, ILogger log) { // pull the filename from the event log.LogInformation($"Event received {eventGridEvent.Id}"); StorageBlobCreatedEventData data = (eventGridEvent.Data as JObject).ToObject <StorageBlobCreatedEventData>(); var fileName = string.Empty; var uri = new Uri(data.Url); fileName = System.IO.Path.GetFileName(uri.LocalPath); log.LogInformation($"filename is {fileName}"); // check its the file we're interested in if (!fileName.EndsWith(".delta")) { log.LogInformation($"Not interested in this event { fileName}"); return; } var storage = new StorageProvider(); var newFileName = $"{fileName}.completed"; var containerName = Environment.GetEnvironmentVariable("region"); // set to run as singleton so this is belt and brace if (await storage.FileExistsBlobStorageAsync(containerName, newFileName)) { log.LogInformation($"This delta received already and completed. No further action."); return; } log.LogInformation($"delta {fileName} received"); // // action delta // var newFile = new ServiceTagFile() { ChangeNumber = fileName }; var stream = StringToStream(SerializeFile(newFile)); await storage.WriteStreamAsBlobToStorageAsync(stream, containerName, newFileName); // enqueue reference to delta for function to write access restrictions log.LogInformation($"C# function actioned {fileName} and wrote completed {newFileName}"); }