Silverlight Application.InstallState - Incorrect - silverlight

I'm using the pattern Tim Heuer outlines here for my Silverlight 4 OOB installation pattern:
http://timheuer.com/blog/archive/2009/08/12/silverlight-out-of-browser-force-install-pattern.aspx
Here is my app's *Application_Startup* method:
private void Application_Startup(object sender, StartupEventArgs e)
{
//string _USERID = e.InitParams["UserAccount"];
if ((App.Current.InstallState == InstallState.Installed) && (!App.Current.IsRunningOutOfBrowser))
{
this.RootVisual = new Installed();
}
else if (!App.Current.IsRunningOutOfBrowser)
{
this.RootVisual = new Installer();
}
else
{
this.RootVisual = new MainPage();
}
ShowBusy(false);
}
The problem is that even when the app is installed and running App.Current.InstallState returns NotInstalled and App.Current.IsRunningOutOfBrowser is false - so my control Installed never shows, it always show the Installer control.
This is the case in both my dev and deployed environments.
I'm stumped on this one, anyone have thoughts?

I have seen problems with this when the browser is in private browsing mode.

UPDATE: Red Herring - refer comments
Have the same problem.
I've heard that this only works proper when the application has been code-signed. Don't know if this is true as I cannot test to verify.
This might relate: http://msdn.microsoft.com/en-us/library/dd550721(v=vs.95).aspx

Related

passing values between silverlight applications

I have created a Silverlight Business Application which runs as my main silverlight page. For each hyperlink button on my "menu" I launch another Silverlight Application which is created as a different project in Visual Studio. These are non-Business Applications.
Everything is working well. However I'm trying to pass a value from my main SL application to the SL application inside.
I have been googling a lot and cannot find an answer.
As I understand the InitParam is used between ASP and SL, and not between SL apps.
Since the App config is launched for the first SL app and the app config for the second application in never lauched, I'm not able to use that (thats at least my understanding)
The value I want to pass is the login name and role, which is possible to get from webcontext in the Silverlight Business application, but I'm unable to get webcontext in the non-Business application which run inside.
This is how I launch my SL app inside the main SL app:
public Customers()
{
InitializeComponent();
this.Title = ApplicationStrings.CustomersPageTitle;
if (WebContext.Current.User.IsInRole("Users") || WebContext.Current.User.IsInRole("Administrators"))
{
WebClient client = new WebClient();
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
client.OpenReadAsync(new Uri("customers.xap", UriKind.Relative));
}
}
void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
string appManifest = new StreamReader(Application.GetResourceStream(new StreamResourceInfo(e.Result, null),
new Uri("AppManifest.xaml", UriKind.Relative)).Stream).ReadToEnd();
XElement deploymentRoot = XDocument.Parse(appManifest).Root;
List<XElement> deploymentParts =
(from assemblyParts in deploymentRoot.Elements().Elements() select assemblyParts).ToList();
Assembly asm = null;
AssemblyPart asmPart = new AssemblyPart();
foreach (XElement xElement in deploymentParts)
{
string source = xElement.Attribute("Source").Value;
StreamResourceInfo streamInfo = Application.GetResourceStream(new StreamResourceInfo(e.Result, "application/binary"), new Uri(source, UriKind.Relative));
if (source == "customers.dll")
{
asm = asmPart.Load(streamInfo.Stream);
}
else
{
asmPart.Load(streamInfo.Stream);
}
}
UIElement myData = asm.CreateInstance("customers.MainPage") as UIElement;
stackCustomers.Children.Add(myData);
stackCustomers.UpdateLayout();
}
Anyone?
i agree with ChrisF ,I think that Prism or MEF can resolve you problem.
any way,do some search on the web and look for these two classes:
**
LocalMessageSender
LocalMessageReceiver
**
good luck

Sharepoint COM works from Silverlight but not from WPF

I'm running into an interesting situation. I need to access a SharePoint site asset library from both a WPF application and an Silverlight application. My Silverlight application is working 100%, but my WPF application gets a (500) Internal Server Error back from the service.
Silverlight Code:
private void Button_Click(object sender, RoutedEventArgs e)
{
ClientContext clientContext = new ClientContext("http://myfullyQualifiedName.com");
clientContext.Load(clientContext.Web);
clientContext.ExecuteQueryAsync(onQuerySucceeded, onQueryFailed);
}
private void onQuerySucceeded(object sender, ClientRequestSucceededEventArgs args)
{
}
private void onQueryFailed(object sender, ClientRequestFailedEventArgs args)
{
}
WPF Code:
private void Button_Click(object sender, RoutedEventArgs e)
{
ClientContext clientContext = new ClientContext("http://myfullyqualifiedname.com/");
//clientContext.Credentials = new NetworkCredential("UserName", "Password", "Domain");
clientContext.Load(clientContext.Web);
clientContext.ExecuteQuery();
}
I have tried with and without specifying credentials, either way I get the Internal server error.
Both Silverlight and non Silverlight Sharepoint client DLL's that I use has is version 14.4762.1000.
Now if I change the URL to one of our other sites, the WPF Code works flawlessly. So I think it must be a SharePoint settings somewhere.
Solved !! Why WPF Authentication wouldn't work when Silverlight works. (WPF was trying to use Kerberos, Silverlight was using NTLM) - Simple fix:
ClientContext _clientContext = new ClientContext(sharePointSiteUrl);
Web _web = _clientContext.Web;
_clientContext.Load(_web, website => website.Title);
_clientContext.Load(_web.Webs);
CredentialCache cc = new CredentialCache();
cc.Add(new Uri(sharePointSiteUrl), "NTLM", CredentialCache.DefaultNetworkCredentials);
_clientContext.Credentials = cc;
_clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
_clientContext.ExecuteQuery();
ListCollection _listCollection = _web.Lists;

