Beispiel #1
0
        public FileProcessorTests()
        {
            rootPath             = Path.GetTempPath();
            combinedTestFilePath = Path.Combine(rootPath, attributeSubPath);
            Directory.CreateDirectory(combinedTestFilePath);
            DeleteTestFiles(combinedTestFilePath);

            config = new FilesConfiguration()
            {
                RootPath = rootPath
            };

            FileTriggerAttribute attribute = new FileTriggerAttribute(attributeSubPath, "*.dat");

            processor = CreateTestProcessor(attribute);

            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                DateFormatHandling = DateFormatHandling.IsoDateFormat,
            };

            _serializer = JsonSerializer.Create(settings);

            Environment.SetEnvironmentVariable("WEBSITE_INSTANCE_ID", InstanceId);
        }
 public FileTriggerBinding(FilesConfiguration config, ParameterInfo parameter)
 {
     _config          = config;
     _parameter       = parameter;
     _attribute       = parameter.GetCustomAttribute <FileTriggerAttribute>(inherit: false);
     _bindingContract = CreateBindingContract();
 }
        public async Task UploadAsync_ShouldThrowExceptionWhenFileLenghtIsBiggerThanMax()
        {
            // ARRANGE
            var filesConfiguration = new FilesConfiguration {
                Directory = @"C:\Users\E7450\source\repos\TrainingDivision\TrainingDivisionKedis.BLL.Tests\bin\Debug\netcoreapp2.2\", MaxSize = 10000
            };
            IOptions <FilesConfiguration> options = Options.Create(filesConfiguration);

            _sut = new LocalFileService <FilesConfiguration>(options);

            var file = new Mock <IFormFile>();

            file.Setup(f => f.Length).Returns(10001000).Verifiable();

            try
            {
                // ACT
                var actual = await _sut.UploadAsync(file.Object);
            }
            catch (Exception ex)
            {
                // ASSERT
                Assert.Equal("Размер файла должен быть не более " + filesConfiguration.MaxSize + "КБ.", ex.Message);
            }
        }
