示例#1
0
        public void AddProfileDataWithLimit(string Profile, int Limit)
        {
            if (Limit < 1)
            {
                return;
            }
            if (ProfileData.Count >= Limit)
            {
                ProfileData = ProfileData.OrderBy(x => x.ID).ToList();
                int Removed = 0;
                while (ProfileData.Count >= Limit)
                {
                    ProfileData.RemoveAt(0);
                    Removed++;
                }
                if (Removed > 0)
                {
                    foreach (ProfileState ProfileState in ProfileData)
                    {
                        ProfileState.ID -= Removed;
                    }
                }
            }

            int MaxID = 0;

            if (ProfileData.Count > 0)
            {
                MaxID = ProfileData.Max(x => x.ID);
            }
            ProfileState NewEntry = new()
            {
                ID      = MaxID + 1,
                Profile = ObjectOperations.ByteArrayToBase64(System.Text.Encoding.UTF8.GetBytes(Profile)),
                Check_p = ObjectOperations.ByteArrayToBase64(ObjectOperations.ByteArrayToSHA512(System.Text.Encoding.UTF8.GetBytes(Profile)))
            };

            //Profile data will always be new and unique (because it includes the date it's created) so just add NewEntry at every occurrence
            ProfileData.Add(NewEntry);
            CreateBackup();
        }