public TailViewStateControllerFactory([NotNull] IStateBucketService stateBucketService, [NotNull] ISchedulerProvider schedulerProvider, [NotNull] ISearchStateToMetadataMapper searchStateToMetadataMapper, [NotNull] ILogFactory loggerFactory) { if (stateBucketService == null) { throw new ArgumentNullException(nameof(stateBucketService)); } if (schedulerProvider == null) { throw new ArgumentNullException(nameof(schedulerProvider)); } if (searchStateToMetadataMapper == null) { throw new ArgumentNullException(nameof(searchStateToMetadataMapper)); } if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } _stateBucketService = stateBucketService; _schedulerProvider = schedulerProvider; _searchStateToMetadataMapper = searchStateToMetadataMapper; _loggerFactory = loggerFactory; }
public GlobalSearchOptions(ISearchMetadataCollection metadata, ISearchStateToMetadataMapper converter, ISetting<SearchState[]> searchStateSettings) { Metadata = metadata; var loader = searchStateSettings.Value .Take(1) .Select(items => items.Select(state => converter.Map(state,true))) .Subscribe(metadata.Add); var writer = metadata.Metadata.Connect() .ToCollection() .Select(metaData => metaData.ToArray()) .Throttle(TimeSpan.FromMilliseconds(250)) .Select(searchStateItems => searchStateItems.Select(converter.Map).ToArray()) .Subscribe(searchStateSettings.Write); _cleanUp = new CompositeDisposable(loader, writer); }
public GlobalSearchOptions(ISearchMetadataCollection metadata, ISearchStateToMetadataMapper converter, ISetting <SearchState[]> searchStateSettings) { Metadata = metadata; var loader = searchStateSettings.Value .Take(1) .Select(items => items.Select(state => converter.Map(state, true))) .Subscribe(metadata.Add); var writer = metadata.Metadata.Connect() .ToCollection() .Select(metaData => metaData.ToArray()) .Throttle(TimeSpan.FromMilliseconds(250)) .Select(searchStateItems => searchStateItems.Select(converter.Map).ToArray()) .Subscribe(searchStateSettings.Write); _cleanUp = new CompositeDisposable(loader, writer); }
public TailViewStateController([NotNull] TailViewModel tailView, IStateBucketService stateBucketService, ISchedulerProvider schedulerProvider, ISearchStateToMetadataMapper searchStateToMetadataMapper, ILogger logger) { if (tailView == null) { throw new ArgumentNullException(nameof(tailView)); } _tailView = tailView; bool loadingSettings = false; const string type = "TailView"; logger.Info("Loading state for {0}", tailView.Name); stateBucketService .Lookup(type, tailView.Name) .Convert(state => { var converter = new TailViewToStateConverter(); return(converter.Convert((State)state)); }).IfHasValue(tailviewstate => { schedulerProvider.Background.Schedule(() => { try { loadingSettings = true; logger.Info("Applying {0} saved search settings for {1} ", tailviewstate.SearchItems.Count(), tailView.Name); var searches = tailviewstate.SearchItems.Select(searchStateToMetadataMapper.Map); _tailView.SearchMetadataCollection.Add(searches); tailView.SearchCollection.Select(tailviewstate.SelectedSearch); logger.Info("DONE: Applied {0} search settings for {1} ", tailviewstate.SearchItems.Count(), tailView.Name); } finally { loadingSettings = false; } }); }); var selectedChanged = tailView.SearchCollection .WhenValueChanged(sc => sc.Selected, false) .Select(vm => vm.Text); var metaChanged = _tailView.SearchMetadataCollection.Metadata.Connect() .ToCollection() .Select(metaData => metaData.ToArray()); var writer = selectedChanged.CombineLatest(metaChanged, (selected, metadata) => new { selected, metadata }) .Where(_ => !loadingSettings) .Throttle(TimeSpan.FromMilliseconds(250)) .Select(x => Convert(_tailView.Name, x.selected, x.metadata)) .Subscribe(state => { stateBucketService.Write(type, tailView.Name, state); }); _cleanUp = new CompositeDisposable(writer); }
public TailViewStateRestorer(ILogger logger, ISearchStateToMetadataMapper searchStateToMetadataMapper) { _logger = logger; _searchStateToMetadataMapper = searchStateToMetadataMapper; }