Thoughts about using Silverlight In Desktop Apps? - c#

To summarize, as we all know,
a) Silverlight is expected to be hosted by a browser, and runs in an isolated sandbox so that there won’t be any security issues
Silverlight don’t have direct access
to the file system, other than the
isolated storage area
There is no
direct way to open common dialog
boxes like File Save in Silverlight (Though Opendialog box is supported).
b) Silverlight can’t access local resources like a printer
What are the ways to go beyond the sandbox, so that I can host a Silverlight application locally, to read files and save them back if required, to hand over data to a printer, and so on..
Update:
Is full WPF is not an option for me? No. I'm also interested in a cross platform solution - for instance, you could host Silverlight in Mono Web browser control, so that you can run it virtually anywhere.
The idea is to re-use the same application that I'm building for web in my desktop as well, by providing separation of concerns at some areas - like persistence, resource access etc.
Scenarios:
1- Some kind of gadget container, with access to local resources.
2 - A desktop Silver light based media application
Update:
I just did a POC to enable me to access printer and save files locally, of course through a shell where I'm hosting my Silverlight application. If you wan't you can have a look at the post here in my blog

Two ways I can think about is,
Create a "Shell"
Host the HTML Page with Silverlight, in a Winforms desktop application, using a web browser control, and communicate to and fro using HTML DOM. Then I can request the hosted shell to do things like printing. See details here
Mono also has a web browser control - based on FireFox XULRunner instead of IE - not yet succeeded in loading Silverlight inside that. Another option might be using Webkit.
Embed a web server
Embed a light weight web server with in the Host application, and handle requests to perform such operations. You can probably define a protocol on top of HTTP for things like saving to a local folder, sending data to print etc.

Is a full WPF application not an option for your situation?
As you probably know Silverlight uses a subset of WPF so you may be able to change your application relatively easy.
A wpf app would be easier than having a web server etc bundled within your application.
You wont in the foreseeable future be able to have access to resources such as printer and files (apart from isolated storage) through Silverlight as you know.
You could have a seperate part of your app to upload files to the webserver then read these in your silverlight app from a service.
Depending on your printing requirements (e.g. if you just want to send everything to an office printer) you could send the informaton you wanted printed to a service that will then print it for you. However I am guessing you want each client machine to be able to print in which case this wont work for you.

I am attempting to also reuse a codebase for both desktop and silverlight. There are two options that I know of in addition to the ones mentioned
If you directly reference (instead of a project reference) a silverlight dll from a normal project, it should work. This would let you reference a silverlight dll for both projects.
Have two project files (one wpf, one silverlight) that point to the same set of files. You might have to have to use a few compiler flags here and there, but this should let you use the same files for both.

Related

Creating a web application that can be accessed both online and offline

I am newbie to the web programming. I have been working as desktop application programmer for the last 8 years. Now one of my projects is to create a web application using HTML 5 and some java script that can be live on the cloud as well as downloadable as a desktop application to work offline. I don't need any database to store any data. I am thinking of writing a C# win form application with a web browser control to load the HTML pages and the .js files.
My questions are:
Is it possible to achieve? if so, is there any other way than what I mentioned above?
What about the security concerns such as accessing the files(the html files, java script files, etc)? Whether this can be called into my application from the local hard disk?
If I can run it as a desktop application, how to make sure that the source code is not accessed by anyone in the client machine?
It's achievable, but why you would want to wrap it in a C# web browser control doesn't really make sense to me. With HTML5 you can define cache manifest files to create offline apps that run in any browser that supports it, no need to wrap it with anything as long as the client has a capable browser. They don't even have to know it's an offline app!
Not quite sure what you mean here with regards to security concerns. That's a massive topic. Just use common sense and realize that anything you store on their computers will be accessible by them (e.g. do not give them your public/private key pair or store any passwords or anything you don't want them reading in the files you're sending to them) and use a secure connection to send sensitive data back and forth between the client and your server.
You really can't prevent anyone from accessing the source code if it's on their machine. The best you can do is obfuscate it to a reasonable degree before deployment to make it harder on the person trying to read it.