Beispiel #4
0
        public async Task CatchAllFilter_AutoDelete_ProcessesAndDeletesFiles()
        {
            Mock <ITriggeredFunctionExecutor> mockExecutor   = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);
            ConcurrentBag <string>            processedFiles = new ConcurrentBag <string>();
            FunctionResult result = new FunctionResult(true);

            mockExecutor.Setup(p => p.TryExecuteAsync(It.IsAny <TriggeredFunctionData>(), It.IsAny <CancellationToken>())).ReturnsAsync(result);

            FilesConfiguration config = new FilesConfiguration()
            {
                RootPath = rootPath
            };
            FileTriggerAttribute attribute = new FileTriggerAttribute(attributeSubPath, changeTypes: WatcherChangeTypes.Created, filter: "*.*", autoDelete: true);

            FileListener listener = new FileListener(config, attribute, mockExecutor.Object, new TestTraceWriter());
            await listener.StartAsync(CancellationToken.None);

            // create a few files with different extensions
            WriteTestFile("jpg");
            WriteTestFile("txt");
            WriteTestFile("png");

            // wait for the files to be processed fully and all files deleted (autoDelete = true)
            await TestHelpers.Await(() =>
            {
                return(Directory.EnumerateFiles(testFileDir).Count() == 0);
            });

            listener.Dispose();
        }
        public void MBTransferedToBytes(int megabytes)
        {
            FilesConfiguration configuration = CreateConfiguration(dataFileMaximumSizeMB: megabytes);

            Assert.IsNotNull(configuration);
            Assert.AreEqual(1024 * 1024 * megabytes, configuration.DataFileMaximumSizeB);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            JobHostConfiguration config = new JobHostConfiguration();

            config.Tracing.ConsoleLevel = TraceLevel.Verbose;

            // Set to a short polling interval to facilitate local
            // debugging. You wouldn't want to run prod this way.
            config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(2);

            FilesConfiguration filesConfig = new FilesConfiguration();

            if (string.IsNullOrEmpty(filesConfig.RootPath))
            {
                // when running locally, set this to a valid directory
                filesConfig.RootPath = @"c:\temp\files";
            }
            ;
            EnsureSampleDirectoriesExist(filesConfig.RootPath);
            config.UseFiles(filesConfig);

            config.UseTimers();
            config.UseSample();
            config.UseCore();

            JobHost host = new JobHost(config);

            host.Call(typeof(FileSamples).GetMethod("ReadWrite"));
            host.Call(typeof(SampleSamples).GetMethod("Sample_BindToStream"));
            host.Call(typeof(SampleSamples).GetMethod("Sample_BindToString"));
            host.Call(typeof(TableSamples).GetMethod("CustomBinding"));

            host.RunAndBlock();
        }
 public FileBinding(FilesConfiguration config, ParameterInfo parameter, BindingTemplate bindingTemplate)
 {
     _config          = config;
     _parameter       = parameter;
     _bindingTemplate = bindingTemplate;
     _attribute       = _parameter.GetCustomAttribute <FileAttribute>(inherit: false);
 }
 public FileBinding(FilesConfiguration config, ParameterInfo parameter, BindingTemplate bindingTemplate)
 {
     _config = config;
     _parameter = parameter;
     _bindingTemplate = bindingTemplate;
     _attribute = _parameter.GetCustomAttribute<FileAttribute>(inherit: false);
 }
        public FileListener(FilesConfiguration config, FileTriggerAttribute attribute, ITriggeredFunctionExecutor triggerExecutor, TraceWriter trace)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }
            if (triggerExecutor == null)
            {
                throw new ArgumentNullException("triggerExecutor");
            }
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            _config                  = config;
            _attribute               = attribute;
            _triggerExecutor         = triggerExecutor;
            _trace                   = trace;
            _cancellationTokenSource = new CancellationTokenSource();

            if (string.IsNullOrEmpty(_config.RootPath) || !Directory.Exists(_config.RootPath))
            {
                throw new InvalidOperationException(string.Format("Path '{0}' is invalid. FilesConfiguration.RootPath must be set to a valid directory location.", _config.RootPath));
            }

            _watchPath = Path.Combine(_config.RootPath, _attribute.GetRootPath());
        }
 public FileTriggerBinding(FilesConfiguration config, ParameterInfo parameter)
 {
     _config = config;
     _parameter = parameter;
     _attribute = parameter.GetCustomAttribute<FileTriggerAttribute>(inherit: false);
     _bindingContract = CreateBindingContract();
 }
        public void BackupFolderNormalized()
        {
            FilesConfiguration configuration = CreateConfiguration(backupFolder: "/data0/");

            Assert.IsNotNull(configuration);
            Assert.AreEqual("/data0", configuration.BackupFolder);
        }
        public async Task UploadAsync_ShouldReturnFileNameWhenFileLenghtIsLessThanMax()
        {
            // ARRANGE
            var filesConfiguration = new FilesConfiguration {
                Directory = @"C:\Users\E7450\source\repos\TrainingDivision\TrainingDivisionKedis.BLL.Tests\bin\Debug\netcoreapp2.2\", MaxSize = 10000
            };
            IOptions <FilesConfiguration> options = Options.Create(filesConfiguration);

            _sut = new LocalFileService <FilesConfiguration>(options);

            var file      = new Mock <IFormFile>();
            var sourceImg = File.OpenRead(@"C:\Users\E7450\Pictures\handMade\64d735876ce855d858a742001e0585ea.jpg");
            var ms        = new MemoryStream();
            var writer    = new StreamWriter(ms);

            writer.Write(sourceImg);
            writer.Flush();
            ms.Position = 0;
            var fileName = "QQ.png";

            file.Setup(f => f.FileName).Returns(fileName).Verifiable();
            file.Setup(f => f.Length).Returns(9999000).Verifiable();
            file.Setup(_ => _.CopyToAsync(It.IsAny <Stream>(), It.IsAny <CancellationToken>()))
            .Returns((Stream stream, CancellationToken token) => ms.CopyToAsync(stream))
            .Verifiable();

            // ACT
            var actual = await _sut.UploadAsync(file.Object);

            // ASSERT
            Assert.Contains("QQ", actual);
            Assert.Contains(".png", actual);
        }
