/// <summary>
        /// Constructs a <see cref="LockToken"/> based on the <paramref name="absoluteUri"/>.
        /// </summary>
        /// <param name="absoluteUri">The lock token in absolute-URI format as defined in https://tools.ietf.org/html/rfc3986#section-4.3.</param>
        /// <remarks>Use the strong-typed constructors to create a new <see cref="LockToken"/>.</remarks>
        /// <exception cref="WebDavException">Thrown when <paramref name="absoluteUri"/> is null.</exception>
        public LockToken(AbsoluteUri absoluteUri)
        {
            AbsoluteUri = absoluteUri ?? throw new WebDavException($"The {nameof(absoluteUri)} cannot be null.");

            var codedUrl = new CodedUrl(absoluteUri);

            LockTokenHeaderFormat   = codedUrl;
            IfHeaderNoTagListFormat = new NoTagList(codedUrl);
        }
示例#2
0
        /// <summary>
        /// Tries to parse the given <paramref name="rawCodedUrl"/> to a <see cref="CodedUrl"/>.
        /// See <see href="https://tools.ietf.org/html/rfc4918#section-10.1"/> for the Coded-URL definition.
        /// </summary>
        /// <param name="rawCodedUrl">The raw coded URL to parse into the <see cref="CodedUrl"/>.</param>
        /// <param name="codedUrl">The <see cref="CodedUrl"/>.</param>
        /// <returns>The parsed <see cref="CodedUrl"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="rawCodedUrl"/> is null.</exception>
        public static bool TryParse(string rawCodedUrl, out CodedUrl codedUrl)
        {
            if (rawCodedUrl == null)
            {
                throw new ArgumentNullException(nameof(rawCodedUrl));
            }

            if (!rawCodedUrl.StartsWith(CodedUrlPrefix.ToString()) || !rawCodedUrl.EndsWith(CodedUrlPostfix.ToString()))
            {
                codedUrl = null;
                return(false);
            }

            var rawAbsoluteUri = rawCodedUrl.Trim(CodedUrlPrefix, CodedUrlPostfix);

            if (AbsoluteUri.TryParse(rawAbsoluteUri, out var absoluteUri))
            {
                codedUrl = new CodedUrl(absoluteUri);
                return(true);
            }

            codedUrl = null;
            return(false);
        }
 /// <summary>
 /// Constructs a No Tag List based on the <paramref name="codedUrl"/>.
 /// See <see href="https://tools.ietf.org/html/rfc4918#section-10.4.2"/> for the No Tag List definition.
 /// </summary>
 /// <param name="codedUrl">The coded-URL for this No-Tag list.</param>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="codedUrl"/> is null.</exception>
 internal NoTagList(CodedUrl codedUrl)
 {
     CodedUrl = codedUrl ?? throw new ArgumentNullException(nameof(codedUrl));
 }