Popup Window from Silverlight 5 - silverlight

I have strange problem with SL5 Pop-up.
My SL5 app works and fetch data from WCF service located on other domain. On one button click, some service method is called and returns a path of file. On return from service, result is used to open popup window. Since it is not user instantiated following code is used to achieve this
new Repository().SaveExporttoExcelData(builder.ToString(), (result) =>
{
this.Dispatcher.BeginInvoke(() =>
{
var options = new System.Windows.Browser.HtmlPopupWindowOptions();
options.Left = 0; options.Top = 0; options.Width = 80; options.Height = 60;
string servicePath= path;
if (result != null)
{
string excelPath = servicePath.Replace("\\","/") +"/"+ result.ToString();
System.Windows.Browser.HtmlPage.Window.Eval(string.Format("window.open('{0}','{1}','{2}')", excelPath, "new", options.ToString()));
}
else
{
MessageDialog.Show("Error in downloading file. Please try again.");
}
});
});
This works fine if I am running SL5 app from VS and service pointed to prod service environment. But the same SL does not work when I host xap on prod web. I am on citrix, and the same also work from same network where web is hosted. I have also closed the proxy connection, before opening the popup.
The url is generated fine, and popup appears for a while and close without downloading the file. but if I copy the URL and open in browser, I am able to download the file. I have checked the popup blocker settings and proxy connection.

Related

Allow only one Chromium app instance