Launch Windows Explorer from Metro style app

I would like to download a file to the DownloadsFolder in a Windows Store App. And then I'd like to bring up a Windows Explorer open on the DownloadsFolder (actually on the folder I create in the DownloadsFolder)
But I can't figure out how to do it.
This stackoverflow question Launching a Desktop Application with a Metro-style app suggests using Launcher.LaunchUriAsync. But the documentation claims:
You cannot use this method to launch a URI in the local zone. For example, apps cannot use the file:/// protocol to access files on the local computer. Instead, you must use the Storage APIs to access files.
And indeed, I was trying to use the "file:" protocol to bring up the explorer window. When I did try this mechanism Launcher.LaunchIUriAsync fails.
If the browser can do this, why can't I?
Is there a way for me to bring up windows explorer, or is that outside the real of possibility?
I don't think you can launch the Windows Explorer from metro. One thing you can use, however, is the File Picker.
http://code.msdn.microsoft.com/windowsapps/File-picker-app-extension-0cb95155
If you're willing to have some non-Windows Store components in your solution, there is a workaround for this. Although you can't launch a process directly, you can always run a HTTP listener inside a Windows service which listens for commands from your sandboxed Windows Store (Metro-style) app and launches Explorer (or any other process) for you. A trivial way to do this would be a Web API service inside a Windows service - just implement the GET action in your controller and have arguments for the executable to launch and optionally executable arguments as well.
This is kind of doing an end-run around the sandbox security, though, so you might want to have a tailored Web API instead which just launches a pre-packaged set of apps (like Explorer or one of your own apps).
Of course, for consumer apps this is not a good solution because you can't just install everything from the Windows Store. For LOB apps, though, it's not a bad compromise because you typically have more control over the environment. This is a good way to surface some metrics or other data into a live tile and have your desktop app launch when the tile is clicked. Whether or not this makes for a good user experience is a totally different conversation.
BatRT allows you to run batch file commands from WinRT applications. It utilizes URI calls. This can be used to open up applications or perform file operations.

best solution for architecture of a enterprise web App, that use hardware & local resources & heavy data entry forms

we have an APP, that uses many local resources, such as windows printing API, windows registry, some Active X to connect to POS devices(to pay money & get receipt, the price is sent from APP), Barcode printer to print labels, RFID devices to read & write some data. The application is written with .Net framework 3.5, and uses some new features of .Net framework (e.g.: WCF). The forms in app are very heavy forms(7 of them are essential), in each form, there are over 100 Textboxes, combos, radio buttons, panels & many other controls, that according to need of user are shown or hidden, disabled or enabled, filled & cleared, many many times.
After the user does the work, prints most be sent to previously selected printer automatically, labels most be printed by barcode printer, RFID & POS devices are called if neede.
The problem is that now we need a web base version of this. the reason is that there are an administration department who needs to be aware of any transactions online (there is a dashboard software). In the WIN APP version, we use WCF to send & receive new data (something like replication happens).
According to my searches, there are 3(even 4), way to accomplish this goal, as below.
Using WPF technology
Using Clickonce
Using Pure html + Active X(meaning asp.net, very heavy javascript & Write Active X)
Hosting windows forms controls in IE
WPF’s XBAP is good, but:
It needs to download all dll’s to local machine & then start the application. This also happens every time a new version is uploaded to server. The sizes of dll’s are about 5meg.
Also there is a risk that a user can disassemble the dll’s. Also we need to sign the assemblies in order to be able to use win API’s, and the user need to add the site to its secure site.
The main disadvantage is that WPF is not actually in Web architecture, I mean, dll’s do calculations on client side & the server is only responsible for saving entities (& does some validations).
refer to https://stackoverflow.com/tags/web-applications/info
Clickonce:
No idea at all, we can deploy App(the WPF version or windows forms version) as a clickonce app, but the server is only responsible for updating new versions of software.
Pure web & HTML + Active X:
This is the time consuming work, everything seems to be ok, but actually we need to be JQuery & AJAX masters & I think most of time is spent on debugging javascript. Also only IE can run the App # all, because of Active X controls in page.
Winform in IE:
Not a good choice at all, but we can do this, the output is works only in IE, also the rendered UI, is in very bad style.
There is also another way, may be a hack, when we develop with pure web, we can write some WCF services to do the hardware part(commiunicating with hardware, local resources & other things) & install them on clients(run for example with cassini). So when we need for example to work with hardware & local resources(POS, RFID, Registry & others), we can call them from our site with the web service call(that points to local host).
Which of these are good choice & what?
Is there any other solution?
any idea can help.
many thanks.
Cleanest solution may be to go WPF for the presentation tier (silverlight will require an additional step to access the local machine) and click-once (just because you are considering click-once doesnt mean your server is now just a distribution mechanism, also correct me if im wrong but you can also include the .Net runtime as part of the click-once distribution package)
Also just because its WPF doesnt mean all your business logic needs to be downloaded with the client, id collect your business logic server side, at least the sensitive stuff and call it via wcf -with security of your choice-.
EDIT
Some useful links
Learning WPF with BabySmash -Manually Managing ClickOnce and some more Designer Goodness
Deploying a WPF Application (WPF)
Silverlight, Wpf Web App (xbap) or Click Once? Pros and Cons
I'm not sure I understand all of your requirements correctly. It looks to me that all you need is a service component that tracks the transactions. Rather than rewriting everything as WPF/SL, why not modify your current application (you didn't mention the technology used nor if you can modify it) to log any transaction to a service endpoint.
The service endpoint records the transactions in a database (e.g., WCF over https, storing data in SQL Server). From there you can either expose the information as part of the dashboard software you mentioned, or you can create your own reporting application using something like ASP.NET MVC.

