Example #1
0
        /// <summary>
        /// Parses <paramref name="format"/> into a <see cref="FileContentInfo"/> object.
        ///
        /// The value  must correspond to the format defined by the <see cref="Render"/> method
        /// or <see cref="ContractException"/> is thrown.
        /// </summary>
        public static FileContentInfo Parse(string format)
        {
            Contract.Requires(format != null);

            string[] splits = format.Split(new[] { RenderSeparator }, StringSplitOptions.None);
            if (splits.Length != 2)
            {
                throw Contract.AssertFailure(I($"Invalid format: expected '{RenderSeparator}' to divide '{format}' into exactly 2 parts."));
            }

            ContentHash hash;

            if (!ContentHash.TryParse(splits[0], out hash))
            {
                throw Contract.AssertFailure(I($"Invalid ContentHash format: '{splits[0]}'"));
            }

            long lengthAndExistence;

            if (!long.TryParse(splits[1], out lengthAndExistence))
            {
                throw Contract.AssertFailure(I($"Invalid file length format: '{splits[1]}'"));
            }

            return(new FileContentInfo(hash, LengthAndExistence.Deserialize(lengthAndExistence)));
        }
Example #2
0
        /// <summary>
        /// Creates a <see cref="FileContentInfo"/> with real USN version information.
        /// </summary>
        public FileContentInfo(ContentHash hash, long length)
        {
            Contract.Requires(length >= 0);

            m_lengthAndExistence = new LengthAndExistence(
                length,
                // if the length is valid, assign the existence value
                IsValidLength(length, hash)
                    ? PathExistence.ExistsAsFile
                    : (PathExistence?)null);

            Hash = hash;
        }
Example #3
0
 /// <summary>
 /// Creates a <see cref="FileContentInfo"/> using a combined existence/length value.
 /// </summary>
 /// <remarks>
 /// Mainly used for deserialization and files with unknown length.
 /// </remarks>
 public FileContentInfo(ContentHash hash, LengthAndExistence lengthAndExistence)
 {
     m_lengthAndExistence = lengthAndExistence;
     Hash = hash;
 }