Last active
December 29, 2015 02:49
-
-
Save IshamMohamed/7603039 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net; | |
//this method can be called in a button tap event | |
private void calculate() | |
{ | |
string calculationText = txtInput.Text; | |
try | |
{ | |
WebClient wc = new WebClient(); | |
wc.DownloadStringCompleted += HttpCompleted; | |
string uri = String.Format("http://gcdc2013-easyapisproject.appspot.com/eval?q={0}", WebUtility.UrlEncode(calculationText)); | |
wc.DownloadStringAsync(new Uri(uri)); | |
} | |
catch (Exception x) | |
{ | |
MessageBox.Show(x.Message); | |
} | |
} | |
private void HttpCompleted(object sender, DownloadStringCompletedEventArgs e) | |
{ | |
try | |
{ | |
string result = e.Result; | |
result = result.Substring(1); | |
result = result.Remove(result.Length - 1); | |
string[] results = result.Split(new string[] { "}{" }, StringSplitOptions.None); | |
result = results[1]; | |
if (result != "URL Encode/Decode Error, Escape specl chars") | |
MessageBox.Show(result); | |
else | |
MessageBox.Show("Couldn't perform equation"); | |
} | |
catch (Exception err) | |
{ | |
MessageBox.Show("No Internet connectivity, please connect to internet to perform"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment