/// <summary> /// Initializes a new instance of the <see cref="WatchedAsset{T}"/> class. /// </summary> /// <param name="owner">The content manager that owns the resource.</param> /// <param name="assetPath">The asset path of the asset which is represented by this wrapper.</param> /// <param name="assetDensity">The density bucket for which to load the asset, or <see langword="null"/> to use the density of the primary display.</param> /// <param name="validating">A delegate which implements the <see cref="DelegateAssetWatcher{T}.OnValidating(String, T)"/> method.</param> /// <param name="validationComplete">A delegate which implements the <see cref="DelegateAssetWatcher{T}.OnValidationComplete(String, T, Boolean)"/> method.</param> public WatchedAsset(ContentManager owner, String assetPath, ScreenDensityBucket?assetDensity, AssetWatcherValidatingHandler <T> validating = null, AssetWatcherValidationCompleteHandler <T> validationComplete = null) { var instance = default(T); if (assetDensity == null) { instance = owner.Load <T>(assetPath); } else { instance = owner.Load <T>(assetPath, assetDensity.Value); } this.Owner = owner; this.AssetPath = assetPath; this.AssetDensity = assetDensity; this.ValidatingValue = instance; this.Value = instance; this.watcher = new DelegateAssetWatcher <T>( (p, a) => { this.ValidatingValue = a; return(validating?.Invoke(p, a) ?? true); }, (p, a, v) => { this.ValidatingValue = default(T); this.Value = a; validationComplete?.Invoke(p, a, v); }); if (assetDensity == null) { this.Owner.AddWatcher(assetPath, watcher); } else { this.Owner.AddWatcher(assetPath, assetDensity.Value, watcher); } }
/// <summary> /// Creates a new <see cref="LocalStyleSheet"/> instance. /// </summary> /// <param name="validating">A delegate which implements the <see cref="DelegateAssetWatcher{T}.OnValidating(String, T)"/> method.</param> /// <param name="validationComplete">A delegate which implements the <see cref="DelegateAssetWatcher{T}.OnValidationComplete(String, T, Boolean)"/> method.</param> /// <returns>The <see cref="LocalStyleSheet"/> which was created.</returns> public static LocalStyleSheet Create(AssetWatcherValidatingHandler <UvssDocument> validating = null, AssetWatcherValidationCompleteHandler <UvssDocument> validationComplete = null) { var uv = UltravioletContext.DemandCurrent(); return(new LocalStyleSheet(uv, validating, validationComplete)); }
/// <summary> /// Initializes a new instance of the <see cref="LocalStyleSheet"/> class. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="validating">A delegate which implements the <see cref="DelegateAssetWatcher{T}.OnValidating(String, T)"/> method.</param> /// <param name="validationComplete">A delegate which implements the <see cref="DelegateAssetWatcher{T}.OnValidationComplete(String, T, Boolean)"/> method.</param> private LocalStyleSheet(UltravioletContext uv, AssetWatcherValidatingHandler <UvssDocument> validating = null, AssetWatcherValidationCompleteHandler <UvssDocument> validationComplete = null) : base(uv) { this.validating = validating; this.validationComplete = validationComplete; }
/// <summary> /// Initializes a new instance of the <see cref="WatchedAsset{T}"/> class. /// </summary> /// <param name="owner">The content manager that owns the resource.</param> /// <param name="assetPath">The asset path of the asset which is represented by this wrapper.</param> /// <param name="validating">A delegate which implements the <see cref="DelegateAssetWatcher{T}.OnValidating(String, T)"/> method.</param> /// <param name="validationComplete">A delegate which implements the <see cref="DelegateAssetWatcher{T}.OnValidationComplete(String, T, Boolean)"/> method.</param> public WatchedAsset(ContentManager owner, String assetPath, AssetWatcherValidatingHandler <T> validating = null, AssetWatcherValidationCompleteHandler <T> validationComplete = null) : this(owner, assetPath, null, validating, validationComplete) { }
/// <summary> /// Initializes a new instance of the <see cref="DelegateAssetWatcher{T}"/> class. /// </summary> /// <param name="validating">A delegate which implements the <see cref="OnValidating(String, T)"/> method.</param> /// <param name="validationComplete">A delegate which implements the <see cref="OnValidationComplete(String, T, Boolean)"/> method.</param> public DelegateAssetWatcher(AssetWatcherValidatingHandler <T> validating, AssetWatcherValidationCompleteHandler <T> validationComplete) { this.validating = validating; this.validationComplete = validationComplete; }
/// <summary> /// Initializes a new instance of the <see cref="CompositeUvssDocumentChild"/> class. /// </summary> /// <param name="contentManager">The content manager with which to load the asset.</param> /// <param name="assetPath">The asset path of the document to load.</param> /// <param name="validating">A delegate which implements the <see cref="DelegateAssetWatcher{T}.OnValidating(String, T)"/> method.</param> /// <param name="validationComplete">A delegate which implements the <see cref="DelegateAssetWatcher{T}.OnValidationComplete(String, T, Boolean)"/> method.</param> public CompositeUvssDocumentChild(ContentManager contentManager, String assetPath, AssetWatcherValidatingHandler <UvssDocument> validating = null, AssetWatcherValidationCompleteHandler <UvssDocument> validationComplete = null) { Contract.Require(contentManager, nameof(contentManager)); Contract.Require(assetPath, nameof(assetPath)); this.contentManager = contentManager; this.assetPath = assetPath; this.assetVersions = new Dictionary <Byte, WatchedAsset <UvssDocument> >(); this.validating = validating; this.validationComplete = validationComplete; }