From f89f308c525e9deebc6d2cf6416e27dfe1a299dc Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sun, 19 May 2019 16:03:38 +0200 Subject: Cleanup DiscoBot Project --- FireBase/FirebaseKeyGenerator.cs | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) (limited to 'FireBase/FirebaseKeyGenerator.cs') diff --git a/FireBase/FirebaseKeyGenerator.cs b/FireBase/FirebaseKeyGenerator.cs index acad399..70a855d 100644 --- a/FireBase/FirebaseKeyGenerator.cs +++ b/FireBase/FirebaseKeyGenerator.cs @@ -7,7 +7,7 @@ namespace Firebase.Database /// Offline key generator which mimics the official Firebase generators. /// Credit: https://github.com/bubbafat/FirebaseSharp/blob/master/src/FirebaseSharp.Portable/FireBasePushIdGenerator.cs /// - public class FirebaseKeyGenerator + public class FirebaseKeyGenerator { // Modeled after base64 web-safe chars, but ordered by ASCII. private const string PushCharsString = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"; @@ -37,31 +37,25 @@ namespace Firebase.Database // characters we generated because in the event of a collision, we'll use those same // characters except "incremented" by one. var id = new StringBuilder(20); - var now = (long)(DateTimeOffset.Now - Epoch).TotalMilliseconds; + var now = (long) (DateTimeOffset.Now - Epoch).TotalMilliseconds; var duplicateTime = now == lastPushTime; lastPushTime = now; var timeStampChars = new char[8]; - for (int i = 7; i >= 0; i--) + for (var i = 7; i >= 0; i--) { - var index = (int)(now % PushChars.Length); + var index = (int) (now % PushChars.Length); timeStampChars[i] = PushChars[index]; - now = (long)Math.Floor((double)now / PushChars.Length); + now = (long) Math.Floor((double) now / PushChars.Length); } - if (now != 0) - { - throw new Exception("We should have converted the entire timestamp."); - } + if (now != 0) throw new Exception("We should have converted the entire timestamp."); id.Append(timeStampChars); if (!duplicateTime) { - for (int i = 0; i < 12; i++) - { - lastRandChars[i] = (byte)random.Next(0, PushChars.Length); - } + for (var i = 0; i < 12; i++) lastRandChars[i] = (byte) random.Next(0, PushChars.Length); } else { @@ -69,24 +63,16 @@ namespace Firebase.Database // except incremented by 1. var lastIndex = 11; for (; lastIndex >= 0 && lastRandChars[lastIndex] == PushChars.Length - 1; lastIndex--) - { lastRandChars[lastIndex] = 0; - } lastRandChars[lastIndex]++; } - for (int i = 0; i < 12; i++) - { - id.Append(PushChars[lastRandChars[i]]); - } + for (var i = 0; i < 12; i++) id.Append(PushChars[lastRandChars[i]]); - if (id.Length != 20) - { - throw new Exception("Length should be 20."); - } + if (id.Length != 20) throw new Exception("Length should be 20."); return id.ToString(); } } -} +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf