Can .NET DLLs be created using Javascript or JScript.NET? - javascript

I'm creating a video game that has single player and multiplayer. The single player is done in C# (Unity), and want to use Gamesparks BaaS that works on Javascript (NodeJS) for their server code.
Since I want the multiplayer server to be authoritative, I need the server code to run Javascript and the client will run C#, which means duplicated code
But, if I can create .NET dlls in Javascript I can reduce code duplication heavily by using those libraries in Unity and using the Javascript code on the server.
Thanks!

If you want to use javascript (and by javascript I mean nodejs), along with c# and communicate between those two, you can use electron-edge. It helps you to run c# code using nodejs through Electron API.
Here is the link of their Github url: Electron-Edge-documentation
You can also interact with dlls, using an creating your application as an electron app. You refer this question where you will find some more details regarding it.

Related

Can I add pre-existing Javascript code to an ASP.NET MVC C# application

Apologies if this is a silly question. I currently have a small backend system written in ASP.NET Mvc in C# that allows you to do multiple features relating to profiles (Add, Edit, Delete, View) amongst other features.
My friend has an application he created as his University project and we're both just curious if we can merge his application with mine as his is purely a front-end system and mine is a back-end.
He has written an SQL web application that tests you with some general T-SQL questions with a pre-set SQLite3 database that you can modify based on the questions asked. He has written it all in Javascript and using HTML and CSS. He has 3 folders, a folder contaning all the javascript, a folder with an SQLITE3 database and a folder with the HTML/CSS.
I was just wondering, can I essentially 'drag and drop' all the 3 folders into my application on Visual Studio and will it just run seamlessly?. I assume I will need to go into the Javascript and modify any changes to the paths of the database which I can do. I'm not interested in calling any js functions or anything yet, just making it so I can start the application, be taken the HTML for the SQL application and then all the js scripts work for that page.
If this is not the case, is it a case where I can only use Javascript by injecting it into ASP.NET by using the tag <script type="text/javascript">?
Trying what I have stated. As it webpage was in HTML, I created an action in my controller that opens up the HTML page in CSHTML. This will display the HTML but no methods are called when the page loads therefore no database is loaded or what I presume to be any Javascript commands.
If there are any materials that help with this issue, can you please link them below. I had done some research but could not find anything that points to this specific issue.
Can I add pre-existing Javascript code to an ASP.NET MVC C# application
Yes.
Apologies if this is a silly question.
It isn't a silly question because there is an ambiguity in the question that might make the answer "no" in your specific case.
Firstly the good news - you can reference scripts written in Javascript in your HTML, and you can put blocks of Javascript in you CSHTML too. It's possible to use Razor to create a page that includes HTML, Javascript and C# in the same page - BUT there is a difference about where and when the code executes that might be an issue for you.
The question you need to determine is if your friend's project is written using the Node.js framework. Javascript is a language and it can be used in both front-end (execute in the client's browser) and back-end applications.
You can use your ASP application (which is server-side or back-end code) to write documents that either include Javscript or reference scripts to be executed by the client-side code in the browser. You can't get your back-end to run the Javascript in the same application) as it is intended for a different framework.
You can have two applications hosted on the same server, and make calls between them both and use them together in that respect, but otherwise you need to select one or other as the back-end providing framework for your web application.
So you can include Javascript in your ASP application, but for execution on the client-side in their browser. Your mentioning of database connections heavily implies that you are describing server-side code - so talk to your friend about Node.js to ensure that is what they are using.
You can read about Node.js here: https://nodejs.org/en/
There are some details about mixing ASP and Node on Azure here: Mixing node.js and ASP.NET projects in a single Azure Web Role?

Create WebAssembly using c#

