public async Task Start(Action <KnbOptions> action) { var options = new KnbOptions(); action.Invoke(options); if (string.IsNullOrWhiteSpace(options.FileName)) { throw new ArgumentException(); } CardSelectorOptions.MlModelFileName = options.MlModelFileName; KnbSimulator = ServiceProvider.GetService <IKnbSimulator>() ?? throw new InvalidOperationException(); KnbSimulator.OnPeriodChange = OnPeriodChange ?? KnbSimulator.OnPeriodChange; KnbSimulator.OnPlayFinished = OnPlayFinished ?? KnbSimulator.OnPlayFinished; KnbSimulator.OnSimulatorStopped = OnSimulatorStopped ?? KnbSimulator.OnSimulatorStopped; await KnbSimulator.Start(op => { op.FileName = options.FileName; op.MlModelFileName = options.MlModelFileName; op.NoOfTimes = options.NoOfTimes; op.NoOfCardPacks = options.NoOfCardPacks; op.NoOfPlayers = options.NoOfPlayers; op.NoOfTimesPerPeriod = options.NoOfTimesPerPeriod; }); }
public async Task Start(Action <KnbOptions> action) { if (action == null) { throw new ArgumentNullException(); } var options = new KnbOptions(); action.Invoke(options); Options = options; if (string.IsNullOrWhiteSpace(options.FileName)) { throw new ArgumentException(); } try { await StartSimulator(); } catch (UnauthorizedAccessException ex) { throw new UnauthorizedAccessException("User may not have permission to access the required file"); } catch (System.IO.FileNotFoundException ex) { throw new System.IO.FileNotFoundException("File does not found"); } catch (Exception ex) { throw new Exception("Unexpected error occured"); } }