1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

Changed all C# control flow block statements to include space between keyword and open paren

This commit is contained in:
Chad Scharf
2020-03-27 14:36:37 -04:00
parent 943aea9a12
commit 9800b752c0
243 changed files with 2258 additions and 2258 deletions

View File

@ -10,15 +10,15 @@ namespace Bit.Api.Utilities
public async static Task<T> ReadJsonFileFromBody<T>(HttpContext httpContext, IFormFile file, long maxSize = 51200)
{
T obj = default(T);
if(file != null && httpContext.Request.ContentLength.HasValue && httpContext.Request.ContentLength.Value <= maxSize)
if (file != null && httpContext.Request.ContentLength.HasValue && httpContext.Request.ContentLength.Value <= maxSize)
{
try
{
using(var stream = file.OpenReadStream())
using(var reader = new StreamReader(stream))
using (var stream = file.OpenReadStream())
using (var reader = new StreamReader(stream))
{
var s = await reader.ReadToEndAsync();
if(!string.IsNullOrWhiteSpace(s))
if (!string.IsNullOrWhiteSpace(s))
{
obj = JsonConvert.DeserializeObject<T>(s);
}

View File

@ -20,7 +20,7 @@ namespace Bit.Api.Utilities
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
{
if(context.Result is JsonResult jsonResult)
if (context.Result is JsonResult jsonResult)
{
context.Result = new JsonResult(jsonResult.Value, _jsonSerializerSettings);
}

View File

@ -27,7 +27,7 @@ namespace Bit.Api.Utilities
var errorMessage = "An error has occurred.";
var exception = context.Exception;
if(exception == null)
if (exception == null)
{
// Should never happen.
return;
@ -35,12 +35,12 @@ namespace Bit.Api.Utilities
PublicApi.ErrorResponseModel publicErrorModel = null;
InternalApi.ErrorResponseModel internalErrorModel = null;
if(exception is BadRequestException badRequestException)
if (exception is BadRequestException badRequestException)
{
context.HttpContext.Response.StatusCode = 400;
if(badRequestException.ModelState != null)
if (badRequestException.ModelState != null)
{
if(_publicApi)
if (_publicApi)
{
publicErrorModel = new PublicApi.ErrorResponseModel(badRequestException.ModelState);
}
@ -54,11 +54,11 @@ namespace Bit.Api.Utilities
errorMessage = badRequestException.Message;
}
}
else if(exception is StripeException stripeException &&
else if (exception is StripeException stripeException &&
stripeException?.StripeError?.ErrorType == "card_error")
{
context.HttpContext.Response.StatusCode = 400;
if(_publicApi)
if (_publicApi)
{
publicErrorModel = new PublicApi.ErrorResponseModel(stripeException.StripeError.Parameter,
stripeException.Message);
@ -69,31 +69,31 @@ namespace Bit.Api.Utilities
stripeException.Message);
}
}
else if(exception is GatewayException)
else if (exception is GatewayException)
{
errorMessage = exception.Message;
context.HttpContext.Response.StatusCode = 400;
}
else if(exception is NotSupportedException && !string.IsNullOrWhiteSpace(exception.Message))
else if (exception is NotSupportedException && !string.IsNullOrWhiteSpace(exception.Message))
{
errorMessage = exception.Message;
context.HttpContext.Response.StatusCode = 400;
}
else if(exception is ApplicationException)
else if (exception is ApplicationException)
{
context.HttpContext.Response.StatusCode = 402;
}
else if(exception is NotFoundException)
else if (exception is NotFoundException)
{
errorMessage = "Resource not found.";
context.HttpContext.Response.StatusCode = 404;
}
else if(exception is SecurityTokenValidationException)
else if (exception is SecurityTokenValidationException)
{
errorMessage = "Invalid token.";
context.HttpContext.Response.StatusCode = 403;
}
else if(exception is UnauthorizedAccessException)
else if (exception is UnauthorizedAccessException)
{
errorMessage = "Unauthorized.";
context.HttpContext.Response.StatusCode = 401;
@ -106,7 +106,7 @@ namespace Bit.Api.Utilities
context.HttpContext.Response.StatusCode = 500;
}
if(_publicApi)
if (_publicApi)
{
var errorModel = publicErrorModel ?? new PublicApi.ErrorResponseModel(errorMessage);
context.Result = new ObjectResult(errorModel);
@ -115,7 +115,7 @@ namespace Bit.Api.Utilities
{
var errorModel = internalErrorModel ?? new InternalApi.ErrorResponseModel(errorMessage);
var env = context.HttpContext.RequestServices.GetRequiredService<IWebHostEnvironment>();
if(env.IsDevelopment())
if (env.IsDevelopment())
{
errorModel.ExceptionMessage = exception.Message;
errorModel.ExceptionStackTrace = exception.StackTrace;

View File

@ -18,14 +18,14 @@ namespace Bit.Api.Utilities
public override void OnActionExecuting(ActionExecutingContext context)
{
var model = context.ActionArguments.FirstOrDefault(a => a.Key == "model");
if(model.Key == "model" && model.Value == null)
if (model.Key == "model" && model.Value == null)
{
context.ModelState.AddModelError(string.Empty, "Body is empty.");
}
if(!context.ModelState.IsValid)
if (!context.ModelState.IsValid)
{
if(_publicApi)
if (_publicApi)
{
context.Result = new BadRequestObjectResult(new PublicApi.ErrorResponseModel(context.ModelState));
}

View File

@ -20,36 +20,36 @@ namespace Bit.Api.Utilities
var reader = new MultipartReader(boundary, request.Body);
var firstSection = await reader.ReadNextSectionAsync();
if(firstSection != null)
if (firstSection != null)
{
if(ContentDispositionHeaderValue.TryParse(firstSection.ContentDisposition, out var firstContent))
if (ContentDispositionHeaderValue.TryParse(firstSection.ContentDisposition, out var firstContent))
{
if(HasFileContentDisposition(firstContent))
if (HasFileContentDisposition(firstContent))
{
// Old style with just data
var fileName = HeaderUtilities.RemoveQuotes(firstContent.FileName).ToString();
using(firstSection.Body)
using (firstSection.Body)
{
await callback(firstSection.Body, fileName, null);
}
}
else if(HasKeyDisposition(firstContent))
else if (HasKeyDisposition(firstContent))
{
// New style with key, then data
string key = null;
using(var sr = new StreamReader(firstSection.Body))
using (var sr = new StreamReader(firstSection.Body))
{
key = await sr.ReadToEndAsync();
}
var secondSection = await reader.ReadNextSectionAsync();
if(secondSection != null)
if (secondSection != null)
{
if(ContentDispositionHeaderValue.TryParse(secondSection.ContentDisposition,
if (ContentDispositionHeaderValue.TryParse(secondSection.ContentDisposition,
out var secondContent) && HasFileContentDisposition(secondContent))
{
var fileName = HeaderUtilities.RemoveQuotes(secondContent.FileName).ToString();
using(secondSection.Body)
using (secondSection.Body)
{
await callback(secondSection.Body, fileName, key);
}
@ -67,12 +67,12 @@ namespace Bit.Api.Utilities
private static string GetBoundary(MediaTypeHeaderValue contentType, int lengthLimit)
{
var boundary = HeaderUtilities.RemoveQuotes(contentType.Boundary);
if(StringSegment.IsNullOrEmpty(boundary))
if (StringSegment.IsNullOrEmpty(boundary))
{
throw new InvalidDataException("Missing content-type boundary.");
}
if(boundary.Length > lengthLimit)
if (boundary.Length > lengthLimit)
{
throw new InvalidDataException($"Multipart boundary length limit {lengthLimit} exceeded.");
}

View File

@ -8,7 +8,7 @@ namespace Bit.Api.Utilities
{
var controllerNamespace = controller.ControllerType.Namespace;
var publicApi = controllerNamespace.Contains(".Public.");
if(publicApi)
if (publicApi)
{
controller.Filters.Add(new CamelCaseJsonResultFilterAttribute());
}