/// <summary> /// Called by the web controller to start an effect (after first stopping any active effect). /// Configuration and active state is persisted to file. /// </summary> /// <param name="config"></param> /// <param name="handler"></param> /// <returns></returns> public async Task StartEffect(EffectConfig config, EffectHandler handler) { // Cancel previous handler if there is one _effectCancellationTokenSource?.Cancel(); // Start the new handler _effectCancellationTokenSource = new CancellationTokenSource(); handler.Start(_effectCancellationTokenSource.Token); ActiveHandler = handler; // Save config including state var otherConfig = config.GetType() == typeof(XmasEffectConfig) ? (EffectConfig)await _storageService.LoadConfig <WarmupEffectConfig>() : (EffectConfig)await _storageService.LoadConfig <XmasEffectConfig>(); otherConfig.Active = false; config.Active = true; await _storageService.SaveConfig(otherConfig); await _storageService.SaveConfig(config); }
private string GetPath(EffectConfig config) => Path.Combine(_environment.ContentRootPath, config.GetType().Name + ".json");