示例#1
0
        public CommitPointsModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider permissionsProvider)
        {
            this.RequiresBrightstarStorePermission(permissionsProvider, get: StorePermissions.ViewHistory, post: StorePermissions.Admin);

            Get["/{storeName}/commits"] = parameters =>
            {
                int      skip      = Request.Query["skip"].TryParse <int>(0);
                int      take      = Request.Query["take"].TryParse <int>(DefaultPageSize);
                DateTime timestamp = Request.Query["timestamp"].TryParse <DateTime>();
                DateTime earliest  = Request.Query["earliest"].TryParse <DateTime>();
                DateTime latest    = Request.Query["latest"].TryParse <DateTime>();

                var request = this.Bind <CommitPointsRequestModel>();
                ViewBag.Title = request.StoreName + " - Commit History";

                if (timestamp != default(DateTime))
                {
                    // Request for a single commit point
                    var commitPoint = brightstarService.GetCommitPoint(parameters["storeName"], timestamp);
                    return(commitPoint == null ? HttpStatusCode.NotFound : MakeResponseObject(commitPoint));
                }
                if (earliest != default(DateTime) && latest != default(DateTime))
                {
                    IEnumerable <ICommitPointInfo> results =
                        brightstarService.GetCommitPoints(parameters["storeName"], latest, earliest, skip, take + 1);
                    var resourceUri = String.Format("commits?latest={0}&earliest={1}", latest.ToString("s"), earliest.ToString("s"));
                    return(Negotiate.WithPagedList(request, results.Select(MakeResponseObject), skip, take, DefaultPageSize, resourceUri));
                }
                IEnumerable <ICommitPointInfo> commitPointInfos = brightstarService.GetCommitPoints(parameters["storeName"], skip, take + 1);
                return(Negotiate.WithPagedList(request, commitPointInfos.Select(MakeResponseObject), skip, take, DefaultPageSize, "commits"));
            };

            Post["/{storeName}/commits"] = parameters =>
            {
                var commitPoint = this.Bind <CommitPointResponseModel>();
                if (commitPoint == null ||
                    String.IsNullOrEmpty(commitPoint.StoreName) ||
                    !commitPoint.StoreName.Equals(parameters["storeName"]))
                {
                    return(HttpStatusCode.BadRequest);
                }

                var commitPointInfo = brightstarService.GetCommitPoint(parameters["storeName"], commitPoint.Id);
                if (commitPointInfo == null)
                {
                    return(HttpStatusCode.BadRequest);
                }

                brightstarService.RevertToCommitPoint(parameters["storeName"], commitPointInfo);
                return(HttpStatusCode.OK);
            };
        }
        public CommitPointsModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider permissionsProvider)
        {
            this.RequiresBrightstarStorePermission(permissionsProvider, get:StorePermissions.ViewHistory, post:StorePermissions.Admin);

            Get["/{storeName}/commits"] = parameters =>
                {
                    int skip = Request.Query["skip"].TryParse<int>(0);
                    int take = Request.Query["take"].TryParse<int>(DefaultPageSize);
                    DateTime timestamp = Request.Query["timestamp"].TryParse<DateTime>();
                    DateTime earliest = Request.Query["earliest"].TryParse<DateTime>();
                    DateTime latest = Request.Query["latest"].TryParse<DateTime>();

                    var request = this.Bind<CommitPointsRequestModel>();
                    ViewBag.Title = request.StoreName + " - Commit History";
                    
                    if (timestamp != default(DateTime))
                    {
                        // Request for a single commit point
                        var commitPoint = brightstarService.GetCommitPoint(parameters["storeName"], timestamp);
                        return commitPoint == null ? HttpStatusCode.NotFound : MakeResponseObject(commitPoint);
                    }
                    if (earliest != default(DateTime) && latest != default(DateTime))
                    {
                        IEnumerable<ICommitPointInfo> results =
                            brightstarService.GetCommitPoints(parameters["storeName"], latest, earliest, skip, take + 1);
                        var resourceUri = String.Format("commits?latest={0}&earliest={1}", latest.ToString("s"), earliest.ToString("s"));
                        return Negotiate.WithPagedList(request, results.Select(MakeResponseObject), skip, take, DefaultPageSize, resourceUri);
                    }
                    IEnumerable<ICommitPointInfo> commitPointInfos = brightstarService.GetCommitPoints(parameters["storeName"], skip, take + 1);
                    return Negotiate.WithPagedList(request, commitPointInfos.Select(MakeResponseObject), skip, take, DefaultPageSize, "commits");
                };

            Post["/{storeName}/commits"] = parameters =>
                {
                    var commitPoint = this.Bind<CommitPointResponseModel>();
                    if (commitPoint == null ||
                        String.IsNullOrEmpty(commitPoint.StoreName) ||
                        !commitPoint.StoreName.Equals(parameters["storeName"]))
                    {
                        return HttpStatusCode.BadRequest;
                    }

                    var commitPointInfo = brightstarService.GetCommitPoint(parameters["storeName"], commitPoint.Id);
                    if (commitPointInfo == null) return HttpStatusCode.BadRequest;

                    brightstarService.RevertToCommitPoint(parameters["storeName"], commitPointInfo);
                    return HttpStatusCode.OK;
                };
        }
 public Stream GetResultsStream(SparqlResultsFormat format, RdfFormat graphFormat, DateTime?ifNotModifiedSince, out ISerializationFormat streamFormat)
 {
     if (_commitId > 0)
     {
         var commitPointInfo = _service.GetCommitPoint(_storeName, _commitId);
         if (commitPointInfo == null)
         {
             throw new InvalidCommitPointException();
         }
         return(_service.ExecuteQuery(commitPointInfo, _sparqlRequest.Query, _sparqlRequest.DefaultGraphUri, format, graphFormat, out streamFormat));
     }
     return(_service.ExecuteQuery(_storeName, _sparqlRequest.Query, _sparqlRequest.DefaultGraphUri, ifNotModifiedSince, format, graphFormat, out streamFormat));
 }
