示例#1
0
        private IEnumerable <PatchOperationResult> ReplaceInternal(string path, object value, object objectToApplyTo, Operation operation)
        {
            var treeAnalysisResult = new ScimPatchObjectAnalysis(
                _ServerConfiguration,
                objectToApplyTo,
                path,
                ContractResolver,
                operation);

            if (treeAnalysisResult.ErrorType != null)
            {
                throw new ScimPatchException(
                          treeAnalysisResult.ErrorType,
                          operation);
            }

            var operations = new List <PatchOperationResult>();

            foreach (var patchMember in treeAnalysisResult.PatchMembers)
            {
                if (treeAnalysisResult.UseDynamicLogic)
                {
                    throw new NotSupportedException(); // TODO: (DG) Added support if needed.
                }
                else
                {
                    operations.AddRange(ReplaceNonDynamic(value, operation, patchMember));
                }
            }

            return(operations);
        }
示例#2
0
        /// <summary>
        /// The "remove" operation removes the value at the target location
        /// specified by the required attribute "path".
        /// </summary>
        /// <param name="operation"></param>
        /// <param name="objectToApplyTo"></param>
        /// <returns></returns>
        public IEnumerable <PatchOperationResult> Remove(Operation operation, object objectToApplyTo)
        {
            if (operation == null)
            {
                throw new ArgumentNullException("operation");
            }

            if (objectToApplyTo == null)
            {
                throw new ArgumentNullException("objectToApplyTo");
            }

            // o  If "path" is unspecified, the operation fails with HTTP status
            //    code 400 and a "scimType" error code of "noTarget".
            if (string.IsNullOrWhiteSpace(operation.Path))
            {
                throw new ScimPatchException(ScimErrorType.NoTarget, operation);
            }

            var treeAnalysisResult = new ScimPatchObjectAnalysis(
                _ServerConfiguration,
                objectToApplyTo,
                operation.Path,
                ContractResolver,
                operation);

            if (treeAnalysisResult.ErrorType != null)
            {
                throw new ScimPatchException(
                          treeAnalysisResult.ErrorType,
                          operation);
            }

            var operations = new List <PatchOperationResult>();

            foreach (var patchMember in treeAnalysisResult.PatchMembers)
            {
                if (treeAnalysisResult.UseDynamicLogic)
                {
                    throw new NotSupportedException(); // TODO: (DG) If actually needed.
                }
                else
                {
                    operations.Add(RemoveNonDynamic(operation, patchMember));
                }
            }

            return(operations);
        }
示例#3
0
        private IEnumerable <PatchOperationResult> AddInternal(
            string path,
            object value,
            object objectToApplyTo,
            Operation operation)
        {
            if (objectToApplyTo == null)
            {
                throw new ArgumentNullException("objectToApplyTo");
            }

            if (operation == null)
            {
                throw new ArgumentNullException("operation");
            }

            // ScimPatchObjectAnalysis.cs will handle resolving the actual
            // path to object members and parsing any filters.
            var patchAnalysis = new ScimPatchObjectAnalysis(
                _ServerConfiguration,
                objectToApplyTo,
                path,
                ContractResolver,
                operation);

            if (patchAnalysis.ErrorType != null)
            {
                throw new ScimPatchException(
                          patchAnalysis.ErrorType,
                          operation);
            }

            var operations = new List <PatchOperationResult>();

            foreach (var patchMember in patchAnalysis.PatchMembers)
            {
                if (patchAnalysis.UseDynamicLogic)
                {
                    throw new NotSupportedException(); // TODO: (DG) Add support if needed.
                }
                operations.AddRange(AddNonDynamic(value, operation, patchMember));
            }

            return(operations);
        }