public static async Task Add <T>(this IGameDatabase db, params string [] databaseIndexes) where T : IDatabaseEntry { var entryListData = await db.GetData <EntryListData>(typeof(T).Name); bool doAdd = false; if (entryListData == null) { entryListData = new EntryListData() { Type = typeof(T).Name }; //signal that we need to add this to the EntryListData itself doAdd = entryListData.Type != entryListData.GetType().Name; } foreach (var dbEntry in databaseIndexes) { if (!entryListData.Entries.Contains(dbEntry)) { entryListData.Entries.Add(dbEntry); } } if (doAdd) { await db.Add(entryListData); } await db.SaveData(entryListData); }
// To add new game menu items override GetGameMenuItems public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args) { Game GameMenu = args.Games.First(); List <GameMenuItem> gameMenuItems = new List <GameMenuItem> { // Show plugin view with all activities for all game in database with data of selected game new GameMenuItem { //MenuSection = "", Icon = Path.Combine(pluginFolder, "icon.png"), Description = resources.GetString("LOCGameActivityViewGameActivity"), Action = (gameMenuItem) => { DatabaseReference = PlayniteApi.Database; var ViewExtension = new GameActivityView(settings, PlayniteApi, this.GetPluginUserDataPath(), GameMenu); Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCGameActivity"), ViewExtension); windowExtension.ShowDialog(); } } }; #if DEBUG gameMenuItems.Add(new GameMenuItem { MenuSection = resources.GetString("LOCGameActivity"), Description = "Test", Action = (mainMenuItem) => { } }); #endif return(gameMenuItems); }
public GameManager(BoxOptionsApiSettings settings, IGameDatabase database, ICoefficientCalculator calculator, IAssetQuoteSubscriber quoteFeed, IWampHostedRealm wampRealm, IMicrographCache micrographCache, IBoxConfigRepository boxConfigRepository, ILogRepository logRepository, ILog appLog, IHistoryHolder historyHolder) { this.database = database; this.calculator = calculator; this._assetQuoteSubscriber = quoteFeed; this.settings = settings; this.logRepository = logRepository; this.appLog = appLog; this.wampRealm = wampRealm; this.boxConfigRepository = boxConfigRepository; this.micrographCache = micrographCache; _historyHolder = historyHolder; _coefficientCache = new CoefficientCache(); if (this.settings != null && this.settings != null && this.settings.GameManager != null) { MaxUserBuffer = this.settings.GameManager.MaxUserBuffer; } GameManagerId = Guid.NewGuid().ToString(); userList = new List <UserState>(); betCache = new List <GameBet>(); assetCache = new Dictionary <string, PriceCache>(); this._assetQuoteSubscriber.MessageReceived += QuoteFeed_MessageReceived; //calculateBoxConfig = null; dbBoxConfig = Task.Run(() => LoadBoxParameters()).Result; Console.WriteLine("Db Box Config = [{0}]", string.Join(",", dbBoxConfig.Select(b => b.AssetPair))); coefStatus = new Dictionary <string, string>(); _historyHolder.InitializationFinished += HistoryHolder_InitializationFinished; }
public static async Task AddTag(this IGameDatabase db, string unicode, string fancyName, ITagsList tagsList = null) { string emojiDatabaseIndex = string.Join(" ", Encoding.UTF8.GetBytes(unicode)); //now check if we exist TagData tagData = await db.GetData <TagData>(emojiDatabaseIndex); if (tagData == null) { tagData = new TagData() { Name = emojiDatabaseIndex, Emoji = unicode, FancyName = fancyName, }; await db.SaveData(tagData); } await db.Add(tagData); if (tagsList != null && !tagsList.Tags.Contains(emojiDatabaseIndex)) { tagsList.Tags.Add(emojiDatabaseIndex); } }
public static Version GetVersion(this IGameDatabase db, string key) { if (!db.ContainsKey(key)) { return(null); } return(new Version(db.GetString(key))); }
/// <summary> /// Ideally these two should not be used whatsoever, please deprecate after moving the code over /// </summary> /// <typeparam name="T"></typeparam> /// <param name="db"></param> /// <param name="databaseIndexes"></param> public static async Task <List <T> > GetAllData <T>(this IGameDatabase db, List <string> databaseIndexes) where T : IDatabaseEntry { List <T> dataList = new List <T>(); foreach (var entryIndex in databaseIndexes) { dataList.Add(await db.GetData <T>(entryIndex)); } return(dataList); }
public static void SetDate(this IGameDatabase db, string key, DateTime?value) { if (value.HasValue) { db.SetLong(key, value.Value.ToBinary()); } else { db.SetLong(key, -1); } }
public static async Task <List <string> > GetAll <T>(this IGameDatabase db) where T : IDatabaseEntry { List <string> databaseIndexes = new List <string>(); var entryListData = await db.GetData <EntryListData>(typeof(T).Name); if (entryListData != null) { databaseIndexes.AddRange(entryListData.Entries); } return(databaseIndexes); }
/// <summary> /// Iterate over the specified /// </summary> /// <typeparam name="T"></typeparam> /// <param name="db"></param> /// <param name="callback"></param> /// <param name="databaseIndexes"></param> /// <returns></returns> public static async Task IterateOver <T>(this IGameDatabase db, Func <T, Task <bool> > callback, List <string> databaseIndexes) where T : IDatabaseEntry { List <Task> tasks = new List <Task>(); var tokenSource = new CancellationTokenSource(); foreach (string dataName in databaseIndexes) { tasks.Add(IteratorTask(db, dataName, callback, tasks, tokenSource)); } await Task.WhenAll(tasks); }
public static async Task ImportBackup(this IGameDatabase db, Dictionary <string, Dictionary <string, IDatabaseEntry> > backup) { foreach (var dataTypeKV in backup) { var dataTypeName = dataTypeKV.Key; var dataTypeValue = dataTypeKV.Value; foreach (var dataEntry in dataTypeValue) { await db.SaveData(dataEntry.Value); } } }
public GameActivity(IPlayniteAPI api) : base(api) { settings = new GameActivitySettings(this); DatabaseReference = PlayniteApi.Database; // Old database oldToNew = new OldToNew(this.GetPluginUserDataPath()); // Loading plugin database PluginDatabase = new ActivityDatabase(PlayniteApi, settings, this.GetPluginUserDataPath()); PluginDatabase.InitializeDatabase(); // Temp Task.Run(() => { System.Threading.SpinWait.SpinUntil(() => PluginDatabase.IsLoaded, -1); settings.tmp = true; this.SavePluginSettings(settings); }); // Get plugin's location pluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); // Add plugin localization in application ressource. PluginLocalization.SetPluginLanguage(pluginFolder, api.ApplicationSettings.Language); // Add common in application ressource. Common.Load(pluginFolder); Common.SetEvent(PlayniteApi); // Check version if (settings.EnableCheckVersion) { CheckVersion cv = new CheckVersion(); cv.Check("GameActivity", pluginFolder, api); } // Init ui interagration gameActivityUI = new GameActivityUI(api, settings, this.GetPluginUserDataPath()); // Custom theme button EventManager.RegisterClassHandler(typeof(Button), Button.ClickEvent, new RoutedEventHandler(gameActivityUI.OnCustomThemeButtonClick)); // Add event fullScreen if (api.ApplicationInfo.Mode == ApplicationMode.Fullscreen) { EventManager.RegisterClassHandler(typeof(Button), Button.ClickEvent, new RoutedEventHandler(BtFullScreen_ClickEvent)); } }
/// <summary> /// Get all the winners as a merged string /// </summary> /// <param name="data"></param> /// <param name="DB"></param> /// <returns>EG: "Willox Jvs"</returns> internal static async Task <string> GetAllWinners(IGameDatabase DB, IWinner data) { string winners = string.Empty; var playerWinners = await DB.GetAllData <PlayerData>(data.GetWinners()); winners = string.Join(" ", playerWinners.Select(x => x?.GetName())); if (string.IsNullOrEmpty(winners)) { winners = "Nobody"; } return(winners); }
/// <summary> /// Legacy, please use IGameDatabase.IterateOverAll directly /// </summary> /// <param name="db"></param> /// <param name="matchOrRound">true for match, false for round</param> /// <param name="callback">The callback, return false to interrupt the iteration</param> /// <returns></returns> public static async Task IterateOverAllRoundsOrMatches(this IGameDatabase db, bool matchOrRound, Func <IWinner, Task <bool> > callback) { if (matchOrRound) { async Task <bool> matchTask(MatchData matchData) => await callback(matchData); await db.IterateOverAll <MatchData>(matchTask); } else { async Task <bool> roundTask(RoundData roundData) => await callback(roundData); await db.IterateOverAll <RoundData>(roundTask); } }
public GameEngine( IGameDatabase gameDatabase, IInputReader reader, IOutputWriter writer) { this.gameDatabase = gameDatabase; this.reader = reader; this.writer = writer; this.points = 0; this.currentRow = 0; this.currentCol = 0; this.PrintWelcomeMessage(); }
public FullscreenCollectionView( IGameDatabase database, PlayniteSettings settings, ExtensionFactory extensions) : base(database, extensions, settings.Fullscreen.FilterSettings) { this.settings = settings; Database.Games.ItemCollectionChanged += Database_GamesCollectionChanged; Database.Games.ItemUpdated += Database_GameUpdated; viewSettings = settings.Fullscreen.ViewSettings; viewSettings.PropertyChanged += ViewSettings_PropertyChanged; using (CollectionView.DeferRefresh()) { SetViewDescriptions(); Items.AddRange(Database.Games.Select(x => new GamesCollectionViewEntry(x, GetLibraryPlugin(x), settings))); }; }
public override IEnumerable <ExtensionFunction> GetFunctions() { return(new List <ExtensionFunction> { new ExtensionFunction( resources.GetString("LOCGameActivity"), () => { // Add code to be execute when user invokes this menu entry. // Show GameActivity DatabaseReference = PlayniteApi.Database; new GameActivityView(settings, PlayniteApi, this.GetPluginUserDataPath()).ShowDialog(); }) }); }
public static async Task CallForRegisteredTypes(this IGameDatabase db, Func <Type, Task> method) { var registeredTypes = new List <Type>() { typeof(EntryListData), typeof(RoundData), typeof(MatchData), typeof(LevelData), typeof(TagData), typeof(PlayerData), }; foreach (var registeredType in registeredTypes) { await method.Invoke(registeredType); } }
public static DateTime?GetDate(this IGameDatabase db, string key) { if (!db.ContainsKey(key)) { return(null); } var l = db.GetLong(key); if (l == -1) { return(null); } var d = DateTime.FromBinary(l); return(d); }
private static async Task IteratorTask <T>(IGameDatabase db, string dataName, Func <T, Task <bool> > callback, List <Task> tasks, CancellationTokenSource tokenSource) where T : IDatabaseEntry { if (tokenSource.IsCancellationRequested) { return; } T iterateItem = await db.GetData <T>(dataName); if (!await callback(iterateItem)) { tokenSource.Cancel(); //immediately clear the tasks list so we don't await anything for no reason anymore //the tasks may still run but they won't get any further than the cancellation request check tasks.Clear(); } }
public MatchRecorderService(IModToRecorderMessageQueue messageQueue, IGameDatabase db, IConfiguration configuration, IHostApplicationLifetime lifetime) { AppLifeTime = lifetime; MessageQueue = messageQueue; GameDatabase = db; Configuration = configuration; Configuration.Bind(BotSettings); Configuration.Bind(OBSSettings); Configuration.Bind(RecorderSettings); RecorderHandler = new ObsLocalRecorder(this); if (RecorderSettings.DuckGameProcessID > 0) { DuckGameProcess = Process.GetProcessById(RecorderSettings.DuckGameProcessID); } }
public DatabaseVotePaginator(DiscordClient client, IGameDatabase database, IEnumerable <string> databaseIndexes, DiscordUser usr, DiscordMessage message) { DiscordClient = client; DatabaseIndexes = new List <string>(databaseIndexes); User = usr; DB = database; PaginatorMessage = message; TimeoutToken = new CancellationTokenSource(TimeSpan.FromMinutes(5)); TimeoutToken.Token.Register(() => CompletitionCondition.TrySetResult(true)); //no need for pagination emojis when it's only one item to vote for if (DatabaseIndexes.Count == 1) { PaginationEmojis.Left = null; PaginationEmojis.SkipLeft = null; PaginationEmojis.Right = null; PaginationEmojis.SkipRight = null; } }
// To add new main menu items override GetMainMenuItems public override List <MainMenuItem> GetMainMenuItems(GetMainMenuItemsArgs args) { string MenuInExtensions = string.Empty; if (settings.MenuInExtensions) { MenuInExtensions = "@"; } List <MainMenuItem> mainMenuItems = new List <MainMenuItem> { // Show plugin view with all activities for all game in database new MainMenuItem { MenuSection = MenuInExtensions + resources.GetString("LOCGameActivity"), Description = resources.GetString("LOCGameActivityViewGamesActivities"), Action = (mainMenuItem) => { DatabaseReference = PlayniteApi.Database; var ViewExtension = new GameActivityView(settings, PlayniteApi, this.GetPluginUserDataPath()); Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCGameActivity"), ViewExtension); windowExtension.ShowDialog(); } } }; #if DEBUG mainMenuItems.Add(new MainMenuItem { MenuSection = MenuInExtensions + resources.GetString("LOCGameActivity"), Description = "Test", Action = (mainMenuItem) => { } }); #endif return(mainMenuItems); }
public static void seed(IGameDatabase database) { //Collection initializer var games = new[] { new Game() { Name = "DOOM", Description = "Space Marine", Price = 49.99M }, new Game() { Name = "Oblivion", Description = "Medieval", Price = 89.99M }, new Game() { Name = "Fallout 76", Description = "Failed MMO", Price = 0.01M } }; foreach (var game in games) { database.add(game); } }
public static void Seed(this IGameDatabase source) { //Collection initializer var games = new [] { new Game() { Name = "TimeSplitters", Description = "2000", Price = 49.99M }, new Game() { Name = "Super Smash Bros. Ultimate", Description = "2018", Price = 59.99M }, new Game() { Name = "Steven Universe: Save the Light", Description = "2017", Price = 24.99M } }; foreach (var game in games) { source.Add(game); } }
public static async Task <Dictionary <string, Dictionary <string, IDatabaseEntry> > > GetBackupAllOut(this IGameDatabase db) { var backupTasks = new List <Task <Dictionary <string, IDatabaseEntry> > >() { db.GetBackup <EntryListData>(), db.GetBackup <RoundData>(), db.GetBackup <MatchData>(), db.GetBackup <LevelData>(), db.GetBackup <TagData>(), db.GetBackup <PlayerData>(), }; await Task.WhenAll(backupTasks); return(new Dictionary <string, Dictionary <string, IDatabaseEntry> >() { [nameof(EntryListData)] = await backupTasks [0], [nameof(RoundData)] = await backupTasks [1], [nameof(MatchData)] = await backupTasks [2], [nameof(LevelData)] = await backupTasks [3], [nameof(TagData)] = await backupTasks [4], [nameof(PlayerData)] = await backupTasks [5], }); }
private static async Task CopyDatabaseOverTo(IGameDatabase from, IGameDatabase to) { var backup = await from.GetBackupAllOut(); await to.ImportBackup(backup); }
internal static async Task <Video> GetVideoDataForDatabaseItem <T>(IGameDatabase DB, T data) where T : IPlayersList, IStartEnd, IWinner, IDatabaseEntry, IVideoUpload { string mainWinners = await GetAllWinners(DB, data); string description = string.Empty; string privacystatus = "unlisted"; if (data.VideoType == VideoType.VideoLink) { description = $"Recorded on {DB.SharedSettings.DateTimeToString( data.TimeStarted )}\nThe winner is {mainWinners}"; } //only update the description for the main video if (data.VideoType == VideoType.MergedVideoLink && data is MatchData matchData) { privacystatus = "public"; var builder = new StringBuilder(); builder .Append($"Recorded on {DB.SharedSettings.DateTimeToString( data.TimeStarted )}") .AppendLine() .Append($"The winner is {mainWinners}") .AppendLine() .AppendLine() .Append($"Rounds: {matchData.Rounds.Count}") .AppendLine(); //now add the rounds down here so that the whole youtube chaptering thing works foreach (var roundName in matchData.Rounds) { var roundData = await DB.GetData <RoundData>(roundName); builder .Append($"{roundData.VideoStartTime:mm\\:ss} - {data.DatabaseIndex} {await GetAllWinners( DB , roundData ) }") .AppendLine(); } description = builder.ToString(); } Video videoData = new Video() { Snippet = new VideoSnippet() { Title = $"{data.DatabaseIndex} {mainWinners}", Tags = new List <string>() { "duckgame", "peniscorp" }, CategoryId = "20", Description = description, }, Status = new VideoStatus() { PrivacyStatus = privacystatus, MadeForKids = false, }, RecordingDetails = new VideoRecordingDetails() { RecordingDate = data.TimeStarted.ToString("s", CultureInfo.InvariantCulture), } }; return(videoData); }
public MatchTrackerCommands(IGameDatabase database, IConfigurationRoot configuration) { DB = database; Configuration = configuration; }
public YoutubeRoundUploader(IGameDatabase gameDatabase, UploaderSettings settings) : base(gameDatabase, settings) { }
public GameDeleteEventArgs(ICoreService eventCoreInstance, IGameInfo gameInfo, IGameDatabase gameDatabase) : base(eventCoreInstance, gameInfo) { this.GameDatabase = gameDatabase; }
public static async Task <Dictionary <string, IDatabaseEntry> > GetBackup <T>(this IGameDatabase db) where T : IDatabaseEntry { var entryNames = await db.GetAll <T>(); var dataTasks = new List <Task <T> >(); foreach (var entryName in entryNames) { dataTasks.Add(db.GetData <T>(entryName)); } await Task.WhenAll(dataTasks); var allData = dataTasks.Select(x => { var value = x.Result; return(new KeyValuePair <string, IDatabaseEntry>(value.DatabaseIndex, value)); }).ToDictionary(x => x.Key, x => x.Value); return(allData); }