I have the Chromium source on Windows 7, and launch my custom app with the --app="..url" switch through a .bat file. How can I prevent users from opening more than one instance of my Chromium app? This includes opening the .exe directly, using the .bat file and by selecting "Chromium" from the jump list menu on the task bar.
If the app is launched with the --app="...url" flag, then the following solution will prevent further "instances" of Chrome being opened. I say "instances" because Chrome doesn't actually create new Chrome base processes. Instead, it opens a new window with a process used for rendering that particular window.
So, when the app is in --app mode, all you need to do is prevent new windows from opening. This can be accomplished by modifying the OpenApplicationWindow() method within the Chromium source code Application_launch class: chrome/browser/ui/extensions/application_launch.cc.
...
OpenApplicationWindow(const AppLaunchParams& params) {
browser = chrome::FindBrowserWithProfile(profile, params.desktop_type);
#endif
WebContents* web_contents;
if (!browser) {
browser = new Browser(browser_params);
web_contents = chrome::AddSelectedTabWithURL(
browser, url, content::PAGE_TRANSITION_AUTO_TOPLEVEL);
web_contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
web_contents->GetRenderViewHost()->SyncRendererPrefs();
}
else {
web_contents = browser->tab_strip_model()->GetActiveWebContents();
}
browser->window()->Show();
...
*NOTE: There should be some Windows 8 code in this method already. The idea is to remove the conditions for Windows 8 Metro Mode, so new Windows are always prevented.

WPF webrowser control - flash working only first time

I have a very strange problem on my wpf application.
I use a webbrowser control to display a third-party web page that uses flash to provide some functionality.
On internet explorer 9 and 10 i have a particular behaviour : the first time I open the webbrowser control everything works fine, and the application puts a .SWF file inside my temporary internet files folder. When I close and reopen the webcontrol, the following error arise :
"object does not support property or method 'UpdateTimeLeft'".
If i manually delete the .SWF file inside the temporary folder, close ad reopen the application, everything works fine again.
This is the code that arise the exception :
var swfUrl = "//" + serverName + "/js/tv/FlashTurboLotto3.swf";
var expressSwfUrl = "//" + serverName + "/js/tv/expressInstall.swf";
var flashvars = {};
var params = {wmode:"transparent", allowscriptaccess:"always" };
var attributes = {id:"FlashTurboLotto3", name:"FlashTurboLotto3", align:"top"};
swfobject.embedSWF(
swfUrl,
"flashcontent",
"100%",
"197",
"9.0.0",
expressSwfUrl,
flashvars,
params,
attributes
);
function updateTimeleft(drawID, timeleft)
{
var swf = document.getElementById("FlashTurboLotto3");
swf.updateTimeleft(parseInt(drawID), timeleft);
}
does anyone have an idea of why this appens and how to solve the issue?
Thank in advance.
I found the solution - It is a very particular bug of Flash. Sometimes happens that when the flash application runs in a non-native browser (like, in my case, a webbrowser control in WPF) the javascript fails at retrieving the .swf file from the cache, so the Flash object will not get initialized.
I solved, for now, by forcing to not use the browser cache, simply adding a random value to the .Swf download Url.

How to upload file in silverlight

I want to save (upload) a file in silverlight into the silverlight application folder.
I get the URI of the application
string str3 = App.Current.Host.Source.AbsoluteUri + "/Recording/";
but i don't know how to save file.
I use this code.....
string extension = "wav";
// Create an instance of the open file dialog box.
OpenFileDialog openFileDialog1 = new OpenFileDialog();
// Set filter options and filter index.
openFileDialog1.Filter = String.Format("{1} files (*.{0})|*.{0}|WAV FILES (*.*)|*.*", extension, "Audio");
openFileDialog1.FilterIndex = 1;
openFileDialog1.Multiselect = false;
// Call the ShowDialog method to show the dialog box.
bool? userClickedOK = openFileDialog1.ShowDialog();
// Process input if the user clicked OK.
if (userClickedOK == true)
{
string str = App.Current.Host.Source.AbsoluteUri + "/Recording/";
openFileDialog1.File.CopyTo(str);
}
That won't work by itself (I assume your application is hosted on a web server), you need an uploader that will send the content to the server, and a server side handler that will receive and store the file.
Take you pick from one of those Silverlight uploaders:
Silverlight File Uploader
Silverlight File Upload
Silverlight Multi File Uploader
Personally I went with the first one, but I believe they're all quite good.

Is it possible to launch a Silverlight 4 OOB application from a web page? [duplicate]

This question already has an answer here:
Launch Silverlight Out-of-Browser from browser post-installation
(1 answer)
Closed 2 years ago.
I'm planning to build a download manager application and would like to be able to launch the application when a user clicks a button the site. The application would obviously already need to be installed on the client machine.
There are a few reasons why this needs to be written using Silverlight, but they're not really relevant to the question. I only mention it so that people don't suggest that I use another technology.
Doing a bit of a mash up from two other posts [1] and [2].
But of course this will only work for Windows not Mac. There you will have to fallback to the #michael-s-scherotter style solution.
private void Button_Click(object sender, RoutedEventArgs e)
{
if (Application.Current.HasElevatedPermissions && System.Windows.Interop.ComAutomationFactory.IsAvailable)
{
string run = "\""%ProgramFiles%\\Microsoft Silverlight\\sllauncher.exe"\" /emulate:"Silverface.xap" /origin:\"http://www.silverlight.net/content/samples/apps/facebookclient/ClientBin/Silverface.xap\" /overwrite";
dynamic cmd = ComAutomationFactory.CreateObject("WScript.Shell");
cmd.Run(run, 1, true);
}
}
Yes. Here is an example:
http://www.silverlight.net/content/samples/apps/facebookclient/sfcquickinstall.aspx
I found a trick that launches the installed silverlight OOB from the silverlight app in-browser. Both applications should be singed and have the elevated trust.
When a user installs the silverlight OOB App first time, retrive the path and argument values from the shortcut file of the OOB app on desktop. (ref: How I can use Shell32.dll in Silverlight OOB) If you know the the path and argument values, you can launch the OOB app using Com Object.
Send the retrive the path and argument values to the silverlight App in-browser. (ref: http://msdn.microsoft.com/en-us/library/dd833063(v=vs.95).aspx)
Store the path and argument values in a cookie.
Now, the silverlight app in-browser is able to launch the silverlight OOB using the path and argument values in the cookie.
using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
{
shell.Run(launchPath);
}
I hope this trick is useful to you :)
It is possible if you agree to install the app each time the user clicks on it.
You also should set the app to require elevated trust in its OOB settings.
Just uninstall the app on startup (for example, in main window constructor):
if (Application.Current.HasElevatedPermissions && Application.Current.InstallState == InstallState.Installed)
{
string launcherPath = string.Empty;
using (dynamic shell = AutomationFactory.CreateObject("Shell.Application"))
{
string launcher64 = #"C:\Program Files (x86)\Microsoft Silverlight";
string launcher32 = #"C:\Program Files\Microsoft Silverlight";
dynamic folder64 = shell.NameSpace(launcher64);
if (folder64 != null)
{
launcherPath = launcher64;
}
else
{
dynamic folder32 = shell.NameSpace(launcher32);
if (folder32 != null)
{
launcherPath = launcher32;
}
}
}
using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
{
var origin = Application.Current.Host.Source.OriginalString;
var launchCmd = string.Format(#"""{0}\sllauncher.exe"" /uninstall /origin:""{1}""", launcherPath, origin);
shell.Run(launchCmd);
}
}
(the code for uninstall was taken from this post: http://www.wintellect.com/blogs/sloscialo/programmatically-uninstalling-silverlight-out-of-browser-application)

Will Prism OnDemand module loading work in an OOB scenerio?

Should the loading of OnDemand Prism modules work in an OOB scenerio? If so, I cannot seem to make it work. Everything is currently working in browser without any problems. Specifically I:
register my modules in code:
protected override IModuleCatalog GetModuleCatalog() {
var catalog = new ModuleCatalog();
Uri source;
if( Application.Current.IsRunningOutOfBrowser ) {
source = IsolatedStorageSettings.ApplicationSettings[SOURCEURI] as Uri;
}
else {
var src = Application.Current.Host.Source.ToString();
src = src.Substring( 0, src.LastIndexOf( '/' ) + 1 );
source = new Uri( src );
IsolatedStorageSettings.ApplicationSettings[SOURCEURI] = source;
IsolatedStorageSettings.ApplicationSettings.Save();
}
if( source != null ) {
var mod2 = new ModuleInfo { InitializationMode = InitializationMode.OnDemand,
ModuleName = ModuleNames.mod2,
ModuleType = "mod2.Module, mod2.Directory, '1.0.0.0', Culture=neutral, PublicKeyToken=null" ),
Ref = ( new Uri( source, "mod2.xap" )).AbsoluteUri };
catalog.AddModule( mod2 );
}
// per Jeremy Likeness - did not help.
Application.Current.RootVisual = new Grid();
return ( catalog );
}
later request for the module to be loaded is made:
mModuleManager.LoadModule( ModuleNames.mod2 );
and wait for a response to an event published during the initialization of that loaded module.
The module appears to never be loaded, and when the application is running under the debugger there will be a message box that states that the web server returned a 'not found' error. I can take the requesting url for the module and enter it into Firefox and download the module with no problem.
I have not been able to find any reference to this actually being workable, but it seems as though it should. The most I have found on the subject is a blog entry by Jeremy Likeness, which covers loading modules in MEF, but applying his knowledge here did not help.
The server is localhost (I have heard it mentioned that this might cause problems). The server has a clientaccesspolicy.xml file - although I don't expect that is needed.
I am using the client stack and register it during app construction:
WebRequest.RegisterPrefix( Current.Host.Source.GetComponents( UriComponents.SchemeAndServer, UriFormat.UriEscaped ), WebRequestCreator.ClientHttp );
Followup questions:
Can all of the xaps be installed to the client desktop in some manner - or only the main application xap? specify them in appmanifest.xml somehow??
Is it worth it make this work if only the application.xap is installed and the rest of the xaps must be downloaded anyway?
Once I worked on a similar scenario. The trick is having the modules stored in isolated storage and use a module loader that reads from isolated storage when working offline.
This is because otherwise, you can't get download the modules that are in a different .xap file than the Shell.
Thanks,
Damian
It is possible to hook custom module loaders into Prism if you're willing to tweak the Prism source and build it yourself. I was actually able to get this to work pretty easily - in our app, I look on disk first for the module, and if it's not found, I fall back to loading it from the server via a third-party commercial HTTP stack that supports client certificates.
To do this, download the Prism source code, and locate the Microsoft.Practices.Composite.Modularity.XapModuleTypeLoader class. This class uses another Prism class, Microsoft.Practices.Composite.Modularity.FileDownloader, to download the .xap content; but it instantiates it directly, giving you no chance to inject your own or whatever.
So - in XapModuleTypeLoader, I added a static property to set the type of the downloader:
public static Type DownloaderType { get; set; }
Then I modified the CreateDownloader() method to use the type specified above in preference to the default one:
protected virtual IFileDownloader CreateDownloader() {
if (_downloader == null) {
if (DownloaderType == null) {
_downloader = new FileDownloader();
} else {
_downloader = (IFileDownloader)Activator.CreateInstance(DownloaderType);
}
}
return _downloader;
}
When my app starts up, I set the property to my own downloader type:
XapModuleTypeLoader.DownloaderType = typeof(LocalFileDownloader);
Voila - now Prism calls your code to load its modules.
I can send you my LocalFileDownloader class as well as the class it falls back to to load the .xap from the web if you're interested... I suspect though that if you look at Prism's FileDownloader class you'll see that it's simple enough.
With regard to your other questions, the clientaccesspolicy.xml file is probably not needed if the URL the app is installed under is the same one you're talking to, or if you're in elevated trust.
The .xaps can definitely be pre-installed on the client, but it's a bit of work. What we did was write a launcher app that is a standalone .NET 2.0 desktop app. It downloads the main .xap plus certain modules* (checking for updates and downloading only as needed), then uninstalls/reinstalls the app if necessary, then launches the app. The last two are done via sllauncher.exe, which is installed as part of Silverlight. Here's a good intro to that: http://timheuer.com/blog/archive/2010/03/25/using-sllauncher-for-silent-install-silverlight-application.aspx.
Assuming you're running under elevated trust, it should also be possible to pre-fetch the module .xaps from within the SL client, but before they're actually requested due to user action. You'd just need to put them in a folder under My Documents somewhere, and then use the custom module loading approach described above to pull them from there.
*In our case, our main .xap is 2/3 of the application. The rest of our .xaps are small, so we download them on-the-fly, with the exception of some .xaps we created as containers for third-party components. We don't expect to update those very often, so we pre-install them.

Resources