Run Javascript+WinJS code from universal windows application on C# - c#

Some time ago we started development of our application for Win8.1/Win10 on Javascript+WinJS (it wasn't my decision to use Javascript, but well, it was done). After a half of the year we published our product to Windows application store, and a few months later we realised we can't implement all features we want on Javascript. So now we decided to switch to C#/XAML. But well, we already have pretty big codebase written on Javascript+WinJS. There was idea we can build new application (UI, new features) on C#, but also reuse current JS code. I've read MSDN a lot and as far as I see it is possible to create class library on C# and use it from JS, but our case is just opposite - I need to encapsulate JS+WinJS in some "component" and use it from our new C# application. Is it possible? I don't even see in Visual Studio such type of project as "Javasctipt library for universal applications".
Things could be not so bad our application was pure JS (I always can put WebView on form and eval some JS code). But WinJS doesn't work in WebView!
So I can't use our JS+WinJS code as "class library" and I can't run it in WebView. Any chances I can use some other approach?

WinJS is just a JS library, it isn't tied to any of Windows Runtime APIs. WinJS can even be used in web development (check this out).
The standart WinJS app template handles the Application.Activated event and invokes WinJS.UI.processAll() in the handler. As long as you host the code in the WebView control, the Application.Activated event doesn't fire because the application is already activated.
The problem solves easily, you just need to invoke WinJS.UI.processAll() explicitly:
<script>
WinJS.UI.processAll();
</script>

Related

Running my UI app (WPF App) inside Worker Service with C# .Net Core

I'm new in programming with .Net and C# and, as said in the title, I have a WPF app which is accessible in a system tray icon and I want to run it a windows service.
Typically, I want an output like it was described in an answer provided in a discussion here.
If you want it in the system tray I think what you'll have to do is make it a Windows service. I've only written 1 Windows Service and that was years ago, but I believe that's what you'll have to do. If I'm correct about writing a Windows service, then what I would suggest you do is create a new Visual Studio solution and add two projects to it. One would be a DLL which would run as a Windows service. The second project would be a WPF project that will be your UI the user interacts with. Then you'll have to use some messaging system to communicate between the two. For the action messages that would mimic what Outlook does, I've used some WPF toast messages to accomplish that. If you Bing/Google "WPF toast popup" you'll get lots of results.
I have many searched in Internet and find some helpful answers like:
URL1
You can't, not directly, because the windows service will necessarily start when the machine does, not when a user logs in. The service will also be running in a different context, likely as a different user. What you can do is to write a separate system tray based "controller" that interacts with the service.
URL2
It needs some effort to achieve. Well, just two hints: 1) use static property System.Environment.UserInteractive to detect in which mode your application is running, see http://msdn.microsoft.com/en-us/library/system.environment.userinteractive.aspx; 2) get rid of app.xaml, because it will force starting WPF Application in all cases; instead, create and run and instance of System.Windows.Application (or better, a specially derived class) explicitly and only for interactive mode, see http://msdn.microsoft.com/en-us/library/system.windows.application.aspx.
And, I could not apply their instructions.
Thanks advance!

Silverlight an alternative to activeX?