示例#4
0
        public JobsModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider permissionsProvider)
        {
            this.RequiresBrightstarStorePermissionData(permissionsProvider);

            Get["/{storeName}/jobs"] = parameters =>
                {
                    var jobsRequestObject = this.Bind<JobsRequestModel>();
                    ViewBag.Title = jobsRequestObject.StoreName + " - Jobs";
                    if (jobsRequestObject == null || jobsRequestObject.StoreName == null)
                    {
                        return HttpStatusCode.BadRequest;
                    }
                    if (jobsRequestObject.Take <= 0) jobsRequestObject.Take = DefaultPageSize;
                    var jobs = brightstarService.GetJobInfo(jobsRequestObject.StoreName, jobsRequestObject.Skip,
                                                            jobsRequestObject.Take + 1);
                    return Negotiate.WithPagedList(jobsRequestObject,
                                                   jobs.Select(j=>j.MakeResponseObject(jobsRequestObject.StoreName)),
                                                   jobsRequestObject.Skip, jobsRequestObject.Take, DefaultPageSize,
                                                   "jobs");
                };

            Get["/{storeName}/jobs/{jobId}"] = parameters =>
                {
                    var request = this.Bind<JobRequestModel>();
                    if (request == null ||
                        request.StoreName == null ||
                        request.JobId == null)
                    {
                        return HttpStatusCode.BadRequest;
                    }
                    ViewBag.Title = request.StoreName + " - Job - " + request.JobId;
                    var job = brightstarService.GetJobInfo(request.StoreName, request.JobId);
                    if (job == null) return HttpStatusCode.NotFound;
                    var responseDto = job.MakeResponseObject(request.StoreName);
                    return responseDto;
                };

            Post["/{storeName}/jobs"] = parameters =>
                {
                    var jobRequestObject = this.Bind<JobRequestObject>();
                    ViewBag.Title = jobRequestObject.StoreName + "- Jobs";
                    // Validate
                    if (jobRequestObject == null) return HttpStatusCode.BadRequest;
                    if (String.IsNullOrWhiteSpace(jobRequestObject.JobType)) return HttpStatusCode.BadRequest;

                    var storeName = parameters["storeName"];
                    var label = jobRequestObject.Label;
                    try
                    {
                        IJobInfo queuedJobInfo;
                        switch (jobRequestObject.JobType.ToLowerInvariant())
                        {
                            case "consolidate":
                                AssertPermission(StorePermissions.Admin);
                                queuedJobInfo = brightstarService.ConsolidateStore(storeName, label);
                                break;

                            case "createsnapshot":
                                AssertPermission(StorePermissions.Admin);
                                PersistenceType persistenceType;

                                // Validate TargetStoreName and PersistenceType parameters
                                if (!jobRequestObject.JobParameters.ContainsKey("TargetStoreName") ||
                                    String.IsNullOrWhiteSpace(jobRequestObject.JobParameters["TargetStoreName"]) ||
                                    !jobRequestObject.JobParameters.ContainsKey("PersistenceType") ||
                                    !Enum.TryParse(jobRequestObject.JobParameters["PersistenceType"],
                                                   out persistenceType))
                                {
                                    return HttpStatusCode.BadRequest;
                                }
                                // Extract optional commit point parameter
                                ICommitPointInfo commitPoint = null;
                                if (jobRequestObject.JobParameters.ContainsKey("CommitId"))
                                {
                                    ulong commitId;
                                    if (!UInt64.TryParse(jobRequestObject.JobParameters["CommitId"], out commitId))
                                    {
                                        return HttpStatusCode.BadRequest;
                                    }
                                    commitPoint = brightstarService.GetCommitPoint(storeName, commitId);
                                    if (commitPoint == null)
                                    {
                                        return HttpStatusCode.BadRequest;
                                    }
                                }

                                // Execute
                                queuedJobInfo = brightstarService.CreateSnapshot(
                                    storeName, jobRequestObject.JobParameters["TargetStoreName"],
                                    persistenceType, commitPoint, label);
                                break;

                            case "export":
                                AssertPermission(StorePermissions.Export);
                                if (!jobRequestObject.JobParameters.ContainsKey("FileName") ||
                                    String.IsNullOrWhiteSpace(jobRequestObject.JobParameters["FileName"]))
                                {
                                    return HttpStatusCode.BadRequest;
                                }
                                RdfFormat format = jobRequestObject.JobParameters.ContainsKey("Format")
                                                       ? RdfFormat.GetResultsFormat(
                                                           jobRequestObject.JobParameters["Format"])
                                                       : RdfFormat.NQuads;

                                queuedJobInfo = brightstarService.StartExport(
                                    storeName,
                                    jobRequestObject.JobParameters["FileName"],
                                    jobRequestObject.JobParameters.ContainsKey("GraphUri") ? jobRequestObject.JobParameters["GraphUri"] : null,
                                    format,
                                    label);
                                break;

                            case "import":
                                AssertPermission(StorePermissions.TransactionUpdate);
                                if (!jobRequestObject.JobParameters.ContainsKey("FileName") ||
                                    String.IsNullOrWhiteSpace(jobRequestObject.JobParameters["FileName"]))
                                {
                                    return HttpStatusCode.BadRequest;
                                }
                                RdfFormat importFormat = null;
                                if (jobRequestObject.JobParameters.ContainsKey("ImportFormat"))
                                {
                                    importFormat = RdfFormat.GetResultsFormat(jobRequestObject.JobParameters["ImportFormat"]);
                                    if (importFormat == null) return HttpStatusCode.BadRequest;
                                }
                                queuedJobInfo = brightstarService.StartImport(
                                    storeName,
                                    jobRequestObject.JobParameters["FileName"],
                                    jobRequestObject.JobParameters.ContainsKey("DefaultGraphUri") ? jobRequestObject.JobParameters["DefaultGraphUri"] : Constants.DefaultGraphUri,
                                    label, 
                                    importFormat);
                                break;

                            case "repeattransaction":
                                AssertPermission(StorePermissions.Admin);
                                if (!jobRequestObject.JobParameters.ContainsKey("JobId") ||
                                    String.IsNullOrWhiteSpace(jobRequestObject.JobParameters["JobId"]))
                                {
                                    return HttpStatusCode.BadRequest;
                                }
                                Guid jobId;
                                if (!Guid.TryParse(jobRequestObject.JobParameters["JobId"], out jobId))
                                {
                                    return HttpStatusCode.BadRequest;
                                }
                                var transaction = brightstarService.GetTransaction(storeName, jobId);
                                if (transaction == null)
                                {
                                    return HttpStatusCode.BadRequest;
                                }
                                queuedJobInfo = brightstarService.ReExecuteTransaction(storeName, transaction, label);
                                break;

                            case "sparqlupdate":
                                AssertPermission(StorePermissions.SparqlUpdate);
                                if (!jobRequestObject.JobParameters.ContainsKey("UpdateExpression") ||
                                    String.IsNullOrWhiteSpace(jobRequestObject.JobParameters["UpdateExpression"]))
                                {
                                    return HttpStatusCode.BadRequest;
                                }
                                queuedJobInfo = brightstarService.ExecuteUpdate(
                                    storeName,
                                    jobRequestObject.JobParameters["UpdateExpression"],
                                    false,
                                    label);
                                break;

                            case "transaction":
                                AssertPermission(StorePermissions.TransactionUpdate);
                                var preconditions = jobRequestObject.JobParameters.ContainsKey("Preconditions")
                                                        ? jobRequestObject.JobParameters["Preconditions"]
                                                        : null;
                                var nonexistence =
                                    jobRequestObject.JobParameters.ContainsKey("NonexistencePreconditions")
                                        ? jobRequestObject.JobParameters["NonexistencePreconditions"]
                                        : null;
                                var deletePatterns = jobRequestObject.JobParameters.ContainsKey("Deletes")
                                                         ? jobRequestObject.JobParameters["Deletes"]
                                                         : null;
                                var insertTriples = jobRequestObject.JobParameters.ContainsKey("Inserts")
                                                        ? jobRequestObject.JobParameters["Inserts"]
                                                        : null;
                                var defaultGraphUri =
                                    jobRequestObject.JobParameters.ContainsKey("DefaultGraphUri") &&
                                    !String.IsNullOrEmpty(jobRequestObject.JobParameters["DefaultGraphUri"])
                                        ? jobRequestObject.JobParameters["DefaultGraphUri"]
                                        : null;

                                queuedJobInfo = brightstarService.ExecuteTransaction(
                                    storeName, new UpdateTransactionData
                                        {
                                            ExistencePreconditions = preconditions,
                                            NonexistencePreconditions = nonexistence,
                                            DeletePatterns = deletePatterns,
                                            InsertData = insertTriples,
                                            DefaultGraphUri = defaultGraphUri
                                        },
                                    false,
                                    label);
                                break;

                            case "updatestats":
                                AssertPermission(StorePermissions.Admin);
                                queuedJobInfo = brightstarService.UpdateStatistics(storeName, label);
                                break;

                            default:
                                return HttpStatusCode.BadRequest;
                        }

                        var jobUri = (string) storeName + "/jobs/" + queuedJobInfo.JobId;
                        return Negotiate.WithModel(new JobResponseModel
                            {
                                JobId = queuedJobInfo.JobId,
                                Label = queuedJobInfo.Label,
                                StatusMessage = queuedJobInfo.StatusMessage,
                                JobStatus = queuedJobInfo.GetJobStatusString(),
                                ExceptionInfo = queuedJobInfo.ExceptionInfo,
                                QueuedTime = queuedJobInfo.QueuedTime,
                                StartTime = queuedJobInfo.StartTime,
                                EndTime = queuedJobInfo.EndTime
                            })
                            .WithHeader("Location", jobUri)
                            .WithStatusCode(HttpStatusCode.Created);
                    }
                    catch (UnauthorizedAccessException)
                    {
                        return HttpStatusCode.Unauthorized;
                    }

                };
        }
