public static TSource Bind <TSource, T>(this TSource view, IObservable <T> source, ILifeTime lifeTime, Action <T> target, int frameThrottle = 1) where TSource : ILifeTimeContext { source .Bind(target, frameThrottle) .AddTo(lifeTime); return(view); }
public static IObservable <ISortedChangeSet <TObject, TKey> > Bind <TObject, TKey>( this IObservable <ISortedChangeSet <TObject, TKey> > source, ReactiveList <TObject> target, int resetThreshold = 25) { if (target == null) { throw new ArgumentNullException("target"); } var adaptor = new SortedReactiveListAdaptor <TObject, TKey>(target, resetThreshold); return(source.Bind(adaptor)); }
public AudioPanelViewModel(EncodingWindowViewModel encodingWindowViewModel) : base(encodingWindowViewModel) { this.fallbackEncoderChoices = new List <AudioEncoderViewModel>(); IObservable <IChangeSet <AudioEncodingViewModel> > audioEncodingsObservable = this.audioEncodings.Connect(); audioEncodingsObservable.Bind(this.AudioEncodingsBindable).Subscribe(); IObservable <IChangeSet <AudioOutputPreview> > audioOutputPreviewObservable = this.audioOutputPreviews.Connect(); audioOutputPreviewObservable.Bind(this.AudioOutputPreviewsBindable).Subscribe(); // HasAudioTracks audioOutputPreviewObservable .Count() .StartWith(this.audioOutputPreviews.Count) .Select(c => c > 0) .ToProperty(this, x => x.HasAudioTracks, out this.hasAudioTracks); this.main.WhenAnyValue(x => x.SelectedTitle) .Skip(1) .Subscribe(_ => { this.NotifyAudioInputChanged(); }); this.main.AudioTracks .Connect() .WhenAnyPropertyChanged() .Subscribe(_ => { this.NotifyAudioInputChanged(); }); this.presetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.ContainerName) .Skip(1) .Subscribe(_ => { this.RefreshFallbackEncoderChoices(); this.RefreshCopyMaskChoices(); }); this.presetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile) .Subscribe(Observer.Create((VCProfile _) => { this.OnProfileChanged(); })); // AutoPassthroughSettingsVisible audioEncodingsObservable .WhenAnyPropertyChanged(nameof(AudioEncodingViewModel.SelectedAudioEncoder), nameof(AudioEncodingViewModel.SelectedPassthrough)) .Subscribe(_ => { this.RaisePropertyChanged(nameof(this.AutoPassthroughSettingsVisible)); }); audioEncodingsObservable.Subscribe(changeSet => { if (changeSet.Adds > 0 || changeSet.Removes > 0) { this.RaisePropertyChanged(nameof(this.AutoPassthroughSettingsVisible)); } }); this.presetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.AudioEncoderFallback) .Subscribe(audioEncoderFallback => { if (!this.userUpdatingFallbackEncoder) { this.audioEncoderFallback = this.fallbackEncoderChoices.FirstOrDefault(c => c.Encoder.ShortName == audioEncoderFallback); if (this.audioEncoderFallback == null) { this.audioEncoderFallback = this.fallbackEncoderChoices[0]; } this.RaisePropertyChanged(nameof(this.AudioEncoderFallback)); } }); // Make user updates change the profile IObservable <IChangeSet <CopyMaskChoiceViewModel> > copyMaskChoicesObservable = this.copyMaskChoices.Connect(); copyMaskChoicesObservable.Bind(this.CopyMaskChoicesBindable).Subscribe(); copyMaskChoicesObservable.WhenValueChanged(choice => choice.Enabled, notifyOnInitialValue: false).Subscribe(_ => { this.userUpdatingCopyMask = true; this.SaveCopyMasksToProfile(); this.userUpdatingCopyMask = false; this.RefreshAudioPreview(); }); // Make profile changes update the local mask choices this.presetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.AudioCopyMask) .Subscribe(audioCopyMask => { if (this.userUpdatingCopyMask) { return; } this.copyMaskChoices.Edit(copyMaskChoicesInnerList => { copyMaskChoicesInnerList.Clear(); HBContainer container = HandBrakeEncoderHelpers.GetContainer(this.EncodingWindowViewModel.Profile.ContainerName); foreach (HBAudioEncoder encoder in HandBrakeEncoderHelpers.AudioEncoders) { if ((encoder.CompatibleContainers & container.Id) > 0 && encoder.IsPassthrough && encoder.ShortName != AudioEncodingViewModel.AutoPassthroughEncoder) { bool enabled = true; string codec = encoder.ShortName.Substring(5); if (audioCopyMask != null) { CopyMaskChoice profileMaskChoice = audioCopyMask.FirstOrDefault(choice => choice.Codec == codec); if (profileMaskChoice != null) { enabled = profileMaskChoice.Enabled; } } copyMaskChoicesInnerList.Add(new CopyMaskChoiceViewModel(codec, enabled)); } } }); this.RefreshAudioPreview(); }); this.RegisterProfileProperties(); }
public ExtensionsProvider(string contract, IServiceFactory factory, IFilePicker picker) { var catalog = AppExtensionCatalog.Open(contract); var source = new SourceCache <AppExtension, string>(a => a.Id); Connect = ReactiveCommand.CreateFromTask(async() => { var initial = await catalog.FindAllAsync(); source.Edit(x => { x.Clear(); var findAllAsync = initial; x.AddOrUpdate(findAllAsync); refreshers.Dispose(); DisposableMixins.DisposeWith(Observable .FromEventPattern <AppExtensionPackageInstalledEventArgs>(catalog, "PackageInstalled") .Subscribe(args => x.AddOrUpdate(args.EventArgs.Extensions)), refreshers); DisposableMixins.DisposeWith(Observable .FromEventPattern <AppExtensionPackageUninstallingEventArgs>(catalog, "PackageUninstalling") .Subscribe(args => { }), refreshers); }); return(Unit.Default); }); Func <Task <byte[]> > GetLogo(AppExtension appExtension) { return(async() => { try { var open = await appExtension.AppInfo.DisplayInfo.GetLogo(new Size(1, 1)).OpenReadAsync(); var stream = open.AsStreamForRead(); return await StreamMixin.ReadBytes(stream); } catch (Exception e) { return null; } }); } Func <Task <IDictionaryBasedService> > GetService(AppExtension appExtension) { return(async() => { var connInfo = await appExtension.GetConnectionInfo(); return factory.Create(connInfo.Item1, connInfo.Item2); }); } ObservableChangeset = source .Connect() .Transform(ext => new ImportViewModel(ext.DisplayName, ext.Description, GetLogo(ext), GetService(ext), picker)); DisposableMixins.DisposeWith(ObservableChangeset .Bind(out extensions) .Subscribe(), disposables); DisposableMixins.DisposeWith(Connect.Execute() .Subscribe(), disposables); }
public static IDisposable Bind <T> (this IObservable <ValidationResult> validationResult, Func <ValidationFailure, T> selector, Action <T> onAdd, Action <T> onRemove) { return(validationResult.Bind(validation => validation.Errors.Select(selector).ToList( ), projection => projection.ForEach(onAdd), projection => projection.ForEach(onRemove))); }
public static IDisposable Bind(this IObservable <ValidationResult> validationResult, Action <ValidationFailure> onAdd, Action <ValidationFailure> onRemove) { return(validationResult.Bind(validation => validation.Errors.ForEach(onAdd), validation => validation.Errors.ForEach(onRemove))); }
public static IDisposable Bind(this IObservable <ValidationResult> validationResult, Action <IEnumerable <ValidationFailure> > onAdd, Action <IEnumerable <ValidationFailure> > onRemove) { return(validationResult.Bind(validation => onAdd(validation.Errors), validation => onRemove(validation.Errors))); }