PageRenderTime 54ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/IronPython_Main/Hosts/Silverlight/Microsoft.Scripting.SilverLight/DynamicAppManifest.cs

#
C# | 106 lines | 56 code | 9 blank | 41 comment | 3 complexity | fcd3c9dfb24b0fa52ad86388f538431e MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  1. /* ****************************************************************************
  2. *
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
  6. * copy of the license can be found in the License.html file at the root of this distribution. If
  7. * you cannot locate the Apache License, Version 2.0, please send an email to
  8. * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. * by the terms of the Apache License, Version 2.0.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. *
  14. * ***************************************************************************/
  15. #if CLR2
  16. using Microsoft.Scripting.Utils;
  17. #endif
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Text;
  21. using System.Windows;
  22. using System.Reflection;
  23. using System.IO;
  24. using System.Text.RegularExpressions;
  25. namespace Microsoft.Scripting.Silverlight {
  26. public class DynamicAppManifest {
  27. #if SILVERLIGHT_3
  28. /// <summary>
  29. /// List of valid assemblies to be inside Microsoft.Scripting.slvx
  30. /// </summary>
  31. private static List<string> _assemblyNames = new List<string>() {
  32. "Microsoft.Scripting.Core",
  33. "Microsoft.Scripting",
  34. "Microsoft.Dynamic",
  35. "Microsoft.Scripting.Silverlight"
  36. };
  37. #endif
  38. /// <summary>
  39. /// List of all dynamic language assemblies loaded. Contains assemblies
  40. /// from AssemblyParts after construction. After LoadAssemblies is
  41. /// called, any dynamic language assemblies that were loaded as part of
  42. /// ExternalParts is now part of this list.
  43. /// </summary>
  44. public List<Assembly> Assemblies { get; private set; }
  45. /// <summary>
  46. /// List of all dynamic language extensions found in the AppManifest.
  47. /// </summary>
  48. public List<Uri> Extensions { get; private set; }
  49. /// <summary>
  50. /// "Initializes "Assemblies" with any AssemblyParts, and "Extensions"
  51. /// with any ExtensionParts
  52. /// </summary>
  53. public DynamicAppManifest() {
  54. Assemblies = AssemblyParts();
  55. #if SILVERLIGHT_3
  56. Extensions = DLRExtensionParts();
  57. #else
  58. Extensions = new List<Uri>();
  59. #endif
  60. }
  61. /// <summary>
  62. /// Get all AssemblyParts from the AppManifest, as loaded Assembly instances.
  63. /// </summary>
  64. public List<Assembly> AssemblyParts() {
  65. var result = new List<Assembly>();
  66. foreach (var part in Deployment.Current.Parts) {
  67. try {
  68. result.Add(XapPAL.PAL.LoadAssembly(Path.GetFileNameWithoutExtension(part.Source)));
  69. } catch (Exception) {
  70. // skip
  71. // TODO this shouldn't catch all exceptions ... just any
  72. // exceptions that can be thrown the try block ...
  73. }
  74. }
  75. return result;
  76. }
  77. #if SILVERLIGHT_3
  78. /// <summary>
  79. /// Get all DLR/language-specific ExtensionParts, which is just the
  80. /// extension containing the Microsoft.* assemblies.
  81. /// </summary>
  82. /// <returns></returns>
  83. private List<Uri> DLRExtensionParts() {
  84. var dlrExtensions = new List<Uri>();
  85. if (Type.GetType("System.Windows.ExtensionPart, System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e") != null) {
  86. foreach (var externalPart in Deployment.Current.ExternalParts) {
  87. var extensionPart = (ExtensionPart)externalPart;
  88. if (Regex.IsMatch(extensionPart.Source.ToString(), "Microsoft.Scripting.slvx")) {
  89. dlrExtensions.Add(extensionPart.Source);
  90. }
  91. }
  92. }
  93. return dlrExtensions;
  94. }
  95. #endif
  96. }
  97. }