本文整理汇总了C#中IHttpContext.SetStatusToCreated方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpContext.SetStatusToCreated方法的具体用法?C# IHttpContext.SetStatusToCreated怎么用?C# IHttpContext.SetStatusToCreated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpContext
的用法示例。
在下文中一共展示了IHttpContext.SetStatusToCreated方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
var filename = match.Groups[1].Value;
var etag = context.GetEtag();
switch (context.Request.HttpMethod)
{
case "GET":
var attachmentAndHeaders = Database.GetStatic(filename);
if (attachmentAndHeaders == null)
{
context.SetStatusToNotFound();
return;
}
if (context.MatchEtag(attachmentAndHeaders.Etag))
{
context.SetStatusToNotModified();
return;
}
context.WriteData(attachmentAndHeaders.Data, attachmentAndHeaders.Metadata,
attachmentAndHeaders.Etag);
break;
case "PUT":
Database.PutStatic(filename, context.GetEtag(), context.Request.InputStream.ReadData(),
context.Request.Headers.FilterHeaders(isServerDocument:false));
context.SetStatusToCreated("/static/" + filename);
break;
case "DELETE":
Database.DeleteStatic(filename, etag);
context.SetStatusToDeleted();
break;
}
}
示例2: RespondToAdmin
public override void RespondToAdmin(IHttpContext context)
{
var backupRequest = context.ReadJsonObject<BackupRequest>();
var incrementalString = context.Request.QueryString["incremental"];
bool incrementalBackup;
if (bool.TryParse(incrementalString, out incrementalBackup) == false)
incrementalBackup = false;
if (backupRequest.DatabaseDocument == null && Database.Name != null)
{
if (Database.Name.Equals(Constants.SystemDatabase, StringComparison.OrdinalIgnoreCase))
{
backupRequest.DatabaseDocument = new DatabaseDocument {Id = Constants.SystemDatabase};
}
else
{
var jsonDocument = SystemDatabase.Get("Raven/Databases/" + Database.Name, null);
if (jsonDocument != null)
{
backupRequest.DatabaseDocument = jsonDocument.DataAsJson.JsonDeserialization<DatabaseDocument>();
server.Unprotect(backupRequest.DatabaseDocument);
backupRequest.DatabaseDocument.Id = Database.Name;
}
}
}
Database.StartBackup(backupRequest.BackupLocation, incrementalBackup, backupRequest.DatabaseDocument);
context.SetStatusToCreated(BackupStatus.RavenBackupStatusDocumentKey);
}
示例3: Put
private void Put(IHttpContext context, string docId)
{
var json = context.ReadJson();
context.SetStatusToCreated("/docs/" + docId);
var putResult = Database.Put(docId, context.GetEtag(), json, context.Request.Headers.FilterHeaders(isServerDocument: true), GetRequestTransaction(context));
context.WriteJson(putResult);
}
示例4: HandlePut
private void HandlePut(IHttpContext context, string transformer)
{
var data = context.ReadJsonObject<TransformerDefinition>();
if (data == null || string.IsNullOrEmpty(data.TransformResults))
{
context.SetStatusToBadRequest();
context.Write("Expected json document with 'TransformResults' property");
return;
}
try
{
var transformerName = Database.PutTransform(transformer, data);
context.SetStatusToCreated("/transformers");
context.WriteJson(new {Transformer = transformerName});
}
catch (Exception ex)
{
context.SetStatusToBadRequest();
context.WriteJson(new
{
Message = ex.Message,
Error = ex.ToString()
});
}
}
示例5: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
var filename = match.Groups[1].Value;
var etag = context.GetEtag();
switch (context.Request.HttpMethod)
{
case "GET":
Database.TransactionalStorage.Batch(_=> // have to keep the session open for reading of the attachment stream
{
var attachmentAndHeaders = Database.GetStatic(filename);
if (attachmentAndHeaders == null)
{
context.SetStatusToNotFound();
return;
}
if (context.MatchEtag(attachmentAndHeaders.Etag))
{
context.SetStatusToNotModified();
return;
}
context.WriteHeaders(attachmentAndHeaders.Metadata, attachmentAndHeaders.Etag);
using (var stream = attachmentAndHeaders.Data())
{
stream.CopyTo(context.Response.OutputStream);
}
});
break;
case "HEAD":
Database.TransactionalStorage.Batch(_ => // have to keep the session open for reading of the attachment stream
{
var attachmentAndHeaders = Database.GetStatic(filename);
if (attachmentAndHeaders == null)
{
context.SetStatusToNotFound();
return;
}
if (context.MatchEtag(attachmentAndHeaders.Etag))
{
context.SetStatusToNotModified();
return;
}
context.WriteHeaders(attachmentAndHeaders.Metadata, attachmentAndHeaders.Etag);
context.Response.ContentLength64 = attachmentAndHeaders.Size;
});
break;
case "PUT":
var newEtag = Database.PutStatic(filename, context.GetEtag(), context.Request.InputStream,
context.Request.Headers.FilterHeaders(isServerDocument:false));
context.WriteETag(newEtag);
context.SetStatusToCreated("/static/" + filename);
break;
case "DELETE":
Database.DeleteStatic(filename, etag);
context.SetStatusToDeleted();
break;
}
}
示例6: RespondToAdmin
public override void RespondToAdmin(IHttpContext context)
{
var backupRequest = context.ReadJsonObject<BackupRequest>();
var incrementalString = context.Request.QueryString["incremental"];
bool incrementalBackup;
if (bool.TryParse(incrementalString, out incrementalBackup) == false)
incrementalBackup = false;
Database.StartBackup(backupRequest.BackupLocation, incrementalBackup, backupRequest.DatabaseDocument);
context.SetStatusToCreated(BackupStatus.RavenBackupStatusDocumentKey);
}
示例7: Put
private void Put(IHttpContext context, string index)
{
var data = context.ReadJsonObject<IndexDefinition>();
if (data == null || (data.Map == null && (data.Maps == null || data.Maps.Count == 0)))
{
context.SetStatusToBadRequest();
context.Write("Expected json document with 'Map' or 'Maps' property");
return;
}
context.SetStatusToCreated("/indexes/" + index);
context.WriteJson(new { Index = Database.PutIndex(index, data) });
}
示例8: RespondToAdmin
public override void RespondToAdmin(IHttpContext context)
{
var backupRequest = context.ReadJsonObject<BackupRequest>();
var incrementalString = context.Request.QueryString["incremental"];
bool incrementalBackup;
if (bool.TryParse(incrementalString, out incrementalBackup) == false)
incrementalBackup = false;
if (backupRequest.DatabaseDocument == null)
{
backupRequest.DatabaseDocument = SystemDatabase.Get("Raven/Databases/" + Database.Name, null).DataAsJson.JsonDeserialization<DatabaseDocument>();
}
Database.StartBackup(backupRequest.BackupLocation, incrementalBackup, backupRequest.DatabaseDocument);
context.SetStatusToCreated(BackupStatus.RavenBackupStatusDocumentKey);
}
示例9: Respond
public override void Respond(IHttpContext context)
{
switch (context.Request.HttpMethod)
{
case "GET":
long documentsCount = 0;
Etag lastDocEtag = Etag.Empty;
Database.TransactionalStorage.Batch(accessor =>
{
lastDocEtag = accessor.Staleness.GetMostRecentDocumentEtag();
documentsCount = accessor.Documents.GetDocumentsCount();
});
lastDocEtag = lastDocEtag.HashWith(BitConverter.GetBytes(documentsCount));
if (context.MatchEtag(lastDocEtag))
{
context.SetStatusToNotModified();
}
else
{
context.WriteHeaders(new RavenJObject(), lastDocEtag);
using (var cts = new CancellationTokenSource())
{
cts.TimeoutAfter(Settings.DatbaseOperationTimeout);
var startsWith = context.Request.QueryString["startsWith"];
if (string.IsNullOrEmpty(startsWith))
context.WriteJson(Database.GetDocuments(context.GetStart(), context.GetPageSize(Database.Configuration.MaxPageSize), context.GetEtagFromQueryString(), cts.Token));
else
context.WriteJson(Database.GetDocumentsWithIdStartingWith(
startsWith,
context.Request.QueryString["matches"],
context.Request.QueryString["exclude"],
context.GetStart(),
context.GetPageSize(Database.Configuration.MaxPageSize),
cts.Token));
}
}
break;
case "POST":
var json = context.ReadJson();
var id = Database.Put(null, Etag.Empty, json,
context.Request.Headers.FilterHeaders(),
GetRequestTransaction(context));
context.SetStatusToCreated("/docs/" + Uri.EscapeUriString(id.Key));
context.WriteJson(id);
break;
}
}
示例10: Respond
public override void Respond(IHttpContext context)
{
switch (context.Request.HttpMethod)
{
case "GET":
long documentsCount = 0;
Guid lastDocEtag = Guid.Empty;
Database.TransactionalStorage.Batch(accessor =>
{
lastDocEtag = accessor.Staleness.GetMostRecentDocumentEtag();
documentsCount = accessor.Documents.GetDocumentsCount();
});
var array = lastDocEtag.ToByteArray().Concat(BitConverter.GetBytes(documentsCount)).ToArray();
using (var md5 = MD5.Create())
{
var hashed = md5.ComputeHash(array);
lastDocEtag = new Guid(hashed);
}
if (context.MatchEtag(lastDocEtag))
{
context.SetStatusToNotModified();
}
else
{
context.WriteHeaders(new RavenJObject(), lastDocEtag);
var startsWith = context.Request.QueryString["startsWith"];
if (string.IsNullOrEmpty(startsWith))
context.WriteJson(Database.GetDocuments(context.GetStart(), context.GetPageSize(Database.Configuration.MaxPageSize), context.GetEtagFromQueryString()));
else
context.WriteJson(Database.GetDocumentsWithIdStartingWith(
startsWith,
context.Request.QueryString["matches"],
context.GetStart(),
context.GetPageSize(Database.Configuration.MaxPageSize)));
}
break;
case "POST":
var json = context.ReadJson();
var id = Database.Put(null, Guid.Empty, json,
context.Request.Headers.FilterHeaders(),
GetRequestTransaction(context));
context.SetStatusToCreated("/docs/" + Uri.EscapeUriString(id.Key));
context.WriteJson(id);
break;
}
}
示例11: Respond
public override void Respond(IHttpContext context)
{
if(context.User.Identity.IsAuthenticated == false ||
context.User.IsInRole("Administrators"))
{
context.SetStatusToForbidden();
context.WriteJson(new
{
Error = "Only administrators can initiate a backup procedure"
});
}
var backupRequest = context.ReadJsonObject<BackupRequest>();
Database.StartBackup(backupRequest.BackupLocation);
context.SetStatusToCreated(BackupStatus.RavenBackupStatusDocumentKey);
}
示例12: Respond
public override void Respond(IHttpContext context)
{
if(context.IsAdministrator() == false)
{
context.SetStatusToUnauthorized();
context.WriteJson(new
{
Error = "Only administrators can initiate a backup procedure"
});
return;
}
var backupRequest = context.ReadJsonObject<BackupRequest>();
Database.StartBackup(backupRequest.BackupLocation);
context.SetStatusToCreated(BackupStatus.RavenBackupStatusDocumentKey);
}
示例13: Respond
public override void Respond(IHttpContext context)
{
switch (context.Request.HttpMethod)
{
case "GET":
context.WriteJson(Database.GetDocuments(context.GetStart(), context.GetPageSize(Database.Configuration.MaxPageSize), context.GetEtagFromQueryString()));
break;
case "POST":
var json = context.ReadJson();
var id = Database.Put(null, Guid.NewGuid(), json,
context.Request.Headers.FilterHeaders(isServerDocument: true),
GetRequestTransaction(context));
context.SetStatusToCreated("/docs/" + id);
context.WriteJson(id);
break;
}
}
示例14: Respond
public override void Respond(IHttpContext context)
{
if (context.User.IsAdministrator() == false)
{
context.SetStatusToUnauthorized();
context.WriteJson(new
{
Error = "Only administrators can initiate a backup procedure"
});
return;
}
var backupRequest = context.ReadJsonObject<BackupRequest>();
var incrementalString = context.Request.QueryString["incremental"];
bool incrementalBackup;
if (bool.TryParse(incrementalString, out incrementalBackup) == false)
incrementalBackup = false;
Database.StartBackup(backupRequest.BackupLocation, incrementalBackup);
context.SetStatusToCreated(BackupStatus.RavenBackupStatusDocumentKey);
}
示例15: Respond
public override void Respond(IHttpContext context)
{
switch (context.Request.HttpMethod)
{
case "GET":
Guid lastDocEtag = Guid.Empty;
Database.TransactionalStorage.Batch(accessor =>
{
lastDocEtag = accessor.Staleness.GetMostRecentDocumentEtag();
});
if (context.MatchEtag(lastDocEtag))
{
context.SetStatusToNotModified();
}
else
{
context.WriteHeaders(new RavenJObject(), lastDocEtag);
var startsWith = context.Request.QueryString["startsWith"];
if (string.IsNullOrEmpty(startsWith))
context.WriteJson(Database.GetDocuments(context.GetStart(), context.GetPageSize(Database.Configuration.MaxPageSize), context.GetEtagFromQueryString()));
else
context.WriteJson(Database.GetDocumentsWithIdStartingWith(
startsWith,
context.Request.QueryString["matches"],
context.GetStart(),
context.GetPageSize(Database.Configuration.MaxPageSize)));
}
break;
case "POST":
var json = context.ReadJson();
var id = Database.Put(null, Guid.Empty, json,
context.Request.Headers.FilterHeaders(),
GetRequestTransaction(context));
context.SetStatusToCreated("/docs/" + Uri.EscapeUriString(id.Key));
context.WriteJson(id);
break;
}
}