Problem accessing localhost URI from Silverlight

(repost because of SO outage; apologies if the other one re-appears)
I'm building a Silverlight app that will run on Azure. My VS solution has two projects: the web role and the Silverlight. The web role has a Service that works. (I can go to localhost:88/expenseservice.svc/expenses and get the data I want.)
I am trying to access that data from Silverlight:
private void MainPage_Loaded(object sender, RoutedEventArgs args)
{
WebClient data = new WebClient();
data.DownloadStringCompleted += new DownloadStringCompletedEventHandler(data_DownloadStringCompleted);
Uri dataSource = new Uri("localhost:88/expenseservice.svc/expenses");
data.DownloadStringAsync(dataSource);
}
void data_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.InnerException.Message);
return;
}
// ...
}
However, this does not work. The message box shows the error:
The URI prefix is not recognized.
Here is the full exception:
e.Error.InnerException = {System.NotSupportedException: The URI prefix is not recognized.
at System.Net.WebRequest.Create(Uri requestUri)
at System.Net.WebClient.GetWebRequest(Uri address)
at System.Net.WebClient.DownloadStringAsync(Uri address, Object userToken)}
Is it complaining about localhost? Am I supposed to be doing something differently? Perhaps this is what "Add Service Reference" is for?
I think the prefix is not recognized because it is missing. The prefix should be the first part that describes what kind of service your URI is pointing to. For example http:// of svn:// and so on..
Just add the right one and it should work.. (I've never used Silverlight neither anything Microsoftish so I'm just guessing)

Silverlight 3 Out of the Browser Updates

I have a few users that are using a silverlight app that aren't recieving updates when a new release is published. Isn't this suppose to be automatic or perhaps I'm missing an option somewhere? I was also starting to think that maybe the XAP file is cached and I some how need to prevent that.
Any thoughts out there?
You need to write a few lines of code.
If you're familiar with 'one click' deployment then some of the options you're used to don't exist in Silverlight. You need to write the code yourself.
http://nerddawg.blogspot.com/2009/07/silverlight-out-of-browser-apps-how.html
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage();
if (Application.Current.IsRunningOutOfBrowser)
{
Application.Current.CheckAndDownloadUpdateAsync();
}
and then in your App() constructor :
Application.Current.CheckAndDownloadUpdateCompleted +=
new CheckAndDownloadUpdateCompletedEventHandler(Current_CheckAndDownloadUpdateCompleted);
and an event handler :
void Current_CheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
{
// http://nerddawg.blogspot.com/2009/07/silverlight-out-of-browser-apps-how.html
if (e.UpdateAvailable)
{
MessageBox.Show("The application has been updated! Please close and reopen it to load the new version.");
}
else if (e.Error != null && e.Error is PlatformNotSupportedException)
{
MessageBox.Show("An application update is available, " +
"but it requires a new version of Silverlight. " +
"Please contact tech support for further instructions.");
}
}
It only auto updates if the developer performs the CheckAndDownloadUpdateAsync() call. See updates: http://timheuer.com/blog/archive/2009/07/10/silverlight-3-released-what-is-new-and-changed.aspx#oob

Out of browser Silverlight app - how to setup automatic updates?

I'm wondering how to setup my Silverlight project to enable automatic updates for out-of-browser application.
I added some code in app.xaml.cs (see below), rebuild app, installed as out-of-browser, changed versionionfo in asseblyinfo.cs, rebuilded, run again but unfortunatelly no update happened. Am I still missing something?
public App()
{
this.Startup += this.Application_Startup;
this.Exit += this.Application_Exit;
this.UnhandledException += this.Application_UnhandledException;
InitializeComponent();
if (Application.Current.IsRunningOutOfBrowser)
{
App.Current.CheckAndDownloadUpdateCompleted +=
new CheckAndDownloadUpdateCompletedEventHandler(App_CheckAndDownloadUpdateCompleted);
App.Current.CheckAndDownloadUpdateAsync();
}
}
void App_CheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
{
if (e.Error == null && e.UpdateAvailable)
{
MessageBox.Show("Application updated, please restart to apply changes.");
}
}
EDIT
Bonus question:
How App detect that there is an update? From assemblyinfo.cs? Somewhere in manifests?
EDIT
Can anybody explain me WHY IsRunningOutOfBrowser returns always FALSE even if App is run from desktop's shortcut?
Thanks to Silvelright forum, there is a solution.
IsOutOfBrowser property cannot be used in constructor. The time where it starts working is Application started event.
Make sure the web server was running so the client can connect to the server and check for updates. You might also want to check the Error property to see if there where any exceptions.

Resources