public static void GetLocationData(string locationStr, ScheduleDialog dialog)
        {
            var client = new RestClient("https://us1.locationiq.org");

            ProxyWrapper.ApplyProxyToClient(client);

            var request = new RestRequest("v1/search.php");

            request.AddParameter("key", apiKey);
            request.AddParameter("q", locationStr);
            request.AddParameter("format", "json");
            request.AddParameter("limit", "1");

            client.ExecuteAsync <List <LocationIQData> >(request, response =>
            {
                if (response.IsSuccessful)
                {
                    JsonConfig.settings.location = locationStr;
                    HandleLocationSuccess(response.Data[0], dialog);
                }
                else
                {
                    MessageDialog.ShowWarning(_("The location you entered was invalid, or you are not connected to " +
                                                "the Internet. Check your Internet connection and try a different location. You can use a " +
                                                "complete address or just the name of your city/region."), _("Error"));
                }
            });
        }
        private static void LoadLocaleFromWeb()
        {
            var client = new RestClient("https://api.poeditor.com");

            ProxyWrapper.ApplyProxyToClient(client);

            var request = new RestRequest("/v2/projects/export", Method.POST);

            request.AddParameter("api_token", JsonConfig.settings.poeditorApiToken);
            request.AddParameter("id", "293081");
            request.AddParameter("language", currentLocale);
            request.AddParameter("type", "mo");

            var response = client.Execute <PoEditorApiData>(request);

            if (!response.IsSuccessful)
            {
                return;
            }

            using (WebClient wc = new WebClient())
            {
                ProxyWrapper.ApplyProxyToClient(client);
                byte[] moBinary = wc.DownloadData(response.Data.result.url);

                using (Stream stream = new MemoryStream(moBinary))
                {
                    catalog = new Catalog(stream, new CultureInfo(currentLocale));
                }
            }
        }
Exemple #3
0
        private static string GetLatestVersion()
        {
            var client = new RestClient("https://api.github.com");

            ProxyWrapper.ApplyProxyToClient(client);

            var request  = new RestRequest("/repos/t1m0thyj/WinDynamicDesktop/releases/latest");
            var response = client.Execute <GitHubApiData>(request);

            return(response.IsSuccessful ? response.Data.tag_name.Substring(1) : null);
        }
Exemple #4
0
        public DownloadDialog()
        {
            InitializeComponent();
            Localization.TranslateForm(this);

            this.Font                 = SystemFonts.MessageBoxFont;
            this.FormClosing         += OnFormClosing;
            ThemeLoader.taskbarHandle = this.Handle;

            ProxyWrapper.ApplyProxyToClient(wc);
            wc.DownloadProgressChanged += OnDownloadProgressChanged;
            wc.DownloadFileCompleted   += OnDownloadFileCompleted;
        }
        public static void CalcThemeDownloadSize(ThemeConfig theme, Action <string> setSize)
        {
            Task.Run(() =>
            {
                foreach (Uri themeUri in DefaultThemes.GetThemeUriList(theme.themeId))
                {
                    var client = new RestClient(themeUri);
                    ProxyWrapper.ApplyProxyToClient(client);
                    var response = client.Head(new RestRequest());

                    if (response.IsSuccessful)
                    {
                        long sizeBytes = Convert.ToInt64(response.Headers.ToList()
                                                         .Find(x => x.Name == "Content-Length").Value);
                        setSize(string.Format(_("{0} MB"), (sizeBytes / 1024d / 1024d).ToString("0.#")));
                        break;
                    }
                }
            });
        }