public static IObservable <IChangeSet <LoadOrderListing> > GetLiveLoadOrder( FilePath cccFilePath, DirectoryPath dataFolderPath, out IObservable <ErrorResponse> state, bool orderListings = true) { var raw = ObservableExt.WatchFile(cccFilePath.Path) .StartWith(Unit.Default) .Select(_ => { try { return(GetResponse <IObservable <IChangeSet <ModKey> > > .Succeed( File.ReadAllLines(cccFilePath.Path) .Select(x => ModKey.FromNameAndExtension(x)) .AsObservableChangeSet())); } catch (Exception ex) { return(GetResponse <IObservable <IChangeSet <ModKey> > > .Fail(ex)); } }) .Replay(1) .RefCount(); state = raw .Select(r => (ErrorResponse)r); var ret = ObservableListEx.And( raw .Select(r => { return(r.Value ?? Observable.Empty <IChangeSet <ModKey> >()); }) .Switch(), ObservableExt.WatchFolderContents(dataFolderPath.Path) .Transform(x => { if (ModKey.TryFromNameAndExtension(Path.GetFileName(x), out var modKey)) { return(TryGet <ModKey> .Succeed(modKey)); } return(TryGet <ModKey> .Failure); }) .Filter(x => x.Succeeded) .Transform(x => x.Value) .RemoveKey()) .Transform(x => new LoadOrderListing(x, true)); if (orderListings) { ret = ret.OrderListings(); } return(ret); }
public IObservable <IChangeSet <IGrouping <TObject, TGroup> > > Run() { return(_source.Publish(shared => { // Monitor explicit property changes var regrouper = ObservableListEx.WhenValueChanged(shared, _propertySelector, false).ToUnit(); //add a throttle if specified if (_throttle != null) { regrouper = regrouper.Throttle(_throttle.Value, _scheduler ?? Scheduler.Default); } // Use property changes as a trigger to re-evaluate Grouping return shared.GroupWithImmutableState(_groupSelector, regrouper); })); }
public static IObservable <IChangeSet <TListing> > OrderListings <TListing>(this IObservable <IChangeSet <TListing> > e) where TListing : IModListingGetter { return(ObservableListEx.Sort(e, ModListing.GetComparer <TListing>(ModKey.ByTypeComparer))); }