ViewState IPersistentView.CaptureState() { var coverter = new TailViewToStateConverter(); var state = coverter.Convert(_tailView.Name, _tailView.SearchCollection.Selected.Text, _tailView.SearchMetadataCollection.Metadata.Items.ToArray()); return(new ViewState(TailViewModelConstants.ViewKey, state)); }
State IPersistentStateProvider.CaptureState() { var coverter = new TailViewToStateConverter(); var state = coverter.Convert(_tailView.Name, _tailView.SearchCollection.Selected.Text, _tailView.SearchMetadataCollection.Metadata.Items.ToArray()); return(new State(1, state.Value)); }
public HeaderedView Create(ViewState state) { var converter = new TailViewToStateConverter(); var converted = converter.Convert(state.State); var file = converted.FileName; var viewModel = CreateView(new FileInfo(file)); var restorer = (IPersistentView)viewModel; restorer.Restore(state); return(new HeaderedView(new FileHeader(new FileInfo(file)), viewModel)); }
public State CaptureState() { var searchItems = _tailView.SearchOptions .Data .Select(search => new SearchState ( search.Text, search.UseRegex, search.Highlight, search.Filter, false, search.IgnoreCase )); var tailViewState = new TailViewState(_tailView.Name, _tailView.SearchCollection.Selected.Text, searchItems); var converter = new TailViewToStateConverter(); return(converter.Convert(tailViewState)); }
public State Convert(string fileName, string selectedSearch, SearchMetadata[] items) { var searchItems = items .OrderBy(s => s.Position) .Select(search => new SearchState ( search.SearchText, search.Position, search.UseRegex, search.Highlight, search.Filter, false, search.IgnoreCase, search.HighlightHue.Swatch, search.IconKind, search.HighlightHue.Name )).ToArray(); var tailViewState = new TailViewState(fileName, selectedSearch, searchItems); var converter = new TailViewToStateConverter(); return(converter.Convert(tailViewState)); }
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 TailViewStateController([NotNull] TailViewModel tailView, IStateBucketService stateBucketService, ISchedulerProvider schedulerProvider, ITailViewStateRestorer tailViewStateRestorer, ILogger logger, bool loadDefaults) { if (tailView == null) { throw new ArgumentNullException(nameof(tailView)); } var tailView1 = tailView; var converter = new TailViewToStateConverter(); bool loadingSettings = false; const string type = "TailView"; logger.Info("Loading state for {0}", tailView.Name); //Load state if (loadDefaults) { stateBucketService .Lookup(type, tailView.Name) .IfHasValue(tailviewstate => { schedulerProvider.Background.Schedule(() => { try { loadingSettings = true; tailViewStateRestorer.Restore(tailView, tailviewstate); } finally { loadingSettings = false; } }); }); } //write latest to file when something triggers a change var selectedChanged = tailView.SearchCollection .WhenValueChanged(sc => sc.Selected, false) .Where(vm => vm != null) .Select(vm => vm.Text); var metaChanged = tailView1.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 => converter.Convert(tailView1.Name, x.selected, x.metadata)) .Subscribe(state => { stateBucketService.Write(type, tailView.Name, state); }); _cleanUp = new CompositeDisposable(writer); }
public void Restore(TailViewModel view, State state) { var converter = new TailViewToStateConverter(); Restore(view, converter.Convert(state)); }