Beispiel #13
0
 /// <summary>
 /// Constructs a new instance
 /// </summary>
 /// <param name="config">The <see cref="FilesConfiguration"/></param>
 /// <param name="attribute">The <see cref="FileTriggerAttribute"/></param>
 /// <param name="executor">The function executor.</param>
 /// <param name="logger">The <see cref="ILogger"/>.</param>
 public FileProcessorFactoryContext(FilesConfiguration config, FileTriggerAttribute attribute, ITriggeredFunctionExecutor executor, ILogger logger)
 {
     Config    = config ?? throw new ArgumentNullException(nameof(config));
     Attribute = attribute ?? throw new ArgumentNullException(nameof(attribute));
     Executor  = executor ?? throw new ArgumentNullException(nameof(executor));
     Logger    = logger ?? throw new ArgumentNullException(nameof(logger));
 }
        public static JobHostConfiguration CreateConfig()
        {
            var config = new JobHostConfiguration();

            // The environment is determined by the value of the "AzureWebJobsEnv" environment variable. When this
            // is set to "Development", this property will return true.
            if (config.IsDevelopment)
            {
                config.UseDevelopmentSettings();
            }

            //check app.config if your connectionstrings are setup properly

            //if the box has no internet connection you can disable the connectionstrings like this, remember you use any internet enabled functions then.
            //config.DashboardConnectionString = null;
            //config.StorageConnectionString = null;

            //normally use AppSetting and ConfigManager to get paths here.
            FilesConfiguration filesConfig = new FilesConfiguration
            {
                RootPath = @"C:\Users\p.vanek\Desktop\TechDays\FileWatch"
            };

            //enable what you like to use
            config.UseFiles(filesConfig);
            config.UseTimers();

            //lots of these extensions can be found on the internet on places like nuget
            //https://www.nuget.org/packages?q=WebJobs.Extensions

            //used for local development without accidently sharing secrets
            string storageString = Environment.GetEnvironmentVariable("AzureStorageAccount");

            if (!string.IsNullOrWhiteSpace(storageString))
            {
                config.DashboardConnectionString = storageString;
                config.StorageConnectionString   = storageString;
            }


            //find servicebusString in Environment variable, otherwise find it in App.config
            string serviceBusConnection = Environment.GetEnvironmentVariable("AzureServiceBus");

            if (!string.IsNullOrWhiteSpace(serviceBusConnection))
            {
                ServiceBusConfiguration sbConfig = new ServiceBusConfiguration
                {
                    ConnectionString = serviceBusConnection
                                       //set other options if you like
                };

                config.UseServiceBus(sbConfig);
            }
            else
            {
                config.UseServiceBus();
            }

            return(config);
        }
        public static void Main(string[] args)
        {
            JobHostConfiguration config      = new JobHostConfiguration();
            FilesConfiguration   filesConfig = new FilesConfiguration();

            // See https://github.com/Azure/azure-webjobs-sdk/wiki/Running-Locally for details
            // on how to set up your local environment
            if (config.IsDevelopment)
            {
                config.UseDevelopmentSettings();
                filesConfig.RootPath = @"c:\temp\files";
            }

            config.UseFiles(filesConfig);
            config.UseTimers();
            config.UseSample();
            config.UseEasyTables();
            config.UseCore();
            config.UseDocumentDB();
            config.UseNotificationHubs();
            var sendGridConfiguration = new SendGridConfiguration()
            {
                ToAddress   = "*****@*****.**",
                FromAddress = new MailAddress("*****@*****.**", "WebJobs Extensions Samples")
            };

            config.UseSendGrid(sendGridConfiguration);

            ConfigureTraceMonitor(config, sendGridConfiguration);

            EnsureSampleDirectoriesExist(filesConfig.RootPath);

            WebHooksConfiguration webHooksConfig = new WebHooksConfiguration();

            webHooksConfig.UseReceiver <GitHubWebHookReceiver>();
            config.UseWebHooks(webHooksConfig);

            JobHost host = new JobHost(config);

            // Add or remove types from this list to choose which functions will
            // be indexed by the JobHost.
            config.TypeLocator = new SamplesTypeLocator(
                typeof(ErrorMonitoringSamples),
                typeof(FileSamples),
                typeof(MiscellaneousSamples),
                typeof(SampleSamples),
                typeof(SendGridSamples),
                typeof(TableSamples),
                typeof(TimerSamples),
                typeof(WebHookSamples));

            host.Call(typeof(MiscellaneousSamples).GetMethod("ExecutionContext"));
            host.Call(typeof(FileSamples).GetMethod("ReadWrite"));
            host.Call(typeof(SampleSamples).GetMethod("Sample_BindToStream"));
            host.Call(typeof(SampleSamples).GetMethod("Sample_BindToString"));
            host.Call(typeof(TableSamples).GetMethod("CustomBinding"));

            host.RunAndBlock();
        }
 public FileAttributeBindingProvider(FilesConfiguration config)
 {
     if (config == null)
     {
         throw new ArgumentNullException("config");
     }
     _config = config;
 }
 public FileAttributeBindingProvider(FilesConfiguration config)
 {
     if (config == null)
     {
         throw new ArgumentNullException("config");
     }
     _config = config;
 }
