本文整理汇总了C#中System.Uri.IsFile方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.IsFile方法的具体用法?C# Uri.IsFile怎么用?C# Uri.IsFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Uri
的用法示例。
在下文中一共展示了Uri.IsFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
/// <summary>
/// Attempts to load a RDF Graph from a URI asynchronously
/// </summary>
/// <param name="g">Graph to assert triple in</param>
/// <param name="u">URI to load from</param>
/// <param name="parser">Parser to use</param>
/// <param name="callback">Callback to invoke when the operation completes</param>
/// <param name="state">State to pass to the callback</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(IGraph g, Uri u, IRdfReader parser, GraphCallback callback, Object state)
{
if (g == null) throw new RdfParseException("Cannot read RDF into a null Graph");
if (u == null) throw new RdfParseException("Cannot read RDF from a null URI");
#if SILVERLIGHT
if (u.IsFile())
#else
if (u.IsFile)
#endif
{
//Invoke FileLoader instead
UriLoader.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);
}
//FileLoader.Load() will run synchronously so once this completes we can invoke the callback
callback(g, state);
return;
}
if (u.Scheme.Equals("data"))
{
//Invoke DataUriLoader instead
RaiseWarning("This is a data: URI so invoking the DataUriLoader instead");
DataUriLoader.Load(g, u);
//After DataUriLoader.Load() has run (which happens synchronously) can invoke the callback
callback(g, state);
return;
}
//Set Base URI if necessary
if (g.BaseUri == null && g.IsEmpty) g.BaseUri = u;
UriLoader.Load(new GraphHandler(g), u, parser, (_,s) => callback(g, s), state);
}
示例2: AddUrl
/// <summary>
/// Read validation definitions from a <see cref="Uri"/>.
/// </summary>
/// <param name="uri">a <see cref="Uri" /> to read the mappings from.</param>
/// <returns>This configuration object.</returns>
/// <exception cref="ArgumentNullException"><paramref name="uri"/> is null.</exception>
public static void AddUrl(Uri uri)
{
Guard.ArgumentNotNull(uri, "uri");
if (uri.IsFile())
{
AddUrl(uri.OriginalString);
}
else
{
AddUrl(uri.AbsolutePath);
}
}
示例3: Load
/// <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 SILVERLIGHT
if (u.IsFile())
#else
if (u.IsFile)
#endif
{
//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;
}
//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 !SILVERLIGHT
httpRequest.Timeout = Options.UriLoaderTimeout;
#endif
if (_userAgent != null && !_userAgent.Equals(String.Empty))
{
httpRequest.UserAgent = _userAgent;
}
#if DEBUG
//HTTP Debugging
if (Options.HttpDebugging)
{
Tools.HttpDebugRequest(httpRequest);
}
#endif
using (HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse())
{
#if DEBUG
//HTTP Debugging
if (Options.HttpDebugging)
{
Tools.HttpDebugResponse(httpResponse);
}
#endif
//Get a Parser and Load the RDF
if (parser == null)
{
try
{
parser = MimeTypesHelper.GetStoreParser(httpResponse.ContentType);
parser.Warning += RaiseStoreWarning;
parser.Load(handler, new StreamParams(httpResponse.GetResponseStream()));
}
catch (RdfParserSelectionException selEx)
{
String data = new StreamReader(httpResponse.GetResponseStream()).ReadToEnd();
parser = StringParser.GetDatasetParser(data);
//.........这里部分代码省略.........