当前位置: 首页>>代码示例>>C#>>正文


C# Uri.GetEnhancedHashCode方法代码示例

本文整理汇总了C#中System.Uri.GetEnhancedHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.GetEnhancedHashCode方法的具体用法?C# Uri.GetEnhancedHashCode怎么用?C# Uri.GetEnhancedHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Uri的用法示例。


在下文中一共展示了Uri.GetEnhancedHashCode方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddNamespace

        /// <summary>
        /// Adds a Namespace at the Current Nesting Level
        /// </summary>
        /// <param name="prefix">Prefix</param>
        /// <param name="uri">Namespace URI</param>
        public void AddNamespace(string prefix, Uri uri)
        {
            NestedMapping mapping = new NestedMapping(prefix, uri, this._level);
            if (!this._prefixes.ContainsKey(uri.GetEnhancedHashCode())) this._prefixes.Add(uri.GetEnhancedHashCode(), new List<NestedMapping>());

            if (this._uris.ContainsKey(prefix))
            {
                //Is it defined on the current nesting level?
                if (this._uris[prefix].Any(m => m.Level == this._level))
                {
                    //If it is then we override it
                    this._uris[prefix].RemoveAll(m => m.Level == this._level);
                    this._prefixes[uri.GetEnhancedHashCode()].RemoveAll(m => m.Level == this._level);

                    this._uris[prefix].Add(mapping);
                    this._prefixes[uri.GetEnhancedHashCode()].Add(mapping);
                    this.RaiseNamespaceModified(prefix, uri);
                }
                else
                {
                    //If not we simply add it
                    this._uris[prefix].Add(mapping);
                    this._prefixes[uri.GetEnhancedHashCode()].Add(mapping);
                    this.RaiseNamespaceAdded(prefix, uri);
                }
            }
            else
            {
                //Not yet defined so add it
                this._uris.Add(prefix, new List<NestedMapping>());
                this._uris[prefix].Add(mapping);
                this._prefixes[uri.GetEnhancedHashCode()].Add(mapping);
                this.RaiseNamespaceAdded(prefix, uri);
            }
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:40,代码来源:NestedNamespaceMapper.cs

示例2: AddNamespace

        public void AddNamespace(string prefix, Uri uri)
        {
            OffsetMapping mapping = new OffsetMapping(prefix, uri, this._offset);
            if (!this._prefixes.ContainsKey(uri.GetEnhancedHashCode())) this._prefixes.Add(uri.GetEnhancedHashCode(), new List<OffsetMapping>());

            if (this._uris.ContainsKey(prefix))
            {
                //Is it defined at the current offset level?
                if (this._uris[prefix].Any(m => m.Offset == this._offset))
                {
                    //If it is then we override it
                    this._uris[prefix].RemoveAll(m => m.Offset == this._offset);
                    this._prefixes[uri.GetEnhancedHashCode()].RemoveAll(m => m.Offset == this._offset);

                    this._uris[prefix].Add(mapping);
                    this._prefixes[uri.GetEnhancedHashCode()].Add(mapping);
                    this.OnNamespaceModified(prefix, uri);
                }
                else
                {
                    //If not we simply add it
                    this._uris[prefix].Add(mapping);
                    this._prefixes[uri.GetEnhancedHashCode()].Add(mapping);
                    this.OnNamespaceAdded(prefix, uri);
                }
            }
            else
            {
                //Not yet defined so add it
                this._uris.Add(prefix, new List<OffsetMapping>());
                this._uris[prefix].Add(mapping);
                this._prefixes[uri.GetEnhancedHashCode()].Add(mapping);
                this.OnNamespaceAdded(prefix, uri);
            }
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:35,代码来源:OffsetScopedNamespaceMapper.cs

示例3: 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

示例4: RemoveETag

 /// <summary>
 /// Remove the ETag record for the given URI
 /// </summary>
 /// <param name="u">URI</param>
 public void RemoveETag(Uri u)
 {
     try
     {
         if (this._canCacheETag)
         {
             if (this._etags.ContainsKey(u.GetEnhancedHashCode()))
             {
                 this._etags.Remove(u.GetEnhancedHashCode());
                 //If we did remove an ETag then we need to rewrite our ETag cache file
                 using (StreamWriter writer = new StreamWriter(this._etagFile, false, Encoding.UTF8))
                 {
                     foreach (KeyValuePair<int, String> etag in this._etags)
                     {
                         writer.WriteLine(etag.Key + "\t" + etag.Value);
                     }
                     writer.Close();
                 }
             }
         }
     }
     catch (IOException)
     {
         //If an IO Exception occurs ignore it, something went wrong with cache alteration
     }
 }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:30,代码来源:UriLoaderCache.cs

示例5: 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

示例6: 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

示例7: Select

        /// <summary>
        /// Selects Statements from the Source based on a Template
        /// </summary>
        /// <param name="template">Statement Template</param>
        /// <param name="sink">Sink to stream results to</param>
        public void Select(Statement template, StatementSink sink)
        {
            //Convert Template to an Enumerable
            IEnumerable<Triple> ts = Enumerable.Empty<Triple>();
            int hash;

            if (template.Meta != Statement.DefaultMeta && template.Meta != null)
            {
                //Select from the specific Graph if it exists
                Uri graphUri;
                if (template.Meta.Uri == null)
                {
                    hash = new Uri(GraphCollection.DefaultGraphUri).GetEnhancedHashCode();
                    graphUri = null;
                } 
                else 
                {
                    graphUri = new Uri(template.Meta.Uri);
                    hash = graphUri.GetEnhancedHashCode();
                }
                if (this._store.HasGraph(graphUri))
                {
                    ts = this.TemplateToEnumerable(template, this._store.Graph(graphUri));
                    SemWebMapping mapping = this.GetMapping(hash, this._store.Graph(graphUri));

                    foreach (Triple t in ts)
                    {
                        //Keep streaming Triples until the sink tells us to stop
                        Statement stmt = SemWebConverter.ToSemWeb(t, mapping);
                        if (!sink.Add(stmt)) return;
                    }
                }
            }
            else
            {
                //Output the results from each Graph in turn
                foreach (IGraph g in this._store.Graphs)
                {
                    Entity graphUri;
                    if (g.BaseUri == null) 
                    {
                        hash = new Uri(GraphCollection.DefaultGraphUri).GetEnhancedHashCode();
                        graphUri = new Entity(GraphCollection.DefaultGraphUri);
                    } 
                    else 
                    {
                        hash = g.BaseUri.GetEnhancedHashCode();
                        graphUri = new Entity(g.BaseUri.ToString());
                    }
                    SemWebMapping mapping = this.GetMapping(hash, g);
                    foreach (Triple t in this.TemplateToEnumerable(template, g))
                    {
                        Statement stmt = SemWebConverter.ToSemWeb(t, mapping);
                        stmt.Meta = graphUri;
                        if (!sink.Add(stmt)) return;
                    }
                }
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:64,代码来源:StoreSource.cs

示例8: Add

        /// <summary>
        /// Adds a statement to this Source
        /// </summary>
        /// <param name="statement">Statement</param>
        /// <returns></returns>
        public bool Add(Statement statement)
        {
            IGraph g;
            Uri graphUri;
            int hash;

            //Set the Graph URI based on the Statement Meta field
            if (statement.Meta != Statement.DefaultMeta && statement.Meta.Uri != null)
            {
                if (statement.Meta.Uri.Equals(GraphCollection.DefaultGraphUri))
                {
                    graphUri = null;
                    hash = new Uri(GraphCollection.DefaultGraphUri).GetEnhancedHashCode();
                }
                else
                {
                    graphUri = new Uri(statement.Meta.Uri);
                    hash = graphUri.GetEnhancedHashCode();
                }
            }
            else
            {
                graphUri = null;
                hash = new Uri(GraphCollection.DefaultGraphUri).GetEnhancedHashCode();
            }
            if (!this._store.HasGraph(graphUri))
            {
                g = new Graph();
                if (graphUri != null) g.BaseUri = graphUri;
                this._store.Add(g);
            }
            else
            {
                g = this._store.Graph(graphUri);
            }

            //Assert into the appropriate Graph
            g.Assert(SemWebConverter.FromSemWeb(statement, this.GetMapping(hash, g)));

            //We never ask the sink to stop streaming statements so we always return true
            return true;
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:47,代码来源:StoreSource.cs

示例9: GetPrefix

 /// <summary>
 /// Gets the Namespace Prefix for the given URI at the current Nesting Level
 /// </summary>
 /// <param name="uri">Namespace URI</param>
 /// <returns></returns>
 public string GetPrefix(Uri uri)
 {
     int hash = uri.GetEnhancedHashCode();
     if (this._prefixes.ContainsKey(hash))
     {
         return this._prefixes[hash].Last().Prefix;
     }
     else
     {
         throw new RdfException("The Prefix for the given URI '" + uri.ToString() + "' is not known by the in-scope NamespaceMapper");
     }
 }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:17,代码来源:NestedNamespaceMapper.cs

示例10: AddNamespace

        /// <summary>
        /// Adds a Namespace to the Namespace Map
        /// </summary>
        /// <param name="prefix">Namespace Prefix</param>
        /// <param name="uri">Namespace Uri</param>
        public virtual void AddNamespace(String prefix, Uri uri)
        {
            int hash = uri.GetEnhancedHashCode();
            if (!this._uris.ContainsKey(prefix))
            {
                //Add a New Prefix
                this._uris.Add(prefix, uri);

                if (!this._prefixes.ContainsKey(hash))
                {
                    //Add a New Uri
                    this._prefixes.Add(hash, prefix);
                    this.OnNamespaceAdded(prefix, uri);
                }
                else
                {
                    //Check whether the Namespace Uri is actually being changed
                    //If the existing Uri is the same as the old one then we change the prefix
                    //but we don't raise the OnNamespaceModified event
                    this._prefixes[hash] = prefix;
                    if (!this._uris[prefix].ToString().Equals(uri.ToString(), StringComparison.Ordinal))
                    {
                        //Raise modified event
                        this.OnNamespaceModified(prefix, uri);
                    }
                }
            }
            else
            {
                //Check whether the Namespace is actually being changed
                //If the existing Uri is the same as the old one no change is needed
                if (!this._uris[prefix].ToString().Equals(uri.ToString(), StringComparison.Ordinal))
                {
                    //Update the existing Prefix
                    this._uris[prefix] = uri;
                    this._prefixes[hash] = prefix;
                    this.OnNamespaceModified(prefix, uri);
                }
            }
        }
开发者ID:jmahmud,项目名称:RDFer,代码行数:45,代码来源:NamespaceMapper.cs

示例11: LoadNamespaces

        /// <summary>
        /// Loads Namespaces for the Graph with the given ID into the given Graph object
        /// </summary>
        /// <param name="g">Graph to load into</param>
        /// <param name="graphID">Database Graph ID</param>
        public override void LoadNamespaces(IGraph g, string graphID)
        {
            //Build the SQL for getting the Namespaces
            String getNamespaces = "SELECT * FROM NAMESPACES N INNER JOIN NS_PREFIXES P ON N.nsPrefixID=P.nsPrefixID INNER JOIN NS_URIS U ON N.nsUriID=U.nsUriID WHERE graphID=" + graphID;

            //Get the Data
            this.Open(false);
            DataTable data = this.ExecuteQuery(getNamespaces);
            this.Close(false);

            //Load the Namespace into the Graph
            String prefix, uri;
            foreach (DataRow r in data.Rows)
            {
                //Get Prefix and Uri from Row
                prefix = r["nsPrefix"].ToString();
                uri = r["nsUri"].ToString();
                Uri u = new Uri(uri);

                //Add to Graph
                g.NamespaceMap.AddNamespace(prefix, u);

                //Store the IDs for later if not already stored
                try
                {
                    Monitor.Enter(this._nsPrefixIDs);
                    Monitor.Enter(this._nsUriIDs);

                    if (!this._nsPrefixIDs.ContainsKey(prefix))
                    {
                        this._nsPrefixIDs.Add(prefix, r["nsPrefixID"].ToString());
                    }
                    if (!this._nsUriIDs.ContainsKey(u.GetEnhancedHashCode()))
                    {
                        this._nsUriIDs.Add(u.GetEnhancedHashCode(), r["nsUriID"].ToString());
                    }
                }
                finally
                {
                    Monitor.Exit(this._nsPrefixIDs);
                    Monitor.Exit(this._nsUriIDs);
                }
            }
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:49,代码来源:MicrosoftSqlStoreManager.cs

示例12: GetNSUriID

        /// <summary>
        /// Looks up the ID for a Namespace Uri from the Database adding it to the Database if necessary
        /// </summary>
        /// <param name="u">Namespace Uri</param>
        /// <returns></returns>
        private String GetNSUriID(Uri u)
        {
            String uriID;
            Object id;

            //Is it in the Dictionary already?
            if (this._nsUriIDs.ContainsKey(u.GetEnhancedHashCode()))
            {
                try
                {
                    Monitor.Enter(this._nsUriIDs);
                    uriID = this._nsUriIDs[u.GetEnhancedHashCode()];
                }
                finally
                {
                    Monitor.Exit(this._nsUriIDs);
                }
            }
            else
            {
                //Lookup from Database
                String getUri = "SELECT nsUriID FROM NS_URIS WHERE nsUriHash=" + u.GetEnhancedHashCode();
                id = this.ExecuteScalar(getUri);
                if (id == null)
                {
                    //Needs adding to Database
                    String addUri = "INSERT INTO NS_URIS (nsUri, nsUriHash) VALUES (N'" + this.EscapeString(u.ToString()) + "', " + u.GetEnhancedHashCode() + ")";
                    try
                    {
                        this.ExecuteNonQuery(addUri);
                    }
                    catch (SqlException sqlEx)
                    {
                        this.Close(true, true);
                        throw new RdfException("Unable to create a Namespace URI entry in the NS_URIS Table", sqlEx);
                    }

                    //Get the new ID
                    id = this.ExecuteScalar(getUri);
                    if (id == null)
                    {
                        this.Close(true, true);
                        throw new RdfException("Unable to retrieve a required Namespace URI entry from the Database");
                    }
                    else
                    {
                        uriID = id.ToString();
                        try
                        {
                            Monitor.Enter(this._nsUriIDs);
                            if (!this._nsUriIDs.ContainsKey(u.GetEnhancedHashCode()))
                            {
                                this._nsUriIDs.Add(u.GetEnhancedHashCode(), uriID);
                            }
                        }
                        finally
                        {
                            Monitor.Exit(this._nsUriIDs);
                        }
                    }
                }
                else
                {
                    uriID = id.ToString();
                    try
                    {
                        Monitor.Enter(this._nsUriIDs);
                        if (!this._nsUriIDs.ContainsKey(u.GetEnhancedHashCode()))
                        {
                            this._nsUriIDs.Add(u.GetEnhancedHashCode(), uriID);
                        }
                    }
                    finally
                    {
                        Monitor.Exit(this._nsUriIDs);
                    }
                }
            }

            return uriID;
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:86,代码来源:MicrosoftSqlStoreManager.cs

示例13: DoUpgrade

        private void DoUpgrade()
        {
            int completed = 0;
            try
            {
                //First run the Upgrade Script
                //Need to read it in from dotNetRDF assembly
                StreamReader reader = new StreamReader(Assembly.GetAssembly(typeof(VDS.RDF.Graph)).GetManifestResourceStream("VDS.RDF.Storage.UpgradeMSSQLStore_010_011.sql"));
                String upgrade = reader.ReadToEnd();
                reader.Close();

                this._connection.ExecuteNonQuery(upgrade);
                completed++;
                this.OnProgress(completed);

                //Generate Hash Codes for the Graph URIs
                DataTable graphs = this._connection.ExecuteQuery("SELECT graphID, graphUri FROM GRAPHS");
                foreach (DataRow g in graphs.Rows)
                {
                    Uri graphUri = new Uri(g["graphUri"].ToString());
                    int graphHash = graphUri.GetEnhancedHashCode();
                    this._connection.ExecuteNonQuery("UPDATE GRAPHS SET graphHash=" + graphHash + " WHERE graphID=" + g["graphID"].ToString());
                    completed++;
                    this.OnProgress(completed);
                }

                //Generate Hash Codes for the Namespace URIs
                DataTable namespaces = this._connection.ExecuteQuery("SELECT nsUriID, nsUri FROM NS_URIS");
                foreach (DataRow n in namespaces.Rows)
                {
                    Uri nsUri = new Uri(n["nsUri"].ToString());
                    int nsUriHash = nsUri.GetEnhancedHashCode();
                    this._connection.ExecuteNonQuery("UPDATE NS_URIS SET nsUriHash=" + nsUriHash + " WHERE nsUriID=" + n["nsUriID"].ToString());
                    completed++;
                    this.OnProgress(completed);
                }

                //Generate Hash Codes for Nodes
                DataTable nodes = this._connection.ExecuteQuery("SELECT nodeID, nodeType, nodeValue FROM NODES");
                foreach (DataRow n in nodes.Rows)
                {
                    INode temp = this.DecodeNode(n);
                    this._connection.ExecuteNonQuery("UPDATE NODES SET nodeHash=" + temp.GetHashCode() + " WHERE nodeID=" + n["nodeID"].ToString());
                    completed++;
                    this.OnProgress(completed);
                }

                //Generate Hash Codes for Triples
                String getTriples = "SELECT * FROM TRIPLES T INNER JOIN NODES S ON T.tripleSubject=S.nodeID INNER JOIN NODES P ON T.triplePredicate=P.nodeID INNER JOIN NODES O ON T.tripleObject=O.nodeID";
                DataTable triples = this._connection.ExecuteQuery(getTriples);
                foreach (DataRow t in triples.Rows)
                {
                    int tripleHash = (t["nodeHash"].ToString() + t["nodeHash1"].ToString() + t["nodeHash2"].ToString()).GetHashCode();
                    this._connection.ExecuteNonQuery("UPDATE TRIPLES SET tripleHash=" + tripleHash + " WHERE tripleID=" + t["tripleID"].ToString());
                    completed++;
                    this.OnProgress(completed);
                }
            }
            catch (Exception ex)
            {
                this.OnError(ex);
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:63,代码来源:StoreUpgrader.cs


注:本文中的System.Uri.GetEnhancedHashCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。