-
Notifications
You must be signed in to change notification settings - Fork 87
/
URILoader.cs
708 lines (662 loc) · 31.2 KB
/
URILoader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
/*
// <copyright>
// dotNetRDF is free and open source software licensed under the MIT License
// -------------------------------------------------------------------------
//
// Copyright (c) 2009-2021 dotNetRDF Project (http://dotnetrdf.org/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is furnished
// to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
*/
using System;
using System.IO;
using System.Net;
using VDS.RDF.Parsing.Handlers;
namespace VDS.RDF.Parsing
{
/// <summary>
/// Static Helper Class for dereferencing URIs and attempting to parse the results of a HTTP GET request to the URI into RDF.
/// </summary>
/// <remarks>
/// <h3>Caching</h3>
/// <para>
/// As of the 0.2.2 release the loader has support for caching retrieved data locally built into it (for Graphs only), caching is done using ETags where the remote server provides them or just by a user-defineable 'freshness' criteria (i.e. number of hours retrieved resources should be cached for). By default this caching happens in the system temporary directory which means it is non-persistent i.e. if you run your application using dotNetRDF it may cache stuff during the session but once the application is closed the operating system may freely delete the cached data. If you wish to have a persistent cache then you can use the <see cref="UriLoader.CacheDirectory">CacheDirectory</see> property to set your own cache directory. Even when you set your own cache directory dotNetRDF will delete obsolete data from it over time though this will only happen when a new request invalidates previously cached data.
/// </para>
/// <para>
/// If you wish to completely control the Cache you can implement your own <see cref="IUriLoaderCache">IUriLoaderCache</see> implementation and use it by setting the <see cref="UriLoader.Cache">Cache</see> property.
/// </para>
/// </remarks>
public static partial class UriLoader
{
private static String _userAgent;
#region URI Caching
private static IUriLoaderCache _cache = new UriLoaderCache();
/// <summary>
/// Gets/Sets the Directory used for caching Graphs loaded from URIs.
/// </summary>
public static String CacheDirectory
{
get
{
return _cache.CacheDirectory;
}
set
{
_cache.CacheDirectory = value;
}
}
/// <summary>
/// Gets/Sets the amount of time Graphs are cached for.
/// </summary>
/// <remarks>
/// This duration only applies to URIs which don't return an ETag as part of the HTTP response when they are deferenced.
/// </remarks>
public static TimeSpan CacheDuration
{
get
{
return _cache.CacheDuration;
}
set
{
_cache.CacheDuration = value;
}
}
/// <summary>
/// Gets/Sets the Cache that is in use.
/// </summary>
/// <remarks>
/// Setting the Cache to null does not disable it, to disable caching use the <see cref="Options.UriLoaderCaching">Options.UriLoaderCaching</see> property.
/// </remarks>
public static IUriLoaderCache Cache
{
get
{
return _cache;
}
set
{
if (value != null)
{
_cache = value;
}
}
}
/// <summary>
/// Determines whether the RDF behind the given URI is cached.
/// </summary>
/// <param name="u">URI.</param>
/// <returns></returns>
/// <remarks>
/// <para>
/// <strong>Note:</strong> This does not guarantee that the cached content will be used if you load from the URI using the UriLoader. Whether the cached copy is used will depend on whether.
/// </para>
/// </remarks>
public static bool IsCached(Uri u)
{
Uri temp = Tools.StripUriFragment(u);
return _cache.HasLocalCopy(temp, false);
}
#endregion
/// <summary>
/// Gets/Sets an optional User Agent string that will be appended to HTTP Requests.
/// </summary>
public static String UserAgent
{
get
{
return _userAgent;
}
set
{
_userAgent = value;
}
}
/// <summary>
/// Attempts to load a RDF Graph from the given URI into the given Graph.
/// </summary>
/// <param name="g">Graph to assert Triples in.</param>
/// <param name="u">URI to attempt to get RDF from.</param>
/// <remarks>
/// <para>
/// Attempts to select the relevant Parser based on the Content Type header returned in the HTTP Response.
/// </para>
/// <para>
/// If you know ahead of time the Content Type you can just open a HTTP Stream yourself and pass it to an instance of the correct Parser.
/// </para>
/// <para>
/// In the event that the URI is a File URI the <see cref="FileLoader">FileLoader</see> will be used instead. If the URI is a Data URI then the <see cref="DataUriLoader">DataUriLoader</see> will be used instead.
/// </para>
/// <para>
/// <strong>Note:</strong> UriLoader will assign the Graph the source URI as it's Base URI unless the Graph already has a Base URI or is non-empty prior to attempting parsing. Note that any Base URI specified in the RDF contained in the file will override this initial Base URI. In some cases this may lead to invalid RDF being accepted and generating strange relative URIs, if you encounter this either set a Base URI prior to calling this method or create an instance of the relevant parser and invoke it directly.
/// </para>
/// </remarks>
public static void Load(IGraph g, Uri u)
{
Load(g, u, null);
}
/// <summary>
/// Attempts to load a RDF Graph from the given URI into the given Graph.
/// </summary>
/// <param name="g">Graph to assert Triples in.</param>
/// <param name="u">URI to attempt to get RDF from.</param>
/// <param name="parser">Parser to use.</param>
/// <remarks>
/// <para>
/// Uses the supplied parser to attempt parsing regardless of the actual Content Type returned.
/// </para>
/// <para>
/// In the event that the URI is a File URI the <see cref="FileLoader">FileLoader</see> will be used instead. If the URI is a Data URI then the <see cref="DataUriLoader">DataUriLoader</see> will be used instead.
/// </para>
/// <para>
/// <strong>Note:</strong> UriLoader will assign the Graph the source URI as it's Base URI unless the Graph already has a Base URI or is non-empty prior to attempting parsing. Note that any Base URI specified in the RDF contained in the file will override this initial Base URI. In some cases this may lead to invalid RDF being accepted and generating strange relative URIs, if you encounter this either set a Base URI prior to calling this method or create an instance of the relevant parser and invoke it directly.
/// </para>
/// </remarks>
public static void Load(IGraph g, Uri u, IRdfReader parser)
{
if (g == null) throw new RdfParseException("Cannot read RDF into a null Graph");
if (u == null) throw new RdfParseException("Cannot load RDF from a null URI");
if (u.IsFile)
{
// Invoke FileLoader instead
RaiseWarning("This is a file: URI so invoking the FileLoader instead");
if (Path.DirectorySeparatorChar == '/')
{
FileLoader.Load(g, u.ToString().Substring(7), parser);
}
else
{
FileLoader.Load(g, u.ToString().Substring(8), parser);
}
return;
}
if (u.Scheme.Equals("data"))
{
// Invoke DataUriLoader instead
RaiseWarning("This is a data: URI so invoking the DataUriLoader instead");
DataUriLoader.Load(g, u);
return;
}
// Set Base Uri if necessary
if (g.BaseUri == null && g.IsEmpty) g.BaseUri = u;
Load(new GraphHandler(g), u, parser);
}
/// <summary>
/// Attempts to load a RDF Graph from the given URI using a RDF Handler.
/// </summary>
/// <param name="handler">RDF Handler to use.</param>
/// <param name="u">URI to attempt to get RDF from.</param>
/// <remarks>
/// <para>
/// Attempts to select the relevant Parser based on the Content Type header returned in the HTTP Response.
/// </para>
/// <para>
/// If you know ahead of time the Content Type you can just open a HTTP Stream yourself and pass it to an instance of the correct Parser.
/// </para>
/// <para>
/// In the event that the URI is a File URI the <see cref="FileLoader">FileLoader</see> will be used instead. If the URI is a Data URI then the <see cref="DataUriLoader">DataUriLoader</see> will be used instead.
/// </para>
/// </remarks>
public static void Load(IRdfHandler handler, Uri u)
{
Load(handler, u, (IRdfReader)null);
}
/// <summary>
/// Attempts to load a RDF Graph from the given URI using a RDF Handler.
/// </summary>
/// <param name="handler">RDF Handler to use.</param>
/// <param name="u">URI to attempt to get RDF from.</param>
/// <param name="parser">Parser to use.</param>
/// <remarks>
/// <para>
/// Uses the supplied parser to attempt parsing regardless of the actual Content Type returned.
/// </para>
/// <para>
/// In the event that the URI is a File URI the <see cref="FileLoader">FileLoader</see> will be used instead.
/// </para>
/// <para>
/// If the URI is a Data URI then the <see cref="DataUriLoader">DataUriLoader</see> will be used instead.
/// </para>
/// </remarks>
public static void Load(IRdfHandler handler, Uri u, IRdfReader parser)
{
if (handler == null) throw new RdfParseException("Cannot read RDF using a null RDF Handler");
if (u == null) throw new RdfParseException("Cannot load RDF from a null URI");
try
{
if (u.IsFile)
{
// Invoke FileLoader instead
RaiseWarning("This is a file: URI so invoking the FileLoader instead");
if (Path.DirectorySeparatorChar == '/')
{
FileLoader.Load(handler, u.ToString().Substring(7), parser);
}
else
{
FileLoader.Load(handler, u.ToString().Substring(8), parser);
}
return;
}
if (u.Scheme.Equals("data"))
{
// Invoke DataUriLoader instead
RaiseWarning("This is a data: URI so invoking the DataUriLoader instead");
DataUriLoader.Load(handler, u);
return;
}
// Sanitise the URI to remove any Fragment ID
u = Tools.StripUriFragment(u);
// Use Cache if possible
String etag = String.Empty;
String local = null;
if (Options.UriLoaderCaching)
{
if (_cache.HasETag(u))
{
// Get the ETag and then we'll include an If-None-Match header in our request
etag = _cache.GetETag(u);
}
else if (_cache.HasLocalCopy(u, true))
{
// Just try loading from the local copy
local = _cache.GetLocalCopy(u);
if (local != null)
{
try
{
FileLoader.Load(handler, local, new TurtleParser());
}
catch
{
// If we get an Exception we failed to access the file successfully
_cache.RemoveETag(u);
_cache.RemoveLocalCopy(u);
Load(handler, u, parser);
}
return;
}
}
}
// Set-up the Request
HttpWebRequest httpRequest;
httpRequest = (HttpWebRequest)WebRequest.Create(u);
// Want to ask for RDF formats
if (parser != null)
{
// If a non-null parser set up a HTTP Header that is just for the given parser
httpRequest.Accept = MimeTypesHelper.CustomHttpAcceptHeader(parser);
}
else
{
httpRequest.Accept = MimeTypesHelper.HttpAcceptHeader;
}
if (Options.UriLoaderCaching)
{
if (!etag.Equals(String.Empty))
{
httpRequest.Headers[HttpRequestHeader.IfNoneMatch] = etag;
}
}
// Use HTTP GET
httpRequest.Method = "GET";
#if !NETCORE
httpRequest.Timeout = Options.UriLoaderTimeout;
#endif
if (_userAgent != null && !_userAgent.Equals(String.Empty))
{
#if NETCORE
httpRequest.Headers[HttpRequestHeader.UserAgent] = _userAgent;
#else
httpRequest.UserAgent = _userAgent;
#endif
}
Tools.HttpDebugRequest(httpRequest);
using (HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse())
{
Tools.HttpDebugResponse(httpResponse);
if (Options.UriLoaderCaching)
{
// Are we using ETag based caching?
if (!etag.Equals(String.Empty))
{
// Did we get a Not-Modified response?
if (httpResponse.StatusCode == HttpStatusCode.NotModified)
{
// If so then we need to load the Local Copy assuming it exists?
if (_cache.HasLocalCopy(u, false))
{
local = _cache.GetLocalCopy(u);
try
{
FileLoader.Load(handler, local, new TurtleParser());
}
catch
{
// If we get an Exception we failed to access the file successfully
_cache.RemoveETag(u);
_cache.RemoveLocalCopy(u);
Load(handler, u, parser);
}
return;
}
else
{
// If the local copy didn't exist then we need to redo the response without
// the ETag as we've lost the cached copy somehow
_cache.RemoveETag(u);
Load(handler, u, parser);
return;
}
}
// If we didn't get a Not-Modified response then we'll continue and parse the new response
}
}
// Get a Parser and Load the RDF
if (parser == null)
{
// Only need to auto-detect the parser if a specific one wasn't specified
parser = MimeTypesHelper.GetParser(httpResponse.ContentType);
}
parser.Warning += RaiseWarning;
// To do caching we ask the cache to give us a handler and then we tie it to
if (Options.UriLoaderCaching)
{
IRdfHandler cacheHandler = _cache.ToCache(u, Tools.StripUriFragment(httpResponse.ResponseUri), httpResponse.Headers["ETag"]);
if (cacheHandler != null)
{
// Note: We can ONLY use caching when we know that the Handler will accept all the data returned
// i.e. if the Handler may trim the data in some way then we shouldn't cache the data returned
if (handler.AcceptsAll)
{
// We should use the original handler in its capacity as node factory,
// otherwise there might be unexpected differences between its output
// and that of the MultiHandler's
handler = new MultiHandler(new IRdfHandler[] { handler, cacheHandler }, handler);
}
else
{
cacheHandler = null;
}
}
}
try
{
parser.Load(handler, new StreamReader(httpResponse.GetResponseStream()));
}
catch
{
// If we were trying to cache the response and something went wrong discard the cached copy
if (Options.UriLoaderCaching)
{
_cache.RemoveETag(u);
_cache.RemoveETag(Tools.StripUriFragment(httpResponse.ResponseUri));
_cache.RemoveLocalCopy(u);
_cache.RemoveLocalCopy(Tools.StripUriFragment(httpResponse.ResponseUri));
}
throw;
}
}
}
catch (UriFormatException uriEx)
{
// Uri Format Invalid
throw new RdfParseException("Unable to load from the given URI '" + u.AbsoluteUri + "' since it's format was invalid", uriEx);
}
catch (WebException webEx)
{
if (webEx.Response != null)
{
Tools.HttpDebugResponse((HttpWebResponse)webEx.Response);
}
if (Options.UriLoaderCaching)
{
if (webEx.Response != null)
{
if (((HttpWebResponse)webEx.Response).StatusCode == HttpStatusCode.NotModified)
{
// If so then we need to load the Local Copy assuming it exists?
if (_cache.HasLocalCopy(u, false))
{
String local = _cache.GetLocalCopy(u);
try
{
FileLoader.Load(handler, local, new TurtleParser());
}
catch
{
// If we get an Exception we failed to access the file successfully
_cache.RemoveETag(u);
_cache.RemoveLocalCopy(u);
Load(handler, u, parser);
}
return;
}
else
{
// If the local copy didn't exist then we need to redo the response without
// the ETag as we've lost the cached copy somehow
_cache.RemoveETag(u);
Load(handler, u, parser);
return;
}
}
}
}
// Some sort of HTTP Error occurred
throw new WebException("A HTTP Error occurred resolving the URI '" + u.AbsoluteUri + "'", webEx);
}
}
/// <summary>
/// Attempts to load a RDF dataset from the given URI into the given Triple Store.
/// </summary>
/// <param name="store">Triple Store to load into.</param>
/// <param name="u">URI to attempt to get a RDF dataset from.</param>
/// <param name="parser">Parser to use to parse the RDF dataset.</param>
/// <remarks>
/// <para>
/// If the <paramref name="parser"/> parameter is set to null then this method attempts to select the relevant Store Parser based on the Content Type header returned in the HTTP Response.
/// </para>
/// <para>
/// If you know ahead of time the Content Type you can explicitly pass in the parser to use.
/// </para>
/// </remarks>
public static void Load(ITripleStore store, Uri u, IStoreReader parser)
{
if (store == null) throw new RdfParseException("Cannot read a RDF dataset into a null Triple Store");
if (u == null) throw new RdfParseException("Cannot read a RDF dataset from a null URI");
Load(new StoreHandler(store), u, parser);
}
/// <summary>
/// Attempts to load a RDF dataset from the given URI into the given Triple Store.
/// </summary>
/// <param name="store">Triple Store to load into.</param>
/// <param name="u">URI to attempt to get a RDF dataset from.</param>
/// <remarks>
/// <para>
/// Attempts to select the relevant Store Parser based on the Content Type header returned in the HTTP Response.
/// </para>
/// </remarks>
public static void Load(ITripleStore store, Uri u)
{
Load(store, u, null);
}
/// <summary>
/// Attempts to load a RDF dataset from the given URI using a RDF Handler.
/// </summary>
/// <param name="handler">RDF Handler to use.</param>
/// <param name="u">URI to attempt to get a RDF dataset from.</param>
/// <param name="parser">Parser to use to parse the RDF dataset.</param>
/// <remarks>
/// <para>
/// If the <paramref name="parser"/> parameter is set to null then this method attempts to select the relevant Store Parser based on the Content Type header returned in the HTTP Response.
/// </para>
/// <para>
/// If you know ahead of time the Content Type you can explicitly pass in the parser to use.
/// </para>
/// </remarks>
public static void Load(IRdfHandler handler, Uri u, IStoreReader parser)
{
if (u == null) throw new RdfParseException("Cannot read a RDF dataset from a null URI");
if (handler == null) throw new RdfParseException("Cannot read a RDF dataset using a null RDF handler");
try
{
if (u.IsFile)
{
// Invoke FileLoader instead
RaiseWarning("This is a file: URI so invoking the FileLoader instead");
if (Path.DirectorySeparatorChar == '/')
{
FileLoader.Load(handler, u.AbsoluteUri.Substring(7), parser);
}
else
{
FileLoader.Load(handler, u.AbsoluteUri.Substring(8), parser);
}
return;
}
// Sanitise the URI to remove any Fragment ID
u = Tools.StripUriFragment(u);
// Set-up the Request
HttpWebRequest httpRequest;
httpRequest = (HttpWebRequest)WebRequest.Create(u);
// Want to ask for TriG, NQuads or TriX
if (parser != null)
{
// If a non-null parser set up a HTTP Header that is just for the given parser
httpRequest.Accept = MimeTypesHelper.CustomHttpAcceptHeader(parser);
}
else
{
httpRequest.Accept = MimeTypesHelper.HttpRdfDatasetAcceptHeader;
}
// Use HTTP GET
httpRequest.Method = "GET";
#if !NETCORE
httpRequest.Timeout = Options.UriLoaderTimeout;
#endif
if (_userAgent != null && !_userAgent.Equals(String.Empty))
{
#if NETCORE
httpRequest.Headers[HttpRequestHeader.UserAgent] = _userAgent;
#else
httpRequest.UserAgent = _userAgent;
#endif
}
// HTTP Debugging
Tools.HttpDebugRequest(httpRequest);
using (HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse())
{
Tools.HttpDebugResponse(httpResponse);
// Get a Parser and Load the RDF
if (parser == null)
{
try
{
parser = MimeTypesHelper.GetStoreParser(httpResponse.ContentType);
parser.Warning += RaiseStoreWarning;
parser.Load(handler, new StreamReader(httpResponse.GetResponseStream()));
}
catch (RdfParserSelectionException)
{
RaiseStoreWarning("Unable to select a RDF Dataset parser based on Content-Type: " + httpResponse.ContentType + " - seeing if the content is an RDF Graph instead");
try
{
// If not a RDF Dataset format see if it is a Graph
IRdfReader rdfParser = MimeTypesHelper.GetParser(httpResponse.ContentType);
rdfParser.Load(handler, new StreamReader(httpResponse.GetResponseStream()));
}
catch (RdfParserSelectionException)
{
// Finally fall back to assuming a dataset and trying format guessing
String data = new StreamReader(httpResponse.GetResponseStream()).ReadToEnd();
parser = StringParser.GetDatasetParser(data);
parser.Warning += RaiseStoreWarning;
parser.Load(handler, new StringReader(data));
}
}
}
else
{
parser.Warning += RaiseStoreWarning;
parser.Load(handler, new StreamReader(httpResponse.GetResponseStream()));
}
}
}
catch (UriFormatException uriEx)
{
// Uri Format Invalid
throw new RdfException("Unable to load from the given URI '" + u.AbsoluteUri + "' since it's format was invalid, see inner exception for details", uriEx);
}
catch (WebException webEx)
{
if (webEx.Response != null) Tools.HttpDebugResponse((HttpWebResponse)webEx.Response);
// Some sort of HTTP Error occurred
throw new WebException("A HTTP Error occurred resolving the URI '" + u.AbsoluteUri + "', see innner exception for details", webEx);
}
}
/// <summary>
/// Attempts to load a RDF dataset from the given URI using a RDF Handler.
/// </summary>
/// <param name="handler">RDF Handler to use.</param>
/// <param name="u">URI to attempt to get a RDF dataset from.</param>
/// <remarks>
/// <para>
/// Attempts to select the relevant Store Parser based on the Content Type header returned in the HTTP Response.
/// </para>
/// </remarks>
public static void LoadDataset(IRdfHandler handler, Uri u)
{
Load(handler, u, (IStoreReader)null);
}
#region Warning Events
/// <summary>
/// Raises warning messages.
/// </summary>
/// <param name="message">Warning Message.</param>
static void RaiseWarning(String message)
{
RdfReaderWarning d = Warning;
if (d != null)
{
d(message);
}
}
/// <summary>
/// Raises store warning messages.
/// </summary>
/// <param name="message">Warning Message.</param>
static void RaiseStoreWarning(String message)
{
StoreReaderWarning d = StoreWarning;
if (d != null)
{
d(message);
}
}
/// <summary>
/// Event which is raised when a parser that is invoked by the UriLoader notices a non-fatal issue with the RDF syntax
/// </summary>
public static event RdfReaderWarning Warning;
/// <summary>
/// Event which is raised when a store parser that is invoked by the UriLoader notices a non-fatal issue with the RDF dataset syntax
/// </summary>
public static event StoreReaderWarning StoreWarning;
#endregion
}
}