Ejemplo n.º 1
0
        public SyncSetupWizard(bool machineWide)
        {
            InitializeComponent();

            #region State
            bool   usedBefore = false;
            var    server     = new SyncServer();
            string cryptoKey  = null;
            #endregion

            #region Pages
            var welcomePage           = new SetupWelcomePage();
            var serverPage            = new ServerPage();
            var registerPage          = new RegisterPage();
            var credentialsPage       = new CredentialsPage();
            var existingCryptoKeyPage = new ExistingCryptoKeyPage();
            var resetCryptoKeyPage    = new ResetCryptoKeyPage(machineWide);
            var cryptoKeyChangedPage  = new CryptoKeyChangedPage();
            var newCryptoKeyPage      = new NewCryptoKeyPage();
            var finishedPage          = new SetupFinishedPage();
            #endregion

            #region Flows
            welcomePage.UsedBeforeSelected += delegate(bool value)
            {
                usedBefore = value;
                PushPage(serverPage);
            };
            serverPage.OfficialServer += delegate
            {
                server.Uri = credentialsPage.ServerUri = new Uri(Config.DefaultSyncServer);
                resetCryptoKeyPage.Server = existingCryptoKeyPage.Server = server;
                if (usedBefore)
                {
                    PushPage(credentialsPage);
                }
                else
                {
                    PushPage(registerPage);
                }
            };
            serverPage.CustomServer += delegate
            {
                server.Uri = credentialsPage.ServerUri = new Uri(Config.DefaultSyncServer);
                resetCryptoKeyPage.Server = existingCryptoKeyPage.Server = server;
                PushPage(credentialsPage);
            };
            registerPage.Next += () => PushPage(credentialsPage);
            credentialsPage.CredentialsSet += delegate(SyncServer newServer)
            {
                resetCryptoKeyPage.Server = existingCryptoKeyPage.Server = server = newServer;
                if (usedBefore)
                {
                    PushPage(existingCryptoKeyPage);
                }
                else
                {
                    PushPage(newCryptoKeyPage);
                }
            };
            existingCryptoKeyPage.OldKeySet += delegate(string key)
            {
                cryptoKey = key;
                PushPage(finishedPage);
            };
            existingCryptoKeyPage.ResetKey += () => PushPage(resetCryptoKeyPage);
            resetCryptoKeyPage.NewKeySet   += delegate(string key)
            {
                cryptoKey = key;
                PushPage(cryptoKeyChangedPage);
            };
            cryptoKeyChangedPage.Finish += () => PushPage(finishedPage);
            newCryptoKeyPage.NewKeySet  += delegate(string key)
            {
                cryptoKey = key;
                PushPage(finishedPage);
            };
            finishedPage.Finish += delegate
            {
                try
                {
                    var config = Config.Load();
                    config.FromSyncServer(server);
                    config.SyncCryptoKey = cryptoKey;
                    config.Save();
                    Close();

                    Program.RunCommand(SyncApps.Name);
                }
                #region Error handling
                catch (IOException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    Close();
                }
                catch (UnauthorizedAccessException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    Close();
                }
                catch (InvalidDataException ex)
                {
                    Msg.Inform(this, ex.Message + (ex.InnerException == null ? "" : "\n" + ex.InnerException.Message), MsgSeverity.Error);
                    Close();
                }
                #endregion
            };
            #endregion

            PushPage(welcomePage);
        }
Ejemplo n.º 2
0
        /// <exception cref="IOException">A problem occurs while reading the file.</exception>
        /// <exception cref="UnauthorizedAccessException">Read access to the file is not permitted.</exception>
        /// <exception cref="InvalidDataException">A problem occurs while deserializing the config data.</exception>
        public SyncTroubleshootWizard(bool machineWide)
        {
            InitializeComponent();

            #region Pages
            var welcomePage           = new ResetWelcomePage();
            var config                = Config.Load();
            var existingCryptoKeyPage = new ExistingCryptoKeyPage {
                Server = config.ToSyncServer()
            };
            var changeCryptoKeyPage = new ChangeCryptoKeyPage(machineWide);
            var resetCryptoKeyPage  = new ResetCryptoKeyPage(machineWide)
            {
                Server = config.ToSyncServer()
            };
            var cryptoKeyChangedPaged   = new CryptoKeyChangedPage();
            var resetServerPage         = new ResetServerPage(machineWide);
            var resetServerFinishedPage = new ResetServerFinishedPage();
            var resetClientPage         = new ResetClientPage(machineWide);
            var resetClientFinishedPage = new ResetClientFinishedPage();
            #endregion

            #region Flows
            welcomePage.ChangeCryptoKey     += () => PushPage(existingCryptoKeyPage);
            welcomePage.ResetServer         += () => PushPage(resetServerPage);
            welcomePage.ResetClient         += () => PushPage(resetClientPage);
            existingCryptoKeyPage.OldKeySet += delegate(string oldKey)
            {
                changeCryptoKeyPage.OldKey = oldKey;
                PushPage(changeCryptoKeyPage);
            };
            existingCryptoKeyPage.ResetKey += () => PushPage(resetCryptoKeyPage);
            Action <string> newKeySet = delegate(string newKey)
            {
                try
                {
                    config = Config.Load();
                    config.SyncCryptoKey = newKey;
                    config.Save();

                    PushPage(cryptoKeyChangedPaged);
                }
                #region Error handling
                catch (IOException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    Close();
                }
                catch (UnauthorizedAccessException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    Close();
                }
                catch (InvalidDataException ex)
                {
                    Msg.Inform(this, ex.Message + (ex.InnerException == null ? "" : "\n" + ex.InnerException.Message), MsgSeverity.Error);
                    Close();
                }
                #endregion
            };
            changeCryptoKeyPage.NewKeySet  += newKeySet;
            resetCryptoKeyPage.NewKeySet   += newKeySet;
            cryptoKeyChangedPaged.Finish   += Close;
            resetServerPage.Next           += () => PushPage(resetServerFinishedPage);
            resetServerFinishedPage.Finish += Close;
            resetClientPage.Next           += () => PushPage(resetClientFinishedPage);
            resetClientFinishedPage.Finish += Close;
            #endregion

            PushPage(welcomePage);
        }