本文整理汇总了C#中System.Uri.GetSha256Hash方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.GetSha256Hash方法的具体用法?C# Uri.GetSha256Hash怎么用?C# Uri.GetSha256Hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Uri
的用法示例。
在下文中一共展示了Uri.GetSha256Hash方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsExpansionCached
/// <summary>
/// Checks whether a given Expansion is Cached
/// </summary>
/// <param name="u">Uri</param>
/// <returns></returns>
public bool IsExpansionCached(Uri u)
{
if (!this._enabled) return false;
String cachePath = Path.Combine(this._resultsDir, u.GetSha256Hash());
return File.Exists(cachePath) && this.IsFresh(cachePath);
}
示例2: ToCache
public void ToCache(Uri requestUri, Uri responseUri, IGraph g, String etag)
{
//Cache a local copy of the Graph
try
{
bool cacheTwice = !requestUri.ToString().Equals(responseUri.ToString() , StringComparison.OrdinalIgnoreCase);
if (this._canCacheGraphs)
{
String graph = Path.Combine(this._graphDir, requestUri.GetSha256Hash());
this._ttlwriter.Save(g, graph);
//If applicable also cache under the responseUri
if (cacheTwice)
{
graph = Path.Combine(this._graphDir, responseUri.GetSha256Hash());
this._ttlwriter.Save(g, graph);
}
}
//Cache the ETag if present
if (this._canCacheETag && etag != null && !etag.Equals(String.Empty))
{
int id = requestUri.GetEnhancedHashCode();
bool requireAdd = false;
if (this._etags.ContainsKey(id))
{
if (!this._etags[id].Equals(etag))
{
//If the ETag has changed remove it and then re-add it
this.RemoveETag(requestUri);
requireAdd = true;
}
}
else
{
requireAdd = true;
}
if (requireAdd)
{
//Add a New ETag
this._etags.Add(id, etag);
using (StreamWriter writer = new StreamWriter(this._etagFile, true, Encoding.UTF8))
{
writer.WriteLine(id + "\t" + etag);
writer.Close();
}
}
//Cache under the Response URI as well if applicable
if (cacheTwice)
{
id = responseUri.GetEnhancedHashCode();
requireAdd = false;
if (this._etags.ContainsKey(id))
{
if (!this._etags[id].Equals(etag))
{
//If the ETag has changed remove it and then re-add it
this.RemoveETag(responseUri);
requireAdd = true;
}
}
else
{
requireAdd = true;
}
if (requireAdd)
{
using (StreamWriter writer = new StreamWriter(this._etagFile, true, Encoding.UTF8))
{
writer.WriteLine(id + "\t" + etag);
writer.Close();
}
}
}
}
}
catch (IOException)
{
//Ignore - if we get an IO Exception we failed to cache somehow
}
catch (RdfOutputException)
{
//Ignore - if we get an RDF Output Exception then we failed to cache
}
}
示例3: GetLocalCopy
/// <summary>
/// Gets the path to the locally cached copy of the Graph from the given URI
/// </summary>
/// <param name="u">URI</param>
/// <returns></returns>
/// <remarks>
/// This method does not do any cache expiry calculations on the file. This is due to the fact that we'll store local copies of Graphs for which we have ETags and when using ETags we rely on the servers knowledge of whether the resource described by the URI has changed rather than some arbitrary caching duration that we/the user has set to use.
/// </remarks>
public String GetLocalCopy(Uri u)
{
if (this._canCacheGraphs)
{
if (this._nocache.Contains(u.GetSha256Hash())) return null;
String graph = Path.Combine(this._graphDir, u.GetSha256Hash());
if (File.Exists(graph))
{
return graph;
}
else
{
return null;
}
}
else
{
return null;
}
}
示例4: HasLocalCopy
/// <summary>
/// Is there a locally cached copy of the Graph from the given URI which is not expired
/// </summary>
/// <param name="u">URI</param>
/// <param name="requireFreshness">Whether the local copy is required to meet the Cache Freshness (set by the Cache Duration)</param>
/// <returns></returns>
public bool HasLocalCopy(Uri u, bool requireFreshness)
{
try
{
if (this._canCacheGraphs)
{
if (this._nocache.Contains(u.GetSha256Hash())) return false;
String graph = Path.Combine(this._graphDir, u.GetSha256Hash());
if (File.Exists(graph))
{
if (requireFreshness)
{
//Check the freshness of the local copy
DateTime created = File.GetCreationTime(graph);
TimeSpan freshness = DateTime.Now - created;
if (freshness > this._cacheDuration)
{
//Local copy has expired
File.Delete(graph);
return false;
}
else
{
return true;
}
}
else
{
return true;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
catch
{
//If we get an error trying to detect if a URI is cached then it can't be in the cache
return false;
}
}
示例5: RemoveLocalCopy
/// <summary>
/// Removes a locally cached copy of a URIs results from the Cache
/// </summary>
/// <param name="u">URI</param>
public void RemoveLocalCopy(Uri u)
{
if (u == null) return;
try
{
String graph = Path.Combine(this._graphDir, u.GetSha256Hash());
if (File.Exists(graph))
{
File.Delete(graph);
}
}
catch
{
//If error add to the list of uncachable URIs
this._nocache.Add(u.GetSha256Hash());
}
}
示例6: GetETag
/// <summary>
/// Gets the ETag for the given URI
/// </summary>
/// <param name="u">URI</param>
/// <returns></returns>
/// <exception cref="KeyNotFoundException">Thrown if there is no ETag for the given URI</exception>
public String GetETag(Uri u)
{
if (this._canCacheETag)
{
if (this._nocache.Contains(u.GetSha256Hash())) throw new KeyNotFoundException("No ETag was found for the URI " + u.ToString());
int id = u.GetEnhancedHashCode();
if (this._etags.ContainsKey(id))
{
return this._etags[id];
}
else
{
throw new KeyNotFoundException("No ETag was found for the URI " + u.ToString());
}
}
else
{
throw new KeyNotFoundException("No ETag was found for the URI " + u.ToString());
}
}
示例7: HasETag
/// <summary>
/// Gets whether there is an ETag for the given URI
/// </summary>
/// <param name="u">URI</param>
/// <returns></returns>
public bool HasETag(Uri u)
{
if (this._canCacheETag)
{
if (this._nocache.Contains(u.GetSha256Hash())) return false;
return this._etags.ContainsKey(u.GetEnhancedHashCode()) && this.HasLocalCopy(u, false);
}
else
{
return false;
}
}
示例8: Add
/// <summary>
/// Adds an Expansion to the Cache
/// </summary>
/// <param name="u">Uri</param>
/// <param name="profile">Expansion Profile Uri</param>
/// <param name="expansion">Expansion</param>
/// <returns></returns>
public void Add(Uri u, Uri profile, IInMemoryQueryableStore expansion)
{
String cachePath = Path.Combine(this._resultsDir, profile.GetSha256Hash() + "_" + u.GetSha256Hash());
this._writer.Save(expansion, new StreamParams(cachePath));
}
示例9: GetExpansion
/// <summary>
/// Gets an Expansion from the Cache
/// </summary>
/// <param name="u">Uri</param>
/// <param name="profile">Expansion Profile Uri</param>
/// <returns></returns>
public IInMemoryQueryableStore GetExpansion(Uri u, Uri profile)
{
String cachePath = Path.Combine(this._resultsDir, profile.GetSha256Hash() + "_" + u.GetSha256Hash());
TripleStore store = new TripleStore();
this._parser.Load(store, new StreamParams(cachePath));
return store;
}