Esempio n. 1
0
        public void Start([AllowNull] IConnection connection)
        {
            if (connection != null)
            {
                uiProvider.AddService(typeof(IConnection), connection);
                connection.Login()
                .Select(c => hosts.LookupHost(connection.HostAddress))
                .Do(host =>
                {
                    machine.Configure(UIViewType.None)
                    .Permit(Trigger.Auth, UIViewType.Login)
                    .PermitIf(Trigger.Create, UIViewType.Create, () => host.IsLoggedIn)
                    .PermitIf(Trigger.Create, UIViewType.Login, () => !host.IsLoggedIn)
                    .PermitIf(Trigger.Clone, UIViewType.Clone, () => host.IsLoggedIn)
                    .PermitIf(Trigger.Clone, UIViewType.Login, () => !host.IsLoggedIn)
                    .PermitIf(Trigger.Publish, UIViewType.Publish, () => host.IsLoggedIn)
                    .PermitIf(Trigger.Publish, UIViewType.Login, () => !host.IsLoggedIn);
                })
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(_ => { }, () =>
                {
                    Debug.WriteLine("Start ({0})", GetHashCode());
                    Fire((Trigger)(int)currentFlow);
                });
            }
            else
            {
                connectionManager
                .IsLoggedIn(hosts)
                .Do(loggedin =>
                {
                    if (!loggedin && currentFlow != UIControllerFlow.Authentication)
                    {
                        connectionAdded = (s, e) => {
                            if (e.Action == NotifyCollectionChangedAction.Add)
                            {
                                uiProvider.AddService(typeof(IConnection), e.NewItems[0]);
                            }
                        };
                        connectionManager.Connections.CollectionChanged += connectionAdded;
                    }

                    machine.Configure(UIViewType.None)
                    .Permit(Trigger.Auth, UIViewType.Login)
                    .PermitIf(Trigger.Create, UIViewType.Create, () => loggedin)
                    .PermitIf(Trigger.Create, UIViewType.Login, () => !loggedin)
                    .PermitIf(Trigger.Clone, UIViewType.Clone, () => loggedin)
                    .PermitIf(Trigger.Clone, UIViewType.Login, () => !loggedin)
                    .PermitIf(Trigger.Publish, UIViewType.Publish, () => loggedin)
                    .PermitIf(Trigger.Publish, UIViewType.Login, () => !loggedin);
                })
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(_ => { }, () =>
                {
                    Debug.WriteLine("Start ({0})", GetHashCode());
                    Fire((Trigger)(int)currentFlow);
                });
            }
        }
Esempio n. 2
0
        CloneRequest ShowCloneDialog(IUIProvider uiProvider, IGitRepositoriesExt gitRepositories, ISimpleRepositoryModel repository = null)
        {
            string basePath = null;

            uiProvider.AddService(this, gitRepositories);

            var load = uiProvider.SetupUI(repository == null ? UIControllerFlow.Clone : UIControllerFlow.StartPageClone,
                                          null //TODO: set the connection corresponding to the repository if the repository is not null
                                          );

            load.Subscribe(x =>
            {
                if ((repository == null && x.Data.ViewType == Exports.UIViewType.Clone) ||       // fire the normal clone dialog
                    (repository != null && x.Data.ViewType == Exports.UIViewType.StartPageClone) // fire the clone dialog for re-acquiring a repo
                    )
                {
                    var vm = x.View.ViewModel as IBaseCloneViewModel;
                    if (repository != null)
                    {
                        vm.SelectedRepository = repository;
                    }
                    x.View.Done.Subscribe(_ =>
                    {
                        basePath = vm.BaseRepositoryPath;
                        if (repository == null)
                        {
                            repository = vm.SelectedRepository;
                        }
                    });
                }
            });

            uiProvider.RunUI();
            uiProvider.RemoveService(typeof(IGitRepositoriesExt), this);

            return(new CloneRequest(basePath, repository));
        }
