示例#1
0
        public async Task <ActionResult> QueryResult(QueryInfo queryInfo)
        {
            if (queryInfo == null)
            {
                return(BadRequest());
            }
            ViewData[nameof(SearchInfo)] = queryInfo;
            object results;

            try
            {
                /*** validation ***/
                queryInfo.Validate();

                /*** query preparation ***/
                SparqlRemoteEndpoint endpoint = SearchPreparing.CreateEndpoint(queryInfo.Endpoints[0], queryInfo.Timeout, queryInfo.DefaultGraph);
                SparqlQuery          query    = QueryParsing.ParseQuery(queryInfo.QueryString);

                /*** query processing ***/
                results = await QueryProcessing.ProcessQuery(query, endpoint);

                //ViewData["ExecutionTime"] = query.QueryExecutionTime;
            }
            catch (BrowserException e)
            {
                return(View("QueryResultError", e.Message));
            }
            catch (Exception)
            {
                //TODO: better text
                return(View("QueryResultError", "Unknown error..."));
            }

            /*** result processing ***/
            if (results is SparqlResultSet)
            {
                return(View("QueryResultSet", (SparqlResultSet)results));
            }
            else if (results is IGraph)
            {
                return(View("QueryResultGraph", (IGraph)results));
            }
            else if (results is AsyncError)
            {
                return(View("QueryResultError", ErrorProcessing.ProcessAsyncError((AsyncError)results)));
            }
            else
            {
                //TODO: better text
                return(View("QueryResultError", "Unknown error..."));
            }
        }
示例#2
0
        private static async Task <Dictionary <string, int> > RetrievePopularPropertiesFromEndpoint()
        {
            string errorMessage = "";
            object results      = null;

            try
            {
                SparqlQuery          query    = QueryParsing.ParseQuery(QueryCreating.GetQueryTemplateCopy(QueryTemplates.SelectPopularProperties));
                SparqlRemoteEndpoint endpoint = SearchPreparing.CreateEndpoint(Config.LOV_SPARQL_ENDPOINT, Config.LOV_PREDICATES_SEARCH_TIMEOUT);
                results = await QueryProcessing.ProcessQuery(query, endpoint);
            }
            catch (BrowserException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new BrowserException("An unexpected error occured while retrieving the list of popular predicates.", e);
            }

            if (results is SparqlResultSet)
            {
                return(ResultSetToDictionary((SparqlResultSet)results));
            }
            else if (results is AsyncError)
            { /*TODO: remove exceptions */
                throw ((AsyncError)results).Error.InnerException;
                //errorMessage += ResultProcessing.ProcessAsyncError((AsyncError)results);
                //return null;
            }
            /*TODO: remove exceptions*/
            throw new Exception(errorMessage);

            //otherwise it should be null and errorMessage should be already set
            //return null;
        }