Passing data from a javascript function in my remote website to a c# application on my desktop application - c#

I have a dynamic program. These are the steps that the program follows.
i) I have a windows form application and I have divided the window into two parts. One part contains a ChromiumWebBrowser where it loads a remote website (like www.abc.com). The other part does normal operations of fetching data from a wampserver MYSQL DATABASE installed on the local computer and gives output on the same window division.
ii) Now I use the Chromium web browser to import data from the remote website and send it to a local php file in the local wampserver and then inside the php file I send the data to appropriate local database tables.
iii) When the remote website loads, there is a button "Import data" and then this importation is processed via an AJAX call and now it is in the ajax success: function(){ } that I send the data to my local php file. (I have control over both remote and local wampservers)
iv) NOW MY QUESTION IS how do I pass the data from the external javascript ajax to my c# application so that I don't need to have the local php file i.e. The received data will be sent to database directly from c#
v) And are there any security threats in the process?
I hope I'm was clear, Any suggestions are welcome

Easiest option is to implement a custom scheme. So for example you would make your requests to custom://ajax/uploadToDatabase. You can then parse the request, update the database and respond accordingly.
http://rawgit.com/cefsharp/CefSharp/master/CefSharp.Example/Resources/Home.html#features-custom-schemes
https://github.com/cefsharp/CefSharp/blob/cefsharp/45/CefSharp.Example/CefSharpSchemeHandler.cs#L51
The CefSharp.WinForms.Example and CefSharp.Wpf.Example projects both provide a working implementation. They're available on GitHub
https://github.com/cefsharp/CefSharp

Related

Can I use a php file on a server, to send data to a C# file which then validates the data, and sends the result back to the php file?

I'll try to be as simplistic and transparent as I can.
My goal is to: send leaderboard data to a server, have it validated, then added to a MySQL table..
How I want to achieve this:
Player completes game, gets highscore data.
The highscore data is sent to a file on the server, "leaderboard.php"
The leaderboard.php file sends the playthrough data to a C# file on the server, "PlaythroughSimulator.cs" to run a simulation of the playthrough
After the PlaythroughSimulator.cs file has confirmed or denied the validity of the playthrough, it sends a true/false value back to the leaderboard.php file
If the recording was valid, the leaderboard.php file adds it to the table as expected.
I have the php process working for receiving and adding scores to the leaderboards on the server, and I've created the playthrough simulator in C# OUTSIDE of the server.
My problem now is bringing the playthrough simulator onto the server and making it work entwined with the php script.
I did a bit of reading and see that I should be able to call C# scripts from php, but I'm not sure how to send or retrieve data between them.
Generally speaking, different programs on a computer don't know or care what language each other are written in; they care what protocols they speak - what inputs they expect, what outputs they'll give, and where that information needs to be passed.
For instance, when you have data in the browser and you want to send it to a PHP program, the browser doesn't need to know what PHP is; instead, it sends the data over the internet, using the HTTP protocol. On the server, a process listens for that request, and it just happens that you've set that up so that it runs your PHP script.
In the same way, you won't be telling PHP to "run a C# file"; you'll be telling it to send some data to another program, and that program will happen to be written in C#. An important consequence of this is that it helps you break the problem down, always a key skill in programming, because you can run the program you wrote in C# directly, and confirm how it behaves, before telling PHP to talk to it.
The simplest "protocol" to use in this scenario is a command-line script:
Write a C# program that takes the playthrough data as a command-line argument, or reads it from a file, and outputs a result
Use shell_exec in your PHP code to run the script, passing it the data, or the name of a temporary file containing the data

Socket.IO & Express alternative for C#?

I'm looking to see if it's possible to create an application using C# that creates a local web server and allows me to pass information from the server, to the client website.
I've been using Node.js with Express to create a local web server and then using Socket.io to pass information through to the client, to display in realtime with Javascript. Only issue is I'm more comfortable with C# and I'd like to distribute this application, with Node Modules and Electron the app is clocking in at around 150MB, it's also many files and folders as opposed to just a .exe
Details of Application:
Reads data from log files
Decodes Json inside files
Sends specific data to website
Client receives data and displays
I've managed to get halfway there by using HttpListener, but from what I understand I cant send data to it? So I figured I could edit the html before I sent it and have yet to setup the FindDivByID method
TLDR; Is there a way to create a Local Web Server (Application) that is able to send data to the Client Website.
EDIT: Thanks for the suggestion, though I'm hoping to keep it all down to one distributable application, that reads the data from the local PC, creates the web server and sends to the clients
Well, if you wanna go full C#, I'd recommend SignalR, very solid
https://www.asp.net/signalr
Alternatively, you could keep your Socket.IO server in Node.JS and use this Socket.IO C# client library to interface with it (although I never really did tried)
https://github.com/Quobject/SocketIoClientDotNet

