Identifying Silverlight at server side - silverlight

What I have?
I have a web part on which I am displaying a hierarchical diagram picking the information from a List. The diagram is drawn using Silverlight and HTML.
What I want to do?
I want to show Silverlight diagram if Silverlight is installed on the client machine otherwise I want to show HTML diagram.
What problem am I facing?
I want to check if Silverlight is installed or not on the server side and render the appropriate diagram. Basically, I don't want to use JavaScript to identify it and do a unnecessary post back for loading the diagram.
Is it possible to achieve this on the server side?
Thanks for your time!

You could give this a try:
<asp:Silverlight runat="server" ID="SilverlightControl"
Source="~/Control.xap" Windowless="true">
<PluginNotInstalledTemplate>
<!-- here go your HTML fallback content -->
</PluginNotInstalledTemplate>
</asp:Silverlight>
Of course, this can be translated to a <OBJECT> element, if you're not using ASP.NET

Strictly speaking, it isn't possible. You have no access to the client side other than through the HTTP cycle and consequently, you need a client side mechanism of returning this information, i.e. something like JavaScript.
What you could do though, is position the diagram with CSS and position the Silverlight over the top (again using CSS) if it's present. To be honest though, this would have as much overhead as the roundtrip would as you'd always be loading the data twice. If you require Silverlight to display the diagram, then simply make it a requirement that the user must install Silverlight to view it - after all, you'd expect them to load Flash if they wanted to view a Flash image.

I am not sure, but I don't think it is possible. There is nothing in the browser string which identifies silverlight support. Anyway, the additional fetch of the silverlight will not typically be very expensive if you are using HTTP 1.1.

Related

Scraping Data from Silverlight Control within Browser

I have been using Excel VBA and WPF applications to scrape data from various websites, and all has gone well. But now I have run into something I cant get past.
The website is displaying its data within a Silverlight control:
<OBJECT width="100%" height=400 id=rnSilverlightGrid
data="data:application/x-oleobject;base64,QfXq3+...blah blah thousands of characters...AAAA=="
type=application/x-silverlight-2
</OBJECT>
(Left out what I thought was not helpful.)
getElementById("rnSilverlightGrid") returns nothing, but I am able to get a handle to the object with ie.document.all.tags("Object").Item(0), but have been unable to go further into the object to get data.
Can anyone tell me how now to get the data out of this Silverlight grid? This is currently coded in Excel VBA, but if necessary I can switch to WPF and use the WebBrowser control. I would rather not make the switch if avoidable (not sure how to do it there either anyways). I looked into White (seems like a dead end), and have seen other questions about this which have gone unanswered.
Thanks in advance!
Silverlight has the capability to make certain objects available to JavaScript calls so that JavaScript developers can affect the Silverlight application externally.
These are called "Scriptable Objects".
further reading: https://msdn.microsoft.com/en-us/library/cc645085(v=vs.95).aspx
My understanding is that this feature is available in SL4 and SL5.

dynamic inline silverlight from string without files

for my final project in university i am developing in asp.net mvc3 and using silverlight for vector graphics.
I store silverlight code as string/xml in a database, and i want the ability to manipulate it dynamically (change proportions etc..) and display it in my aspx view. i don't want and can't use files because of scalability issues (there will be a lot of them) and because of possible porting of the application to the cloud (Azure).
basically i want to build a controller that will take raw xaml code from the DB and display it. all the solutions i found on the web are about two options which is not helpful for me:
http://msdn.microsoft.com/en-us/library/cc189044(VS.95).aspx - which involves manually creating the entire dom object and integrating it in an existing silverlight page, which i don't have
http://visualstudiomagazine.com/articles/2008/01/21/using-inline-xaml-with-silverlight-listing-2.aspx - using embedded header in the html itself - again not pracrtical..
maybe someone can suggest me a practical solution for my problem
I would suggest the you spend sometime examining in detail how the Silverlight navigation framework can be used.
I'm think you should be able to use the Frame element with your own implementation of INavigationContentLoader assigned to its ContentLoader property and possibly your own derivative to UriMapperBase assigned to its UriMapper property.
You would then use a URL like this:-
http://yoursite.com/yourHostController#/yourXamlController/someReference
You would have two views, "yourHost" would simply generate the HTML nececessary to host the Silverlight application you will build. The "yourXaml" view would simply serve up the raw Xaml.
Your Uri mapper will take the relative url supplied after the # (this is how silverlight intra-application navigation works) and create a Uri that can points at yourXaml controller.
Your implementation of INavigationContentLoader will then fetch the Xaml from the Uri and load it up.
Assuming the Xaml contains hyperlinks to using urls like "/yourXamlController/otherReference". You should be able to navigate around your stored Xaml without reloading the Silverlight app. Everything will be about referencing and downloading new chunks of Xaml.

