Пример #1
0
        public static async Task <string> Run(
            [ServiceBusTrigger("scan-for-virus")] string myQueueItem,
            [Blob("%AzureStorage:Container%", FileAccess.Read, Connection = "AzureStorage:ConnectionString")] CloudBlobContainer cloudBlobContainer,
            ILogger log)
        {
            log.LogInformation($"Scanning {myQueueItem}");

            var config = new ConfigurationBuilder()
                         .AddEnvironmentVariables()
                         .Build();

            // Download Blob Content
            var cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(myQueueItem);
            var memoryStream   = new MemoryStream();
            await cloudBlockBlob.DownloadToStreamAsync(memoryStream);

            // Scan for Viruses
            var virusScanner = new CloudmersiveVirusScanner();

            virusScanner.SetConfiguration(config);

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            FileTrackerRepository.AddOperationResult(myQueueItem, "Virus Scan");

            var scanResult = await virusScanner.ScanStreamAsync(memoryStream);

            stopWatch.Stop();

            FileTrackerRepository.UpdateOperationResult(myQueueItem, "Virus Scan", stopWatch.ElapsedMilliseconds, false, scanResult.Message);

            log.LogInformation($"Scan Results for {myQueueItem}, Safe: {scanResult.IsSafe}, Message: {scanResult.Message}");

            return(myQueueItem);
        }
Пример #2
0
        public static async Task <string> Run(
            [ServiceBusTrigger("parse-and-validate")] string myQueueItem,
            [Blob("%AzureStorage:Container%", FileAccess.Read, Connection = "AzureStorage:ConnectionString")] CloudBlobContainer cloudBlobContainer,
            ILogger log)
        {
            log.LogInformation($"Parsing and validating: {myQueueItem}");

            // Download Blob Content
            var cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(myQueueItem);
            var memoryStream   = new MemoryStream();
            await cloudBlockBlob.DownloadToStreamAsync(memoryStream);

            // Parse and Validate File
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            FileTrackerRepository.AddOperationResult(myQueueItem, "Parse and Validate");

            var parseErrors = CsvFile.Validate(memoryStream);

            stopWatch.Stop();

            FileTrackerRepository.UpdateOperationResult(myQueueItem, "Parse and Validate", stopWatch.ElapsedMilliseconds, true);

            if (parseErrors.Count > 0)
            {
                log.LogInformation($"Parsing and validating results for: {myQueueItem}, {string.Join(",", parseErrors)}");
                throw new ApplicationException("File is not valid");
            }
            else
            {
                log.LogInformation($"Parsing and validating results for: {myQueueItem}, looks good for next stage");
            }

            return(myQueueItem);
        }