I have a question regarding hosting silverlight in asp.net web page. I have a functionality which I tried to achieve through activeX earlier but it didn't work out (hosting related issue etc) so now I am planning to get it done through silverlight.
But I have a doubt here, I want to know how will it work I mean where will silverlight code get executed (Client side or server side) if I call silverlight component's methods through java script ?
Can siliverlight be used as an alternative to activeX controls?
That is a lot of questions.
Silverlight will get executed on client side. You can call webservice though from silverlight which will then execute on server side. Silverlight is comparing to ActiveX "caged" - it is running in sandbox, which will get access only to limited set of functions and local resources (you can use them all, but then you'll have to ask user to run the app in trusted mode, which is not by default). Also it requires plugin in browser (while ActiveX at least for IE does not). You can invoke silverlight application methods trough javascript.
In summary - Silverlight can be alternative to ActiveX for some scenarios.
And as for ActiveX - I recommend do not use them at all, unless you absolutely have to.

trigger a .net application on the server from web asp.net with parsing some argument

I dont know whether this is possible but it would be great if there is a solution for this:
I have an asp.net webpage. When the user opens a webpage. I would like that webpage to trigger to run a .net application running on the client machine. In addition, during that trigger, that webpage also passes some parameters as arguments to the .net application.
I hope to get some ideas how to achieve this issue somehow?
thanks in advance.
Pretty vague question, but you might look into either:
SignalR - a long polling library for ASP.Net that lets you make calls to client side code from the server side "faking a persistently open connection"
Node.js - a javascript library for the server-side.
I would suggest starting with SignalR
Edit:
https://github.com/SignalR/SignalR
http://chatapp.apphb.com/
See this question: Running application from browser ASP.NET
In short you can't do this with HTML & JS, you may be able to with silverlight depending on what you want to do
Do you have control over the client-side app? If so, Click Once is one approach. Silverlight is another.
For a general purpose solution, the app either needs to be registered with the browser for a specific MIME type (this is how the browser knows to start Acrobat Reader for PDF files, for example), or you would need to create and have your users install an Active-X plug-in (native C++ code, though).

Running Windows Forms Through In the Browser

I wrote a client/server program using windows form application in visual studio. Now i want to put this program onto a web page, so on the client side they can just go onto any browser and and access the server.
Can i just embed the program i already hav onto a webpage or do i need to rewrite it using visual studio web application or maybe web services?? If so, will it be any different than a regular windows form application?
Sorry, you'll have to rewrite it. Your windows forms application runs on the client, but you want to run it through the browser, where it would have to run on the server.
If you've followed good design principles, the core functionality of your app will not be in the forms, but in classes (hopefully in a class library) that are not specifically tied to the UI. If that is the case, you'll just need to create a web front end (UI), and you can reuse the existing C# classes.
If, however, like many inexperienced developers, you've coupled the underlying logic tightly to the UI - a good example is putting code in the form's .cs file that's not really UI-centric - you're looking at a lot of refactoring, and THEN writing a web front end.
Perhaps you should have a look at ClickOnce deployment. I believe you can utilize it to download the WinForm app from a website.

C# Making a Frontend to a Console Program?

I wrote a console program in c# that takes up to three files as input, and does some data calculations on them.
I'd like to make a simple frontend that allows the user to easily
import files - basically choose up to three files to be routed to the backend code
change settings - I have about 10 settings that I'm currently storing in an app.config file. maybe a simple settings box would be nice
see what's going on - the console program shows some status messages that might be useful to display on a GUI
I have practically no experience with windows forms or GUI design, so I really don't know where to begin. I compiled the backend stuff into a *.dll and am currently playing around in design mode of sharpdevelop...but i really have no idea how to get the two to work together.
any pointers would be greatly appreciated!
The usual pattern, in cases like these, is to make the main features of the application into a class library and call that from a wrapping executable, such as a console app, winforms app or webforms app (if possible). That way you can easily adapt the interface as needed and simply route input and output to and from the class library.
Edit: I realize this isn't a very indepth answer, but I hope it helps to get started at least, together with any other answer that may arrive.
If you want to get started with GUI design in .NET, I recommend you choose WPF (Windows Presentation Foundation). This is the latest technology released in the UI/graphics area by Microsoft and is where everything is heading now. (Windows Forms won't be obsolete for a long time, though it is surely but slowly becoming deprecated.) I noticed however that you are using SharpDevelop, which doesn't yet have real support for WPF (as far as I know), whereas it certainly does for WinForms. If there's any chance you can use Visual Studio, I recommend you begin by learning WPF. You have the advantage of not being confused by previous experience with the styles and methodologies of WinForms, so it would very much be the right way to go.
Whichever you wish to learn, the Getting Started page of WindowsClient.NET (the official MS site for both WinForms and WPF) would be a great resource. There's also a few MSDN articles on getting started with WPF.
Hope that helps.
Have you tried Visual Studio Express editions? They're free and come with a designer for either WinForms or WPF applications.
As a first pass you'll need 3 text areas for the filenames, with associated buttons to bring up the file open dialog (it doesn't actually open the file just returns the filename).
A label to display the status - updated from your worker code.
Then either the various radio buttons, check boxes etc for your configuration settings.
Oh and don't forget the "Start" button to set off your process.
If your process takes a while you ought to use a background worker thread. You can then implement a "Cancel" button to safely abort the process and tidy up if it goes wrong.
There will be optimisations and reorganisations that you can do once you've got it working.
Your question is quite indistinct. If you're asking about working with GUI, you should read some book on Windows Forms.
And if you're asking about how to put your dll in your new windows forms application, then you should just add a reference to it in winforms project's properties and then use classes from dll's namespace.

Categories