public void SetupStorage() { Storage = new JsonStorage((serializer) => { serializer.ContractResolver = new JsonFileReferenceResolver() { NamingStrategy = new SnakeCaseNamingStrategy() }; }); }
/// <summary> /// Initializes a new instance of the <see cref="TimestampCacheProvider"/> class. /// </summary> /// <param name="storage">The storage for this cacheprovider.</param> /// <param name="network">The network.</param> /// <param name="synchronizer">The synchronizer.</param> /// <param name="areWeCachingThis">The are we caching this.</param> public TimestampCacheProvider(IStructuredStorage storage, INetworkInformation network, ISynchronizer synchronizer, Func<Uri, bool> areWeCachingThis = null) { Contract.Requires<ArgumentNullException>(storage != null, "storage"); Contract.Requires<ArgumentNullException>(network != null, "network"); Contract.Requires<ArgumentNullException>(synchronizer != null, "synchronizer"); this.network = network; this.storage = storage; this.synchronizer = synchronizer; this.areWeCachingThis = areWeCachingThis ?? (u => true); }
public async Task StartAsync() { PrimaryStorage = new YamlStorage(new UnderscoredNamingConvention()); Configuration = PrimaryStorage.Load <BotSettings>("config"); if (Configuration.Discord == null) { Console.WriteLine($"No 'discord' key with a token in config.{PrimaryStorage.FileExtension}!"); return; } if ((WolframAlpha.AppID = Configuration.Wolfram) == null) { Console.WriteLine($"No 'wolfram' key with an app ID in config.{PrimaryStorage.FileExtension}!"); return; } Client = new DiscordSocketClient(); Client.MessageReceived += HandleCommandAsync; Commands = new CommandService(); Games = new GameManager(this); Services = new ServiceCollection() .AddSingleton(Client) .AddSingleton(Commands) .AddSingleton(Games) .BuildServiceProvider(); Games.Init(); await Commands.AddModulesAsync(Assembly.GetEntryAssembly(), Services); Client.Log += async(e) => { Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}"); await Task.Delay(0); }; Client.UserJoined += async(e) => { if (!e.IsBot) { await e.Guild.DefaultChannel.SendMessageAsync("Welcome to " + e.Guild.Name + ", **" + e.Username + "**!"); } }; Client.UserLeft += async(e) => { if (!e.IsBot) { await e.Guild.DefaultChannel.SendMessageAsync("**" + e.Username + "** left the server."); } }; await Client.LoginAsync(TokenType.Bot, Configuration.Discord); await Client.StartAsync(); await Task.Delay(-1); }
public DnDPlayerCharacter GetPlayer(IStructuredStorage storage, string name) { name = name.ToLowerInvariant().StripNonAlphaNumeric(); if (!CachedPlayers.TryGetValue(name, out DnDPlayerCharacter player)) { player = GameData.Players.Where((p) => p.Name.ToLowerInvariant().StripNonAlphaNumeric() == name).FirstOrDefault(); if (player == null) { player = storage.Load <DnDPlayerCharacter>(CharactersFolder + name); } if (player != null) { CachedPlayers.Add(name, DnDMigrate.Migrate(player)); } } return(player); }
public void Init(IStructuredStorage storage, IEEGData parent) { if (storage == null) { throw new ArgumentNullException(nameof(storage)); } try { eegStorage = storage as IEEGStorage; filename = storage.GetStreamText("DataPath"); datafile = new NedfFile(filename); eegProperties = GetProperties(); } catch (Exception ex) { throw new AnalyzerException("NedfDataReader::Init", "Reader error", ex.Message, ex); } }
/// <summary> /// Initializes a new instance of the <see cref="TimestampSynchronizer"/> class. /// </summary> /// <param name="storage">The storage.</param> public TimestampSynchronizer(IStructuredStorage storage) { Contract.Requires<ArgumentNullException>(storage != null, "storage"); this.storage = storage; }
public void Save(IStructuredStorage storage) { storage.Write(MainFile, GameData); }
public void Load(IStructuredStorage storage) { GameData = storage.Load <T>(MainFile); }
public static T Load <T>(this IStructuredStorage storage, string fileName) { fileName += "." + storage.FileExtension; if (!File.Exists(fileName)) { return(default);