public EncodingConfig(IEngineConfig config, Encoding encoding) { _variableKeys = new List <byte[]>(); Encoding = encoding; LineEndings = new TokenTrie(); Whitespace = new TokenTrie(); WhitespaceOrLineEnding = new TokenTrie(); Variables = new TokenTrie(); foreach (string token in config.LineEndings) { byte[] tokenBytes = encoding.GetBytes(token); LineEndings.AddToken(tokenBytes); WhitespaceOrLineEnding.AddToken(tokenBytes); } foreach (string token in config.Whitespaces) { byte[] tokenBytes = encoding.GetBytes(token); Whitespace.AddToken(tokenBytes); WhitespaceOrLineEnding.AddToken(tokenBytes); } _values = new Func <object> [config.Variables.Count]; ExpandVariables(config, encoding); }
static async Task Main(string[] args) { // get engine config IEngineConfig engineConfig = EngineConfigProvider.GetConfig(); ILogger logger = EngineLoggerProvider.GetLogger(engineConfig); ConsoleUtility.HideWindow(); try { // Create objects for current environment ITestE2EReader e2eReader = TestE2EReaderProvider.GetReader(logger); IComputer computer = ComputerSelector.GetCurrentComputer(); IReadOnlyList <ICloudOCRService> ocrServices = CloudOCRServiceProvider.GetCloudOCRServices(computer, engineConfig, logger); // create engine IEngine engine = new Engine(e2eReader, computer, ocrServices, engineConfig, logger); // run tests await engine.RunAsync(args).ConfigureAwait(false); } catch (Exception ex) { logger.WriteError("Error = " + ex); } ConsoleUtility.ShowWindow(); }
public Engine(ILogger <Engine> logger, ILoggerFactory loggerFactory, IDbContext dbContext, IEngineConfig configuration) { this.logger = logger; this.loggerFactory = loggerFactory; this.dbContext = dbContext; Configuration = configuration; this.services = new ServiceCollection(); }
public TestE2EExecutor(ITestE2E testE2E, IComputer computer, IReadOnlyList <ICloudOCRService> ocrService, ILogger logger, IEngineConfig engineConfig) { _testE2E = testE2E; _computer = computer; _ocrService = ocrService; _logger = logger; _engineConfig = engineConfig; }
private void DecideLoggerType(IEngineConfig config) { if (string.Equals("Console", config[loggerTypeKey], StringComparison.OrdinalIgnoreCase)) { _writeAction = WriteToConsole; } // TODO : extend to other logger type here. }
public void Update(IEngineConfig config) { ConstantDepth = config.ConstantDepth; Depth = config.Depth; TimeLimit = config.TimeLimit; NullMoveDepthReduction = config.NullMoveDepthReduction; Multithreading = config.Multithreading; UseOpeningBook = config.UseOpeningBook; }
public ArtemisEngine(GameState gameState, IEngineConfig config, OpeningBook openingBook) { this.gameState = gameState; transpositionTable = new TranspositionTable(config); evConfig = new EvaluationConfig(); evaluator = new PositionEvaluator(gameState, evConfig); Config = config; this.openingBook = openingBook; threadMaster = new ThreadMaster(this, gameState, transpositionTable, config); }
private void ExpandVariables(IEngineConfig config, Encoding encoding) { foreach (string key in config.Variables.Keys) { string formattedKey = string.Format(config.VariableFormatString, key); byte[] keyBytes = encoding.GetBytes(formattedKey); _variableKeys.Add(keyBytes); _values[Variables.AddToken(keyBytes)] = () => config.Variables[key]; } }
public TestStepForImage(IReadOnlyList <ICloudOCRService> ocrServices, IComputer computer, ITestStep action, ILogger logger, IEngineConfig config, IOpenCVSUtils openCVService) : base(ocrServices, config, computer, logger, openCVService) { _step = action; }
private static void Ensure(IEngineConfig config, string key, string fallback) { string value = config[key]; if (string.IsNullOrEmpty(value)) { value = fallback; } FileUtility.EnsureParentFolder(value); }
public Engine(ITestE2EReader reader, IComputer computer, IReadOnlyList <ICloudOCRService> ocrServices, IEngineConfig engineConfig, ILogger logger) { _testE2EReader = reader; _computer = computer; _ocrServices = ocrServices; _engineConfig = engineConfig; _logger = logger; // ensure environment EngineEnvironment.EnsureEnvironment(engineConfig); }
/// <summary> /// Initialize components and plugins in the sm environment. /// </summary> /// <param name="config">Config</param> public void Initialize(IEngineConfig config) { InitializeContainer(_containerConfigurer, _eventBroker, config); bool databaseInstalled = DataSettingsHelper.DatabaseIsInstalled(); if (databaseInstalled) { //startup tasks RunStartupTasks(); } }
public SearchThread(ArtemisEngine engine, ThreadMaster master, GameState gameState, TranspositionTable transpositionTable, ConcurrentDictionary <ulong, bool> searchedNodes, IEngineConfig config) { this.master = master; this.gameState = gameState; EvaluationConfig evConfig = new EvaluationConfig(); evaluator = new PositionEvaluator(gameState, evConfig); moveEvaluator = new MoveEvaluator(evConfig); quietSearch = new QuiescenceSearch(engine, gameState, evaluator, moveEvaluator); pvSearch = new PVSearch(engine, gameState, transpositionTable, killerMoves, evaluator, moveEvaluator, quietSearch, searchedNodes, config); this.config = config; }
public TestStepForBase(IReadOnlyList <ICloudOCRService> ocrServices, IEngineConfig config, IComputer computer, ILogger logger, IOpenCVSUtils openCVService) { OCRServices = ocrServices; _engineConfig = config; Computer = computer; Logger = logger; OpenCVService = openCVService; }
public ThreadMaster(ArtemisEngine engine, GameState gameState, TranspositionTable transpositionTable, IEngineConfig config) { this.gameState = gameState; this.transpositionTable = transpositionTable; this.config = config; threadsNum = Environment.ProcessorCount; searchThreads = new SearchThread[threadsNum]; for (int t = 0; t < threadsNum; t++) { GameState threadState = new GameState(gameState.PregeneratedAttacks, gameState.ZobristHashUtils); searchThreads[t] = new SearchThread(engine, this, threadState, transpositionTable, searchedNodes, config); } }
public PVSearch(ArtemisEngine engine, GameState gameState, TranspositionTable transpositionTable, KillerMoves killerMoves, PositionEvaluator evaluator, MoveEvaluator moveEvaluator, QuiescenceSearch quietSearch, ConcurrentDictionary <ulong, bool> searchedNodes, IEngineConfig config) { this.engine = engine; this.gameState = gameState; this.transpositionTable = transpositionTable; this.killerMoves = killerMoves; this.evaluator = evaluator; this.moveEvaluator = moveEvaluator; this.quietSearch = quietSearch; this.searchedNodes = searchedNodes; this.config = config; }
public AzureOCRService(IComputer computer, IOCRResultTextFinder textFinder, string serviceUrl, string serviceKey, ILogger logger, IEngineConfig config) { _computer = computer; _textFinder = textFinder; _azureOCRUrl = serviceUrl; _azureOCRKey = serviceKey; _logger = logger; _config = config; }
public GameManager(Canvas boardCanvas, MovesHistory movesHistory, ISettings settings) { this.boardCanvas = boardCanvas; this.movesHistory = movesHistory; this.settings = settings; engineConfig = settings; boardCanvas.Background = new ImageBrush { ImageSource = GetImage("board.png") }; lastMoveHighlight = new LastMoveHighlight(this, boardCanvas); gameState = new GameState(pregeneratedAttacks, zobristHashUtils); openingBook = new OpeningBook(pregeneratedAttacks, zobristHashUtils); engine = new ArtemisEngine(gameState, engineConfig, openingBook); }
/// <summary> /// Creates a factory instance and adds a http application injecting facility. /// </summary> /// <returns>A new factory</returns> public static IEngine CreateEngineInstance(IEngineConfig config) { if (config != null && !string.IsNullOrEmpty(config.EngineType)) { var engineType = Type.GetType(config.EngineType); if (engineType == null) { throw new ConfigurationErrorsException("The type '" + engineType + "' could not be found. Please check the configuration at /configuration/LifenxiangConfig/engine[@engineType] or check for missing assemblies."); } if (!typeof(IEngine).IsAssignableFrom(engineType)) { throw new ConfigurationErrorsException("The type '" + engineType + "' doesn't implement 'Chenyuan.Core.Infrastructure.IEngine' and cannot be configured in /configuration/LifenxiangConfig/engine[@engineType] for that purpose."); } return(Activator.CreateInstance(engineType) as IEngine); } return(new DefaultAppEngine()); }
public static ITestStepExecutor Generate(ITestStep testStep, IComputer computer, IReadOnlyList <ICloudOCRService> ocrSerivces, ILogger logger, IEngineConfig config) { if (string.Equals(testStep.Target, "image", StringComparison.OrdinalIgnoreCase)) { return(new TestStepForImage(ocrSerivces, computer, testStep, logger, config, OpenCVService)); } else if (string.Equals(testStep.Target, "text", StringComparison.OrdinalIgnoreCase)) { return(new TestStepForText(ocrSerivces, computer, testStep, logger, config, OpenCVService)); } else if (string.IsNullOrEmpty(testStep.Target)) { return(new TestStepForActionOnly(computer, testStep, logger)); } return(null); }
public TranspositionTable(IEngineConfig engineConfig) { this.engineConfig = engineConfig; }
public ProcessorState(Stream source, Stream target, int bufferSize, int flushThreshold, IEngineConfig config, IReadOnlyList <IOperationProvider> operationProviders) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (target == null) { throw new ArgumentNullException(nameof(target)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } if (operationProviders == null) { throw new ArgumentNullException(nameof(operationProviders)); } if (source.CanSeek) { try { if (source.Length < bufferSize) { bufferSize = (int)source.Length; } } catch { //The stream may not support getting the length property (in NetworkStream for instance, which throw a NotSupportedException), suppress any errors in // accessing the property and continue with the specified buffer size } } //Buffer has to be at least as large as the largest BOM we could expect else if (bufferSize < 4) { bufferSize = 4; } _source = source; _target = target; Config = config; _flushThreshold = flushThreshold; CurrentBuffer = new byte[bufferSize]; CurrentBufferLength = ReadExactBytes(source, CurrentBuffer, 0, CurrentBuffer.Length); Encoding encoding = EncodingUtil.Detect(CurrentBuffer, CurrentBufferLength, out byte[] bom); EncodingConfig = new EncodingConfig(Config, encoding); _bomSize = bom.Length; CurrentBufferPosition = _bomSize; CurrentSequenceNumber = _bomSize; target.Write(bom, 0, _bomSize); bool explicitOnConfigurationRequired = false; Dictionary <Encoding, Trie <OperationTerminal> > byEncoding = TrieLookup.GetOrAdd(operationProviders, x => new Dictionary <Encoding, Trie <OperationTerminal> >()); List <string> turnOnByDefault = OperationsToExplicitlySetOnByDefault.GetOrAdd(operationProviders, x => { explicitOnConfigurationRequired = true; return(new List <string>()); }); if (!byEncoding.TryGetValue(encoding, out Trie <OperationTerminal> trie)) { trie = new Trie <OperationTerminal>(); for (int i = 0; i < operationProviders.Count; ++i) { IOperation op = operationProviders[i].GetOperation(encoding, this); if (op != null) { for (int j = 0; j < op.Tokens.Count; ++j) { if (op.Tokens[j] != null) { trie.AddPath(op.Tokens[j].Value, new OperationTerminal(op, j, op.Tokens[j].Length, op.Tokens[j].Start, op.Tokens[j].End)); } } if (explicitOnConfigurationRequired && op.IsInitialStateOn && !string.IsNullOrEmpty(op.Id)) { turnOnByDefault.Add(op.Id); } } } byEncoding[encoding] = trie; } foreach (string state in turnOnByDefault) { config.Flags[state] = true; } _trie = new TrieEvaluator <OperationTerminal>(trie); if (bufferSize < _trie.MaxLength + 1) { byte[] tmp = new byte[_trie.MaxLength + 1]; Buffer.BlockCopy(CurrentBuffer, CurrentBufferPosition, tmp, 0, CurrentBufferLength - CurrentBufferPosition); int nRead = ReadExactBytes(_source, tmp, CurrentBufferLength - CurrentBufferPosition, tmp.Length - CurrentBufferLength); CurrentBuffer = tmp; CurrentBufferLength += nRead - _bomSize; CurrentBufferPosition = 0; CurrentSequenceNumber = 0; } }
private static ICloudOCRService CreateAzureOCR(string serviceUrl, string serviceKey, IComputer computer, ILogger logger, IEngineConfig config) { if (_azureService == null) { IOCRResultTextFinder textFinder = new AzureRecognizeTextFinder(); _azureService = new AzureOCRService(computer, textFinder, serviceUrl, serviceKey, logger, config); } return(_azureService); }
public static ICloudOCRService Create(string providerName, string serviceUrl, string serviceKey, IComputer computer, ILogger logger, IEngineConfig config) { if (string.IsNullOrEmpty(providerName)) { return(null); } if (string.Equals(providerName, "azure", StringComparison.OrdinalIgnoreCase)) { return(CreateAzureOCR(serviceUrl, serviceKey, computer, logger, config)); } // Create other service here...l return(null); }
public static void EnsureEnvironment(IEngineConfig config) { Ensure(config, _imageFolderKey, _imageFolderFallback); Ensure(config, _ArtifactsFolderKey, _ArtifactsFolderFallback); }
public EngineLogger(IEngineConfig config) { DecideLoggerType(config); }
public static IReadOnlyList <ICloudOCRService> GetCloudOCRServices(IComputer computer, IEngineConfig config, ILogger logger) { IReadOnlyList <IOCRProviderConfig> ocrProviders = config.GetOCRProviders(); if (ocrProviders == null || ocrProviders.Count == 0) { return(null); } List <ICloudOCRService> services = new List <ICloudOCRService>(); foreach (IOCRProviderConfig providerConfig in ocrProviders) { ICloudOCRService service = CloudOCRServiceFactory.Create(providerConfig.Provider, providerConfig.Endpoint, providerConfig.Key, computer, logger, config); if (service != null) { services.Add(service); } } return(services); }
public ProcessorState(Stream source, Stream target, int bufferSize, int flushThreshold, IEngineConfig config, IReadOnlyList <IOperationProvider> operationProviders) { bool sizedToStream = false; //Buffer has to be at least as large as the largest BOM we could expect if (bufferSize < 4) { bufferSize = 4; } else { try { if (source.Length < bufferSize) { sizedToStream = true; bufferSize = (int)source.Length; } } catch { //The stream may not support getting the length property (in NetworkStream for instance, which throw a NotSupportedException), suppress any errors in // accessing the property and continue with the specified buffer size } } _source = source; _target = target; Config = config; _flushThreshold = flushThreshold; CurrentBuffer = new byte[bufferSize]; CurrentBufferLength = source.Read(CurrentBuffer, 0, CurrentBuffer.Length); byte[] bom; Encoding encoding = EncodingUtil.Detect(CurrentBuffer, CurrentBufferLength, out bom); Encoding = encoding; CurrentBufferPosition = bom.Length; target.Write(bom, 0, bom.Length); Dictionary <Encoding, OperationTrie> byEncoding; if (!TrieLookup.TryGetValue(operationProviders, out byEncoding)) { TrieLookup[operationProviders] = byEncoding = new Dictionary <Encoding, OperationTrie>(); } if (!byEncoding.TryGetValue(encoding, out _trie)) { List <IOperation> operations = new List <IOperation>(operationProviders.Count); for (int i = 0; i < operationProviders.Count; ++i) { IOperation op = operationProviders[i].GetOperation(encoding, this); if (op != null) { operations.Add(op); } } byEncoding[encoding] = _trie = OperationTrie.Create(operations); } if (bufferSize < _trie.MaxLength && !sizedToStream) { byte[] tmp = new byte[_trie.MaxLength]; Buffer.BlockCopy(CurrentBuffer, CurrentBufferPosition, tmp, 0, CurrentBufferLength - CurrentBufferPosition); int nRead = _source.Read(tmp, CurrentBufferLength - CurrentBufferPosition, tmp.Length - CurrentBufferLength); CurrentBuffer = tmp; CurrentBufferLength += nRead; CurrentBufferPosition = 0; } }
public static ILogger GetLogger(IEngineConfig config) { return(new EngineLogger(config)); }
/// <summary> /// /// </summary> /// <param name="engine"></param> /// <param name="containerManager"></param> /// <param name="broker"></param> /// <param name="configuration"></param> public virtual void Configure(IEngine engine, ContainerManager containerManager, EventBroker broker, IEngineConfig configuration) { //other dependencies containerManager.AddComponentInstance <IEngineConfig>(configuration, "Chenyuan.configuration"); containerManager.AddComponentInstance <IEngine>(engine, "Chenyuan.engine"); containerManager.AddComponentInstance <ContainerConfigurer>(this, "Chenyuan.containerConfigurer"); //type finder containerManager.AddComponent <ITypeFinder, WebAppTypeFinder>("Chenyuan.typeFinder"); //register dependencies provided by other assemblies var typeFinder = containerManager.Resolve <ITypeFinder>(); containerManager.UpdateContainer(x => { var drTypes = typeFinder.FindClassesOfType <IDependencyRegistar>(); var drInstances = new List <IDependencyRegistar>(); foreach (var drType in drTypes) { drInstances.Add((IDependencyRegistar)Activator.CreateInstance(drType)); } //sort drInstances = drInstances.OrderBy(t => t.Order).ToList(); foreach (var dependencyRegistrar in drInstances) { dependencyRegistrar.Register(x, typeFinder); } }); //event broker containerManager.AddComponentInstance(broker); }