public static IDisposable BuildChildNodes <TNode>( this IExplicitConnectionCache explicitConnectionCache, IImplicitConnectionCache implicitConnectionCache, GroupedConnectionKey parentKey, GroupedConnectionKeyLevel childKeyLevel, Func <GroupedConnection, TNode> childNodeFactory, IComparer <TNode> sortComparer, IScheduler scheduler, out ReadOnlyObservableCollection <TNode> nodes) { return(explicitConnectionCache.Connect() //user could dupe the connections, so we group em all .Filter(FilterBuilder <ExplicitConnection>(parentKey)) .Group(explicitCn => new GroupedConnectionKey(explicitCn, childKeyLevel)) .FullJoin( implicitConnectionCache.Connect() .Filter(FilterBuilder <ImplicitConnection>(parentKey)) .Group( implicitCn => new GroupedConnectionKey(implicitCn, childKeyLevel)), implicitGroup => implicitGroup.Key, (key, left, right) => new GroupedConnection(key, left.GetOptionalConnections(), right.GetOptionalConnections())) .Filter(gc => !string.IsNullOrEmpty(gc[childKeyLevel])) .Transform(childNodeFactory) .DisposeMany() .Sort(sortComparer) .ObserveOn(scheduler) .Bind(out nodes) .Subscribe()); }
private static Func <TConnection, bool> FilterBuilder <TConnection>(GroupedConnectionKey parentKey) where TConnection : IConnection { return(cn => parentKey == null || Equals(new GroupedConnectionKey(cn, parentKey.Level), parentKey)); }
public GroupedConnection(GroupedConnectionKey key, IEnumerable <ExplicitConnection> explicitConnections, IEnumerable <ImplicitConnection> implicitConnections) { if (explicitConnections == null) { throw new ArgumentNullException(nameof(explicitConnections)); } if (implicitConnections == null) { throw new ArgumentNullException(nameof(implicitConnections)); } if (key == null) { throw new ArgumentNullException(nameof(key)); } ExplicitConnections = explicitConnections; ImplicitConnections = implicitConnections; Key = key; var exemplar = ExplicitConnections.Select(explicitCn => (Connection)explicitCn) .Concat(ImplicitConnections.Select(implicitCn => (Connection)implicitCn)) .FirstOrDefault(); if (exemplar == null) { throw new ArgumentException("No connection was provided."); } _valueIndex = new Dictionary <GroupedConnectionKeyLevel, string>(); if (key.Level >= (int)GroupedConnectionKeyLevel.Host) { _valueIndex.Add(GroupedConnectionKeyLevel.Host, exemplar.Host); } if ((int)key.Level >= (int)GroupedConnectionKeyLevel.AuthorisationKey) { _valueIndex.Add(GroupedConnectionKeyLevel.AuthorisationKey, exemplar.AuthorisationKey); } if ((int)key.Level >= (int)GroupedConnectionKeyLevel.DatabaseId) { _valueIndex.Add(GroupedConnectionKeyLevel.DatabaseId, exemplar.DatabaseId); } if ((int)key.Level >= (int)GroupedConnectionKeyLevel.CollectionId) { _valueIndex.Add(GroupedConnectionKeyLevel.CollectionId, exemplar.CollectionId); } }
protected bool Equals(GroupedConnectionKey other) { return(_hashCode == other._hashCode); }