Displaying PDF content within Silverlight

The requirement is below:
--> The version of Silverlight is 3.0
--> I don’t want to convert it to jpg, png etc. since I want end user to copy data from the displayed data.
--> I am currently using IFrame to display pdf but it has some problems like IFrame not supported consistently across different browsers.
--> I could not find any control (third party) that displays pdf with SL 3.0 Most of the controls that I came across are either for 4.0 or does conversion into some png kind of format which doesn’t allow user to copy data. If there is nothing that can be done from SL easily then I am ready to use 3rd party controls that are meant to work with SL 3.0 and allow end user to copy data.
--> I thought about reading data from pdf and displaying again over some control like text block but this would eventually become complicated for scenarios where I have to maintain formatting and displaying images etc.
Please suggest on this.
I think you gonna lose this one. I don't know of anything that renders PDF well in Silverlight 4 let alone Silverlight 3.
Whilst this comment "IFrame not supported consistently across different browsers" may be true IFrame is generally supported by the all major browsers.
Hence your best bet is to test and tweak your IFrame solution with these browsers.
Alternatively launch an independent browser window to display the PDF or let the users local system use whatever it has installed to display the PDF.

How to control MFC application from another program?

I have a binary application on windows (train timetable software) which contains a lot of interresting data which I need for my project (nothing illegal, just some weird optimization algorithm). But the application has no api and the data files have undocumented binary form.
So my idea is to control the application from my own code. I would like to send keystrokes to it to fill a form, run query and save result to a file (there are buttons and menu items for this in the app). And repeat many times.
Is there a library for this? Or an example? I have a general idea how to do it, but I am lazy and I do not want to invent the wheel.
Also, the same data is available on the web. Is there some solution for the same task with ASP (Win forms) web applications? I could probably handle parsing the results but I do not know how to fill the values of webforms controls.
Thanks in advance.
You can use simple Win32 APIs to do this.
FindWindowEx and then once you have the window handle you can send any message (such as WM_KEYDOWN) to it by using SendMessage.
A good tool which helps with this process is Spy++ because it allows you to see the window hierarchy more easily and also which messages are being used internally for the application you are monitoring.
As for web form controls, you will probably have to do more work than this because typically the web will be one canvas control that things are drawn custom onto depending on the browser. Perhaps doing this via some kind of proxy is a better approach where you actually filter the HTML pages.

Can I re-use a Silverlight app in different areas of my page?

I've got a single Silverlight app that I'd like to display in a grid. The way the Silverlight app displays its content is dependent on the unique ID of the record in each grid row. Unfortunately, the XAP file is re-downloaded for each row in the grid. With a size of 700KB, this really impacts performance. Is it possible to download the XAP file once and then just re-use it for each row in the grid?
Once a XAP is downloaded Silverlight will cache the assemblies etc locally per instance of a Silverlight control. If you create another instance of a Silverlight control then this in turn has it's own domain that it in turn looks after.
My suggestion is to abstract out the parts you requrie and bake them into a seperate xaml, then load them into areas where you need them the most. If you still require a central .xap to handle the marshalling / event management etc then in Silverlight 3 we've put in place a Local Connection API which allows other Silverlight instances to talk to one another within the one browser page locally (ie SilverlighA can talk to SilverlightB all within index.html)
This can then allow you to establish a sort of local proxy if you will.
Scott Barnes / Rich Platforms Product Manager / Microsoft.
I'm not sure you can. Theoretically it should be cached, but in this case theory don't seem worth squat.
It's all down to the way the < object > tag behaves with it's various params and this is (another) one of the "sparsely" documented areas of silverlight.
It is possible but not easy to do. You could download the xap and save it to IsolatedStorage and create a silverlight host each time you need one referencing your cached xap but you only have 1MB space available and you aren't guaranteed that if you have other silverlight apps from the same domain.
Given what you described I still don't see any value in doing what you want to do. I think you have it backwards.

Resources