summaryrefslogtreecommitdiff
path: root/FireBase/FirebaseKeyGenerator.cs
diff options
context:
space:
mode:
authorDennis Kobert <d-kobert@web.de>2019-05-19 16:03:38 +0200
committerDennis Kobert <d-kobert@web.de>2019-05-19 16:03:38 +0200
commitf89f308c525e9deebc6d2cf6416e27dfe1a299dc (patch)
tree7097ef871ead0245efda696198443eab8e443d3a /FireBase/FirebaseKeyGenerator.cs
parentf3983341be939235c1a6cd522b3bb5cc318a6d1a (diff)
Cleanup DiscoBot Project
Diffstat (limited to 'FireBase/FirebaseKeyGenerator.cs')
-rw-r--r--FireBase/FirebaseKeyGenerator.cs34
1 files changed, 10 insertions, 24 deletions
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
/// </summary>
- 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