How to parse response text from some service? - c#

so this is my problem.
I use a prepaid account.
I call *100#, and get response from my phone operator about my account balance.
response link
This says "You have 1.12 BAM left on you account and you can use it until 02.08.2014.
Here is the question.
I want to make this cal programmatically, from code.
I know it's easy, using PhoneCallTask.
Is there any way to parse this response???

No, there is no way to parse the response and no way to make the call programmatically (PhoneCallTask just shows the UI with the number filled in and the user has to confirm it)

Related

How to Parse Google Speech API response in text box

I am working on google speech API in c#.
Google is returning results with no problem and its response is shown on my text box.
Now I want limited text to be displayed on text box. As given response below, I want only recognized text to be displayed e.g. the Text box should display you said Ball.
Result string and alternative transcripts should be eliminated.
this is the response from google speech API when I said Ball:
{"result":[]}
{"result":[
{"alternative":[
{"transcript":"boa"},
{"transcript":"ball"},
{"transcript":"bull"},
{"transcript":"boys"},
{"transcript":"call"}
],
"final":true}
],
"result_index":0}
You probably want to pass the single_utterance option to StreamingRecognitionConfig. There's some more information available here:
https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#google.cloud.speech.v1beta1.StreamingRecognitionConfig
If you're not going to use the alternatives, you can also set maxAlternatives to 1 or leave it with the default of 1. interim_results should also be set to the default value of false.
I'm not sure the exact syntax in C#. You'll still have to pick out the final transcript, but there will be less unwanted information in the response.

Editing html templates

I am going to create a function in my application that is going to send som status mails to several receivers in a list.
Earlier i used plane text format on the email, but now i want to send the mail based on som html templates. I need tips reguarding a good way to insert data into these templates before sending them.
eks
%CpuStatus%
%HardriveStatus%
and so on. I have the solution for everything except a way to fill anchors like that with data. This is a WinForm application so i dont have access to the ASP functionality
Maybe this sort of thing would be the simplest?
// This would most likely be loaded from a file or database.
string emailBody = "CPU Status: %CpuStatus%\nHard Drive Status: %HardriveStatus%";
string cpuStatus = MyService.GetCpuStatus();
emailBody.Replace("%CpuStatus%", cpuStatus);
If you really wanted to make a big project out of it, you can use a webbrowser control, load it with your html file and then use the WebBrowser's Document property to get an HtmlDocument object. You can then loop through it's children (recursively) to find the tags you want to change.
Personally, I would do the .Replace method suggested previously.

Sending/Setting a value to a Password Field on a Website

I have written a small application that needs to log in to a website to perform some actions.
The problem is that whenever I try to set the password field on the website it doesn't accept the password.
I have found a way around this by using the SendKeys function. The problem with that is that it requires focus and the program requires to run in the background.
Is there a way to do this?
Here is an example of how you'd set the Username Field:
WebBrowser.Document.GetElementById("field-username").SetAttribute("value", "UserName")
Any help would be great.
The answer to this question is as follows:
WebBrowser.Document.GetElementById("field-loginFormPassword").SetAttribute("maxLength", "20")
WebBrowser.Document.GetElementById("field-loginFormPassword").SetAttribute("value", "yourpassword")
By changing the "maxlength" value it allows you to set the "value" to the desired text and then you can submit the Form and it will accept it.
Try with mshtml or Html Agility Pack

Metro Search Charm - clear search box programmatically after user accepted the result suggestion

I would like to clear the search box in metro search charm after the user accepted one of the result suggestion my app is providing to the charm. How? Sounds easy but it is not, SearchPane.QueryText is read only.
I am actually surprised by the default system behavior. After the user accepted the ResultSuggestion (please remember to distinguish from QuerySuggestion) it does not make sense in my eyes to pre-populate the search box with this accepted result...
Try
var searchPane = Windows.ApplicationModel.Search.SearchPane.getForCurrentView();
searchPane.trySetQueryText("myQueryText");
The user's text stays there in case after looking at one of the results they decide "oh that's not it, I will look at this other result from" and the other result could even be from a different app. There is no way for an app to override this.

Advice needed: Geolocation for c# web app - need country location to set what user can see or not

My scenario is I want to trap the user's country when they access the web page. Based on the user's country i want to set a cookie that will allow me to do a simple "if" statement in the code behind that would let them to see certain information on web pages.
I started doing some research and i can use the Google Geocode V3 and get the country from code behind c#. But to get the Google Geocode to work i need to pass in the longitude and latitude.
And the only way i've seen this is from Javascript call like:
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
});
}
So i'm hoping for some advice if I'm doing this right.
On the loaded method in my c# code I think I can get the javascript to run by ScriptManager.RegisterStartUpScript method. So my challenge now is getting the latitude and longitude values. Since i'm not going a button event or something, i need to get those values out and then pass them into my c# method that would get the country code using the Google Geocode.
Does that sound right? If this is the right path, can someone suggest how i could get those values from the javascript?
thanks.
You could make an Ajax call to your server which contains the client's geolocation.
What about using RegionInfo.CurrentRegion instead? That will give you the country according to the browser headers assuming you have globalization culture turned to auto. This is simpler, but will also not be 100% correct all the time since the user can change their culture settings.
You may also want to look into using IP address based geolocation which might be a little more accurate.
It would help to know why you're trying to do this.
Most sites that really need to make sure that content stays within national boundaries work with content that is chargeable - for instance, most music sites, Amazon, and so on.
Their simple, yet effective, technique is to use the country on the user's billing address on their credit card.

Categories

Resources