Inheritance: PropertyBagHolder, ISarifNode
Beispiel #1
0
        public static FileData Create(Uri uri, bool computeHashes)
        {
            if (uri == null) { throw new ArgumentNullException(nameof(uri)); }

            var fileData = new FileData()
            {
                MimeType = SarifWriters.MimeType.DetermineFromFileExtension(uri)
            };

            if (computeHashes && uri.IsAbsoluteUri && uri.IsFile)
            {
                HashData hashes = HashUtilities.ComputeHashes(uri.LocalPath);
                fileData.Hashes = new List<Hash>
                        {
                            new Hash()
                            {
                                Value = hashes.MD5,
                                Algorithm = AlgorithmKind.MD5,
                            },
                            new Hash()
                            {
                                Value = hashes.Sha1,
                                Algorithm = AlgorithmKind.Sha1,
                            },
                            new Hash()
                            {
                                Value = hashes.Sha256,
                                Algorithm = AlgorithmKind.Sha256,
                            },
                        };
            }

            return fileData;
        }
Beispiel #2
0
 public bool ValueEquals(FileData other) => ValueComparer.Equals(this, other);
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileData" /> class from the specified instance.
        /// </summary>
        /// <param name="other">
        /// The instance from which the new instance is to be initialized.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if <paramref name="other" /> is null.
        /// </exception>
        public FileData(FileData other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            Init(other.Uri, other.UriBaseId, other.ParentKey, other.Offset, other.Length, other.MimeType, other.Contents, other.Hashes, other.Properties);
        }
Beispiel #4
0
        public void FileData_Create_NullUri()
        {
            Action action = () => { FileData.Create(null, OptionallyEmittedData.None); };

            action.Should().Throw <ArgumentNullException>();
        }
Beispiel #5
0
 public bool ValueEquals(FileData other) => ValueComparer.Equals(this, other);