I'm developing application for windows phone 8 and I need to get user data from remote MySQL database. This database is also used by the web-application.
What is the solution for this problem? Where I can read some information about using remote data storages with windows phone 8?
You can use the restsharp client for windows phone. Its fully documented and a nuget install is also available. heres the link http://restsharp.org/
A better and simpler way is to perform all the db operations in server side code (like php) and the information can be passed to the php file using a query string and the reverse by echo statement.
var webclient = new WebClient();
webclient.OpenReadAsync(new Uri("http://website.com/filename.php?name=" + myname.Text );
webclient.OpenReadCompleted += new OpenReadCompletedEventHandler(handler);
private void opener(object sender, OpenReadCompletedEventArgs e)
{
// throw new NotImplementedException();
using (var reader = new StreamReader(e.Result))
{
string response = reader.ReadLine();
MessageBox.Show(response);
}
}
Related
I am currently moving an ASP.NET application made by a third party from Windows to Linux. I read the documentation and nothing indicates this should be a problem, but sadly
var profile = new CredentialProfile(profileName, credentials) {
Region = RegionEndpoint.EUWest1
};
var netSDKFile = new NetSDKCredentialsFile();
netSDKFile.RegisterProfile(profile);
throws the following exception
Unhandled Exception: Amazon.Runtime.AmazonClientException: The encrypted store is not available. This may be due to use of a non-Windows operating system or Windows Nano Server, or the current user account may not have its profile loaded.
at Amazon.Util.Internal.SettingsManager.EnsureAvailable()
at Amazon.Runtime.CredentialManagement.NetSDKCredentialsFile..ctor()
Is the Amazon .NET SDK(or a part of it) not supported on Linux? If that is the case, is there a possible workaround?
For the most part there is very little that isn't supported on Linux that is supported on Windows. Off of the top of my head I can't think of anything besides NetSDKCredentialsFile which is due to the fact it uses Win32 API to encrypt credentials.
You can use SharedCredentialsFile to register a profile in the credentials file stored under ~/.aws/credentials. This is the same credential stored supported by all of the other AWS SDK and Tools.
Following on from Norm's answer, I found this resource that explained how to use Shared Credentials: https://medium.com/#somchat/programming-using-aws-net-sdk-9ce3f5119633
This is how I was previously using NetSDKCredentials, which won't work for Linux/Mac OS:
//Try this code on a non-Windows platform and you will see the above error
var options = new CredentialProfileOptions
{
AccessKey = "access_key",
SecretKey = "secret_key"
};
var profile = new CredentialProfile("default", options);
profile.Region = RegionEndpoint.USWest1;
NetSDKCredentialsFile file = new NetSDKCredentialsFile();
file.RegisterProfile(profile);
But I was then able to use this example to use SharedCredentials:
var credProfileStoreChain = new CredentialProfileStoreChain();
if (credProfileStoreChain.TryGetAWSCredentials("default", out AWSCredentials awsCredentials))
{
Console.WriteLine("Access Key: " + awsCredentials.GetCredentials().AccessKey);
Console.WriteLine("Secret Key: " + awsCredentials.GetCredentials().SecretKey);
}
Console.WriteLine("Hello World!");
You'll then be able to see your code is able to access the keys:
Access Key: A..................Q
Secret Key: 8.......................................p
Hello World!
I then used System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform() (as I am using this code on both Windows and Linux), to determine which credentials to use:
using System.Runtime.InteropServices;
//NETSDK Credentials only work on Windows - must use SharedCredentials on Linux
bool isLinux = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
if (isLinux) {
//Use SharedCredentials
} else {
//Use NetSDKCredentials
}
You may find this section of the AWS documentation helpful, too: https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-config-creds.html#creds-locate
I'm developing an API for my android app.
I'm using the API for accessing MySql from android via Asp.Net.
Like this,
[Route("api/v1/getMethodExample")]
[HttpGet]
public int GetMethodExample(string parametre)
{
mySqlConnection = new MySqlConnection("");
mySqlConnection.Open();
...
//Do something with mysql
int value = mySqlConnection.get("myTable","4");//in example
mySqlConnection.Close();
return value;
}
In short, for every web API call, I'm connecting MySql, getting data and closing MySql.
Is this right way?
Yes. It's default behavior. In other way you will block context for other requests
I'm building an app and I would like to track my device data session information.
For example duration, received bytes, sent bytes, bearer, access point, local IP address, protocol when connected using wifi, 3g, gprs, cell network.
If I can get all would be perfect, but getting 1 is more than enough.
I hope someone could show me some solutions or possibles APIs, if possible.
Thanks a lot in advance.
There are 3 namespaces in WP8 that provide network information: System.Net.NetworkInformation, Microsoft.Phone.Net.NetworkInformation and the new WP8 WinPRT namespace Windows.Networking.Connectivity.
While DataUsage/DataPlan APIs are available in the new WP8 namespace, they aren't supported on WP8 and only exist for Win8 API compatibility. You can use either the new WP8 APIs or WP7 APIs to enumerate over all connected interface type and check if they're WiFi/Ethernet/3G/etc:
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
foreach (var network in new NetworkInterfaceList())
{
Debug.WriteLine(network.InterfaceType);
}
}
I am want to make a 'hello world' application whereby I can send some data/make a request to a server or a WCF service. A simple query, save, delete etc application. I am targeting this learning app to be on the Windows Phone 8 platform.
I have done some work in WCF and RavenDB in the past but, not sure what to do in this situation.
Can someone please give me some tips/tutorials on how to achieve this please?
I used WCF to create a Service. The Service contained an Interface which were operations that were exposed and they were implemented in a different file. I then created a windows phone app and added the Service Reference by providing a URL to the service. The code to query the service was simply:
private void button1_Click(object sender, RoutedEventArgs e)
{
ServiceReference1.Service1Client myClient = new Service1Client();
myClient.AddNumbersCompleted += new EventHandler<AddNumbersCompletedEventArgs>(myClient_AddNumbersCompleted);
myClient.AddNumbersAsync(textBox1.Text, textBox2.Text);
}
void myClient_AddNumbersCompleted(object sender, AddNumbersCompletedEventArgs e)
{
textBlock1.Text = "Answer:" + e.Result.ToString();
}
I want to launch a local exe-file (without saving it to another location first) upon clicking on a link on a local html file.
It either needs to work in IE, Firefox, Chrome or Opera, I don't care. It's just for a presentation tomorrow.
It's simply not possible. If it was, it would be considered a security flaw and fixed. On Firefox within hours, on IE within some months.
UPDATE: You could try registering your custom protocol: http://openwinforms.com/run_exe_from_javascript.html
But I believe the browser will still prompt you whether you want to run the app.
I want to share my experience.
The accepted response says that it is not possible but it is quite possible indirectly.
If you want to execute an exe on a pc, it means that you have acces on this pc and you can install your exe on that machine.
In my case, I had to take a 3D scan from a 3D scanner via a web application. It seemed impossible at the beginning.
After lots of research, I found that we can send socket messages via javascript.
It means that if we had an application which listens a specific port, it can communicate with a website.
Let's explain how I did this.
In my web application, I created a javascript method like this :
function openCapron3DScanner(foot) {
$("#div-wait").show();
//Creates a web socket pointed to local and the port 21000
var ws = new WebSocket("ws://127.0.0.1:21000");
ws.onopen = function () {
//Sends the socket message to the application which listens the port 21000
ws.send(foot + "-" + #ProjectHelper.CurrentProject.Proj_ID);
};
ws.onerror = function myfunction() {
$("#div-wait").hide();
alert("Erreur connection scanner.");
}
ws.onmessage = function (evt) {
//Receives the message and do something...
var received_msg = evt.data;
if (received_msg == "ErrorScan") {
alert("Erreur scan.");
}
else {
refreshCurrentProject();
}
};
ws.onclose = function () {
$("#div-wait").hide();
};
};
And I created a windows forms application who listens the localhost and port 21000.
This application is hidden, only shown in icon tray.
The only thing to do is to add the application on windows startup via code on the first load to assure that the next restart of windows it will be executed and listen the port.
private static WebSocketServer wsServer;
static WebSocketSession LastSession;
private void Form1_Load(object sender, EventArgs e)
{
wsServer = new WebSocketServer();
int port = 21000;
wsServer.Setup(port);
wsServer.NewMessageReceived += WsServer_NewMessageReceived;
wsServer.Start();
}
private static void WsServer_NewMessageReceived(WebSocketSession session, string value)
{
if (value.StartsWith("ScanComplete-"))
{
//If the scan is ok, uploads the result to the server via a webservice and updates the database.
UploadImage(value);
//Sends a confirmation answer to the web page to make it refresh itself and show the result.
if (LastMacSession != null)
LastMacSession.Send("ScanComplete");
}
else if (value == "ErrorScan")
{
//If the C++ application sends an error message
if (LastMacSession != null)
LastMacSession.Send("ErrorScan");
}
else//call the 3D Scanner from the web page
{
LastSession = session;//Keeps in memory the last session to be able to answer via a socket message
//Calls the C++ exe with parameters to save the scan in the related folder.
//In could be don in this same application if I had a solution to consume the scanner in C#.
var proc = System.Diagnostics.Process.Start(#"C:\Program Files\MyProjectFolder\MyScannerAppC++.exe", projectID + " " + param);
}
}
I hope it will help.
Use System.Diagnostics.Process.Start() method.
protected void LinkButton1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("notepad.exe");
}
You'll have to use C#, but since that's on your post, it should work. You'll also need the full path, if the file is not in your environment path that's loaded in memory.
For a 'regular link' you'd still need to place this in an ASPX page.....
Click me
We're getting really fugly now though.
You can't run an exe file on a website. (First, if it's a Linux server, exe files won't run on it and second, if you're on a Windows server, your host would kill the program immediately. And probably terminate your account.)
That link (assuming it was Play Now!) will just allow your user to download the file. (C:\Program Files\World of Warcraft\ exists on your computer, but it doesn't exist on the web server.)
You could setup a custom protocol on your local OS, if it's Windows, in regedit.
Check out this and this.
Then you create a simple HTML page, and place a link, something like this :
Start!
Given that you registered your custom "presentation" protocol, and configured it correctly in the registry, the application should launch when you click that link.