Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorCore/Utils/Xml/DynamicXmlUrlResolver.cs @ 13348

Last change on this file since 13348 was 12762, checked in by aballeit, 9 years ago

#2283 GUI updates, Tree-chart, MCTS Version 2 (prune leaves)

File size: 2.3 KB
Line 
1using System;
2using System.Xml;
3
4namespace SharpVectors.Xml
5{
6    /// <summary>
7    /// Hook URL solving
8    /// </summary>
9    public sealed class DynamicXmlUrlResolver : XmlUrlResolver
10    {
11        /// <summary>
12        /// Event handler type
13        /// </summary>
14        public delegate string ResolveEventHandler(string relativeUri);
15
16        /// <summary>
17        /// Fires when GetEntity is called
18        /// </summary>
19        public delegate object GettingEntityEventHandler(Uri absoluteUri, string role, Type ofObjectToReturn);
20
21        /// <summary>
22        /// Occurs when trying to resolve an Uri.
23        /// </summary>
24        public event ResolveEventHandler Resolving;
25
26        /// <summary>
27        /// Occurs when getting entity.
28        /// </summary>
29        public event GettingEntityEventHandler GettingEntity;
30
31        public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
32        {
33            if (this.GettingEntity != null)
34            {
35                object entity = GettingEntity(absoluteUri, role, ofObjectToReturn);
36                if (entity != null)
37                    return entity;
38            }
39
40            return base.GetEntity(absoluteUri, role, ofObjectToReturn);
41        }
42
43        /// <summary>
44        /// Resolves the absolute URI from the base and relative URIs.
45        /// </summary>
46        /// <param name="baseUri">The base URI used to resolve the relative URI.</param>
47        /// <param name="relativeUri">The URI to resolve. The URI can be absolute or relative. If absolute, this value effectively replaces the <paramref name="baseUri"/> value. If relative, it combines with the <paramref name="baseUri"/> to make an absolute URI.</param>
48        /// <returns>
49        /// A <see cref="T:System.Uri"/> representing the absolute URI, or null if the relative URI cannot be resolved.
50        /// </returns>
51        /// <exception cref="T:System.ArgumentNullException">
52        ///   <paramref name="baseUri "/>is null or <paramref name="relativeUri"/> is null</exception>
53        public override Uri ResolveUri(Uri baseUri, string relativeUri)
54        {
55            if (this.Resolving != null)
56                relativeUri = Resolving(relativeUri);
57
58            return base.ResolveUri(baseUri, relativeUri);
59        }
60    }
61}
Note: See TracBrowser for help on using the repository browser.