private void GetThread_Result(RequestResult result) { if (this.InvokeRequired) { this.Invoke(new Action<RequestResult>(GetThread_Result), result); return; } if (!result.IsSuccessfully) { webBrowser1.DocumentText = result.ToString(); return; } string messages = ""; foreach (UniValue item in result["items"]) { string message = Properties.Resources.MessageTemplate; if (item.Key == "0") { messages = String.Format("<h3>{0}</h3>", item["title"]); this.Text = item["title"].ToString(); } message = message.Replace("%author%", String.Join(", ", item["authors"].Select(author=>author["name"].ToString()))); message = message.Replace("%date%", Convert.ToDateTime(item["createdDate"]).ToString("d MMM yyyy, HH:mm:ss")); message = message.Replace("%text%", item["summary"].ToString()); messages += message; } webBrowser1.DocumentText = Properties.Resources.ThreadTemplate.Replace("%body%", messages); }
private void GetFiles_Result(RequestResult result) { if (this.InvokeRequired) { this.Invoke(new Action<RequestResult>(GetFiles_Result), result); return; } if (result.StatusCode == 200) { listBox1.Items.Clear(); listBox1.DisplayMember = "path"; foreach (UniValue file in result["contents"]) { listBox1.Items.Add(file); } if (this.CurrentPath != "/") { listBox1.Items.Insert(0, UniValue.ParseJson("{path: '..'}")); } } else { MessageBox.Show("Error..."); } }
private void Upload_Result(RequestResult result) { if (this.InvokeRequired) { this.Invoke(new Action<RequestResult>(Upload_Result), result); return; } }
public void GetFiles_Result(RequestResult result) { if(result.StatusCode == 200) { foreach (UniValue item in result["contents"]) { DropBoxFile drop = new DropBoxFile(item); file.Add(drop); } } }
private void create_folder_result(RequestResult result) { if (this.InvokeRequired) { this.Invoke(new Action<RequestResult>(create_folder_result), result); return; } if (result.StatusCode == 200) { this.GetFiles(); } else { if (result["erros"].HasValue) { MessageBox.Show(result["erros"].ToString()); } else { MessageBox.Show(result.ToString()); } } }
private void Upload_Result(RequestResult result) { }
private void GetFiles_Result(RequestResult result) { }
private void deleteCategoryCallback(RequestResult result) { if (result.StatusCode == 200) { string categoryName = result["path"].ToString().Replace("/", ""); Category cat = catList.searchByName(categoryName); cat.deleteFiles(); cat.unassignAllContacts(); if (cat.delete() > 0) { this.Dispatcher.Invoke((Action)(() => { showCategoryList(); })); MessageBox.Show("Category and all its files was deleted."); } else { MessageBox.Show("Cannot delete category."); } } else { MessageBox.Show("Something went wrong, cannot delete this category."); } selectedCategory = 0; }
private void FileOperation_Result(RequestResult result) { if (this.InvokeRequired) { this.Invoke(new Action<RequestResult>(FileOperation_Result), result); return; } if (result.StatusCode == 200) { this.UpdateList(); } else { this.RequestEnd(result); } }
private void UploadFile_Result(RequestResult result) { if (this.InvokeRequired) { this.Invoke(new Action<RequestResult>(UploadFile_Result), result); return; } if (result.StatusCode != 200) { if (result["error"].HasValue) { MessageBox.Show(result["error"].ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(result.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } progressBar1.Value++; if (progressBar1.Value == progressBar1.Maximum) { ((MainForm)this.Owner).UpdateList(); this.Close(); } }
/// <summary> /// Initializes a new instance of the <see cref="OAuthAccessToken"/> class. /// </summary> /// <param name="result">Result of request to the OAuth server.</param> public OAuthAccessToken(RequestResult result) : base(result) { this.Value = result["oauth_token"].ToString(); this.TokenSecret = result["oauth_token_secret"].ToString(); }
private void GetShareLink_Result(RequestResult result) { }
private void upload_file(RequestResult result) { if (this.InvokeRequired) { this.Invoke(new Action<RequestResult>(upload_file), result); return; } else { if (result["erros"].HasValue) { MessageBox.Show(result["erros"].ToString(), "Health Care Application"); } else { MessageBox.Show("successfully uploaded", "Health Care Application"); } } }
/// <summary> /// Initializes a new instance of the <see cref="ApiException"/> class with a specified <see cref="RequestResult"/> and error message. /// </summary> /// <param name="result">The result of the request.</param> /// <param name="message">The error message that explains the reason for this exception.</param> public ApiException(RequestResult result, string message) : base(result.ContentType, result.Source, new Exception(message), result.HttpHeaders, result.StatusCode) { }
/// <summary> /// Initializes a new instance of the <see cref="ApiException"/> class with a specified <see cref="RequestResult"/> and the exception that is the cause of this exception. /// </summary> /// <param name="result">The result of the request.</param> /// <param name="innerException">The exception that is the cause of the current exception, or a <b>null</b> reference (<b>Nothing</b> in Visual Basic) if no inner exception is specified.</param> public ApiException(RequestResult result, Exception innerException) : base(result.ContentType, result.Source, innerException, result.HttpHeaders, result.StatusCode) { }
private void CheckAccessToken_Result(RequestResult result) { if (result.StatusCode == 401) { // error, show login form this.GetAccessToken(); // hide progress this.RequestEnd(new RequestResult(statusCode: 200)); } else { // success //this.RequestEnd(result); this.UpdateList(); } }
private void UpdateList_Result(RequestResult result) { if (this.InvokeRequired) { this.Invoke(new Action<RequestResult>(UpdateList_Result), result); return; } listView1.Items.Clear(); if (result.StatusCode == 200) { var fileList = result["contents"].OrderBy(itm => Path.GetFileName(itm["path"].ToString())).OrderByDescending(itm => Convert.ToBoolean(itm["is_dir"])); foreach (UniValue file in fileList) { var item = new ListViewItem(); item.ImageKey = file["icon"].ToString(); item.SubItems.Add(Path.GetFileName(file["path"].ToString())); item.SubItems.Add(file["size"].ToString()); item.SubItems.Add(file["mime_type"].ToString()); item.Tag = file; listView1.Items.Add(item); } if (!String.IsNullOrEmpty(this.CurrentPath)) { var root = new ListViewItem(); root.ImageKey = "folder"; root.SubItems.Add(".."); listView1.Items.Insert(0, root); } } listView1_SelectedIndexChanged(listView1, null); this.RequestEnd(result); }
public void Serialization_RequestResult() { // Serialize var r = new RequestResult ( contentType: "text/xml", httpHeaders: new NameValueCollection { { "X-Test", "123" } }, statusCode: 200, source: Encoding.UTF8.GetBytes("<items><item>1</item><item>2</item><item>3</item></items>") ); var bf = new BinaryFormatter(); var m = new MemoryStream(); bf.Serialize(m, r); // Deserialize m.Position = 0; var r2 = (RequestResult)bf.Deserialize(m); if (r2.ContentType == "text/xml" && r2.StatusCode == 200 && r2.HttpHeaders["X-Test"] == "123" && r2.Source.Length == r.Source.Length && r2["items"]["item"][0] == 1) { Console.WriteLine("OK"); } else { Assert.Fail(); } }
private void RequestEnd(RequestResult result) { if (this.InvokeRequired) { this.Invoke(new Action<RequestResult>(RequestEnd), result); return; } if (result.StatusCode < 200 || result.StatusCode > 299) { if (result["error"].HasValue) { lblStatus.Text = result["error"].ToString(); MessageBox.Show(result["error"].ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { lblStatus.Text = result.ToString(); MessageBox.Show(result.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } picStatus.Image = Properties.Resources.error; } else { lblStatus.Text = "OK"; picStatus.Image = Properties.Resources.success; } }
private void GetFiles_Result(RequestResult result) { if (this.InvokeRequired) { this.Invoke(new Action<RequestResult>(GetFiles_Result), result); return; } if (result.StatusCode == 200) { checkedListBox1.Items.Clear(); foreach (UniValue file in result["contents"]) { this.Invoke((MethodInvoker)(() => checkedListBox1.Items.Add(file["path"]))); //listBox1.Items.Add(file["path"]); } if (this.CurrentPath != "/") { checkedListBox1.Items.Insert(0, "..."); } } else { MessageBox.Show("error"); } }
private void UpdateList_Result(RequestResult result) { if (this.InvokeRequired) { this.Invoke(new Action<RequestResult>(UpdateList_Result), result); return; } if (!result.IsSuccessfully) { if (!this.AccessTokenIsCheked) { this.GetAccessToken(); } else { MessageBox.Show("Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.RequestEnd(); } return; } if (!this.AccessTokenIsCheked) { this.AccessTokenIsCheked = true; } // set list of messages to the dataGridView dataGridView1.DataSource = result["items"].Select ( item => new { id = Convert.ToInt64(item["id"]), title = item["title"].ToString(), author = item["authors"].First()["name"].ToString(), createdDate = Convert.ToDateTime(item["createdDate"]) } ).ToArray(); // update list of pages flowLayoutPanel1.Controls.Clear(); int start = (int)result["pagination"]["page"]; int end = (int)result["pagination"]["totalPages"]; if (this.CurrentPage > 1) { if (this.CurrentPage - 4 > 0) { start = this.CurrentPage - 4; } else { start = start - this.CurrentPage + 1; } } if (end - start > 10) { end = start + 10; } else { end = start + (end - start); } if (start - 1 > 0) { this.AddPage(this.CurrentPage - 1, "<<"); } for (int i = start; i < end; i++) { this.AddPage(i); } if (end < (int)result["pagination"]["totalPages"]) { this.AddPage(this.CurrentPage + 1, ">>"); } // hide progress this.RequestEnd(); }
private void GetFiles_Result(RequestResult result) { if (result.StatusCode == 200) { String userName = result["display_name"].ToString(); String userEmail = result["email"].ToString(); this.Dispatcher.Invoke((Action)(() => { this.user_email_text.Text = userEmail; RegisterEventHandler(this.registerButton, null); this.syncCategories(); this.syncFiles(); this.getCategoriesFromService(); })); // show a list of files } else { // show an error message if (result["error"].HasValue) { MessageBox.Show ( result["error"].ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error ); this.Dispatcher.Invoke((Action)(() => { this.user_email_text.IsEnabled = true; })); } else { MessageBox.Show(result.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void Upload_Result(RequestResult result) { if (this.InvokeRequired) { this.Invoke(new Action<RequestResult>(Upload_Result), result); return; } if (result.StatusCode == 200) { this.GetFiles(); } else { if (result["error"].HasValue) { MessageBox.Show(result["error"].ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(result.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void getCategoriesFromServiceCallback(RequestResult result) { CategoryList catList = new CategoryList(); if (result.StatusCode == 200) { foreach (UniValue value in result["contents"]) { String folderName = value["path"].ToString().Replace("/", ""); if ((Boolean)value["is_dir"] == true && !catList.isInserted(folderName)) { Category c = new Category(); c.name = folderName; c.owner_id = Easyshare.Classes.Owner.SessionOwnerId; c.sync = true; c.insert(); this.getFilesFromService(c); } } /* String userName = result["display_name"].ToString(); String userEmail = result["email"].ToString(); this.Dispatcher.Invoke((Action)(() => { this.user_email_text.Text = userEmail; RegisterEventHandler(this.registerButton, null); })); */ // show a list of files } }
/// <summary> /// Initializes a new instance of the <see cref="ErrorResult"/> class. /// </summary> /// <param name="result">The request results.</param> public ErrorResult(RequestResult result) : base(result) { }
private void getFilesFromServiceCallback(RequestResult result) { CategoryList catList = new CategoryList(); if (result.StatusCode == 200) { foreach (UniValue value in result["contents"]) { String path = value["path"].ToString(); if ((Boolean)value["is_dir"] == false) { var split = path.Split(new char[] {'/'}); if (split.Count() == 3) { string categoryName = split[1].ToString(); string fileName = split[2].ToString(); Category catObject = catList.searchByName(categoryName); Easyshare.Classes.File file = new Easyshare.Classes.File(); file.name = System.IO.Path.ChangeExtension(fileName, null); file.categoryId = catObject.id; file.path = "Downloaded/" + fileName; file.sync = true; file.insertFile(); } } } } }
private void GetShareLink_Result(RequestResult result) { if (this.InvokeRequired) { this.Invoke(new Action<RequestResult>(GetShareLink_Result), result); string appPath = Path.GetDirectoryName(Application.ExecutablePath); var rezultat = result.ToString(); Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(rezultat); try { string url = values["url"]; url = url.Remove(url.Length - 1, 1) + "1"; TextBox.CheckForIllegalCrossThreadCalls = false; textBox1.Text = url; string1 = url; } catch (Exception ex) { MessageBox.Show("You are not connected to Dropbox"); } XDocument doc = new XDocument(new XElement("body", new XElement("line", string1) ) ); doc.Save(appPath + "\\" + "Data.xml"); FileStream upstream = new FileStream((appPath + "\\" + "Data.xml").ToString(), FileMode.Open); OAuthUtility.PutAsync ( "https://api-content.dropbox.com/1/files_put/auto/", new HttpParameterCollection { {"access_token",Properties.Settings.Default.AccessToken}, {"path",Path.Combine(Path.GetFileName("Data.xml")).Replace("\\","/")}, {"overwrite","false"}, {"autorename","false"}, {upstream} }, callback: Upload_Result ); return; } }
private void createFolderCallback2(RequestResult result) { if (result.StatusCode == 200) { string qy1 = string.Format(@"update category set category_sync ='{0}' where category_id = '{1}';", 1, id); db.insert(qy1); } }
private void DeleteFile_Result(RequestResult result) { }
/// <summary> /// Initializes a new instance of the <see cref="OAuth2AccessToken"/> class. /// </summary> /// <param name="result">Result of request to the OAuth server.</param> public OAuth2AccessToken(RequestResult result) : base(result) { this.Value = result["access_token"].ToString(); if (result.ContainsKey("expires_in")) { this.ExpiresIn = Convert.ToInt64(result["expires_in"]); } // todo: think /*if (result.ContainsKey("expires")) { this.ExpiresIn = Convert.ToInt64(result["expires"]); }*/ if (result.ContainsKey("refresh_token") && result["refresh_token"].HasValue) { this.RefreshToken = result["refresh_token"].ToString(); } if (result.ContainsKey("scope") && result["scope"].HasValue) { this.Scope = result["scope"].ToString(); } if (result.ContainsKey("token_type") && result["token_type"].HasValue) { this.TokenType = result["token_type"].ToString(); } }