Esempio n. 1
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);
    }