How to start up your .NET program from web browser?

Could you provide example of JavaScript function for starting up application installed on your computer from a web browser (eg google chrome 4). It particular if .Net APPs have any special simplifying this process apis of out there are some libs for such staff, please share link with us.
so how to create and store in run on start up programs a small local server which would handel some local urls like http://localhost/maAppServer/MyAppCalculator/Start for starting apps that have written in its config file their names and local urls on install?
So how to start up your C# .NET app\program from web browser?
I don't believe its possible in Chrome, starting an EXE on a users computer could be considered a security violation. Some ActiveX, and file:// links in internet explorer may work. Also, OneClick deployment may do something similar to what you are after (not exactly though I don't think, and I believe they require an add-in which may not be available for Crhome) http://www.15seconds.com/issue/041229.htm
I'm not sure what you're asking for. You can start an application on your computer just by linking to it in the HTML page. However, if you need to pass data to it, then it's a different matter altogether, although it's still simple.
An example is what www.nexon.com does with it's MMORPG, MapleStory. You log on to the website, and the web page starts the game after the authentication. Another example would be the magnet links on file-sharing sites.
You need to create a protocol handler, it can be in any language like C++/C# and register it on the client's computer. Like so - http://msdn.microsoft.com/en-us/library/aa767914(VS.85).aspx
Then, just use the protocol you built to pass on whatever data necessary. You can add a link that can be clicked, a button, Response.Redirect() from the server, whatever you like.

Embedding .net remoting program in WEB

So, here is a deal.
I have client-server application(dotNet remoting). Client side has few trackbars, checkboxes, buttons and picturebox. Server is a console application and does only calculation from client. Client's picturebox make some visualisation of calculation in picturebox. All calulations and relative classes are in dll file.
Now I have to embed client application in web site. All kind of technologies are accepted, but I want to minimize forces applied to embedding. So, what is the best way to do embedding?
What about SilverLight or Flash?
You need to create a web site that accesses your remoting server and renders output as HTML. I seriously doubt that you will be able to get remoting working inside a browser environment, even using something like Silverlight.
If you don't want to use a full blown web server then use the .net class HttpListener in your server application to create an embedded web server.
If you want to take a C# application and access it through a web server, look into iHttpHandler. You need to compile to a DLL, and configure your IIS server.
There are a number of tutorials on the web. One is: http://www.codeproject.com/KB/aspnet/CustomImageHandler.aspx

Categories

Resources