當前位置: 首頁>>代碼示例>>C#>>正文


C# Uri.GetSha256Hash方法代碼示例

本文整理匯總了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);
        }
開發者ID:jbunzel,項目名稱:MvcRQ_git,代碼行數:12,代碼來源:ExpansionCache.cs

示例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
            }
        }
開發者ID:almostEric,項目名稱:DotNetRDF-4.0,代碼行數:89,代碼來源:UriLoaderCache.cs

示例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;
            }
        }
開發者ID:almostEric,項目名稱:DotNetRDF-4.0,代碼行數:29,代碼來源:UriLoaderCache.cs

示例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;
            }
        }
開發者ID:almostEric,項目名稱:DotNetRDF-4.0,代碼行數:54,代碼來源:UriLoaderCache.cs

示例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());
            }
        }
開發者ID:almostEric,項目名稱:DotNetRDF-4.0,代碼行數:22,代碼來源:UriLoaderCache.cs

示例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());
     }
 }
開發者ID:almostEric,項目名稱:DotNetRDF-4.0,代碼行數:26,代碼來源:UriLoaderCache.cs

示例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;
     }
 }
開發者ID:almostEric,項目名稱:DotNetRDF-4.0,代碼行數:17,代碼來源:UriLoaderCache.cs

示例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));
 }
開發者ID:jbunzel,項目名稱:MvcRQ_git,代碼行數:12,代碼來源:ExpansionCache.cs

示例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;
        }
開發者ID:jbunzel,項目名稱:MvcRQ_git,代碼行數:14,代碼來源:ExpansionCache.cs


注:本文中的System.Uri.GetSha256Hash方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。