I went through below article
https://medium.freecodecamp.org/get-started-with-webassembly-using-only-14-lines-of-javascript-b37b6aaca1e4
and very impressed that we can use c++ code in javascript using web assembly.
Do we have any option to create such web assembly using c# where we can create web assembly and use in javascript like angular or react.
went through
https://learn.microsoft.com/en-us/aspnet/core/client-side/spa/blazor/get-started?view=aspnetcore-3.0&tabs=visual-studio
But that does not look like creating an assembly that can be used in a separate angular only project with by importing
Thanks
From msdn:
JavaScript interop
For apps that require third-party JavaScript libraries and browser APIs, Blazor interoperates with JavaScript. Components are capable of using any library or API that JavaScript is able to use. C# code can call into JavaScript code, and JavaScript code can call into C# code. For more information, see JavaScript interop.
[https://learn.microsoft.com/en-us/aspnet/core/client-side/spa/blazor/?view=aspnetcore-3.0][1]
Ithink looking to Blazor source code can help you to.
I think what you're looking for isn't Blazor, because it's a complete UI framework for ASP.NET client/server stuff using SignalR, that uses WASM at the client side. Maybe too much for your purposes, even if you're able to use any JavaScript framework together with Blazor, too.
But you're looking for a simple way to create just a WASM that exports methods to JavaScript that you can write using C#, right? Well, then I suggest you to have a look here:
https://itnext.io/run-c-natively-in-the-browser-through-the-web-assembly-via-mono-wasm-60f3d55dd05a
It seems the Mono way is working as you'd expect: You write methods in C#, compile a WASM and then you're ready to load and call them from any JavaScript client app, and you don't have to deal with ASP.NET stuff at all.
Compared to a WASM that has been created using lower level C++, you'll have a big bunch of DLLs for the Mono runtime, that need to be loaded to the client browser (!). That's a huge overhead, if you plan only a small feature set to be exported by the WASM. The best argument for creating WASM using Mono for me is, that I can use my existing codebase with all the algorithms and business logic for a really complex app, so I don't have to write and maintenance the same code twice in different languages.

How to make a web GUI for Python 3 (Javascript communications)?

I've made a program in Python 2.7 with a wxWidgets GUI. Now, I want to improve it by making a web GUI, make it multi-platform and port it in Python 3.4. For this purpose, I have to make Javascript and Python communicate (i.e : I want my Python to react on some event on the page and I want my page to react on some Python actions).
I don't really know how to do it, and I don't even know if it's possible.
I've find some libraries, but some are just for Python 2 (pyjamas), and some don't provide what I search, or I don't search enough ^^ (web2py, turbogear, cherrypy).
I would like to find a complete library that ease this communication, and that is rather known and supported, with a compete documentation.
Maybe, there are other ways to do such a web GUI, but I don't find them.
Thanks !
I guess what you want is a single page application.
I would suggest to wrap your python code in a RESTful Api using a python web framework like Flask. This would isolate your python code from the presentation layer.
You could then write the UI in html and javascript and use AJAX to call your python api from javascript.

Calling MATLAB in JavaScript

I'm new to JavaScript and is coding a simple webpage game using JavaScript for my research. People can play the game and some data will be collected. The collected data needs to be processed by MATLAB and the results will be returned to the JavaScript code. The JavaScript code will be run on client-side and the MATLAB will be in server-side.
How can a JavaScript program call functions in MATLAB and also receive the data from MATLAB? I searched online and found that MATLAB can be used as an Automation server and then be called by web applications (http://www.mathworks.com/help/matlab/matlab_external/call-matlab-functions-from-a-web-application.html).
The link gives an example using VBScript to call MATLAB files. However, I cannot find any resource for using JavaScript to call. What should I do with JavaScript? Besides, is there a way that JavaScript can interact with MATLAB?
Your question is somewhat vague. It is a Web app, so there are two parties involved, the server side and the client side. Does MATLAB need to be called at the server side or the client side?
Assuming it is server side, there are multiple options
1) The COM automation server you mentioned works only if the server is running Windows, because COM is for Windows only.
2) Interface the server side code with C/C++ somehow, for example, using CGI, and use the C/C++ code to invoke the MATLAB Engine.
3) Use MATLAB Builder JA to convert MATLAB code to a JAR file, which can be invoked from your Java-based web app. Similarly, you can use MATLAB Builder EX to convert MATLAB code to a .NET assembly DLL, which can be invoked from your C# based (ASP.NET) web app.
4) Set up an MATLAB Production Server (MPS) and deploy code using MATLAB Compiler. The deployed MATLAB code can be invoked using Java, Python or .NET client code that run inside your server-side web app.
If it is client side JavaScript talking to MATLAB, I am afraid there is no easy way to make the two talk directly. MPS is still a possibility, but it will be via the server-side web app. Perhaps you can explore the possibility of using MATLAB Coder to convert the MATLAB code into C code and then use something like a transpiler to convert the C code into JavaScript code that can be run directly in the browser.
I think that you can create a client programs using the RESTful API and JSON:
Step 1: Write MATLAB Code
Step 2: Create a deployable archive with the production server compiler app
Step 3: Place the deployable archive on a server
Step 4: Enable cross-origin resource sharing (CORS) on the server
Step 5: Write JavaScript code using the RESTful API and JSON
Step 6: Embed JavaScript within the HTML code
Step 7: Run the example
These steps were taken from this link:
Example: Web-Based Bond Pricing Tool Using JavaScript