Esempio n. 3
0
        public void Start([AllowNull] IConnection conn)
        {
            connection = conn;
            if (connection != null)
            {
                if (mainFlow != UIControllerFlow.Authentication)
                {
                    uiProvider.AddService(this, connection);
                }
                else // sanity check: it makes zero sense to pass a connection in when calling the auth flow
                {
                    Debug.Assert(false, "Calling the auth flow with a connection makes no sense!");
                }

                connection.Login()
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(_ => { }, () =>
                {
                    Debug.WriteLine("Start ({0})", GetHashCode());
                    Fire(Trigger.Next);
                });
            }
            else
            {
                connectionManager
                .GetLoggedInConnections(hosts)
                .FirstOrDefaultAsync()
                .Select(c =>
                {
                    bool loggedin = c != null;
                    if (mainFlow != UIControllerFlow.Authentication)
                    {
                        if (loggedin)     // register the first available connection so the viewmodel can use it
                        {
                            connection = c;
                            uiProvider.AddService(this, c);
                        }
                        else
                        {
                            // a connection will be added to the list when auth is done, register it so the next
                            // viewmodel can use it
                            connectionAdded = (s, e) =>
                            {
                                if (e.Action == NotifyCollectionChangedAction.Add)
                                {
                                    connection = e.NewItems[0] as IConnection;
                                    if (connection != null)
                                    {
                                        uiProvider.AddService(typeof(IConnection), this, connection);
                                    }
                                }
                            };
                            connectionManager.Connections.CollectionChanged += connectionAdded;
                        }
                    }
                    return(loggedin);
                })
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(_ => { }, () =>
                {
                    Debug.WriteLine("Start ({0})", GetHashCode());
                    Fire(Trigger.Next);
                });
            }
        }
Esempio n. 4
0
        public void Start([AllowNull] IConnection connection)
        {
            if (connection != null)
            {
                if (currentFlow != UIControllerFlow.Authentication)
                {
                    uiProvider.AddService(connection);
                }
                else // sanity check: it makes zero sense to pass a connection in when calling the auth flow
                {
                    Debug.Assert(false, "Calling the auth flow with a connection makes no sense!");
                }

                connection.Login()
                .Select(c => hosts.LookupHost(connection.HostAddress))
                .Do(host =>
                {
                    machine.Configure(UIViewType.None)
                    .Permit(Trigger.Auth, UIViewType.Login)
                    .PermitIf(Trigger.Create, UIViewType.Create, () => host.IsLoggedIn)
                    .PermitIf(Trigger.Create, UIViewType.Login, () => !host.IsLoggedIn)
                    .PermitIf(Trigger.Clone, UIViewType.Clone, () => host.IsLoggedIn)
                    .PermitIf(Trigger.Clone, UIViewType.Login, () => !host.IsLoggedIn)
                    .PermitIf(Trigger.Publish, UIViewType.Publish, () => host.IsLoggedIn)
                    .PermitIf(Trigger.Publish, UIViewType.Login, () => !host.IsLoggedIn);
                })
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(_ => { }, () =>
                {
                    Debug.WriteLine("Start ({0})", GetHashCode());
                    Fire((Trigger)(int)currentFlow);
                });
            }
            else
            {
                connectionManager
                .GetLoggedInConnections(hosts)
                .FirstOrDefaultAsync()
                .Select(c =>
                {
                    bool loggedin = c != null;
                    if (currentFlow != UIControllerFlow.Authentication)
                    {
                        if (loggedin)     // register the first available connection so the viewmodel can use it
                        {
                            uiProvider.AddService(c);
                        }
                        else
                        {
                            // a connection will be added to the list when auth is done, register it so the next
                            // viewmodel can use it
                            connectionAdded = (s, e) =>
                            {
                                if (e.Action == NotifyCollectionChangedAction.Add)
                                {
                                    uiProvider.AddService(typeof(IConnection), e.NewItems[0]);
                                }
                            };
                            connectionManager.Connections.CollectionChanged += connectionAdded;
                        }
                    }

                    machine.Configure(UIViewType.None)
                    .Permit(Trigger.Auth, UIViewType.Login)
                    .PermitIf(Trigger.Create, UIViewType.Create, () => loggedin)
                    .PermitIf(Trigger.Create, UIViewType.Login, () => !loggedin)
                    .PermitIf(Trigger.Clone, UIViewType.Clone, () => loggedin)
                    .PermitIf(Trigger.Clone, UIViewType.Login, () => !loggedin)
                    .PermitIf(Trigger.Publish, UIViewType.Publish, () => loggedin)
                    .PermitIf(Trigger.Publish, UIViewType.Login, () => !loggedin);

                    return(loggedin);
                })
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(_ => { }, () =>
                {
                    Debug.WriteLine("Start ({0})", GetHashCode());
                    Fire((Trigger)(int)currentFlow);
                });
            }
        }
Esempio n. 5
0
 public void AddService(Type t, object owner, object instance) => theRealProvider.AddService(t, owner, instance);