calling a hosted Filemaker Application from a .net program

In my c# application, I am trying to generically open a filemaker application that is hosted on the filemaker server assuming my c# application executes from the server that hosts the filemaker server. Currently it seems the only way I can do this is to open a generic fmp12 file that contains an External Data Source with the name "Open", type Filemaker, Details "fmnet:/fmserv/Open" where "fmserv" is the filemaker server hardcoded, along with a script trigger to Open File ["Open"]
First, is there any better way to do this programmatically in c# other than just opening this shell filemaker program? I may need to do this for over 20 different locations.
I would use the fmp:// URL protocol. You can just call it as if it were a web URL, but FileMaker Pro registers to handle all fmp:// calls. You would use it in the format fmp://server.ip.address.or.dns.name/filemakerDatabaseName.
You can even use it to call scripts and send parameters/variables to your database. See http://www.filemaker.com/help/12/fmp/html/sharing_data.16.7.html for more information.

Connect to a SQL Database from Android

I want to develop an Android application which would connect to a SQL Database which is already created . We developed this news site :
e-Cmunio. This site is based on a SQL Database that already has a lot of news and stuff in. For now, what we want for our Android app is to connect to that database and show some random news in a listView.
The problem is that I don't know how to connect to it from Android.
I have already read about some WebServices, but I have no idea from where to start.
We ( me and a friend ) are in HighSchool. The site was developed in C#. We are new in Android and java, but we are familiar with algorithms and data structures.
Could you please give me some tutorials and entry-level information about how can we access our DataBase?
Sorry if I hasted your time, but I really have no idea where to start from.
The easiest way is to use PHP to parse ur data to JSon and read that data and parse it in ur Android phone..
SQL to PHP to JSon to read from.
http://www.bin-co.com/php/scripts/sql2json/
Parse JSON to Android
http://www.vogella.com/articles/AndroidJSON/
What you want to do is make a webservice on your server side that connects to your database and returns whatever you want to return in your favorite format(XML / JSON).
Next, on Android(client side) you want to have an AsyncTask to access that webservice and fetch your news and save them to your Android SQLite Database.
Later like you suggested you can load those news from a cursor directly to your listView with a Listview adapter.
You can read about Saving data in SQLite here: http://developer.android.com/training/basics/data-storage/databases.html
You can read about AsyncTask here: http://developer.android.com/reference/android/os/AsyncTask.html
You already have an elaborate answer in connect to sql server from android.
Web services define interface for your website in a standardized way, so that
other websites/applications can access it. It is more extensible and generic solution
then directly accessing server's database.
Simple web service can be just an XML or a JSON file generated after querying your
website with specific parameters. So as an exercise in your case I would implement
handling of specified URL in your C# server code and generate XML file with your
news (query in URL) and then just open your page with this URL on your android app
and read this XML. When your app will become more complex, then you can start moving to
some standard web service solution.

How to create and save a text file with JavaScript

Do you know any cross-browser method to create and save a file with JavaScript on the client-side?
Considerations:
I can't save it on the server because the file is going to be read from a fiscal printer.
The server can't access the client. This is obvious because we are talking about a web application in the web, so the server can't access a client folder.
New ActiveXObject("Scripting.FileSystemObject"); is ONLY for Internet Explorer and even then not for all versions.
We are talking about printing on a fiscal printer, so I can't ask the cashier in the supermarket to download the text file and save it in a folder where the fiscal printer can read it.
If not JavaScript, what else can I use in my ASP, .Net 4.0, C# web application?
Basically, you said it, "we are talking about a web application." Do you know any web applications that save a file to your hard drive (besides cookies) without showing you a download prompt first?
Having said that, browsers have started to offer a persistence API that goes beyond cookies. (See, for example, this article.) But such a solution wouldn't meet your requirement of being cross-browser.
Your only options are to use persistance APIs from HTML5 or to create a browser plugin (activex control on IE, NPAPI plugin on others) that can do the file access for you. You could use FireBreath to do this, and it would be relatively simple if you know C++.
That said, it is a really dangerous idea; it is difficult to prevent people from using your plugin in other pages, so your plugin has to somehow be smart enough to keep itself from being abused by malicious sites that want to read (or even write) arbitrary data to your hard drive.
There is, after all, a reason why browsers don't natively support this. I'd look at HTML5.
you can do that by Client side Web services just make a function in web service to create a text file in your hard drive then convert the web service in to the client side service when u do that .Net framework make a client side java script then u will be able to call the server side function using Java script in client side after that your file will not be posted in the server it will remain save in your hard drive ok
we came out with a simple windows service nodejs app to be installed in the local machine.
When the web application need to create a file it just sends an API call to this app using localhost and that will write the file for it.
Cheers.

Categories