|
- using System;
- using System.Collections.Generic;
- using SUISS.Scheduling;
- using SUISS.Storage;
-
- public class LikeRegistrar
- {
- private static Dictionary<string, object> storage
- {
- get
- {
- return Storage.Get(StorageLifecycle.Forever).GetDictionary("LikeRegistrar");
- }
- }
-
- public static int VotesLeft
- {
- get
- {
- return 10 - LikeRegistrar.Cleanup();
- }
- }
-
- public static bool HaveVotedFor(string installUuid)
- {
- LikeRegistrar.Cleanup();
- return LikeRegistrar.storage.ContainsKey(installUuid);
- }
-
- public static void SaveVoteFor(string installUuid)
- {
- LikeRegistrar.storage[installUuid] = Timing.UtcNow;
- }
-
- public static void SaveNumberOfLikes(string installUuid, int likes)
- {
- LikeRegistrar.storage[installUuid + "likes"] = likes;
- }
-
- public static int GetNumberOfLikes(string installUuid)
- {
- LikeRegistrar.Cleanup();
- if (LikeRegistrar.storage.ContainsKey(installUuid + "likes"))
- {
- return (int)LikeRegistrar.storage[installUuid + "likes"];
- }
- return 0;
- }
-
- private static int Cleanup()
- {
- List<string> list = new List<string>(LikeRegistrar.storage.Keys);
- double utcNow = Timing.UtcNow;
- int num = 0;
- foreach (string text in list)
- {
- if (!text.EndsWith("likes"))
- {
- object obj = LikeRegistrar.storage[text];
- if (obj is double)
- {
- double num2 = utcNow - (double)obj;
- if (num2 > 86400.0)
- {
- LikeRegistrar.storage.Remove(text);
- }
- else
- {
- num++;
- }
- }
- }
- }
- return num;
- }
-
- private const string StorageKey = "LikeRegistrar";
-
- private const double LikeExpireTimeSeconds = 86400.0;
-
- private const int VotesAvailable = 10;
- }
|