Ejemplo n.º 1
0
        public bool RegisterWithServerManagementComplete(ServerManagementAccount serverManagementAccount,
            string registrationIdentifier, string clientToken, string emailToken, 
            out string serverRegistrationIdentifier, out string serverClientToken)
        {
            serverRegistrationIdentifier = "";
            serverClientToken = "";

            var apiClient = new ApiClient(serverManagementAccount.HttpsEnabled, serverManagementAccount.Host, 
                serverManagementAccount.Port, serverManagementAccount.ApiVersion);

            var request = new RegisterComplete
            {
                RegistrationIdentifier = registrationIdentifier,
                ClientToken = clientToken, 
                EmailToken = emailToken
            };

            RegisterComplete.ResponseParams response;
            try
            {
                response = request.GetResponse(apiClient);
            }
            catch (NotFoundException e)
            {
                Logger.Warning("Incorrect confirmation code: " + e.Message);
                //MessageBox.Show(@"The code appears to be incorrect.");
                return false;
            }
            catch (RequestException e)
            {
                //MessageBox.Show(@"An unexpected error occured contacting the server.");
                Logger.Warning("Unexpected error contacting management API: " + e.Message);
                return false;
            }

            serverManagementAccount.UserIdentifier = response.UserIdentifier;
            serverManagementAccount.ApiKey = response.ApiKey;

            serverRegistrationIdentifier = response.ServerRegistrationIdentfier;
            serverClientToken = response.ServerClientToken;

            return true;
        }
Ejemplo n.º 2
0
 private static ApiClient GetDefaultApiClientForServerManagement()
 {
     var apiClient = new ApiClient(
         Config.ManagementHttps, Config.ManagementHost, Config.ManagementPort, Config.ManagementApiVersion);
     
     return apiClient;
 }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
        private static ApiClient GetApiClientForServerManagement()
        {
            var serverManagement = Model.ServerManagementAccounts.Find(new ServerManagementAccount()).FirstOrDefault();
            if (serverManagement == null)
                return null;

            var apiClient = new ApiClient(serverManagement.HttpsEnabled, serverManagement.Host, serverManagement.Port,
                serverManagement.ApiVersion, serverManagement.ApiKey);
            
            return apiClient;
        }