예제 #1
0
        private async Task <bool> IsValidAccountInformation()
        {
            if (!ValidHost())
            {
                MessageBox.Show("Your Host doesn't appear to be a fully formed URL.", "Incorrect Host!", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            BtnSave.IsEnabled       = false;
            GridCoverAll.Visibility = Visibility.Visible;

            KallitheaRestClient <User> client = new KallitheaRestClient <User>("get_user", TbxHost.Text, TbxAPIKey.Text);

            try
            {
                KallitheaResponse <User> response = await client.Run();

                username = response.Result.Username;
                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show("Error: " + e.Message, "Error!\t\t\t\t", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification);

                BtnSave.IsEnabled       = true;
                GridCoverAll.Visibility = Visibility.Hidden;
                return(false);
            }
        }
예제 #2
0
        //  Methods
        //  =======

        /// <exception cref="TimeoutException"></exception>
        /// <exception cref="WebException"></exception>
        /// <exception cref="Kallithea_Klone.Kallithea_API.InvalidKallitheaResponseTypeException"></exception>
        public async Task <KallitheaResponse <T> > Run()
        {
            IRestResponse response = await Task.Run(() =>
            {
                return(client.Execute(request));
            });

            switch (response.ResponseStatus)
            {
            case ResponseStatus.Completed:
                KallitheaResponse <T> result = JsonConvert.DeserializeObject <KallitheaResponse <T> >(response.Content);

                if (result.Result == null)
                {
                    throw new InvalidKallitheaResponseTypeException(typeof(T));
                }

                return(result);

            case ResponseStatus.TimedOut:
                throw new TimeoutException($"Webrequest to {response.ResponseUri} timed out");

            case ResponseStatus.Error:
            case ResponseStatus.Aborted:
            default:
                throw new WebException("Error: " + response.ErrorMessage);
            }
        }
예제 #3
0
        public async Task <ICollection <string> > DownloadRepositories()
        {
            KallitheaRestClient <Repository[]> client = new KallitheaRestClient <Repository[]>("get_repos");

            try
            {
                KallitheaResponse <Repository[]> response = await client.Run();

                if (!Directory.Exists(appDataFolder))
                {
                    Directory.CreateDirectory(appDataFolder);
                }
                File.WriteAllLines(allReposFile, response.Result.Select(r => r.URL).ToArray());

                return(response.Result.Select(r => r.URL).ToArray());
            }
            catch (Exception e)
            {
                MessageBox.Show("Error: " + e.Message, "Error!\t\t\t\t", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification);
                return(null);
            }
        }