Exemplo n.º 1
0
        /// <summary>
        /// Sends a patch operation to the server.
        /// </summary>
        /// <param name="patch">The patch containing the information to be patched.</param>
        /// <returns>Returns the updated version GUID.</returns>
        public Guid Patch(Patch patch)
        {
            if (patch == null)
            {
                throw new ArgumentNullException(nameof(patch));
            }

            if (patch.AppliesTo == null)
            {
                throw new InvalidOperationException();
            }

            // Resource name
            string resourceName = patch.AppliesTo.Type.GetTypeInfo().GetCustomAttribute <XmlTypeAttribute>().TypeName;

            // First we determine which resource we're patching patch
            var tag = patch.AppliesTo.Tag;
            var key = patch.AppliesTo.Key;

            var sPatch = patch.Clone() as Patch;

            sPatch.AppliesTo = null;

            var version = this.Client.Patch <Patch>($"{resourceName}/{key.Value}", this.Client.Accept, tag, sPatch);

            return(Guid.ParseExact(version, "N"));
        }