FileCacheItem.cs 1.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
using System;
using System.Diagnostics.CodeAnalysis;

namespace MySocialPortalLib.Model
{
    [SuppressMessage("ReSharper", "CA1056")]
    public class FileCacheItem
    {
        public DateTimeOffset CreationTime { get; set; }

        public string Id { get; set; }
12
        
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
        public string LocalFileName { get; set; }
        
        public string OriginalUrl { get; set; }

        public FileCacheItem()
        {
            Id = Guid.NewGuid().ToString();
            OriginalUrl = "";
            LocalFileName = "";
            CreationTime = DateTimeOffset.UnixEpoch;
        }

        public bool AllEquals(FileCacheItem other)
        {
            const double threshold = 2.0;
            if (other == null)
            {
                return false;
            }
            return Math.Abs(CreationTime.Subtract(other.CreationTime).TotalMilliseconds) < threshold
                   && Id == other.Id 
                   && LocalFileName == other.LocalFileName 
                   && OriginalUrl == other.OriginalUrl;
        }

        protected bool Equals(FileCacheItem other)
        {
            if (other == null)
            {
                return false;
            }
            
            return Id == other.Id;
        }

48
        public override bool Equals(object? other)
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
        {
            if (other == null)
            {
                return false;
            }
            
            if (ReferenceEquals(this, other)) return true;
            if (other.GetType() != this.GetType()) return false;
            return Equals((FileCacheItem) other);
        }

        public override int GetHashCode()
        {
            return (Id != null ? Id.GetHashCode(StringComparison.InvariantCulture) : 0);
        }
    }
}