/// <summary> /// Initializes a new instance of the <see cref="PlaylistViewModel" /> class. /// </summary> /// <param name="publicTransport">The public transport.</param> /// <param name="playlistService">The playlist service.</param> /// <param name="dispatcher">The dispatcher.</param> /// <param name="playerService">The audio player service.</param> /// <param name="fileInfoBuilder">The fileInfoBuilder.</param> /// <param name="configurationManager">The configuration manager.</param> /// <param name="globalHotkeyService">The global hotkey service.</param> /// <param name="windowManager">The window manager.</param> /// <param name="searchView">The search view.</param> public PlaylistViewModel(IPublicTransport publicTransport, IPlaylistService playlistService, IDispatcher dispatcher, IPlayerService playerService, IInfoBuilder <StorableTaggedFile> fileInfoBuilder, IConfigurationManager configurationManager, IGlobalHotkeyService globalHotkeyService, IWindowManager windowManager, ISearchView searchView) { this.publicTransport = Guard.IsNull(() => publicTransport); Guard.IsNull(() => configurationManager); this.dispatcher = Guard.IsNull(() => dispatcher); this.fileInfoBuilder = Guard.IsNull(() => fileInfoBuilder); this.globalHotkeyService = Guard.IsNull(() => globalHotkeyService); this.windowManager = Guard.IsNull(() => windowManager); this.searchView = Guard.IsNull(() => searchView); publicTransport.ApplicationEventBus.Subscribe <PlaylistUpdatedEvent>(OnPlaylistUpdated); publicTransport.ApplicationEventBus.Subscribe <TrackChangedEvent>(OnTrackChanged); searchHotkey = configurationManager.GetValue("Search", new HotkeyDescriptor(ModifierKeys.Control | ModifierKeys.Alt, Key.J), KnownConfigSections.GlobalHotkeys); searchHotkey.ValueChanged += SearchHotkeyOnValueChanged; globalHotkeyService.RegisterHotkey(searchHotkey.Value, OnSearch); searchView.PlayFile += SearchViewOnPlayFile; Files = new List <FileItem>(playlistService.Files.Select(x => new FileItem(x))); var currenTrack = playerService.CurrentTrackAsReadonly; if (null == currenTrack) { return; } SetPlayingFile(playlistService.Files.Find(x => x.Filename == currenTrack.Name)); }
public BassPlayer(IConfigurationManager configurationManager, ILogger logger) { this.logger = logger; sampleRate = configurationManager.GetValue("Sample Rate", 96000, "Bass"); bufferSize = configurationManager.GetValue("Buffer Size (ms)", 100, "Bass"); Setup(); }
internal ResettingNumbersBucket(IClock clock, IConfigurableValue<long> periodMillis) { _clock = clock; _periodMillis = periodMillis; _counters = CreateCounters(); _lastResetAtTime = clock.GetMillisecondTimestamp(); }
protected override void RegisterTypes() { storageFile = Container.Resolve <IConfigurationManager>().GetValue("NHibernate.StorageFile", "Storage.db"); InitStorage(); Container.RegisterType <ISessionScoper, SingletonSessionScoper>(new ContainerControlledLifetimeManager()); Container.RegisterType(typeof(IDataAdapter <>), typeof(NHibernateAdapter <>), new ContainerControlledLifetimeManager()); }
private static SettingsValueViewModelBase MakeDefaultView(IConfigurableValue value) { var displayType = typeof(SettingsValueViewModelBase <>); displayType = displayType.MakeGenericType(value.Value.GetType()); return((SettingsValueViewModelBase)Activator.CreateInstance(displayType, value, true)); }
public object CreateFor(IConfigurableValue value) { var type = value.Value.GetType(); Func <IConfigurableValue, SettingsValueViewModelBase> builder; return(!typeTable.TryGetValue(type, out builder) ? MakeWrapper(value, MakeDefaultView) : MakeWrapper(value, builder)); }
/// <summary> /// </summary> /// <param name="playlistService">The playlist service.</param> /// <param name="player">The player.</param> /// <param name="publicTransport">The public transport.</param> /// <param name="configurationManager">The configuration manager.</param> /// <param name="hotkeyService">The hotkey service.</param> public NonManagingPlayerService(IPlaylistService playlistService, IAudioPlayer player, IPublicTransport publicTransport, IConfigurationManager configurationManager, IGlobalHotkeyService hotkeyService) { state = PlayingState.Stopped; this.playlistService = Guard.IsNull(() => playlistService); this.player = Guard.IsNull(() => player); this.publicTransport = Guard.IsNull(() => publicTransport); this.configurationManager = Guard.IsNull(() => configurationManager); this.hotkeyService = Guard.IsNull(() => hotkeyService); Subscribe(); prebufferSongs = configurationManager.GetValue("PrebufferSongs", 2, "PlayerService"); PlayNextThreshold = configurationManager.GetValue("PlayNextThreshnoldMs", 500d, "PlayerService"); TrackInterchangeCrossfadeTime = configurationManager.GetValue("TrackInterchangeCrossfadeTimeMs", 500d, "PlayerService"); TrackInterchangeCrossFadeSteps = configurationManager.GetValue("TrackInterchangeCrossfadeSteps", 50, "PlayerService"); maxBackStack = configurationManager.GetValue("MaxBackStack", 2000, "PlayerService"); LastPlayed = configurationManager.GetValue("PlayerService.LastPlayed", Guid.Empty, KnownConfigSections.Hidden); LastPlayedOffset = configurationManager.GetValue("PlayerService.LastPlayedOffset", 0d, KnownConfigSections.Hidden); VolumeValue = configurationManager.GetValue("PlayerService.Volume", 1f, KnownConfigSections.Hidden); preBuffered = new List <TrackContainer>(prebufferSongs.Value); backStack = new List <TrackContainer>(maxBackStack.Value); VolumeValue.ValueChanged += VolumeValueOnValueChanged; RegisterHotkeys(); LoadLastPlayed(); UpdateState(); SendProgress(); }
internal ResettingNumbersBucket(IClock clock, IConfigurableValue <long> periodMillis) { _clock = clock; _periodMillis = periodMillis; _counters = CreateCounters(); _lastResetAtTime = clock.GetMillisecondTimestamp(); }
/// <summary> /// Initializes a new instance of the <see cref="ComponentBase" /> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="playlistService">The playlist service.</param> /// <param name="player">The player.</param> /// <param name="publicTransport">The public transport.</param> /// <param name="configurationManager">The configuration manager.</param> /// <param name="hotkeyService">The hotkey service.</param> public NonManagingPlayerService(ILogger logger, IPlaylistService playlistService, IAudioPlayer player, IPublicTransport publicTransport, IConfigurationManager configurationManager, IGlobalHotkeyService hotkeyService) : base(logger) { playlistService.Guard("playlistService"); player.Guard("player"); publicTransport.Guard("publicTransport"); configurationManager.Guard("configurationManager"); state = PlayingState.Stopped; this.playlistService = playlistService; this.player = player; this.publicTransport = publicTransport; this.configurationManager = configurationManager; this.hotkeyService = hotkeyService; publicTransport.ApplicationEventBus.Subscribe <PlaylistUpdatedEvent>(OnPlaylistUpdated); publicTransport.ApplicationEventBus.Subscribe <ShuffleChangedEvent>(OnShuffleChanged); prebufferSongs = configurationManager.GetValue("PlayerService.PrebufferSongs", 2); PlayNextThreshold = configurationManager.GetValue("PlayerService.PlayNextThreshnoldMs", 500d); TrackInterchangeCrossfadeTime = configurationManager.GetValue("PlayerService.TrackInterchangeCrossfadeTimeMs", 500d); TrackInterchangeCrossFadeSteps = configurationManager.GetValue("PlayerService.TrackInterchangeCrossfadeSteps", 50); maxBackStack = configurationManager.GetValue("PlayerService.MaxBackStack", 2000); preBuffered = new List <TrackContainer>(prebufferSongs.Value); backStack = new List <TrackContainer>(maxBackStack.Value); RegisterHotkeys(); }
// ReSharper restore PrivateFieldCanBeConvertedToLocalVariable /// <summary> /// Constructs a new GaugeTimer that invokes the provided handler. /// /// If the interval millis override is provided, it'll be used. Otherwise a /// ConfigurableValue for "mjolnir.gaugeIntervalMillis" || 5000 will be used. /// /// intervalMillisOverride should typically only be used for testing. /// </summary> /// <param name="onTick">Event handler to invoke on tick</param> /// <param name="intervalMillisOverride">Interval override (for unit testing)</param> internal GaugeTimer(ElapsedEventHandler onTick, IConfigurableValue<long> intervalMillisOverride = null) { _gaugeIntervalMillis = intervalMillisOverride ?? new ConfigurableValue<long>("mjolnir.gaugeIntervalMillis", 5000, UpdateStatsGaugeInterval); _timer = new Timer(_gaugeIntervalMillis.Value) { AutoReset = true }; _timer.Elapsed += onTick; _timer.Enabled = true; }
/// <summary> /// Initializes a new instance of the <see cref="SimpleFFTVisualizationViewModel" /> class. /// </summary> /// <param name="threadManager">The thread manager.</param> /// <param name="playerService">The player service.</param> /// <param name="publicTransport">The public transport.</param> /// <param name="dispatcher">The dispatcher.</param> /// <param name="configurationManager"></param> public SimpleFFTVisualizationViewModel(IThreadManager threadManager, IPlayerService playerService, IPublicTransport publicTransport, IDispatcher dispatcher, IConfigurationManager configurationManager) : base(threadManager, playerService, publicTransport, dispatcher, configurationManager) { normalizeFft = configurationManager.GetValue("Normalize", true, "FFT Visualization"); TargetRenderHeight = 512; }
/// <summary> /// Initializes a new instance of the <see cref="VisualizationViewModel" /> class. /// </summary> /// <param name="visualizationRegistry">The visualization registry.</param> /// <param name="publicTransport">The public transport.</param> /// <param name="dispatcher">The dispatcher.</param> /// <param name="configurationManager">...</param> public VisualizationViewModel(IVisualizationRegistry visualizationRegistry, IPublicTransport publicTransport, IDispatcher dispatcher, IConfigurationManager configurationManager) { this.visualizationRegistry = visualizationRegistry; this.dispatcher = dispatcher; publicTransport.ApplicationEventBus.Subscribe <VisualizationsChangedEvent>(OnVisualizationsChanged); lastVisualization = configurationManager.GetValue("Visualizations.LastVisualization", string.Empty, KnownConfigSections.Hidden); publicTransport.ApplicationEventBus.Subscribe <ShutdownEvent>(OnShutdown); ResetAvailable(); }
// ReSharper restore PrivateFieldCanBeConvertedToLocalVariable /// <summary> /// Constructs a new GaugeTimer that invokes the provided handler. /// /// If the interval millis override is provided, it'll be used. Otherwise a /// ConfigurableValue for "mjolnir.gaugeIntervalMillis" || 5000 will be used. /// /// intervalMillisOverride should typically only be used for testing. /// </summary> /// <param name="onTick">Event handler to invoke on tick</param> /// <param name="intervalMillisOverride">Interval override (for unit testing)</param> internal GaugeTimer(ElapsedEventHandler onTick, IConfigurableValue <long> intervalMillisOverride = null) { _gaugeIntervalMillis = intervalMillisOverride ?? new ConfigurableValue <long>("mjolnir.gaugeIntervalMillis", 5000, UpdateStatsGaugeInterval); _timer = new Timer(_gaugeIntervalMillis.Value) { AutoReset = true }; _timer.Elapsed += onTick; _timer.Enabled = true; }
/// <summary> /// Initializes a new instance of the <see cref="TaggedFilePersister" /> class. /// </summary> /// <param name="fileAdapter">The file adapter.</param> /// <param name="referenceAdapters">The reference adapters.</param> /// <param name="configurationManager">The configuration manager.</param> public TaggedFilePersister(IDataAdapter <StorableTaggedFile> fileAdapter, IReferenceAdapters referenceAdapters, IConfigurationManager configurationManager) { fileAdapter.Guard("fileAdapter"); referenceAdapters.Guard("referenceAdapters"); configurationManager.Guard("configurationManager"); this.fileAdapter = fileAdapter; this.referenceAdapters = referenceAdapters; maxCacheSize = configurationManager.GetValue("StorableTaggedFilePersister.MaxCacheItems", 200); CreateIndices(); }
public PaletteListViewModel(IConfigurableValue value) : base(value) { entries = new ObservableCollection <PaletteEntryViewModel>(Value.GetMap().Select(x => { var result = new PaletteEntryViewModel(x.Item1, x.Item2); Subscribe(result); return(result); })); }
internal FailurePercentageCircuitBreakerProperties( IConfigurableValue <long> minimumOperations, IConfigurableValue <int> thresholdPercentage, IConfigurableValue <long> trippedDurationMillis, IConfigurableValue <bool> forceTripped, IConfigurableValue <bool> forceFixed) { _minimumOperations = minimumOperations; _thresholdPercentage = thresholdPercentage; _trippedDurationMillis = trippedDurationMillis; _forceTripped = forceTripped; _forceFixed = forceFixed; }
/// <summary> /// Initializes a new instance of the <see cref="SearchViewModel" /> class. /// </summary> /// <param name="playlistService">The playlist service.</param> /// <param name="publicTransport">The public transport.</param> /// <param name="dispatcher">The dispatcher.</param> /// <param name="configurationManager">The configuration manager.</param> public SearchViewModel(IPlaylistService playlistService, IPublicTransport publicTransport, IDispatcher dispatcher, IConfigurationManager configurationManager) { playlistService.Guard("playlistService"); publicTransport.Guard("publicTransport"); dispatcher.Guard("dispatcher"); this.playlistService = playlistService; this.dispatcher = dispatcher; publicTransport.ApplicationEventBus.Subscribe <PlaylistUpdatedEvent>(OnPlaylistChanged); timer = new Timer(OnTimerTick); staysOpen = configurationManager.GetValue("Stays Open on Double Click", false, "Search Dialog"); ResetFiles(); }
/// <summary> /// </summary> /// <param name="threadManager">The thread manager.</param> /// <param name="playerService">The player service.</param> /// <param name="publicTransport">The public transport.</param> /// <param name="configurationManager"></param> /// <param name="dispatcher">The dispatcher.</param> public SpectralFFTVisualizationViewModel(IThreadManager threadManager, IPlayerService playerService, IPublicTransport publicTransport, IConfigurationManager configurationManager, IDispatcher dispatcher) : base(threadManager, playerService, publicTransport, dispatcher, configurationManager) { targetHeight = configurationManager.GetValue("FFT Count", 512, "Spectral FFT"); normalizationLevel = configurationManager.GetValue("Normalization Leve", .75f, "Spectral FFT"); targetHeight.ValueChanged += TargetHeightOnValueChanged; TargetRenderHeight = targetHeight.Value; fftTimer = new Timer(GetFFT); fftBackBuffer = (int *)Marshal.AllocHGlobal((int)TargetRenderHeight * (FFTSize * 4)); }
/// <summary> /// Initializes a new instance of the <see cref="PlayerControlsViewModel" /> class. /// </summary> /// <param name="configurationManager"></param> /// <param name="playlistService">The playlist service.</param>æ /// <param name="publicTransport">The public transport.</param> /// <param name="dispatcher">The dispatcher.</param> public PlayerControlsViewModel(IConfigurationManager configurationManager, IPlaylistService playlistService, IPublicTransport publicTransport, IDispatcher dispatcher) { publicTransport.Guard("publicTransport"); dispatcher.Guard("dispatcher"); publicTransport.ApplicationEventBus.Subscribe <TrackChangedEvent>(OnTrackChanged); publicTransport.ApplicationEventBus.Subscribe <ShuffleChangedEvent>(OnShuffleChanged); publicTransport.ApplicationEventBus.Subscribe <PlayingStateChangedEvent>(OnPlayingStateChanged); publicTransport.ApplicationEventBus.Subscribe <TrackProgressEvent>(OnTrackProgress); volumeValue = configurationManager.GetValue("PlayerService.Volume", 1f, KnownConfigSections.Hidden); volumeValue.ValueChanged += VolumeValueOnValueChanged; this.playlistService = playlistService; this.publicTransport = publicTransport; this.dispatcher = dispatcher; seekTimer = new Timer(OnSeekTimer); Initialize(); }
/// <summary> /// </summary> /// <param name="threadManager">The thread manager.</param> /// <param name="playerService">The player service.</param> /// <param name="publicTransport">The public transport.</param> /// <param name="dispatcher">The dispatcher.</param> /// <param name="configurationManager"></param> public SimpleWaveformVisualizationViewModel(IThreadManager threadManager, IPlayerService playerService, IPublicTransport publicTransport, IDispatcher dispatcher, IConfigurationManager configurationManager) : base(threadManager, playerService, publicTransport, dispatcher) { publicTransport.ApplicationEventBus.Subscribe <ShutdownEvent>(OnShutdown); waveformLength = configurationManager.GetValue("Length", 512, "Waveform"); color1 = configurationManager.GetValue("Colour 1", Color.FromArgb(255, 192, 0, 0), "Waveform"); color2 = configurationManager.GetValue("Colour 2", Color.FromArgb(255, 192, 192, 0), "Waveform"); color3 = configurationManager.GetValue("Colour 3", Color.FromArgb(255, 0, 192, 0), "Waveform"); palette = GetDefaultPalette(); color1.ValueChanged += Color1OnValueChanged; color2.ValueChanged += Color2OnValueChanged; color3.ValueChanged += Color3OnValueChanged; offsetTimer = new Timer(OnOffset, null, 10, 10); }
public MongoWrapper(IConfigurationManager configurationManager) { configurationManager.Guard("configurationManager"); DatabaseName = typeof(MongoWrapper).Assembly.GetName().Name.Replace(".", ""); mongoFile = configurationManager.GetValue("mongofile", "mongod.exe"); dbPath = configurationManager.GetValue("dbpath", string.Format("{0}\\data\\db", Environment.CurrentDirectory)); logFile = configurationManager.GetValue("logfile", "mongodb.log"); mongoPort = configurationManager.GetValue("mongoport", 27017); mongoHost = configurationManager.GetValue("mongohost", "localhost"); mongoArgs = configurationManager.GetValue("mongoargs", string.Format("--port {0} --dbpath \"{1}\" --logpath \"{2}\\{3}\"", mongoPort, dbPath, dbPath.Value, logFile.Value)); if (MongoAvailable) { return; } StartMongo(); }
/// <summary> /// </summary> /// <param name="threadManager">The thread manager.</param> /// <param name="playerService">The player service.</param> /// <param name="publicTransport">The public transport.</param> /// <param name="dispatcher">The dispatcher.</param> /// <param name="configurationManager"></param> protected FFTVisualizationViewModelBase(IThreadManager threadManager, IPlayerService playerService, IPublicTransport publicTransport, IDispatcher dispatcher, IConfigurationManager configurationManager) : base(threadManager, playerService, publicTransport, dispatcher) { Palette = configurationManager.GetValue("Palette", GetDefaultPalette(), "FFT Visualization").Value; fftSize = configurationManager.GetValue("FFT Size", 1024, "FFT Visualization"); if (!fftSize.Value.IsPowerOfTwo()) { fftSize.Value = 1024; } if (256 > fftSize.Value) { fftSize.Value = 256; } fftSize.ValueChanged += FFTSizeOnValueChanged; TargetRenderWidth = fftSize.Value; }
internal StandardCommandMetrics(GroupKey key, IConfigurableValue<long> windowMillis, IConfigurableValue<long> snapshotTtlMillis, IClock clock, IStats stats) { if (key == null) { throw new ArgumentNullException("key"); } _key = key; _clock = clock; _snapshotTtlMillis = snapshotTtlMillis; _resettingNumbersBucket = new ResettingNumbersBucket(_clock, windowMillis); if (stats == null) { throw new ArgumentNullException("stats"); } _stats = stats; }
internal StandardCommandMetrics(GroupKey key, IConfigurableValue <long> windowMillis, IConfigurableValue <long> snapshotTtlMillis, IClock clock, IStats stats) { if (key == null) { throw new ArgumentNullException("key"); } _key = key; _clock = clock; _snapshotTtlMillis = snapshotTtlMillis; _resettingNumbersBucket = new ResettingNumbersBucket(_clock, windowMillis); if (stats == null) { throw new ArgumentNullException("stats"); } _stats = stats; }
// ReSharper restore NotAccessedField.Local internal StpIsolationThreadPool(GroupKey key, IConfigurableValue <int> threadCount, IConfigurableValue <int> queueLength, IStats stats, IConfigurableValue <long> gaugeIntervalMillisOverride = null) { _key = key; _threadCount = threadCount; _queueLength = queueLength; if (stats == null) { throw new ArgumentNullException("stats"); } _stats = stats; var count = _threadCount.Value; var info = new STPStartInfo { ThreadPoolName = _key.Name, MinWorkerThreads = count, MaxWorkerThreads = count, MaxQueueLength = queueLength.Value, AreThreadsBackground = true, UseCallerExecutionContext = true, UseCallerHttpContext = true }; _pool = new SmartThreadPool(info); _timer = new GaugeTimer((source, args) => { _stats.Gauge(StatsPrefix + " activeThreads", null, _pool.ActiveThreads); _stats.Gauge(StatsPrefix + " inUseThreads", null, _pool.InUseThreads); // Note: Don't use _pool.WaitingCallbacks. It has the potential to get locked out by // queue/dequeue operations, and may block here if the pool's getting queued into heavily. _stats.Gauge(StatsPrefix + " pendingCompletion", null, _pool.CurrentWorkItemsCount); }, gaugeIntervalMillisOverride); _pool.OnThreadInitialization += () => _stats.Event(StatsPrefix + " thread", "Initialized", null); _pool.OnThreadTermination += () => _stats.Event(StatsPrefix + " thread", "Terminated", null); _threadCount.AddChangeHandler(UpdateThreadCount); _queueLength.AddChangeHandler(UpdateQueueLength); }
/// <summary> /// Initializes a new instance of the <see cref="PlaylistService" /> class. /// </summary> /// <param name="publicTransport">The public transport.</param> /// <param name="referenceAdapters">The reference adapters.</param> /// <param name="threadManager">The thread manager.</param> /// <param name="configurationManager">The configuration manager.</param> /// <param name="fileAdapter"></param> public PlaylistService(IPublicTransport publicTransport, IReferenceAdapters referenceAdapters, IThreadManager threadManager, IConfigurationManager configurationManager, IDataAdapter <StorableTaggedFile> fileAdapter) { publicTransport.Guard("publicTransport"); referenceAdapters.Guard("referenceAdapters"); threadManager.Guard("threadManager"); this.publicTransport = publicTransport; this.referenceAdapters = referenceAdapters; this.threadManager = threadManager; this.fileAdapter = fileAdapter; playList = configurationManager.GetValue("Playlist.LastPlaylist", new Guid[0], KnownConfigSections.Hidden); LoadPlaylist(playList.Value); shuffleValue = configurationManager.GetValue("Playlist.Shuffle", false, KnownConfigSections.Hidden); shuffleValue.ValueChanged += ShuffleValueOnValueChanged; publicTransport.ApplicationEventBus.Subscribe <ShutdownEvent>(OnShutdown); SubscribeCommands(); }
/// <summary> /// calls <see cref="ThreadedResultWorker{TArgs,TCompletedArgs}" /> /// </summary> /// <param name="infoBuilder">The info builder.</param> /// <param name="storageAdapter">The storage adapter.</param> /// <param name="logger">The logger.</param> /// <param name="configurationManager">The configuration manager.</param> /// <param name="threadManager">The thread manager service.</param> /// <param name="publicTransport">The public transport.</param> public RecursiveAsyncFileScanner(IInfoBuilder <TInfo> infoBuilder, IDataPersister <TInfo> storageAdapter, IConfigurationManager configurationManager, IThreadManager threadManager, IPublicTransport publicTransport, ILogger logger) : base(logger) { infoBuilder.Guard("infoBuilder"); storageAdapter.Guard("storageAdapter"); configurationManager.Guard("configurationManager"); threadManager.Guard("threadManagerService"); publicTransport.Guard("publicTransport"); this.infoBuilder = infoBuilder; this.storageAdapter = storageAdapter; this.threadManager = threadManager; this.publicTransport = publicTransport; pageSize = configurationManager.GetValue("PageSize", 2000, "File Scanner"); scanPaged = configurationManager.GetValue("ScanPaged", true, "File Scanner"); }
// ReSharper restore NotAccessedField.Local internal SemaphoreSlimIsolationSemaphore(GroupKey key, IConfigurableValue <int> maxConcurrent, IStats stats, IConfigurableValue <long> gaugeIntervalMillisOverride = null) { _key = key; if (stats == null) { throw new ArgumentNullException("stats"); } _stats = stats; // Note: Changing the semaphore maximum at runtime is not currently supported. _maxConcurrent = maxConcurrent.Value; _semaphore = new SemaphoreSlim(_maxConcurrent); _timer = new GaugeTimer((source, args) => { var count = _semaphore.CurrentCount; _stats.Gauge(StatsPrefix + " available", (count == 0 ? "Full" : "Available"), count); }, gaugeIntervalMillisOverride); }
// ReSharper restore NotAccessedField.Local internal SemaphoreSlimIsolationSemaphore(GroupKey key, IConfigurableValue<int> maxConcurrent, IStats stats, IConfigurableValue<long> gaugeIntervalMillisOverride = null) { _key = key; if (stats == null) { throw new ArgumentNullException("stats"); } _stats = stats; // Note: Changing the semaphore maximum at runtime is not currently supported. _maxConcurrent = maxConcurrent.Value; _semaphore = new SemaphoreSlim(_maxConcurrent); _timer = new GaugeTimer((source, args) => { var count = _semaphore.CurrentCount; _stats.Gauge(StatsPrefix + " available", (count == 0 ? "Full" : "Available"), count); }, gaugeIntervalMillisOverride); }
internal FailurePercentageCircuitBreaker(GroupKey key, IClock clock, ICommandMetrics metrics, IStats stats, IMetricEvents metricEvents, FailurePercentageCircuitBreakerProperties properties, IConfigurableValue<long> gaugeIntervalMillisOverride = null) { _key = key; _clock = clock; _metrics = metrics; if (stats == null) { throw new ArgumentNullException("stats"); } if (metricEvents == null) { throw new ArgumentNullException("metricEvents"); } _stats = stats; _metricEvents = metricEvents; Properties = properties; _state = State.Fixed; // Start off assuming everything's fixed. _lastTrippedTimestamp = 0; // 0 is fine since it'll be far less than the first compared value. // Old gauge, will be phased out in v3.0 when IStats are removed. _statsTimer = new GaugeTimer((source, args) => { var snapshot = _metrics.GetSnapshot(); _stats.Gauge(StatsPrefix + " total", snapshot.Total >= properties.MinimumOperations.Value ? "Above" : "Below", snapshot.Total); _stats.Gauge(StatsPrefix + " error", snapshot.ErrorPercentage >= properties.ThresholdPercentage.Value ? "Above" : "Below", snapshot.ErrorPercentage); }, gaugeIntervalMillisOverride); _metricsTimer = new GaugeTimer((source, args) => { _metricEvents.BreakerConfigGauge( Name, Properties.MinimumOperations.Value, Properties.ThresholdPercentage.Value, Properties.TrippedDurationMillis.Value); }, ConfigGaugeIntervalMillis); }
/// <summary> /// Initializes a new instance of the <see cref="PlaylistViewModel" /> class. /// </summary> /// <param name="publicTransport">The public transport.</param> /// <param name="playlistService">The playlist service.</param> /// <param name="dispatcher">The dispatcher.</param> /// <param name="playerService">The audio player service.</param> /// <param name="builder">The builder.</param> /// <param name="configurationManager">The configuration manager.</param> /// <param name="globalHotkeyService">The global hotkey service.</param> /// <param name="windowManager">The window manager.</param> /// <param name="searchView">The search view.</param> /// <param name="serializerService">The serializer service.</param> /// <param name="logger">The logger.</param> public PlaylistViewModel(IPublicTransport publicTransport, IPlaylistService playlistService, IDispatcher dispatcher, IPlayerService playerService, IInfoBuilder <StorableTaggedFile> builder, IConfigurationManager configurationManager, IGlobalHotkeyService globalHotkeyService, IWindowManager windowManager, ISearchView searchView, ISerializerService serializerService, ILogger logger) : base(logger) { publicTransport.Guard("publicTransport"); playlistService.Guard("playlistService"); dispatcher.Guard("dispatcher"); playerService.Guard("playerService"); builder.Guard("builder"); configurationManager.Guard("configurationManager"); globalHotkeyService.Guard("globalHotkeyService"); windowManager.Guard("windowManager"); searchView.Guard("searchView"); serializerService.Guard("serializerService"); this.playlistService = playlistService; this.dispatcher = dispatcher; this.playerService = playerService; this.builder = builder; this.globalHotkeyService = globalHotkeyService; this.windowManager = windowManager; this.searchView = searchView; publicTransport.ApplicationEventBus.Subscribe <PlaylistUpdatedEvent>(OnPlaylistUpdated); publicTransport.ApplicationEventBus.Subscribe <TrackChangedEvent>(OnTrackChanged); searchHotkey = configurationManager.GetValue("Search", new HotkeyDescriptor(ModifierKeys.Control | ModifierKeys.Alt, Key.J), KnownConfigSections.GlobalHotkeys); searchHotkey.ValueChanged += SearchHotkeyOnValueChanged; globalHotkeyService.RegisterHotkey(searchHotkey.Value, OnSearch); //globalHotkeyService.RegisterHotkey(new HotkeyDescriptor(ModifierKeys.None, Key.A), () => MessageBox.Show("Stuff")); searchView.PlayFile += SearchViewOnPlayFile; Files = new List <FileItem>(playlistService.Files.Select(x => new FileItem(x))); }
/// <summary> /// Initializes a new instance of the <see cref="PlaylistService" /> class. /// </summary> /// <param name="publicTransport">The public transport.</param> /// <param name="referenceAdapters">The reference adapters.</param> /// <param name="threadManager">The thread manager.</param> /// <param name="configurationManager">The configuration manager.</param> /// <param name="serializerService">The serializer service.</param> /// <param name="logger">The logger.</param> public PlaylistService(IPublicTransport publicTransport, IReferenceAdapters referenceAdapters, IThreadManager threadManager, IConfigurationManager configurationManager, ISerializerService serializerService, ILogger logger) : base(logger) { publicTransport.Guard("publicTransport"); referenceAdapters.Guard("referenceAdapters"); threadManager.Guard("threadManager"); serializerService.Guard("serializerService"); logger.Guard("logger"); this.publicTransport = publicTransport; this.referenceAdapters = referenceAdapters; this.threadManager = threadManager; this.logger = logger; this.serializerService = serializerService; playlistRelPath = configurationManager.GetValue("Playlist Relative Path", ".\\Playlist.bin"); LoadPlaylist(playlistRelPath.Value); publicTransport.ApplicationEventBus.Subscribe <ShutdownEvent>(OnShutdown); }
public SemaphoreBulkheadHolder(GroupKey key, IMetricEvents metricEvents) { if (metricEvents == null) { throw new ArgumentNullException("metricEvents"); } _metricEvents = metricEvents; // The order of things here is very intentional. // We create the configurable value first, retrieve its current value, and then // initialize the semaphore bulkhead. We register the change handler after that. // That ought to help avoid a situation where we might fire a config change handler // before we add the semaphore to the dictionary, potentially trying to add two // entries with different values in rapid succession. var configKey = "mjolnir.bulkhead." + key + ".maxConcurrent"; _config = new ConfigurableValue<int>(configKey, DefaultBulkheadMaxConcurrent); var value = _config.Value; _bulkhead = new SemaphoreBulkhead(key, value); // On change, we'll replace the bulkhead. The assumption here is that a caller // using the bulkhead will have kept a local reference to the bulkhead that they // acquired a lock on, and will release the lock on that bulkhead and not one that // has been replaced after a config change. _config.AddChangeHandler(newLimit => { if (newLimit < 0) { Log.ErrorFormat("Semaphore bulkhead config {0} changed to an invalid limit of {0}, the bulkhead will not be changed", configKey, newLimit); return; } _bulkhead = new SemaphoreBulkhead(key, newLimit); }); _timer = new GaugeTimer((source, args) => { _metricEvents.BulkheadConfigGauge(_bulkhead.Name, "semaphore", _config.Value); }, ConfigGaugeIntervalMillis); }
public CheckBoxViewModel(IConfigurableValue value) : base(value) { }
internal FailurePercentageCircuitBreakerProperties( IConfigurableValue<long> minimumOperations, IConfigurableValue<int> thresholdPercentage, IConfigurableValue<long> trippedDurationMillis, IConfigurableValue<bool> forceTripped, IConfigurableValue<bool> forceFixed) { _minimumOperations = minimumOperations; _thresholdPercentage = thresholdPercentage; _trippedDurationMillis = trippedDurationMillis; _forceTripped = forceTripped; _forceFixed = forceFixed; }
protected SettingsValueViewModelBase(IConfigurableValue value, bool autoSave = true) { this.value = Guard.IsNull(() => value); this.value.ValueChanged += ValueOnValueChanged; this.autoSave = autoSave; }
internal ResettingNumbersBucket(IConfigurableValue<long> periodMillis) : this(new SystemClock(), periodMillis) {}
internal StandardCommandMetrics(GroupKey key, IConfigurableValue <long> windowMillis, IConfigurableValue <long> snapshotTtlMillis, IStats stats) : this(key, windowMillis, snapshotTtlMillis, new SystemClock(), stats) { }
internal StandardCommandMetrics(GroupKey key, IConfigurableValue<long> windowMillis, IConfigurableValue<long> snapshotTtlMillis, IStats stats) : this(key, windowMillis, snapshotTtlMillis, new SystemClock(), stats) {}