public void Register(IUnityContainer container, FileProcessorEndpoint endpoint) { // Registration for the handler if present if (endpoint.Handler != null) { container.RegisterType(typeof(IFileHandler), endpoint.Handler, endpoint.Name); } if (endpoint.PostProcessor == null) { if ((endpoint.Handler != null) && endpoint.Handler.Implements <IFilePostProcessor>()) { endpoint.PostProcessor = endpoint.Handler; } else { endpoint.PostProcessor = typeof(NullPostProcessor); } } // Registration for the post processor container.RegisterType(typeof(IFilePostProcessor), endpoint.PostProcessor, endpoint.Name); container.RegisterType(typeof(IFileFilter), endpoint.AdditionalFilter, endpoint.Name); this.RegisterProcessor(container, endpoint); }
public void Register(IUnityContainer container, FileProcessorEndpoint endpoint) { // Registration for the handler if present if (endpoint.Handler != null) { container.RegisterType(typeof(IFileHandler), endpoint.Handler, endpoint.Name); } if (endpoint.PostProcessor == null) { if ((endpoint.Handler != null) && endpoint.Handler.Implements<IFilePostProcessor>()) { endpoint.PostProcessor = endpoint.Handler; } else { endpoint.PostProcessor = typeof(NullPostProcessor); } } // Registration for the post processor container.RegisterType(typeof(IFilePostProcessor), endpoint.PostProcessor, endpoint.Name); container.RegisterType(typeof(IFileFilter), endpoint.AdditionalFilter, endpoint.Name); this.RegisterProcessor(container, endpoint); }
public void ConvertProcessorElementToEndpointWithEmptyProcessorConfigurator() { var element = new FileProcessorElement { Name = "a", DropPath = "b", Filter = "*", SuccessPath = "c", FailurePath = "d", InProgressPath = "e", ScavengeInterval = 100, RecoveryInterval = 100, }; var expected = new FileProcessorEndpoint { Name = "a", DropPath = "b", Filter = "*", SuccessPath = "c", FailurePath = "d", InProgressPath = "e", NumberOfConsumers = 1, ScavengeInterval = new TimeSpan(0, 0, 100), RecoveryInterval = new TimeSpan(0, 0, 100), ProcessorConfigurator = "EnergyTrading.FileProcessing.Registrars.EventBasedProcessorDefaultRegistrar, EnergyTrading.Unity", AdditionalFilter = typeof(DefaultFileFilter), PollingRestartInterval = new TimeSpan(0, 0, 60) }; var candidate = element.ToEndpoint(); this.Check(expected, candidate); }
public void ConvertProcessorElementToEndpointWithSambaBasedProcessor() { var element = new FileProcessorElement { Name = "a", DropPath = "b", Filter = "*", SuccessPath = "c", FailurePath = "d", InProgressPath = "e", ScavengeInterval = 100, RecoveryInterval = 100, ProcessorConfiguratorType = "PollingBased" }; var expected = new FileProcessorEndpoint { Name = "a", DropPath = "b", Filter = "*", SuccessPath = "c", FailurePath = "d", InProgressPath = "e", NumberOfConsumers = 1, ScavengeInterval = new TimeSpan(0, 0, 100), RecoveryInterval = new TimeSpan(0, 0, 100), ProcessorConfigurator = FileProcessorEndpoint.PollingBasedConfiguratorType, AdditionalFilter = typeof(DefaultFileFilter), PollingRestartInterval = new TimeSpan(0, 0, 60) }; var candidate = element.ToEndpoint(); this.Check(expected, candidate); }
public FileScavenger(FileProcessorEndpoint endpoint, IFileFilter fileFilter, string instanceId) { this.endpoint = endpoint; this.fileFilter = fileFilter; this.instanceId = instanceId; this.timer = new Timer(endpoint.ScavengeInterval.TotalMilliseconds) { AutoReset = true }; this.timer.Elapsed += this.TimerElapsed; }
public PollingBasedv2FileProcessor(FileProcessorEndpoint endpoint, IFileHandler handler, IFilePostProcessor postProcessor, IFileFilter additionalFilter) : base(endpoint, handler, postProcessor, additionalFilter) { this.pollingTimer = new Timer(Endpoint.PollingInterval) { AutoReset = true }; this.pollingTimer.Elapsed += this.TimerElapsed; }
public PollingBasedFileProcessor(FileProcessorEndpoint fileProcessorEndpoint, IHandleFiles fileHandler, IFileFilter additionalFilter) { if (fileProcessorEndpoint == null) { throw new ArgumentNullException("fileProcessorEndpoint"); } if (fileHandler == null) { throw new ArgumentNullException("fileHandler"); } if (additionalFilter == null) { throw new ArgumentNullException("additionalFilter"); } this.fileProcessorEndpoint = fileProcessorEndpoint; this.fileHandler = fileHandler; this.additionalFilter = additionalFilter; }
public static void RegisterProcessor(this IUnityContainer container, FileProcessorEndpoint endpoint) { endpoint.Validate(); // Register the endpoint instance under the name, needed for the processor container.RegisterInstance(endpoint.Name, endpoint); // create file processor configurator instance and invoke var typeResolver = container.Resolve <ITypeResolver>(); var fileProcessorRegistrar = typeResolver.Resolve <IFileProcessorRegistrar>(endpoint.ProcessorConfigurator); fileProcessorRegistrar.Register(container, endpoint); }
protected override void RegisterProcessor(IUnityContainer container, FileProcessorEndpoint endpoint) { // Tie the parameters to the processor container.RegisterType( typeof(IFileProcessor), typeof(PollingBasedv2FileProcessor), endpoint.Name, new PerResolveLifetimeManager(), new InjectionConstructor( new ResolvedParameter<FileProcessorEndpoint>(endpoint.Name), new ResolvedParameter<IFileHandler>(endpoint.Name), new ResolvedParameter<IFilePostProcessor>(endpoint.Name), new ResolvedParameter<IFileFilter>(endpoint.Name))); }
public void CreateDirectories() { DeleteDirectories(); dropLocation = Directory.CreateDirectory(DropDirectoryName).FullName; acknowledgedLocation = Directory.CreateDirectory(AcknowledgedDirectoryName).FullName; tempLocation = Directory.CreateDirectory(TempDirectoryName).FullName; endpoint = new FileProcessorEndpoint { DropPath = dropLocation, InProgressPath = acknowledgedLocation, }; }
protected override void RegisterProcessor(IUnityContainer container, FileProcessorEndpoint endpoint) { // Tie the parameters to the processor container.RegisterType( typeof(IFileProcessor), typeof(EventBasedFileProcessor), endpoint.Name, new PerResolveLifetimeManager(), new InjectionConstructor( new ResolvedParameter <FileProcessorEndpoint>(endpoint.Name), new ResolvedParameter <IFileHandler>(endpoint.Name), new ResolvedParameter <IFilePostProcessor>(endpoint.Name), new ResolvedParameter <IFileFilter>(endpoint.Name))); }
public void RegisterWithoutRestartMechanism(IUnityContainer container, FileProcessorEndpoint fileProcessorEndpoint) { container.RegisterType(typeof(IHandleFiles), typeof(FileProducerConsumerQueue), fileProcessorEndpoint.Name, new PerResolveLifetimeManager(), new InjectionConstructor( fileProcessorEndpoint.NumberOfConsumers, new ResolvedParameter <IFileProcessResultHandler>(fileProcessorEndpoint.Name), new ResolvedParameter <IFileHandler>(fileProcessorEndpoint.Name))); container.RegisterType(typeof(IFileProcessor), typeof(PollingBasedFileProcessor), fileProcessorEndpoint.Name, new PerResolveLifetimeManager(), new InjectionConstructor( fileProcessorEndpoint, new ResolvedParameter <IHandleFiles>(fileProcessorEndpoint.Name))); }
public void ConvertProcessorElementWithCustomFileFilter() { var element = new FileProcessorElement { Name = "a", DropPath = "b", Filter = "*", SuccessPath = "c", FailurePath = "d", InProgressPath = "e", Consumers = 2, ScavengeInterval = 100, RecoveryInterval = 100, PollingInactivityRestartInterval = 100, Handler = "EnergyTrading.UnitTest.FileProcessing.FileHandler, EnergyTrading.UnitTest", PostProcessor = "EnergyTrading.UnitTest.FileProcessing.Configuration.ConfigurationExtensionsFixture+CustomPostProcessor, EnergyTrading.UnitTest", AdditionalFilter = "EnergyTrading.UnitTest.FileProcessing.Configuration.ConfigurationExtensionsFixture+CustomFileFilter, EnergyTrading.UnitTest" }; var expected = new FileProcessorEndpoint { Name = "a", DropPath = "b", Filter = "*", SuccessPath = "c", FailurePath = "d", InProgressPath = "e", NumberOfConsumers = 2, ScavengeInterval = new TimeSpan(0, 0, 100), RecoveryInterval = new TimeSpan(0, 0, 100), ProcessorConfigurator = FileProcessorEndpoint.EventBasedConfiguratorType, Handler = typeof(FileHandler), PollingRestartInterval = new TimeSpan(0, 0, 100), AdditionalFilter = typeof(CustomFileFilter), PostProcessor = typeof(CustomPostProcessor), PollingInterval = 60000 }; var candidate = element.ToEndpoint(); Check(expected, candidate); }
public EventBasedFileProcessor(FileProcessorEndpoint endpoint, IFileHandler handler, IFilePostProcessor postProcessor, IFileFilter additionalFilter) { if (endpoint == null) { throw new ArgumentException("endpoint"); } if (handler == null) { throw new ArgumentException("handler"); } if (postProcessor == null) { throw new ArgumentNullException("postProcessor"); } if (additionalFilter == null) { throw new ArgumentNullException("additionalFilter"); } this.instanceId = Guid.Empty; this.Endpoint = endpoint; this.Handler = handler; this.PostProcessor = postProcessor; this.AdditionalFilter = additionalFilter; this.timer = new Timer(this.Endpoint.ScavengeInterval.TotalMilliseconds) { AutoReset = true }; this.timer.Elapsed += this.TimerElapsed; this.pendingFiles = new ConcurrentQueue <string>(); this.eventHandle = new AutoResetEvent(false); this.quitHandle = new ManualResetEvent(false); this.quitting = false; Logger.DebugFormat("Scavenger interval set at {0:0.0} seconds", endpoint.ScavengeInterval.TotalSeconds); }
public void Register(IUnityContainer container, FileProcessorEndpoint fileProcessorEndpoint) { // Registration for the handler if present if (fileProcessorEndpoint.Handler != null) { container.RegisterType(typeof(IFileHandler), fileProcessorEndpoint.Handler, fileProcessorEndpoint.Name); } container.RegisterType <IFileProcessResultHandler, StrategyFileEventHandler>( fileProcessorEndpoint.Name, new InjectionConstructor(new DeleteSuccessfulFileHandlingStrategy(), new MoveFileHandlingStrategy(fileProcessorEndpoint.DropPath), new MoveFileHandlingStrategy(fileProcessorEndpoint.FailurePath))); if (fileProcessorEndpoint.PostProcessor == null) { if ((fileProcessorEndpoint.Handler != null) && fileProcessorEndpoint.Handler.Implements <IFilePostProcessor>()) { fileProcessorEndpoint.PostProcessor = fileProcessorEndpoint.Handler; } else { fileProcessorEndpoint.PostProcessor = typeof(NullPostProcessor); } } // Registration for the post processor container.RegisterType(typeof(IFilePostProcessor), fileProcessorEndpoint.PostProcessor, fileProcessorEndpoint.Name); container.RegisterType(typeof(IFileFilter), fileProcessorEndpoint.AdditionalFilter, fileProcessorEndpoint.Name); if (fileProcessorEndpoint.PollingRestartInterval.TotalSeconds > 0) { RegisterWithRestartMechanism(container, fileProcessorEndpoint); } else { RegisterWithoutRestartMechanism(container, fileProcessorEndpoint); } }
public void RegisterWithRestartMechanism(IUnityContainer container, FileProcessorEndpoint fileProcessorEndpoint) { var producerConsumerQueue = new FileProducerConsumerQueue(fileProcessorEndpoint.NumberOfConsumers, container.Resolve <IFileProcessResultHandler>(fileProcessorEndpoint.Name), container.Resolve <IFileHandler>(fileProcessorEndpoint.Name)); var fileThroughputAlerter = new FileThroughPutAlerter(producerConsumerQueue, fileProcessorEndpoint.PollingRestartInterval); var fileProcessor = new PollingBasedFileProcessor(fileProcessorEndpoint, fileThroughputAlerter, container.Resolve <IFileFilter>(fileProcessorEndpoint.Name)); fileThroughputAlerter.Alert += (sender, args) => fileProcessor.Restart(); container.RegisterInstance(typeof(IHandleFiles), fileProcessorEndpoint.Name, fileThroughputAlerter); container.RegisterInstance(typeof(IFileProcessor), fileProcessorEndpoint.Name, fileProcessor); }
public static FileProcessorEndpoint ToEndpoint(this FileProcessorElement element) { var endpoint = new FileProcessorEndpoint { Name = element.Name, DropPath = element.DropPath, InProgressPath = element.InProgressPath, Filter = element.Filter, MonitorSubdirectories = element.MonitorSubdirectories, ScavengeInterval = new TimeSpan(0, 0, element.ScavengeInterval), RecoveryInterval = new TimeSpan(0, 0, element.RecoveryInterval), PollingRestartInterval = new TimeSpan(0, 0, element.PollingInactivityRestartInterval), NumberOfConsumers = element.Consumers, SuccessPath = element.SuccessPath, FailurePath = element.FailurePath, ProcessorConfigurator = DetermineProcessorType(element), Handler = element.Handler.ToType(), PostProcessor = element.PostProcessor.ToType(), AdditionalFilter = element.AdditionalFilter.ToType() ?? typeof(DefaultFileFilter) }; return endpoint; }
public EventBasedFileProcessor(FileProcessorEndpoint endpoint, IFileHandler handler, IFilePostProcessor postProcessor, IFileFilter additionalFilter) { if (endpoint == null) { throw new ArgumentException("endpoint"); } if (handler == null) { throw new ArgumentException("handler"); } if (postProcessor == null) { throw new ArgumentNullException("postProcessor"); } if (additionalFilter == null) { throw new ArgumentNullException("additionalFilter"); } this.instanceId = Guid.Empty; this.Endpoint = endpoint; this.Handler = handler; this.PostProcessor = postProcessor; this.AdditionalFilter = additionalFilter; this.timer = new Timer(this.Endpoint.ScavengeInterval.TotalMilliseconds) { AutoReset = true }; this.timer.Elapsed += this.TimerElapsed; this.pendingFiles = new ConcurrentQueue<string>(); this.eventHandle = new AutoResetEvent(false); this.quitHandle = new ManualResetEvent(false); this.quitting = false; Logger.DebugFormat("Scavenger interval set at {0:0.0} seconds", endpoint.ScavengeInterval.TotalSeconds); }
protected FileProcessorBase(FileProcessorEndpoint endpoint, IFileHandler handler, IFilePostProcessor postProcessor, IFileFilter additionalFilter) { if (endpoint == null) { throw new ArgumentException("endpoint"); } if (handler == null) { throw new ArgumentException("handler"); } if (postProcessor == null) { throw new ArgumentNullException("postProcessor"); } if (additionalFilter == null) { throw new ArgumentNullException("additionalFilter"); } this.instanceId = Guid.Empty; this.Endpoint = endpoint; this.Handler = handler; this.PostProcessor = postProcessor; this.AdditionalFilter = additionalFilter; this.scavenger = new FileScavenger(endpoint, additionalFilter, this.InstanceId); this.scavenger.RestartFileChecking += (o, e) => this.RestartNewFileChecking(); this.pendingFiles = new ConcurrentQueue <string>(); this.eventHandle = new AutoResetEvent(false); this.quitHandle = new ManualResetEvent(false); this.quitting = false; Logger.DebugFormat("Scavenger interval set at {0:0.0} seconds", endpoint.ScavengeInterval.TotalSeconds); }
protected FileProcessorBase(FileProcessorEndpoint endpoint, IFileHandler handler, IFilePostProcessor postProcessor, IFileFilter additionalFilter) { if (endpoint == null) { throw new ArgumentException("endpoint"); } if (handler == null) { throw new ArgumentException("handler"); } if (postProcessor == null) { throw new ArgumentNullException("postProcessor"); } if (additionalFilter == null) { throw new ArgumentNullException("additionalFilter"); } this.instanceId = Guid.Empty; this.Endpoint = endpoint; this.Handler = handler; this.PostProcessor = postProcessor; this.AdditionalFilter = additionalFilter; this.scavenger = new FileScavenger(endpoint, additionalFilter, this.InstanceId); this.scavenger.RestartFileChecking += (o, e) => this.RestartNewFileChecking(); this.pendingFiles = new ConcurrentQueue<string>(); this.eventHandle = new AutoResetEvent(false); this.quitHandle = new ManualResetEvent(false); this.quitting = false; Logger.DebugFormat("Scavenger interval set at {0:0.0} seconds", endpoint.ScavengeInterval.TotalSeconds); }
public static FileProcessorEndpoint ToEndpoint(this FileProcessorElement element) { var endpoint = new FileProcessorEndpoint { Name = element.Name, DropPath = element.DropPath, InProgressPath = element.InProgressPath, Filter = element.Filter, MonitorSubdirectories = element.MonitorSubdirectories, ScavengeInterval = new TimeSpan(0, 0, element.ScavengeInterval), RecoveryInterval = new TimeSpan(0, 0, element.RecoveryInterval), PollingRestartInterval = new TimeSpan(0, 0, element.PollingInactivityRestartInterval), NumberOfConsumers = element.Consumers, SuccessPath = element.SuccessPath, FailurePath = element.FailurePath, ProcessorConfigurator = DetermineProcessorType(element), Handler = element.Handler.ToType(), PostProcessor = element.PostProcessor.ToType(), AdditionalFilter = element.AdditionalFilter.ToType() ?? typeof(DefaultFileFilter) }; return(endpoint); }
public void Register(IUnityContainer container, FileProcessorEndpoint endpoint) { // Registration for the handler if present if (endpoint.Handler != null) { container.RegisterType(typeof(IFileHandler), endpoint.Handler, endpoint.Name); } if (endpoint.PostProcessor == null) { if ((endpoint.Handler != null) && endpoint.Handler.Implements <IFilePostProcessor>()) { endpoint.PostProcessor = endpoint.Handler; } else { endpoint.PostProcessor = typeof(NullPostProcessor); } } // Registration for the post processor container.RegisterType(typeof(IFilePostProcessor), endpoint.PostProcessor, endpoint.Name); container.RegisterType(typeof(IFileFilter), endpoint.AdditionalFilter, endpoint.Name); // Tie the parameters to the processor container.RegisterType( typeof(IFileProcessor), typeof(EventBasedFileProcessor), endpoint.Name, new PerResolveLifetimeManager(), new InjectionConstructor( new ResolvedParameter <FileProcessorEndpoint>(endpoint.Name), new ResolvedParameter <IFileHandler>(endpoint.Name), new ResolvedParameter <IFilePostProcessor>(endpoint.Name), new ResolvedParameter <IFileFilter>(endpoint.Name))); }
public void TestValidate(string name, string processConfigurator, string inProgressPath, bool expectException) { var failSuffix = name + ", " + processConfigurator + ", " + inProgressPath; try { var endpoint = new FileProcessorEndpoint { Name = name, ProcessorConfigurator = processConfigurator, InProgressPath = inProgressPath }; var candidate = endpoint.Validate(); if (expectException) { Assert.Fail("expected Exception was not thrown : " + failSuffix); } Assert.IsTrue(candidate); } catch (NotSupportedException) { if (!expectException) { Assert.Fail("Exception was thrown but not expected : " + failSuffix); } } }
public static string GetDropFilter(this FileProcessorEndpoint endpoint) { return(FileProcessorEndpoint.GetStringPropertyOrThrow(() => endpoint.Filter, "File Drop Filter")); }
public EventBasedFileProcessor(FileProcessorEndpoint endpoint, IFileHandler handler, IFilePostProcessor postProcessor, IFileFilter additionalFilter) : base(endpoint, handler, postProcessor, additionalFilter) { }
protected abstract void RegisterProcessor(IUnityContainer container, FileProcessorEndpoint endpoint);
public CustomFileProcessor(FileProcessorEndpoint endpoint, IFileHandler handler, IFilePostProcessor postProcessor) : base(endpoint, handler, postProcessor) { }
public FileProcessorHelper(FileProcessorEndpoint endpoint, IFileHandler handler, IFilePostProcessor postProcessor) : base(endpoint, handler, postProcessor) { }
public static string GetFailurePath(this FileProcessorEndpoint endpoint) { return(FileProcessorEndpoint.GetStringPropertyOrThrow(() => endpoint.FailurePath, "File Failure Path")); }