public async virtual Task <IActionResult> Index([FromBody] BulkParameter bulk) { var json = JsonConvert.SerializeObject(bulk); _logger.LogInformation(string.Format(Global.StartBulk, json)); try { CheckParameter(bulk); var size = ASCIIEncoding.ASCII.GetByteCount(json.ToString()); if (bulk.Operations.Count() > _options.MaxOperations || size > _options.MaxPayloadSize) { throw new SCIMTooManyBulkOperationsException(); } var taskLst = new List <Task <JObject> >(); foreach (var patchOperation in bulk.Operations) { taskLst.Add(ExecuteBulkOperation(patchOperation)); } var taskResult = await Task.WhenAll(taskLst); var result = new JObject { { StandardSCIMRepresentationAttributes.Schemas, new JArray(new [] { StandardSchemas.BulkResponseSchemas.Id }) }, { StandardSCIMRepresentationAttributes.Operations, new JArray(taskResult) } }; return(new ContentResult { StatusCode = (int)HttpStatusCode.OK, Content = result.ToString(), ContentType = SCIMConstants.STANDARD_SCIM_CONTENT_TYPE }); } catch (SCIMBadSyntaxException ex) { _logger.LogError(ex, ex.Message); return(this.BuildError(HttpStatusCode.BadRequest, ex.Message, SCIMConstants.ErrorSCIMTypes.InvalidSyntax)); } catch (SCIMTooManyBulkOperationsException ex) { _logger.LogError(ex, ex.Message); return(this.BuildError(HttpStatusCode.RequestEntityTooLarge, "{'maxOperations': " + _options.MaxOperations + ", 'maxPayloadSize': " + _options.MaxPayloadSize + " }.", SCIMConstants.ErrorSCIMTypes.TooLarge)); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(this.BuildError(HttpStatusCode.InternalServerError, ex.ToString(), SCIMConstants.ErrorSCIMTypes.InternalServerError)); } }
protected static void CheckParameter(BulkParameter bulkParameter) { var requestedSchemas = bulkParameter.Schemas; if (!requestedSchemas.Any()) { throw new SCIMBadSyntaxException(string.Format(Global.AttributeMissing, StandardSCIMRepresentationAttributes.Schemas)); } if (!new List <string> { StandardSchemas.BulkRequestSchemas.Id }.SequenceEqual(requestedSchemas)) { throw new SCIMBadSyntaxException(Global.SchemasNotRecognized); } if (bulkParameter.Operations == null) { throw new SCIMBadSyntaxException(string.Format(Global.AttributeMissing, StandardSCIMRepresentationAttributes.Operations)); } }