public IEnumerable <IOperationAsync> Process(IEnumerable <IOperationAsync> operations) { operations = operations.ToList(); if (operations.Any() && _pipelineData.SelectedResource == null) { throw new InvalidOperationException( $"Null resource detected when there are operations for {_context.Request.Uri}"); } var selectedOperations = new List <IOperationAsync>(); var selectedResourceUriTemplateParameters = _pipelineData.SelectedResource.UriTemplateParameters.ToList(); foreach (var operation in operations) { if (IsEmpty(selectedResourceUriTemplateParameters)) { LogAcceptNoUriParameters(operation); selectedOperations.Add(operation); continue; } foreach (var uriParameterMatches in selectedResourceUriTemplateParameters) { var uriParametersCopy = new NameValueCollection(uriParameterMatches); var matchedParameters = ( from member in operation.Inputs from matchedParameterName in uriParametersCopy.AllKeys where TrySetPropertyAndRemoveUsedKey(member, matchedParameterName, uriParametersCopy, ConvertFromString) select matchedParameterName).ToList(); if (matchedParameters.Count != uriParameterMatches.Count) { continue; } LogOperationAccepted(uriParameterMatches, operation); selectedOperations.Add(operation); } } LogAcceptedCount(selectedOperations.Count); if (selectedOperations.Count == 0) { Errors.AddServerError(CreateErrorNoOperationFound(selectedResourceUriTemplateParameters)); } return(selectedOperations); }
public IEnumerable <IOperationAsync> Process(IEnumerable <IOperationAsync> operations) { int acceptedMethods = 0; foreach (var operation in operations) { if (IsEmpty(_pipelineData.SelectedResource.UriTemplateParameters)) { LogAcceptNoUriParameters(operation); acceptedMethods++; yield return(operation); continue; } foreach (var uriParameterMatches in _pipelineData.SelectedResource.UriTemplateParameters) { var uriParametersCopy = new NameValueCollection(uriParameterMatches); var matchedParameters = from member in operation.Inputs from matchedParameterName in uriParametersCopy.AllKeys where TrySetPropertyAndRemoveUsedKey(member, matchedParameterName, uriParametersCopy, ConvertFromString) select matchedParameterName; if (matchedParameters.Count() == uriParameterMatches.Count) { LogOperationAccepted(uriParameterMatches, operation); acceptedMethods++; yield return(operation); } } } LogAcceptedCount(acceptedMethods); if (acceptedMethods <= 0) { Errors.AddServerError(CreateErrorNoOperationFound(_pipelineData.SelectedResource.UriTemplateParameters)); } }