Converting web2py based web-app into native app using Appcelerator, is it easy? possible?

Here is my problem:
Customer wants my current web application as a Desktop, possibly Executable but without browser for the Client part.
I looked into 3 of following :
Qooxdoo - Needs browser
Adobe Air - Needs plugin and Runtime
Appcelerator - Most interesting , builds into Native Client
Here are the main questions:
Client side:
What i have read on appcelerator is it builds things written in html and javascript
into native executable, so what i have already written (HTML + Jquery + Jquery UI + CSS) can be built into Native Windows / Linux / IOS executables without changes to current code ?
Server side:
No problem as it returms html and json and decided to keep running on server. But wondering how offline contents work.
I'm not sure this will actually work. From what I understand, titanium appcelerator provides a framework primarily for you to create applications on the iOS and Android platforms. I did see some things about the Desktop apps, but nothing about the application being automagically created from the source when your backend code is python (and web2py to boot).
I think it might be impossible to just drop your web2py app in and get a final product. For one, how will Appcelerator know that a given URL corresponds to a given controller and function? How will it perform searches on objects in your database? Do you expect it to read the DAL(...) connection string and just connect?
If you don't do ANY server-side processing, and don't use ANY datasources except for JSON, then maybe this would work. Maybe. But I highly doubt it will be automatic, or even all that easy.
It seems to me that you would have to hit every page and save the pages as html to a disc, and then drop the outputted HTML/CSS/JS markup into Titanium. But that means that if you ARE processing forms or searches, or doing anything interesting in the controllers, the titanium application will not have anything to process the server-side backend stuff.
That being said, titanium does work with php code, but not perfectly, And I see issues when using frameworks as opposed to raw php.
http://www.flickr.com/photos/funkatron/4011561849/
It didn't work that great, regardless. Titanium Desktop does still support PHP though, but developing an app with a server-side framework like CI is basically not going to work.
There was also something in the docs about processing python code, but all I saw was that you can place python in the "client" end of the HTML using a script tag as such:
<script type='text/python'>
# ... python code ?
</script>
(ref: http://developer.appcelerator.com/doc/desktop/python )
But that's not going to help with a web2py app.
IN SHORT -- I advise you download the app and create a hello world project. Then follow a tutorial on migrating or converting your application to Titanium. You'll probably have to rework a lot of things, and I'm not sure how you'd get the execution environment required for web2py, so you might have to rework some of the basic GLUON code which web2py is built on.
Sorry :(
You can, however, probably find a way to create a Java application that includes a copy of (a) rocket webserver, (b) python 2.5 or greater interpreter (c) web2py framework, (d) web2py application and package all this in such a way that it runs inside your java application (which will run on any platform) and shows an HTML view to the enduser. Then you could maintain it as a web2py app and just copy the app to your java bundle. I'm not sure if that's any easier in the end, but it looks like you'll either have to port to Titanium or Wrap with Java (or another language suitable platform-agnostic language).

Categories