Example #1
0
    /// <summary>
    /// Get the permissions of the api key
    /// </summary>
    /// <param name="permissions">Permission strings</param>
    /// <returns>Permissions</returns>
    public static GuildWars2ApiPermission ToPermission(IEnumerable <string> permissions)
    {
        return(permissions.Aggregate(GuildWars2ApiPermission.None,
                                     (combinedPermissions, permissionString) =>
        {
            var permission = permissionString switch
            {
                TokenInformation.Permission.Account => GuildWars2ApiPermission.Account,
                TokenInformation.Permission.Builds => GuildWars2ApiPermission.Builds,
                TokenInformation.Permission.Characters => GuildWars2ApiPermission.Characters,
                TokenInformation.Permission.Guilds => GuildWars2ApiPermission.Guilds,
                TokenInformation.Permission.Inventories => GuildWars2ApiPermission.Inventories,
                TokenInformation.Permission.Progression => GuildWars2ApiPermission.Progression,
                TokenInformation.Permission.PvP => GuildWars2ApiPermission.PvP,
                TokenInformation.Permission.TradingPost => GuildWars2ApiPermission.TradingPost,
                TokenInformation.Permission.Unlocks => GuildWars2ApiPermission.Unlocks,
                TokenInformation.Permission.Wallet => GuildWars2ApiPermission.Wallet,
                _ => GuildWars2ApiPermission.None
            };

            if (permission == GuildWars2ApiPermission.None)
            {
                LoggingService.AddServiceLogEntry(LogEntryLevel.Error, nameof(AccountAdministrationService), "Unknown permission value", permissionString, null);
            }

            combinedPermissions |= permission;

            return combinedPermissions;
        }));
Example #2
0
    /// <summary>
    /// Import worlds
    /// </summary>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public async Task <bool> ImportWorlds()
    {
        var success = false;

        using (var dbFactory = RepositoryFactory.CreateInstance())
        {
            try
            {
                var connector = new GuidWars2ApiConnector(null);
                await using (connector.ConfigureAwait(false))
                {
                    var worlds = await connector.GetWorlds().ConfigureAwait(false);

                    success = true;

                    foreach (var world in worlds)
                    {
                        if (dbFactory.GetRepository <GuildWarsWorldRepository>()
                            .AddOrRefresh(obj => obj.Id == world.Id,
                                          obj =>
                        {
                            obj.Id = world.Id;
                            obj.Name = world.Name;
                        }) == false)
                        {
                            success = false;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingService.AddServiceLogEntry(LogEntryLevel.Error, nameof(WorldsService), ex.Message, null, ex);
            }
        }

        return(success);
    }