예제 #1
0
        public Controller()
        {
            _header = new Header(this);
            _homePage = new HomePage(this);
            _subscriptionInfoBar = new SubscriptionInfoBar(this);
            _mainForm = new MainForm(this, _header, _subscriptionInfoBar);

            //SyncAccounts();

            var serverAccounts = Model.ServerAccounts.Find(new ServerAccount());
            foreach (var serverAccount in serverAccounts)
            {
                _syncServers.Add(serverAccount.Id, new Sync(this, serverAccount.Id));
                _syncServers[serverAccount.Id].Start();
            }

            var managementAccount = Model.ServerManagementAccounts.Find(new ServerManagementAccount()).FirstOrDefault();
            if (managementAccount != null)
            {
                _syncManagement = new SyncManagement(this, managementAccount.Id);
                _syncManagement.Start();
            }
        }
예제 #2
0
        public bool RegisterWithServerManagement()
        {
            var serverManagementAccount = new ServerManagementAccount
            {
                HttpsEnabled = Config.ManagementHttps,
                Host = Config.ManagementHost,
                Port = Config.ManagementPort,
                ApiVersion = Config.ManagementApiVersion,
                Label = Config.ManagementLabel,
                Subscribed = false,
                InTrial = true,
                TrialEndsAt = DateTime.Today.AddDays(Config.TrialLengthDays)
            };

            using (var form = new ServerManagementRegister(this))
            {
                form.ShowDialog();
                if (!form.Success)
                    return false;
                
                using (var formConfirm = new ServerManagementRegisterConfirm(this, serverManagementAccount, 
                    form.RegistrationIdentifier, form.ClientToken))
                {
                    formConfirm.ShowDialog();
                    if (!formConfirm.Success)
                        return false;

                    serverManagementAccount.EmailAddress = form.EmailAddress;
                    
                    var newManagementAccountId = Model.ServerManagementAccounts.Create(serverManagementAccount);

                    _syncManagement = new SyncManagement(this, newManagementAccountId);
                    _syncManagement.Start();

                    var registrationIdentifier = formConfirm.ServerRegistrationIdentifier;
                    var clientToken = formConfirm.ServerClientToken;
                    var recoveryPasswordPlaintext = form.RecoveryPasswordPlainText;

                    Task.Run(() => RegisterServerComplete(registrationIdentifier,
                        clientToken, recoveryPasswordPlaintext));
                }
            }
            
            return true;
        }
예제 #3
0
        public async Task<bool> LogoutServerManagement()
        {
            _syncManagement.Stop();
            _syncManagement = null;

            var serverManagementAccount = GetServerManagementAccount();
            var managedServers = Model.ServerAccounts.Find(new ServerAccount {Managed = true});

            foreach (var server in managedServers)
            {
                await LogoutServer(server.Id, false);

                var databases = Model.Databases.Find(new Database {ServerAccountId = server.Id});
                foreach (var database in databases)
                {
                    if (_activeDatabaseId == database.Id)
                    {
                        _activeDatabase = false;
                        _activeDatabaseId = 0;
                    }

                    if (_databaseViews.ContainsKey(database.Id))
                    {
                        _databaseViews[database.Id].Dispose();
                        _databaseViews.Remove(database.Id);
                    }
                }
            }

            // Logout locally, then attempt to revoke the API key remotely.
            var apiClient = GetApiClientForServerManagement();
            Model.ServerManagementAccounts.Delete(serverManagementAccount.Id);
            
            try
            {
                await new ManagementAPI.Requests.Authenticated.Logout().GetResponseAsync(apiClient);
            }
            catch (RequestException)
            {
                // We'll handle this silently and assume the API key has already been revoked 
                // for some other reason.
            }
            
            return true;
        }
예제 #4
0
        public bool LoginToServerManagement(string emailAddress, string recoveryPassword)
        {
            var apiClient = new ApiClient(
                Config.ManagementHttps, Config.ManagementHost, Config.ManagementPort, Config.ManagementApiVersion);

            LoginWithRecoveryKey.ResponseParams response;
            try
            {
                var request = new LoginWithRecoveryKey
                {
                    EmailAddress = emailAddress,
                    RecoveryPasswordClientHash =
                        HashUtil.GenerateServerManagerRecoveryPasswordHash(emailAddress, recoveryPassword)
                };
                response = request.GetResponse(apiClient);
            }
            catch (UnauthorizedException)
            {
                MessageBox.Show(@"Incorrect email or recovery passphrase");
                return false;
            }
            catch (RequestException)
            {
                MessageBox.Show(@"Error logging in to server");
                return false;
            }

            var managementAccountId = Model.ServerManagementAccounts.Create(new ServerManagementAccount
            {
                HttpsEnabled = Config.ManagementHttps,
                Host = Config.ManagementHost,
                Port = Config.ManagementPort, 
                ApiVersion = Config.ManagementApiVersion,
                UserIdentifier = response.UserIdentifier,
                EmailAddress = emailAddress,
                ApiKey = response.ApiKey
            });

            _syncManagement = new SyncManagement(this, managementAccountId);
            _syncManagement.Start();

            UpdateHeader();

            Task.Run(() => GetServersFromServerManagement(recoveryPassword));

            return true;
        }