private async Task <RotationData> GetRotationAsync(string url) { if (!DB.IsLoaded) { await DB.LoadAsync(); } string convertedURL = URLConverter.Convert(url); HttpWebRequest request = WebRequest.Create(convertedURL) as HttpWebRequest; using (HttpWebResponse response = await Task.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, null) as HttpWebResponse) using (StreamReader streamReader = new StreamReader(response.GetResponseStream())) { string content = await streamReader.ReadToEndAsync(); RotationData data = JsonConvert.DeserializeObject <RotationData>(content); data.Initialize(url); Properties.Settings.Default.lastURL = data.URL; Properties.Settings.Default.Save(); return(data); } }
private async void LoadBtn_Click(object sender, EventArgs e) { if (rotationWindow.Visible) { DialogResult result = MessageBox.Show(this, "You have to stop the rotation.\nProceed?", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (result == DialogResult.OK) { startBtn.PerformClick(); } else { return; } } string url = urlTextBox.Text; if (url == null || url.Length <= 0) { return; } loadBtn.Enabled = false; startBtn.Enabled = false; RotationData data = await GetRotationAsync(url); rotationWindow.LoadData(data); if (data == null || data.Sequence == null || data.Sequence.Count <= 0) { MessageBox.Show(this, "Couldn't load the rotation.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } startBtn.Enabled = true; SetStatusLabel(); }
public void LoadData(RotationData data) { loadedData = data; skillList = DB.Get(data.Sequence); }