protected static void FindSkinAndTheme(out Skin skin, out Theme theme) { IScreenManager screenManager = ServiceRegistration.Get <IScreenManager>(); ISkinResourceBundle bundle = screenManager.CurrentSkinResourceBundle; theme = bundle as Theme; skin = bundle as Skin; if (theme != null) { skin = bundle.InheritedSkinResources as Skin; } }
public override void FinishInitialization(IParserContext context) { base.FinishInitialization(context); ISkinResourceBundle resourceBundle = (ISkinResourceBundle)context.GetContextVariable(typeof(ISkinResourceBundle)); // This resourceBundle is the resource bundle where the screen itself is located. It is necessary to use the resource bundle // of the skin where the screen file which contains the <Screen> element is located and NOT the resource bundle of the // screen which is being loaded by the ScreenManager, because the skin file with the <Screen> element might be included // into that screen which is being loaded by the ScreenManager. // We need the correct resource bundle to get the native size of the skin which defines the <Screen> element. _skinWidth = resourceBundle.SkinWidth; _skinHeight = resourceBundle.SkinHeight; }
/// <summary> /// Loads a skin file from the specified <paramref name="reader"/> and returns the root UIElement. /// </summary> /// <param name="reader">The reader containing the XAML contents of the skin file.</param> /// <param name="actualResourceBundle">Resource bundle which contains the skin file with the given path.</param> /// <param name="loader">Loader callback for GUI models.</param> /// <returns><see cref="UIElement"/> descendant corresponding to the root element in the /// specified skin file.</returns> protected static object Load(TextReader reader, ISkinResourceBundle actualResourceBundle, IModelLoader loader) { try { Parser parser = new Parser(reader, parser_ImportNamespace, parser_GetEventHandler); parser.SetCustomTypeConverter(MPF.ConvertType); parser.SetContextVariable(typeof(IModelLoader), loader); parser.SetContextVariable(typeof(ISkinResourceBundle), actualResourceBundle); return(parser.Parse()); } catch (Exception e) { throw new XamlLoadException("XAML loader: Error reading XAML file from text reader", e); } }
/// <summary> /// Loads a skin file from the specified <paramref name="reader"/> and returns the root UIElement. /// </summary> /// <param name="reader">The reader containing the XAML contents of the skin file.</param> /// <param name="actualResourceBundle">Resource bundle which contains the skin file with the given path.</param> /// <param name="loader">Loader callback for GUI models.</param> /// <returns><see cref="UIElement"/> descendant corresponding to the root element in the /// specified skin file.</returns> protected static object Load(TextReader reader, ISkinResourceBundle actualResourceBundle, IModelLoader loader) { try { Parser parser = new Parser(reader, parser_ImportNamespace, parser_GetEventHandler); parser.SetCustomTypeConverter(MPF.ConvertType); parser.SetContextVariable(typeof(IModelLoader), loader); parser.SetContextVariable(typeof(ISkinResourceBundle), actualResourceBundle); return parser.Parse(); } catch (Exception e) { throw new XamlLoadException("XAML loader: Error reading XAML file from text reader", e); } }
/// <summary> /// Loads the specified skin file and returns the root UIElement. /// </summary> /// <param name="skinFilePath">The path to the XAML skin file.</param> /// <param name="actualResourceBundle">Resource bundle which contains the skin file with the given path.</param> /// <param name="loader">Loader callback for GUI models.</param> /// <returns><see cref="UIElement"/> descendant corresponding to the root element in the /// specified skin file.</returns> public static object Load(string skinFilePath, ISkinResourceBundle actualResourceBundle, IModelLoader loader) { try { using (TextReader reader = new StreamReader(skinFilePath)) return Load(reader, actualResourceBundle, loader); } catch (XamlLoadException e) { // Unwrap the exception thrown by Load(TextReader) throw new XamlLoadException("XAML loader: Error parsing file '{0}'", e.InnerException, skinFilePath); } catch (Exception e) { throw new XamlLoadException("XAML loader: Error parsing file '{0}'", e, skinFilePath); } }
/// <summary> /// Loads the specified skin file and returns the root UIElement. /// </summary> /// <param name="skinFilePath">The path to the XAML skin file.</param> /// <param name="actualResourceBundle">Resource bundle which contains the skin file with the given path.</param> /// <param name="loader">Loader callback for GUI models.</param> /// <returns><see cref="UIElement"/> descendant corresponding to the root element in the /// specified skin file.</returns> public static object Load(string skinFilePath, ISkinResourceBundle actualResourceBundle, IModelLoader loader) { try { using (TextReader reader = new StreamReader(skinFilePath)) return(Load(reader, actualResourceBundle, loader)); } catch (XamlLoadException e) { // Unwrap the exception thrown by Load(TextReader) throw new XamlLoadException("XAML loader: Error parsing file '{0}'", e.InnerException, skinFilePath); } catch (Exception e) { throw new XamlLoadException("XAML loader: Error parsing file '{0}'", e, skinFilePath); } }
private static void GetSkinAndThemeName(ISkinResourceBundle resourceBundle, out string skinName, out string themeName) { ISkin skin = resourceBundle as ISkin; if (skin != null) { skinName = skin.Name; themeName = null; return; } ITheme theme = resourceBundle as ITheme; if (theme == null) { skinName = null; themeName = null; return; } themeName = theme.Name; skin = theme.ParentSkin; skinName = skin == null ? string.Empty : skin.Name; }
public string GetResourceFilePath(string resourceName, bool searchInheritedResources, out ISkinResourceBundle resourceBundle) { if (resourceName == null) { resourceBundle = null; return(null); } CheckResourcesInitialized(); string key = resourceName.ToLowerInvariant(); string result; if (_localResourceFilePaths.TryGetValue(key, out result)) { resourceBundle = this; return(result); } if (searchInheritedResources && _inheritedSkinResources != null) { return(_inheritedSkinResources.GetResourceFilePath(resourceName, true, out resourceBundle)); } resourceBundle = null; return(null); }
public static IEnumerable<Guid> GetMediaSkinOptionalMIATypes(string navigationMode, ISkinResourceBundle bundle) { if (bundle == null) return EMPTY_GUID_LIST; string skinName; string themeName; GetSkinAndThemeName(bundle, out skinName, out themeName); IPluginManager pluginManager = ServiceRegistration.Get<IPluginManager>(); string registrationLocation = Consts.MEDIA_SKIN_SETTINGS_REGISTRATION_PATH + "/" + skinName + "/"; if (!string.IsNullOrEmpty(themeName)) registrationLocation += themeName + "/"; registrationLocation += navigationMode + "/" + Consts.MEDIA_SKIN_SETTINGS_REGISTRATION_OPTIONAL_TYPES_PATH; IEnumerable<Guid> result = pluginManager.RequestAllPluginItems<MIATypeRegistration>( registrationLocation, _mediaSkinMIATypeRegistrationStateTracker).Select(registration => registration.MediaItemAspectTypeId); pluginManager.RevokeAllPluginItems(registrationLocation, _mediaSkinMIATypeRegistrationStateTracker); return result.Union(GetMediaSkinOptionalMIATypes(navigationMode, bundle.InheritedSkinResources)); }
public static IEnumerable <Guid> GetMediaSkinOptionalMIATypes(string navigationMode, ISkinResourceBundle bundle) { if (bundle == null) { return(EMPTY_GUID_LIST); } string skinName; string themeName; GetSkinAndThemeName(bundle, out skinName, out themeName); IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); string registrationLocation = Consts.MEDIA_SKIN_SETTINGS_REGISTRATION_PATH + "/" + skinName + "/"; if (!string.IsNullOrEmpty(themeName)) { registrationLocation += themeName + "/"; } registrationLocation += navigationMode + "/" + Consts.MEDIA_SKIN_SETTINGS_REGISTRATION_OPTIONAL_TYPES_PATH; IEnumerable <Guid> result = pluginManager.RequestAllPluginItems <MIATypeRegistration>( registrationLocation, _mediaSkinMIATypeRegistrationStateTracker).Select(registration => registration.MediaItemAspectTypeId); pluginManager.RevokeAllPluginItems(registrationLocation, _mediaSkinMIATypeRegistrationStateTracker); return(result.Union(GetMediaSkinOptionalMIATypes(navigationMode, bundle.InheritedSkinResources))); }
public string GetResourceFilePath(string resourceName, bool searchInheritedResources, out ISkinResourceBundle resourceBundle) { if (resourceName == null) { resourceBundle = null; return null; } CheckResourcesInitialized(); string key = resourceName.ToLowerInvariant(); string result; if (_localResourceFilePaths.TryGetValue(key, out result)) { resourceBundle = this; return result; } if (searchInheritedResources && _inheritedSkinResources != null) return _inheritedSkinResources.GetResourceFilePath(resourceName, true, out resourceBundle); resourceBundle = null; return null; }