Esempio n. 1
0
        public IKeePassEntry Clone(bool preserveHistory = true)
        {
            KdbxEntry clone = new KdbxEntry(!preserveHistory)
            {
                Parent = Parent,
                Uuid   = Uuid.Clone(),
                IconID = IconID
            };

            if (CustomIconUuid != null)
            {
                clone.CustomIconUuid = CustomIconUuid.Clone();
            }
            else
            {
                clone.CustomIconUuid = null;
            }
            clone.ForegroundColor = ForegroundColor;
            clone.BackgroundColor = BackgroundColor;
            clone.OverrideUrl     = OverrideUrl;
            clone.Tags            = Tags;
            clone.Times           = Times.Clone();
            if (Title != null)
            {
                clone.Title = Title.Clone();
            }
            else
            {
                clone.Title = null;
            }
            clone.Fields = new ObservableCollection <IProtectedString>(Fields.Select(f => f.Clone()));
            if (UserName != null)
            {
                clone.UserName = UserName.Clone();
            }
            else
            {
                clone.UserName = null;
            }
            if (Password != null)
            {
                clone.Password = Password.Clone();
            }
            else
            {
                clone.Password = null;
            }
            if (Url != null)
            {
                clone.Url = Url.Clone();
            }
            else
            {
                clone.Url = null;
            }
            if (Notes != null)
            {
                clone.Notes = Notes.Clone();
            }
            else
            {
                clone.Notes = null;
            }
            clone.Binaries = Binaries;
            clone.AutoType = AutoType;
            if (preserveHistory && History != null)
            {
                clone.History = History.Clone();
            }
            else
            {
                clone.History = null;
            }
            if (CustomData != null)
            {
                clone.CustomData = CustomData.Clone();
            }
            else
            {
                clone.CustomData = null;
            }
            clone._metadata = this._metadata;
            return(clone);
        }
Esempio n. 2
0
        public override bool Equals(object obj)
        {
            KdbxEntry other = obj as KdbxEntry;

            if (other == null)
            {
                return(false);
            }

            if (Parent != null)
            {
                if (other.Parent == null || !Parent.Uuid.Equals(other.Parent.Uuid))
                {
                    return(false);
                }
            }
            else
            {
                if (other.Parent != null)
                {
                    return(false);
                }
            }

            DebugHelper.Assert(Uuid != null);
            if (!Uuid.Equals(other.Uuid))
            {
                return(false);
            }

            if (IconID != other.IconID)
            {
                return(false);
            }

            if (CustomIconUuid != null)
            {
                if (!CustomIconUuid.Equals(other.CustomIconUuid))
                {
                    return(false);
                }
            }
            else
            {
                if (other.CustomIconUuid != null)
                {
                    return(false);
                }
            }

            if (ForegroundColor != other.ForegroundColor || BackgroundColor != other.BackgroundColor)
            {
                return(false);
            }

            if (OverrideUrl != other.OverrideUrl)
            {
                return(false);
            }

            if (Tags != other.Tags)
            {
                return(false);
            }

            if (!Times.Equals(other.Times))
            {
                return(false);
            }

            if (!Title.Equals(other.Title) ||
                !UserName.Equals(other.UserName) ||
                !Password.Equals(other.Password) ||
                !Url.Equals(other.Url))
            {
                return(false);
            }

            if (Notes != null)
            {
                if (!Notes.Equals(other.Notes))
                {
                    return(false);
                }
            }
            else
            {
                if (other.Notes != null)
                {
                    return(false);
                }
            }

            if (Fields.Count != other.Fields.Count)
            {
                return(false);
            }

            for (int i = 0; i < Fields.Count; i++)
            {
                if (!Fields[i].Equals(other.Fields[i]))
                {
                    return(false);
                }
            }

            if (Binaries.Count != other.Binaries.Count)
            {
                return(false);
            }

            for (int i = 0; i < Binaries.Count; i++)
            {
                if (!Binaries[i].Equals(other.Binaries[i]))
                {
                    return(false);
                }
            }

            if (AutoType != null)
            {
                if (!AutoType.Equals(other.AutoType))
                {
                    return(false);
                }
            }
            else
            {
                if (other.AutoType != null)
                {
                    return(false);
                }
            }

            if (History != null)
            {
                DebugHelper.Assert(!this.isHistoryEntry);
                if (!History.Equals(other.History))
                {
                    return(false);
                }
            }
            else
            {
                if (other.History != null)
                {
                    return(false);
                }
            }

            if (CustomData != null)
            {
                if (!CustomData.Equals(other.CustomData))
                {
                    return(false);
                }
            }
            else
            {
                if (other.CustomData != null)
                {
                    return(false);
                }
            }

            return(true);
        }