示例#5
0
        public JobsModule(IBrightstarService brightstarService, AbstractStorePermissionsProvider permissionsProvider)
        {
            this.RequiresBrightstarStorePermissionData(permissionsProvider);

            Get["/{storeName}/jobs"] = parameters =>
            {
                var jobsRequestObject = this.Bind <JobsRequestModel>();
                if (jobsRequestObject == null || jobsRequestObject.StoreName == null)
                {
                    return(HttpStatusCode.BadRequest);
                }
                if (jobsRequestObject.Take <= 0)
                {
                    jobsRequestObject.Take = DefaultPageSize;
                }
                var jobs = brightstarService.GetJobInfo(jobsRequestObject.StoreName, jobsRequestObject.Skip,
                                                        jobsRequestObject.Take + 1);
                return(Negotiate.WithPagedList(jobsRequestObject,
                                               jobs.Select(j => j.MakeResponseObject(jobsRequestObject.StoreName)),
                                               jobsRequestObject.Skip, jobsRequestObject.Take, DefaultPageSize,
                                               "jobs"));
            };

            Get["/{storeName}/jobs/{jobId}"] = parameters =>
            {
                var request = this.Bind <JobRequestModel>();
                if (request == null ||
                    request.StoreName == null ||
                    request.JobId == null)
                {
                    return(HttpStatusCode.BadRequest);
                }
                var job = brightstarService.GetJobInfo(request.StoreName, request.JobId);
                if (job == null)
                {
                    return(HttpStatusCode.NotFound);
                }
                var responseDto = job.MakeResponseObject(request.StoreName);
                return(responseDto);
            };

            Post["/{storeName}/jobs"] = parameters =>
            {
                var jobRequestObject = this.Bind <JobRequestObject>();

                // Validate
                if (jobRequestObject == null)
                {
                    return(HttpStatusCode.BadRequest);
                }
                if (String.IsNullOrWhiteSpace(jobRequestObject.JobType))
                {
                    return(HttpStatusCode.BadRequest);
                }

                var storeName = parameters["storeName"];
                var label     = jobRequestObject.Label;
                try
                {
                    IJobInfo queuedJobInfo;
                    switch (jobRequestObject.JobType.ToLowerInvariant())
                    {
                    case "consolidate":
                        AssertPermission(StorePermissions.Admin);
                        queuedJobInfo = brightstarService.ConsolidateStore(storeName, label);
                        break;

                    case "createsnapshot":
                        AssertPermission(StorePermissions.Admin);
                        PersistenceType persistenceType;

                        // Validate TargetStoreName and PersistenceType parameters
                        if (!jobRequestObject.JobParameters.ContainsKey("TargetStoreName") ||
                            String.IsNullOrWhiteSpace(jobRequestObject.JobParameters["TargetStoreName"]) ||
                            !jobRequestObject.JobParameters.ContainsKey("PersistenceType") ||
                            !Enum.TryParse(jobRequestObject.JobParameters["PersistenceType"],
                                           out persistenceType))
                        {
                            return(HttpStatusCode.BadRequest);
                        }
                        // Extract optional commit point parameter
                        ICommitPointInfo commitPoint = null;
                        if (jobRequestObject.JobParameters.ContainsKey("CommitId"))
                        {
                            ulong commitId;
                            if (!UInt64.TryParse(jobRequestObject.JobParameters["CommitId"], out commitId))
                            {
                                return(HttpStatusCode.BadRequest);
                            }
                            commitPoint = brightstarService.GetCommitPoint(storeName, commitId);
                            if (commitPoint == null)
                            {
                                return(HttpStatusCode.BadRequest);
                            }
                        }

                        // Execute
                        queuedJobInfo = brightstarService.CreateSnapshot(
                            storeName, jobRequestObject.JobParameters["TargetStoreName"],
                            persistenceType, commitPoint, label);
                        break;

                    case "export":
                        AssertPermission(StorePermissions.Export);
                        if (!jobRequestObject.JobParameters.ContainsKey("FileName") ||
                            String.IsNullOrWhiteSpace(jobRequestObject.JobParameters["FileName"]))
                        {
                            return(HttpStatusCode.BadRequest);
                        }
                        RdfFormat format = jobRequestObject.JobParameters.ContainsKey("Format")
                                                       ? RdfFormat.GetResultsFormat(
                            jobRequestObject.JobParameters["Format"])
                                                       : RdfFormat.NQuads;

                        queuedJobInfo = brightstarService.StartExport(
                            storeName,
                            jobRequestObject.JobParameters["FileName"],
                            jobRequestObject.JobParameters.ContainsKey("GraphUri") ? jobRequestObject.JobParameters["GraphUri"] : null,
                            format,
                            label);
                        break;

                    case "import":
                        AssertPermission(StorePermissions.TransactionUpdate);
                        if (!jobRequestObject.JobParameters.ContainsKey("FileName") ||
                            String.IsNullOrWhiteSpace(jobRequestObject.JobParameters["FileName"]))
                        {
                            return(HttpStatusCode.BadRequest);
                        }
                        queuedJobInfo = brightstarService.StartImport(
                            storeName,
                            jobRequestObject.JobParameters["FileName"],
                            jobRequestObject.JobParameters.ContainsKey("DefaultGraphUri") ? jobRequestObject.JobParameters["DefaultGraphUri"] : Constants.DefaultGraphUri,
                            label);
                        break;

                    case "repeattransaction":
                        AssertPermission(StorePermissions.Admin);
                        if (!jobRequestObject.JobParameters.ContainsKey("JobId") ||
                            String.IsNullOrWhiteSpace(jobRequestObject.JobParameters["JobId"]))
                        {
                            return(HttpStatusCode.BadRequest);
                        }
                        Guid jobId;
                        if (!Guid.TryParse(jobRequestObject.JobParameters["JobId"], out jobId))
                        {
                            return(HttpStatusCode.BadRequest);
                        }
                        var transaction = brightstarService.GetTransaction(storeName, jobId);
                        if (transaction == null)
                        {
                            return(HttpStatusCode.BadRequest);
                        }
                        queuedJobInfo = brightstarService.ReExecuteTransaction(storeName, transaction, label);
                        break;

                    case "sparqlupdate":
                        AssertPermission(StorePermissions.SparqlUpdate);
                        if (!jobRequestObject.JobParameters.ContainsKey("UpdateExpression") ||
                            String.IsNullOrWhiteSpace(jobRequestObject.JobParameters["UpdateExpression"]))
                        {
                            return(HttpStatusCode.BadRequest);
                        }
                        queuedJobInfo = brightstarService.ExecuteUpdate(
                            storeName,
                            jobRequestObject.JobParameters["UpdateExpression"],
                            false,
                            label);
                        break;

                    case "transaction":
                        AssertPermission(StorePermissions.TransactionUpdate);
                        var preconditions = jobRequestObject.JobParameters.ContainsKey("Preconditions")
                                                        ? jobRequestObject.JobParameters["Preconditions"]
                                                        : null;
                        var nonexistence =
                            jobRequestObject.JobParameters.ContainsKey("NonexistencePreconditions")
                                        ? jobRequestObject.JobParameters["NonexistencePreconditions"]
                                        : null;
                        var deletePatterns = jobRequestObject.JobParameters.ContainsKey("Deletes")
                                                         ? jobRequestObject.JobParameters["Deletes"]
                                                         : null;
                        var insertTriples = jobRequestObject.JobParameters.ContainsKey("Inserts")
                                                        ? jobRequestObject.JobParameters["Inserts"]
                                                        : null;
                        var defaultGraphUri =
                            jobRequestObject.JobParameters.ContainsKey("DefaultGraphUri") &&
                            !String.IsNullOrEmpty(jobRequestObject.JobParameters["DefaultGraphUri"])
                                        ? jobRequestObject.JobParameters["DefaultGraphUri"]
                                        : null;

                        queuedJobInfo = brightstarService.ExecuteTransaction(
                            storeName, new UpdateTransactionData
                        {
                            ExistencePreconditions    = preconditions,
                            NonexistencePreconditions = nonexistence,
                            DeletePatterns            = deletePatterns,
                            InsertData      = insertTriples,
                            DefaultGraphUri = defaultGraphUri
                        },
                            false,
                            label);
                        break;

                    case "updatestats":
                        AssertPermission(StorePermissions.Admin);
                        queuedJobInfo = brightstarService.UpdateStatistics(storeName, label);
                        break;

                    default:
                        return(HttpStatusCode.BadRequest);
                    }

                    var jobUri = (string)storeName + "/jobs/" + queuedJobInfo.JobId;
                    return(Negotiate.WithModel(new JobResponseModel
                    {
                        JobId = queuedJobInfo.JobId,
                        Label = queuedJobInfo.Label,
                        StatusMessage = queuedJobInfo.StatusMessage,
                        JobStatus = queuedJobInfo.GetJobStatusString(),
                        ExceptionInfo = queuedJobInfo.ExceptionInfo,
                        QueuedTime = queuedJobInfo.QueuedTime,
                        StartTime = queuedJobInfo.StartTime,
                        EndTime = queuedJobInfo.EndTime
                    })
                           .WithHeader("Location", jobUri)
                           .WithStatusCode(HttpStatusCode.Created));
                }
                catch (UnauthorizedAccessException)
                {
                    return(HttpStatusCode.Unauthorized);
                }
            };
        }
        public void ExecuteQueryForHtml(DateTime?ifNotModifiedSince)
        {
            Stream resultsStream;

            // No query => no results rather than triggering an error
            if (String.IsNullOrEmpty(_sparqlRequest.Query))
            {
                HasFormattedResults = false;
                RawResults          = String.Empty;
                return;
            }

            try
            {
                if (_commitId > 0)
                {
                    var commitPointInfo = _service.GetCommitPoint(_storeName, _commitId);
                    if (commitPointInfo == null)
                    {
                        throw new InvalidCommitPointException();
                    }
                    resultsStream = _service.ExecuteQuery(commitPointInfo, _sparqlRequest.Query,
                                                          _sparqlRequest.DefaultGraphUri, ResultsFormat);
                }
                else
                {
                    resultsStream = _service.ExecuteQuery(_storeName, _sparqlRequest.Query,
                                                          _sparqlRequest.DefaultGraphUri,
                                                          ifNotModifiedSince, ResultsFormat);
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = FormatExceptionMessages(ex);
                return;
            }
            if (ResultsFormat == SparqlResultsFormat.Xml)
            {
                XDocument resultsDoc = XDocument.Load(resultsStream);
                HasFormattedResults = true;
                Variables           = resultsDoc.GetVariableNames().ToList();
                Rows = new List <object[]>();
                var varCount = Variables.Count;
                foreach (var resultRow in resultsDoc.SparqlResultRows())
                {
                    var row = new object[varCount];
                    for (int i = 0; i < varCount; i++)
                    {
                        row[i] = resultRow.GetColumnValue(Variables[i]);
                    }
                    Rows.Add(row);
                }
            }
            else
            {
                HasFormattedResults = false;
                using (var rdr = new StreamReader(resultsStream))
                {
                    RawResults = rdr.ReadToEnd();
                }
            }
        }