Beispiel #18
0
 public FileListener(FilesConfiguration config, FileTriggerAttribute attribute, ITriggeredFunctionExecutor triggerExecutor)
 {
     _config                  = config;
     _attribute               = attribute;
     _triggerExecutor         = triggerExecutor;
     _cancellationTokenSource = new CancellationTokenSource();
     _watchPath               = Path.Combine(_config.RootPath, _attribute.GetNormalizedPath());
 }
 public FileTriggerBinding(FilesConfiguration config, ParameterInfo parameter, TraceWriter trace)
 {
     _config = config;
     _parameter = parameter;
     _trace = trace;
     _attribute = parameter.GetCustomAttribute<FileTriggerAttribute>(inherit: false);
     _bindingDataProvider = BindingDataProvider.FromTemplate(_attribute.Path);
     _bindingContract = CreateBindingContract();
 }
Beispiel #20
0
 public FileTriggerBinding(FilesConfiguration config, ParameterInfo parameter, TraceWriter trace)
 {
     _config              = config;
     _parameter           = parameter;
     _trace               = trace;
     _attribute           = parameter.GetCustomAttribute <FileTriggerAttribute>(inherit: false);
     _bindingDataProvider = BindingDataProvider.FromTemplate(_attribute.Path);
     _bindingContract     = CreateBindingContract();
 }
        public void DataFoldersNormalized()
        {
            FilesConfiguration configuration = CreateConfiguration(dataFolders: new[] { "/data1/", "/data2/", "/data3" });

            Assert.IsNotNull(configuration);
            Assert.AreEqual("/data1", configuration.DataFolders.Skip(0).First());
            Assert.AreEqual("/data2", configuration.DataFolders.Skip(1).First());
            Assert.AreEqual("/data3", configuration.DataFolders.Skip(2).First());
        }
Beispiel #22
0
        public static void Main(string[] args)
        {
            JobHostConfiguration config      = new JobHostConfiguration();
            FilesConfiguration   filesConfig = new FilesConfiguration();

            // See https://github.com/Azure/azure-webjobs-sdk/wiki/Running-Locally for details
            // on how to set up your local environment
            if (config.IsDevelopment)
            {
                config.UseDevelopmentSettings();
                filesConfig.RootPath = @"c:\temp\files";
            }

            config.UseFiles(filesConfig);
            config.UseTimers();
            config.UseSample();
            config.UseMobileApps();
            config.UseTwilioSms();
            config.UseCore();
            config.UseCosmosDB();

            var sendGridConfiguration = new SendGridConfiguration()
            {
                ToAddress   = new EmailAddress("*****@*****.**", "WebJobs Extensions Samples"),
                FromAddress = new EmailAddress("*****@*****.**", "WebJobs Extensions Samples")
            };

            config.UseSendGrid(sendGridConfiguration);

            ConfigureTraceMonitor(config, sendGridConfiguration);

            EnsureSampleDirectoriesExist(filesConfig.RootPath);

            JobHost host = new JobHost(config);

            // Add or remove types from this list to choose which functions will
            // be indexed by the JobHost.
            // To run some of the other samples included, add their types to this list
            config.TypeLocator = new SamplesTypeLocator(
                typeof(ErrorMonitoringSamples),
                typeof(FileSamples),
                typeof(MiscellaneousSamples),
                typeof(SampleSamples),
                typeof(TableSamples),
                typeof(TimerSamples));

            // Some direct invocations to demonstrate various binding scenarios
            host.Call(typeof(MiscellaneousSamples).GetMethod("ExecutionContext"));
            host.Call(typeof(FileSamples).GetMethod("ReadWrite"));
            host.Call(typeof(SampleSamples).GetMethod("Sample_BindToStream"));
            host.Call(typeof(SampleSamples).GetMethod("Sample_BindToString"));
            host.Call(typeof(TableSamples).GetMethod("CustomBinding"));

            host.RunAndBlock();
        }
        /// <summary>
        /// Enables use of File System extensions
        /// </summary>
        /// <param name="config">The <see cref="JobHostConfiguration"/> to configure.</param>
        public static void UseFiles(this JobHostConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            FilesConfiguration filesConfiguration = new FilesConfiguration();

            config.UseFiles(filesConfiguration);
        }
        public void Constructor_ShouldThrowExceptionWhenDirectoryNotExists()
        {
            // ARRANGE
            var filesConfiguration = new FilesConfiguration {
                Directory = @"C:\ABC\", MaxSize = 10000
            };
            IOptions <FilesConfiguration> options = Options.Create(filesConfiguration);

            // ASSERT
            Assert.Throws <DirectoryNotFoundException>(() => { var _sut = new LocalFileService <FilesConfiguration>(options); });
        }
