modules/FeedProcessor/ProcessorFactory.psm1
using module '..\Enums.psm1' using module '.\ProcessorBase.psm1' using module '.\BetgeniusProcessor.psm1' using module '.\BetradarProcessor.psm1' using module '.\LSportsProcessor.psm1' using module '.\RampProcessor.psm1' using module '.\SingularProcessor.psm1' using module '..\Helper\ObjectHelper.psm1' class ProcessorFactory { hidden static [Processor[]] $processors # @{ producer; feedId; source) hidden static [hashtable] $mapProducerSource hidden static [hashtable] $mapFeedProducer hidden static [hashtable] $mapFeedSource static [hashtable] $mapExternalKeyPrefix static [string[]] $producers static [Processor] getBySource([SOURCE] $source){ foreach ($processor in [ProcessorFactory]::processors) { if ($processor.source -eq $source) { return $processor } } return $null } static [Processor] getByFeedId([int] $feedId) { foreach ($processor in [ProcessorFactory]::processors) { if ($processor.feedId -eq $feedId) { return $processor } } return $null } static [SOURCE] getSourceByProducer([string] $name){ return [ProcessorFactory]::mapProducerSource[$name] } static [string] getProducerByFeedId([int] $id){ return [ProcessorFactory]::mapFeedProducer[$id] } static [string] getProducersBySource([SOURCE] $source){ $retValue = @() foreach ($key in [ProcessorFactory]::mapProducerSource.Keys) { if ([ProcessorFactory]::mapProducerSource[$key] -eq $source){ $retValue += $key} } return $retValue } static [SOURCE] getSourceByFeedId([int] $id) { return [ProcessorFactory]::mapFeedSource[$id] } #Create an instance static [void] Init([hashtable] $processorTypes) { [ProcessorFactory]::processors = @() [ProcessorFactory]::mapProducerSource = @{} [ProcessorFactory]::mapFeedProducer = @{} [ProcessorFactory]::mapFeedSource = @{} [ProcessorFactory]::mapExternalKeyPrefix = @{} $needFeedProducer = @() foreach ($pt in $processorTypes.GetEnumerator()) { foreach ($p in $pt.Value) { $processorObj = (New-Object -TypeName "$p" -ArgumentList ($pt.key)) if ($processorObj.needFeedProducer) { $needFeedProducer += $processorObj } [SOURCE] $source = $processorObj.source [hashtable] $itemProducers = $processorObj.producers [ProcessorFactory]::processors += $processorObj foreach ($item in $itemProducers.GetEnumerator()) { if (-not [ProcessorFactory]::mapFeedProducer.ContainsKey($item.value)){ [ProcessorFactory]::mapFeedProducer.Add($item.value, $item.key) } if (-not [ProcessorFactory]::mapProducerSource.ContainsKey($item.key)){ [ProcessorFactory]::mapProducerSource.Add($item.key, $source) } if (-not [ProcessorFactory]::mapFeedSource.ContainsKey($item.value)){ [ProcessorFactory]::mapFeedSource.Add($item.value, $source) } } [ProcessorFactory]::mapExternalKeyPrefix += $processorObj.mapExternalKeyPrefix } } foreach ($processorObj in $needFeedProducer) { $processorObj.mapFeedProducer = [ProcessorFactory]::mapFeedProducer } } } |