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


C# IGraph.ExecuteQuery方法代码示例

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


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

示例1: FillConnectionList

        private void FillConnectionList(IGraph config, ListBox lbox)
        {
             SparqlParameterizedString query = new SparqlParameterizedString();
            query.Namespaces.AddNamespace("rdfs", new Uri(NamespaceMapper.RDFS));
            query.Namespaces.AddNamespace("dnr", new Uri(ConfigurationLoader.ConfigurationNamespace));

            query.CommandText = "SELECT * WHERE { ?obj a " + ConfigurationLoader.ClassGenericManager + " . OPTIONAL { ?obj rdfs:label ?label } }";
            query.CommandText += " ORDER BY DESC(?obj)";

            SparqlResultSet results = config.ExecuteQuery(query) as SparqlResultSet;
            if (results != null)
            {
                foreach (SparqlResult r in results)
                {
                    QuickConnect connect;
                    if (r.HasValue("label") && r["label"] != null)
                    {
                        connect = new QuickConnect(config, r["obj"], r["label"].ToString());
                    }
                    else
                    {
                        connect = new QuickConnect(config, r["obj"]);
                    }
                    lbox.Items.Add(connect);
                }
            }
            lbox.DoubleClick += new EventHandler((sender, args) =>
                {
                    QuickConnect connect = lbox.SelectedItem as QuickConnect;
                    if (connect != null)
                    {
                        try
                        {
                            IGenericIOManager manager = connect.GetConnection();
                            StoreManagerForm storeManager = new StoreManagerForm(manager);
                            storeManager.MdiParent = Program.MainForm;
                            storeManager.Show();

                            //Add to Recent Connections
                            Program.MainForm.AddRecentConnection(manager);

                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error Opening Connection " + connect.ToString() + ":\n" + ex.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                });
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:50,代码来源:StartPage.cs

示例2: CreateFeedFromGraph

        /// <summary>
        /// Creates an OData feed response containing a list of entries for a particular type of entity
        /// </summary>
        /// <param name="resultsGraph">The RDF graph containing the SPARQL results</param>
        /// <param name="entityType">The fully qualified domain name for the type of entity to be written</param>
        /// <param name="resultsCount">The count of the total number of results that the server can provide</param>
        /// <param name="originalQueryModel">The SPARQL query that was executed to generate this graph</param>
        public void CreateFeedFromGraph(IGraph resultsGraph, string entityType, int resultsCount, SparqlModel originalQueryModel = null)
        {
            var msgWriter = new ODataMessageWriter(_response, _writerSettings, _map.Model);
            var feedWriter = msgWriter.CreateODataFeedWriter();
            var entries = new List<ODataEntry>();

            var typeUri = _map.GetUriForType(entityType);
            if (!String.IsNullOrEmpty(typeUri))
            {
                var predNode = resultsGraph.CreateUriNode(UriFactory.Create(RdfConstants.RdfType));
                var objNode = resultsGraph.CreateUriNode(UriFactory.Create(typeUri));
                if (originalQueryModel == null || originalQueryModel.Ordering == null)
                {
                    // No sorting required, just iterate all instances
                    foreach (var instanceTriple in resultsGraph.GetTriplesWithPredicateObject(predNode, objNode))
                    {
                        var instanceUri = (instanceTriple.Subject as IUriNode).Uri;
                        entries.Add(CreateODataEntry(resultsGraph, instanceUri.ToString(), entityType));
                    }
                }
                else
                {
                    // We need to apply the same sort criteria to this graph to ensure
                    // that the ODATA results are properly sorted.
                    // NOTE: This will only work if all the properties used in the original query
                    // are present in the graph - this could be a problem with more complex traversals
                    // and the query may instead need to be rewritten / regenerated to extract only
                    // the required sort properties.
                    originalQueryModel.IsDescribe = false;
                    var resultsTable =
                        resultsGraph.ExecuteQuery(originalQueryModel.GetSparqlRepresentation()) as SparqlResultSet;
                    var targetVariable= originalQueryModel.SelectVariables[0];
                    foreach (var result in resultsTable.Results)
                    {
                        var instanceUriNode = result[targetVariable] as IUriNode;
                        if (instanceUriNode != null)
                        {
                            entries.Add(CreateODataEntry(resultsGraph, instanceUriNode.Uri.ToString(), entityType));
                        }
                    }
                }
            }

            var feed = new ODataFeed {Id = _baseUri + _map.GetTypeSet(entityType)};
            if (_writerSettings.Version >= ODataVersion.V2)
            {
                feed.Count = resultsCount;
            }
            if (originalQueryModel != null)
            {
                feed.NextPageLink = GetNextPageLink(originalQueryModel);
            }
            feedWriter.WriteStart(feed);
            foreach (var entry in entries)
            {
                feedWriter.WriteStart(entry);
                feedWriter.WriteEnd();
            }
            feedWriter.WriteEnd();
            feedWriter.Flush();
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:68,代码来源:ODataFeedGenerator.cs

示例3: FillConnectionsMenu

        private void FillConnectionsMenu(ToolStripMenuItem menu, IGraph config, int maxItems, bool addRemoveOption, String persistentFile)
        {
            if (config == null || config.Triples.Count == 0) return;

            SparqlParameterizedString query = new SparqlParameterizedString();
            query.Namespaces.AddNamespace("rdfs", new Uri(NamespaceMapper.RDFS));
            query.Namespaces.AddNamespace("dnr", new Uri(ConfigurationLoader.ConfigurationNamespace));

            query.CommandText = "SELECT * WHERE { ?obj a " + ConfigurationLoader.ClassGenericManager + " . OPTIONAL { ?obj rdfs:label ?label } }";
            query.CommandText += " ORDER BY DESC(?obj)";
            if (maxItems > 0) query.CommandText += " LIMIT " + maxItems;

            SparqlResultSet results = config.ExecuteQuery(query) as SparqlResultSet;
            if (results != null)
            {
                foreach (SparqlResult r in results)
                {
                    ToolStripMenuItem item = new ToolStripMenuItem();
                    if (r.HasValue("label") && r["label"] != null)
                    {
                        INode lblNode = r["label"];
                        if (lblNode.NodeType == NodeType.Literal)
                        {
                            item.Text = ((ILiteralNode)lblNode).Value;
                        }
                        else
                        {
                            item.Text = lblNode.ToString();
                        }
                    }
                    else
                    {
                        item.Text = r["obj"].ToString();
                    }
                    item.Tag = new QuickConnect(config, r["obj"]);
                    item.Click += new EventHandler(QuickConnectClick);

                    if (addRemoveOption)
                    {
                        ToolStripMenuItem remove = new ToolStripMenuItem();
                        remove.Text = "Remove Connection from this List";
                        remove.Tag = new QuickRemove(menu, config, r["obj"], persistentFile);
                        remove.Click += new EventHandler(QuickRemoveClick);
                        item.DropDownItems.Add(remove);

                        ToolStripMenuItem connect = new ToolStripMenuItem();
                        connect.Text = "Open Connection";
                        connect.Tag = new QuickConnect(config, r["obj"]);
                        connect.Click += new EventHandler(QuickConnectClick);
                        item.DropDownItems.Add(connect);
                    }

                    menu.DropDownItems.Add(item);
                }
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:56,代码来源:fclsManager.cs


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