Beispiel #25
0
        public void Constructor_ThrowsOnInvalidRootPath()
        {
            FilesConfiguration   config = new FilesConfiguration();
            FileTriggerAttribute attrib = new FileTriggerAttribute("test", "*.dat");
            Mock <ITriggeredFunctionExecutor> mockExecutor = new Mock <ITriggeredFunctionExecutor>();

            var ex = Assert.Throws <InvalidOperationException>(() =>
            {
                new FileListener(config, attrib, mockExecutor.Object, new TestTraceWriter());
            });

            Assert.Equal("Path '' is invalid. FilesConfiguration.RootPath must be set to a valid directory location.", ex.Message);
        }
Beispiel #26
0
 // Please set the following connection strings in app.config for this WebJob to run:
 // AzureWebJobsDashboard and AzureWebJobsStorage
 public static void Main()
 {
      if(!System.IO.Directory.Exists(@"D:\home\data\XML")) 
      {
           System.IO.Directory.Create(@"D:\home\data\XML");
      }
      JobHostConfiguration jobConfiguration = new JobHostConfiguration();
      FilesConfiguration fileConfiguration = new FilesConfiguration();
      jobConfiguration.UseFiles(fileConfiguration);
      jobConfiguration.UseTimers();
      var host = new JobHost(jobConfiguration);
      host.RunAndBlock();
 }
        /// <summary>
        /// Enables use of File System extensions
        /// </summary>
        /// <param name="config">The <see cref="JobHostConfiguration"/> to configure.</param>
        /// <param name="filesConfig">The <see cref="FilesConfiguration"></see> to use./></param>
        public static void UseFiles(this JobHostConfiguration config, FilesConfiguration filesConfig)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (filesConfig == null)
            {
                throw new ArgumentNullException("filesConfig");
            }

            config.RegisterExtensionConfigProvider(new FilesExtensionConfig(filesConfig));
        }
Beispiel #28
0
        public FileTriggerAttributeBindingProvider(FilesConfiguration config, TraceWriter trace)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            _config = config;
            _trace  = trace;
        }
        public FileAttributeBindingProvider(FilesConfiguration config, INameResolver nameResolver)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (nameResolver == null)
            {
                throw new ArgumentNullException("nameResolver");
            }

            _config = config;
            _nameResolver = nameResolver;
        }
        public void GetFileBytes_ShouldThrowErrorWhenFileNotFound()
        {
            // ARRANGE
            var path = @"C:\Users\E7450\source\repos\TrainingDivision\TrainingDivisionKedis.BLL.Tests\bin\Debug\netcoreapp2.2\";
            var filesConfiguration = new FilesConfiguration {
                Directory = path, MaxSize = 10000
            };
            IOptions <FilesConfiguration> options = Options.Create(filesConfiguration);

            _sut = new LocalFileService <FilesConfiguration>(options);

            // ACT
            Assert.Throws <FileNotFoundException>(() => _sut.GetFileBytes("SomeFileName.txt"));
        }
        public FileTriggerAttributeBindingProvider(FilesConfiguration config, TraceWriter trace)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            _config = config;
            _trace = trace;
        }
        public FileAttributeBindingProvider(FilesConfiguration config, INameResolver nameResolver)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (nameResolver == null)
            {
                throw new ArgumentNullException("nameResolver");
            }

            _config       = config;
            _nameResolver = nameResolver;
        }
