Esempio n. 1
0
        /// <summary>Serves as a hash function for a particular type.</summary>
        /// <returns>A hash code for the current Object.</returns>
        public override int GetHashCode()
        {
            string fullName = FullName;
            string name     = Name;

            unchecked
            {
                int hash = Primes[_random];

                if (!Utils.IsNullOrWhiteSpace(fullName))
                {
                    hash = hash * Primes[1] + fullName.GetHashCode();
                }

                if (!Utils.IsNullOrWhiteSpace(name))
                {
                    hash = hash * Primes[1] + name.GetHashCode();
                }

                hash = hash * Primes[1] + Attributes.GetHashCode();
                hash = hash * Primes[1] + CreationTimeUtc.GetHashCode();
                hash = hash * Primes[1] + LastWriteTimeUtc.GetHashCode();

                return(hash);
            }
        }
Esempio n. 2
0
 public override bool Equals(object?obj)
 {
     return(obj is BlobReference other &&
            Name == other.Name &&
            LastWriteTimeUtc.Equals(other.LastWriteTimeUtc) &&
            Nonce.SequenceEqual(other.Nonce) &&
            ContentUris.SequenceEqual(other.ContentUris));
 }
 public bool Equals(DuplicateFileModel other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(LastWriteTime.Equals(other.LastWriteTime) && LastAccessTimeUtc.Equals(other.LastAccessTimeUtc) && LastAccessTime.Equals(other.LastAccessTime) && CreationTimeUtc.Equals(other.CreationTimeUtc) &&
            CreationTime.Equals(other.CreationTime) && LastWriteTimeUtc.Equals(other.LastWriteTimeUtc) && string.Equals(FullName, other.FullName) && string.Equals(Name, other.Name) && string.Equals(HashValue, other.HashValue) &&
            string.Equals(UniqueIdHashValue, other.UniqueIdHashValue) && IsMaster == other.IsMaster && Equals(DuplicateFiles, other.DuplicateFiles) && FileSize == other.FileSize);
 }
Esempio n. 4
0
        public override void ReuseSha256s(IFile matching)
        {
            if (Name.Equals(matching.Name, StringComparison.Ordinal) &&
                CreationTimeUtc.Equals(matching.CreationTimeUtc) &&
                LastWriteTimeUtc.Equals(matching.LastWriteTimeUtc) &&
                SizeBytes == matching.SizeBytes)
            {
                _Sha256 = matching.Sha256;
            }

            else
            {
                _Sha256 = null;
            }
        }
 public override int GetHashCode() => LastWriteTimeUtc.GetHashCode();
 public override string ToString()
 {
     return($"{Path.GetFileName(FilePath)}, {LastWriteTimeUtc.ToString("u")}, {Hash}");
 }
Esempio n. 7
0
        /// <summary>
        /// Returns a byte array representing the current <see cref="SftpFileAttributes"/>.
        /// </summary>
        /// <returns>
        /// A byte array representing the current <see cref="SftpFileAttributes"/>.
        /// </returns>
        public byte[] GetBytes()
        {
            var stream = new SshDataStream(4);

            uint flag = 0;

            if (IsSizeChanged && IsRegularFile)
            {
                flag |= 0x00000001;
            }

            if (IsUserIdChanged || IsGroupIdChanged)
            {
                flag |= 0x00000002;
            }

            if (IsPermissionsChanged)
            {
                flag |= 0x00000004;
            }

            if (IsLastAccessTimeChanged || IsLastWriteTimeChanged)
            {
                flag |= 0x00000008;
            }

            if (IsExtensionsChanged)
            {
                flag |= 0x80000000;
            }

            stream.Write(flag);

            if (IsSizeChanged && IsRegularFile)
            {
                stream.Write((ulong)Size);
            }

            if (IsUserIdChanged || IsGroupIdChanged)
            {
                stream.Write((uint)UserId);
                stream.Write((uint)GroupId);
            }

            if (IsPermissionsChanged)
            {
                stream.Write(Permissions);
            }

            if (IsLastAccessTimeChanged || IsLastWriteTimeChanged)
            {
                var time = (uint)(LastAccessTimeUtc.ToFileTimeUtc() / 10000000 - 11644473600);
                stream.Write(time);
                time = (uint)(LastWriteTimeUtc.ToFileTimeUtc() / 10000000 - 11644473600);
                stream.Write(time);
            }

            if (IsExtensionsChanged)
            {
                foreach (var item in Extensions)
                {
                    // TODO: we write as ASCII but read as UTF8 !!!

                    stream.Write(item.Key, SshData.Ascii);
                    stream.Write(item.Value, SshData.Ascii);
                }
            }

            return(stream.ToArray());
        }