Exemplo n.º 1
0
 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());
 }
Exemplo n.º 2
0
        public ConnectionsManagerViewModel(IExplicitConnectionCache explicitConnectionCache)
        {
            if (explicitConnectionCache == null)
            {
                throw new ArgumentNullException(nameof(explicitConnectionCache));
            }

            _explicitConnectionCache = explicitConnectionCache;

            AddConnectionCommand = new Command(_ =>
            {
                var vm = new ConnectionEditorViewModel(SaveConnection, () => Mode = ConnectionsManagerMode.Selector)
                {
                    DisplayMode = ConnectionEditorDisplayMode.MultiEdit
                };
                ConnectionEditor = vm;
                Mode             = ConnectionsManagerMode.ItemEditor;
            });
            EditConnectionCommand = new Command(o =>
            {
                var connection = o as ExplicitConnection;
                if (connection == null)
                {
                    return;
                }
                ConnectionEditor = new ConnectionEditorViewModel(connection, SaveConnection, () => Mode = ConnectionsManagerMode.Selector)
                {
                    DisplayMode = ConnectionEditorDisplayMode.MultiEdit
                };
                Mode = ConnectionsManagerMode.ItemEditor;
            }, o => o is ExplicitConnection);
            DeleteConnectionCommand = new Command(DeleteConnection, o => o is ExplicitConnection);

            _connectionCacheSubscription =
                explicitConnectionCache.Connect()
                .Sort(SortExpressionComparer <ExplicitConnection> .Ascending(c => c.Label))
                .Bind(out _connections)
                .Subscribe();

            if (_connections.Count == 0)
            {
                AddConnectionCommand.Execute(null);
            }
        }
Exemplo n.º 3
0
        public AutoSaver(IExplicitConnectionCache explicitConnectionCache, IGeneralSettings generalSettings, IManualSaver manualSaver)
        {
            if (explicitConnectionCache == null)
            {
                throw new ArgumentNullException(nameof(explicitConnectionCache));
            }
            if (generalSettings == null)
            {
                throw new ArgumentNullException(nameof(generalSettings));
            }
            if (manualSaver == null)
            {
                throw new ArgumentNullException(nameof(manualSaver));
            }

            _disposable = explicitConnectionCache.Connect()
                          .Select(_ => Unit.Default)
                          .Merge(generalSettings.OnAnyPropertyChanged().Select(_ => Unit.Default))
                          .Throttle(TimeSpan.FromSeconds(2))
                          .ObserveOn(new EventLoopScheduler())
                          .Subscribe(_ => manualSaver.Save(explicitConnectionCache, generalSettings));
        }