Esempio n. 1
0
        CloneRequest ShowCloneDialog(IGitHubServiceProvider gitHubServiceProvider, IGitRepositoriesExt gitRepositories, IRepositoryModel repository = null)
        {
            string basePath = null;

            gitHubServiceProvider.AddService(this, gitRepositories);
            var uiProvider = gitHubServiceProvider.GetService <IUIProvider>();
            var controller = uiProvider.Configure(repository == null ? UIControllerFlow.Clone : UIControllerFlow.StartPageClone,
                                                  null //TODO: set the connection corresponding to the repository if the repository is not null
                                                  );

            controller.TransitionSignal.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.RunInDialog(controller);
            gitHubServiceProvider.RemoveService(typeof(IGitRepositoriesExt), this);

            return(repository != null && basePath != null ? new CloneRequest(basePath, repository) : null);
        }
Esempio n. 2
0
        /// <summary>
        /// Configures the UI that gets loaded when entering a certain state and which state
        /// to go to for each trigger. Which state to go to depends on which ui flow state machine
        /// is currently active - when a trigger happens, the PermitDynamic conditions will
        /// lookup the currently active state machine from the list of available ones in `machines`,
        /// fire the requested trigger on it, and return the state that it went to, which causes
        /// `uiStateMachine` to load a new UI (or exit)
        /// There is a bit of redundant information regarding valid state transitions between this
        /// state machine and the individual state machines for each ui flow. This is unavoidable
        /// because permited transition triggers have to be explicit, so care should be taken to
        /// make sure permitted triggers per view here match the permitted triggers in the individual
        /// state machines.
        /// </summary>
        void ConfigureUIHandlingStates()
        {
            triggers.Add(Trigger.Next, uiStateMachine.SetTriggerParameters <ViewWithData>(Trigger.Next));

            uiStateMachine.Configure(UIViewType.None)
            .OnEntry(tr => stopping = false)
            .PermitDynamic(Trigger.Next, () =>
            {
                activeFlow = SelectActiveFlow();
                return(Go(Trigger.Next));
            })
            .PermitDynamic(Trigger.Finish, () => Go(Trigger.Finish));

            ConfigureEntriesExitsForView(UIViewType.Clone);
            ConfigureEntriesExitsForView(UIViewType.Create);
            ConfigureEntriesExitsForView(UIViewType.Publish);
            ConfigureEntriesExitsForView(UIViewType.PRList);
            ConfigureEntriesExitsForView(UIViewType.PRDetail);
            ConfigureEntriesExitsForView(UIViewType.PRCreation);
            ConfigureEntriesExitsForView(UIViewType.Login);
            ConfigureEntriesExitsForView(UIViewType.TwoFactor);
            ConfigureEntriesExitsForView(UIViewType.Gist);
            ConfigureEntriesExitsForView(UIViewType.StartPageClone);

            uiStateMachine.Configure(UIViewType.End)
            .OnEntryFrom(Trigger.Cancel, () => End(false))
            .OnEntryFrom(Trigger.Next, () => End(true))
            .OnEntryFrom(Trigger.Finish, () => End(true))
            // clear all the views and viewmodels created by a subflow
            .OnExit(() =>
            {
                // it's important to have the stopping flag set before we do this
                if (activeFlow == selectedFlow)
                {
                    completion?.OnNext(Success.Value);
                    completion?.OnCompleted();
                }

                DisposeFlow(activeFlow);

                if (activeFlow == selectedFlow)
                {
                    gitHubServiceProvider.RemoveService(typeof(IConnection), this);
                    transition.OnCompleted();
                    Reset();
                }
                else
                {
                    activeFlow = stopping || LoggedIn ? selectedFlow : UIControllerFlow.Authentication;
                }
            })
            .PermitDynamic(Trigger.Next, () =>
            {
                // sets the state to None for the current flow
                var state = Go(Trigger.Next);

                if (activeFlow != selectedFlow)
                {
                    if (stopping)
                    {
                        // triggering the End state again so that it can clear up the main flow and really end
                        state = Go(Trigger.Finish, selectedFlow);
                    }
                    else
                    {
                        // sets the state to the first UI of the main flow or the auth flow, depending on whether you're logged in
                        state = Go(Trigger.Next, LoggedIn ? selectedFlow : UIControllerFlow.Authentication);
                    }
                }
                return(state);
            })
            .Permit(Trigger.Finish, UIViewType.None);
        }
 public void RemoveService(Type t, object owner) => theRealProvider.RemoveService(t, owner);