public void TestJsonStorageLoadWrongKey() { const string key = "tesd"; JsonStorage storage = new JsonStorage(); storage.RestoreObject <string>(key); }
// Override the CheckPermissions method public override async Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) { try { var rootObject = _jsonStorage.RestoreObject <RootObject>(context.User.Id.ToString()); var x = command.Module.Group; var y = command.Name; bool result = rootObject.permissions.CommandGroup <object>("response").CommandProperty("ping"); if (result) { //YAY!!! } } catch (Exception e) { Console.WriteLine(e); throw; } _logger.Log($"User: {context.User.Id} failed to execute {command.Name}", "CommandWarning"); await context.Channel.SendMessageAsync($"User needs `permissions.{command.Module.Group}.{command.Name}`"); return(await Task.FromResult( PreconditionResult.FromError("Fail"))); }
public QuotesProvider(string dir) { _quotes = new List <QuotesConfiguration>(); string[] files = System.IO.Directory.GetFiles(dir); foreach (string path in files) { _quotes.Add(JsonStorage.RestoreObject <QuotesConfiguration>(path)); } }
public void TestJsonStorageNoPathKey() { const string key = "TestKey2"; const string dataToStore = "ABC"; JsonStorage storage = new JsonStorage(); storage.StoreObject(dataToStore, key); string dataFromStorage = storage.RestoreObject <string>(key); Assert.Equal(expected: dataToStore, actual: dataFromStorage); }
static UsersExpMute() { if (JsonStorage.FileExist(_filepath)) { _usersExp = JsonStorage.RestoreObject <List <UserExpMute> >(_filepath); } else { _usersExp = new List <UserExpMute>(); Save(); } }
static UsersNicknames() { if (JsonStorage.FileExist(_filePath)) { _nicknames = JsonStorage.RestoreObject <List <UserNicknames> >(_filePath); } else { _nicknames = new List <UserNicknames>(); Save(); } }
static UsersPraises() { if (JsonStorage.FileExist(_filePath)) { _usersPraises = JsonStorage.RestoreObject <List <UserPraises> >(_filePath); } else { _usersPraises = new List <UserPraises>(); Save(); } }
static UsersArchievements() { if (JsonStorage.FileExist(_filePath)) { _usersArchievements = JsonStorage.RestoreObject <List <UserArchievements> >(_filePath); } else { _usersArchievements = new List <UserArchievements>(); Save(); } }
static UsersWarnings() { if (JsonStorage.FileExist(_filePath)) { _usersWarnings = JsonStorage.RestoreObject <List <UserWarnings> >(_filePath); } else { _usersWarnings = new List <UserWarnings>(); Save(); } }
static GuildsCfgs() { if (JsonStorage.FileExist(filepath)) { guildConfigs = JsonStorage.RestoreObject <List <GuildCfg> >(filepath); } else { guildConfigs = new List <GuildCfg>(); Save(); } }
public static void JsonStorageTest() { const string expected = "I'm a unit test!"; const string expectedKey = "xUnitTests/TEST"; IDataStorage storage = new JsonStorage(); storage.StoreObject(expected, expectedKey); var actual = storage.RestoreObject <string>(expectedKey); Assert.Equal(expected, actual); //Assert.Throws<FileNotFoundException>(() => storage.RestoreObject<object>("xUnitTests/FAKE-KEY")); }
static UserHandler() { System.Console.WriteLine("Loading User Accounts..."); //Access JsonStorage to load user list into memory filepath = "Users/UserList"; _storage = new InMemoryStorage(); _jsonStorage = new JsonStorage(); _storage.StoreAllObjects(_jsonStorage.RestoreObject <Dictionary <string, object> >(filepath)); System.Console.WriteLine($"Successfully loaded {_storage.StorageLength()} users."); }
public void DataStorage_JsonStorage_OverrideTest() { const string key = "Config/TestKey"; const string firstString = "I should be overriden"; const string expected = "I should override the previous data"; IDataStorage storage = new JsonStorage(); storage.StoreObject(firstString, key); storage.StoreObject(expected, key); var actual = storage.RestoreObject <string>(key); Assert.Equal(expected, actual); }
static CombatHandler2() { System.Console.WriteLine("Loading Combat Instances..."); //Access JsonStorage to load user list into memory filepath = "MonGameCore/Combat/CombatInstances2"; _dic = new Dictionary <int, CombatInstance2>(); _jsonStorage = new JsonStorage(); foreach (KeyValuePair <int, CombatInstance2> entry in _jsonStorage.RestoreObject <Dictionary <int, CombatInstance2> >(filepath)) { _dic.Add(entry.Key, (CombatInstance2)entry.Value); } System.Console.WriteLine($"Successfully loaded {_dic.Count} combat instances."); }
static UserHandler() { System.Console.WriteLine("Loading User Accounts..."); //Access JsonStorage to load user list into memory filepath = "Users/UserList"; _dic = new Dictionary <ulong, UserAccount>(); _jsonStorage = new JsonStorage(); foreach (KeyValuePair <ulong, UserAccount> entry in _jsonStorage.RestoreObject <Dictionary <ulong, UserAccount> >(filepath)) { _dic.Add(entry.Key, (UserAccount)entry.Value); } System.Console.WriteLine($"Successfully loaded {_dic.Count} users."); }
static TownHandler() { System.Console.WriteLine("Loading Town Accounts..."); //Access JsonStorage to load user list into memory filepath = "Towns/TownList"; _dic = new Dictionary <ulong, TownAccount>(); _jsonStorage = new JsonStorage(); foreach (KeyValuePair <ulong, TownAccount> entry in _jsonStorage.RestoreObject <Dictionary <ulong, TownAccount> >(filepath)) { entry.Value.UpdateTeams(); _dic.Add(entry.Key, (TownAccount)entry.Value); } foreach (KeyValuePair <ulong, TownAccount> kvp in _dic) { Console.WriteLine($"Key: {kvp.Key}\nValue: {kvp.Value}\n"); } System.Console.WriteLine($"Successfully loaded {_dic.Count} users."); }
public void DataStorage_JsonStorage_RestoreObject_MissingKeyTest() { IDataStorage storage = new JsonStorage(); Assert.Throws <System.ArgumentException>(() => storage.RestoreObject <string>("fake-key")); }