Beispiel #33
0
        public void Constructor_Defaults()
        {
            Environment.SetEnvironmentVariable("HOME", null);

            FilesConfiguration config = new FilesConfiguration();

            Assert.Null(config.RootPath);
            Assert.Equal(typeof(DefaultFileProcessorFactory), config.ProcessorFactory.GetType());

            Environment.SetEnvironmentVariable("HOME", @"D:\home");
            config = new FilesConfiguration();
            Assert.Equal(@"D:\home\data", config.RootPath);

            Environment.SetEnvironmentVariable("HOME", null);
        }
        public void EmptyBackupFolderOverriden()
        {
            FilesConfiguration configuration = CreateConfiguration(backupFolder: null);

            Assert.IsNotNull(configuration);
            Assert.AreEqual(FilesConfiguration.DEFAULT_BACKUP_FOLDER, configuration.BackupFolder);

            configuration = CreateConfiguration(backupFolder: String.Empty);
            Assert.IsNotNull(configuration);
            Assert.AreEqual(FilesConfiguration.DEFAULT_BACKUP_FOLDER, configuration.BackupFolder);

            configuration = CreateConfiguration(backupFolder: " ");
            Assert.IsNotNull(configuration);
            Assert.AreEqual(FilesConfiguration.DEFAULT_BACKUP_FOLDER, configuration.BackupFolder);
        }
        public void EmptyDataFoldersOverriden()
        {
            FilesConfiguration configuration = CreateConfiguration(dataFolders: null);

            Assert.IsNotNull(configuration);
            Assert.AreEqual(FilesConfiguration.DEFAULT_DATA_FOLDER, configuration.DataFolders.Single());

            configuration = CreateConfiguration(dataFolders: new string[0]);
            Assert.IsNotNull(configuration);
            Assert.AreEqual(FilesConfiguration.DEFAULT_DATA_FOLDER, configuration.DataFolders.Single());

            configuration = CreateConfiguration(dataFolders: new[] { String.Empty, " ", null });
            Assert.IsNotNull(configuration);
            Assert.AreEqual(FilesConfiguration.DEFAULT_DATA_FOLDER, configuration.DataFolders.Single());
        }
        public void Validate(FilesConfiguration configuration)
        {
            _log.Debug($"Validating {nameof(FilesConfiguration)}");

            if (configuration.DataFolders == null || configuration.DataFolders.Length == 0)
            {
                // this will never take place
                throw new ArgumentNullException(nameof(configuration.DataFolders), "Data folder are not defined");
            }

            foreach (string dataFolder in configuration.DataFolders)
            {
                string fullDataFolder = Path.GetFullPath(dataFolder);
                if (String.IsNullOrEmpty(fullDataFolder))
                {
                    throw new ArgumentException($"Data folder '{dataFolder}' is invalid", nameof(configuration.DataFolders));
                }

                if (!_directoryAbstraction.Exists(fullDataFolder))
                {
                    throw new ArgumentException($"Data folder '{dataFolder}' does not exist", nameof(configuration.DataFolders));
                }
            }

            string fullBackupFolder = Path.GetFullPath(configuration.BackupFolder);

            if (String.IsNullOrEmpty(fullBackupFolder))
            {
                throw new ArgumentException($"Backup folder '{configuration.BackupFolder}' is invalid", nameof(configuration.BackupFolder));
            }

            if (!_directoryAbstraction.Exists(fullBackupFolder))
            {
                throw new ArgumentException($"Backup folder '{fullBackupFolder}' does not exist", nameof(configuration.BackupFolder));
            }

            if (configuration.DataFileMaximumSizeMB < 10)
            {
                throw new ArgumentOutOfRangeException(nameof(configuration.DataFileMaximumSizeMB), $"Minimum value for {nameof(configuration.DataFileMaximumSizeMB)} is 10");
            }

            if (configuration.DataFileMaximumSizeMB > 256)
            {
                throw new ArgumentOutOfRangeException(nameof(configuration.DataFileMaximumSizeMB), $"Maximum value for {nameof(configuration.DataFileMaximumSizeMB)} is 256");
            }

            _log.Info($"{nameof(FilesConfiguration)} valid");
        }
        /// <summary>
        /// Constructs a new instance
        /// </summary>
        /// <param name="config">The <see cref="FilesConfiguration"/></param>
        /// <param name="attribute">The <see cref="FileTriggerAttribute"/></param>
        /// <param name="executor">The function executor.</param>
        public FileProcessorFactoryContext(FilesConfiguration config, FileTriggerAttribute attribute, ITriggeredFunctionExecutor executor)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }
            if (executor == null)
            {
                throw new ArgumentNullException("executor");
            }

            Config = config;
            Attribute = attribute;
            Executor = executor;
        }
        /// <summary>
        /// Constructs a new instance
        /// </summary>
        /// <param name="context">The <see cref="FileProcessorFactoryContext"/></param>
        public FileProcessor(FileProcessorFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            _config = context.Config;
            _attribute = context.Attribute;
            _executor = context.Executor;

            string attributePath = _attribute.GetNormalizedPath();
            _filePath = Path.Combine(_config.RootPath, attributePath);

            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                DateFormatHandling = DateFormatHandling.IsoDateFormat,
            };
            _serializer = JsonSerializer.Create(settings);
        }