Skip to content

Commit

Permalink
# improved ActivationManager class to filter the assemblies using the…
Browse files Browse the repository at this point in the history
… Deployment.Current.Parts collection
  • Loading branch information
Mariano Gabriel Converti committed Nov 9, 2011
1 parent 6a2941a commit 8a9862d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion SilverlightActivator.NuGet/SilverlightActivator.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>SilverlightActivator</id>
<version>1.0.1</version>
<version>1.0.2</version>
<title>Silverlight Activator for Windows Phone</title>
<authors>Mariano Converti, Damian Martinez, and Nicolás Bello Camilletti</authors>
<owners>Mariano Converti, Damian Martinez, and Nicolás Bello Camilletti</owners>
Expand Down
27 changes: 19 additions & 8 deletions SilverlightActivator_WP/ActivationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,36 @@ public ActivationManager()
}
}

private static void Init()
/// <summary>
/// Runs all the available ApplicationStartup methods.
/// </summary>
public static void RunApplicationStartupMethods()
{
Application.Current.Startup += OnStartup;
Application.Current.Exit += OnApplicationExit;
RunActivationMethods<ApplicationStartupMethodAttribute>();
}

private static void OnStartup(object sender, StartupEventArgs e)
/// <summary>
/// Runs all the available ApplicationExit methods.
/// </summary>
public static void RunApplicationExitMethods()
{
RunActivationMethods<ApplicationStartupMethodAttribute>();
RunActivationMethods<ApplicationExitMethodAttribute>();
}

private static void OnApplicationExit(object sender, EventArgs e)
private static void Init()
{
RunActivationMethods<ApplicationExitMethodAttribute>();
Application.Current.Startup += (s, e) => RunApplicationStartupMethods();
Application.Current.Exit += (s, e) => RunApplicationExitMethods();
}

private static void RunActivationMethods<T>() where T : BaseActivationMethodAttribute
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
var deploymentParts = Deployment.Current.Parts.Cast<AssemblyPart>();
var activationAssemblies = AppDomain.CurrentDomain.GetAssemblies()
.Where(a => deploymentParts.Any(p => p.Source.Equals(a.ManifestModule.Name, StringComparison.OrdinalIgnoreCase))
&& (a != typeof(ActivationManager).Assembly));

foreach (var assembly in activationAssemblies)
{
// The activation methods are executed according to the specified order
var activationAttributes = assembly.GetActivationAttributes<T>().OrderBy(at => at.Order);
Expand Down

0 comments on commit 8a9862d

Please sign in to comment.