The Service Manager

Introduction

Because of the complexity of the game and its data, so is the code that encapsulates the available services. To address this problem, the library has a single façade class that acts as the entry point, called the ServiceManager class. This class allows you to access all of the supported service endpoints through simple methods.

Instantiating the service manager

using GW2DotNET.V1;

var service = new ServiceManager();

Notice the constructor overloads that pop up in IntelliSense? All service implementations support dependency injection. This enables complex scenarios, such as injecting a service wrapper that writes to an event log whenever a service request is made.

A practical example is the RestSharp-based library that is provided as a separate file. The IServiceClient implementation in this library can be injected into the ServiceManager to replace the default client with a RestSharp client.

Supported Services

The ServiceManager implements the following interfaces:
  • IBuildService
    • GetBuild
    • GetBuildAsync
  • IColorService
    • GetColors
    • GetColorsAsync
  • IContinentService
    • GetContinents
    • GetContinentsAsync
  • IDynamicEventStateService
    • GetDynamicEvent
    • GetDynamicEventAsync
    • GetDynamicEvents
    • GetDynamicEventsAsync
    • GetDynamicEventsById
    • GetDynamicEventsByIdAsync
    • GetDynamicEventsByMap
    • GetDynamicEventsByMapAsync
    • GetDynamicEventsByWorld
    • GetDynamicEventsByWorldAsync
  • IDynamicEventDetailsService
    • GetDynamicEventDetails
    • GetDynamicEventDetailsAsync
  • IDynamicEventNameService
    • GetDynamicEventNames
    • GetDynamicEventNamesAsync
  • IDynamicEventRotationService
    • GetDynamicEventRotations
  • IFileService
    • GetFiles
    • GetFilesAsync
  • IGuildDetailsService
    • GetGuildDetailsById
    • GetGuildDetailsByIdAsync
    • GetGuildDetailsByName
    • GetGuildDetailsByNameAsync
  • IItemService
  • IItemDiscoveryService
    • GetItems
    • GetItemsAsync
  • IItemDetailsService
    • GetItemDetails
    • GetItemDetailsAsync
  • IMapService
    • GetMap
    • GetMapAsync
    • GetMaps
    • GetMapsAsync
  • IMapFloorService
    • GetMapFloor
    • GetMapFloorAsync
  • IMapNameService
    • GetMapNames
    • GetMapNamesAsync
  • IRecipeService
  • IRecipeDiscoveryService
    • GetRecipes
    • GetRecipesAsync
  • IRecipeDetailsService
    • GetRecipeDetails
    • GetRecipeDetailsAsync
  • IWorldNameService
    • GetWorldNames
    • GetWorldNamesAsync
  • IMatchService
  • IMatchDiscoveryService
    • GetMatches
    • GetMatchesAsync
  • IMatchDetailsService
    • GetMatchDetails
    • GetMatchDetailsAsync
  • IObjectiveNameService
    • GetObjectiveNames
    • GetObjectiveNamesAsync
  • ISkinService
  • ISkinDiscoveryService
    • GetSkins
    • GetSkinsAsync
  • ISkinDetailsService
    • GetSkinDetails
    • GetSkinDetailsAsync


For a complete overview of supported methods, please use tools that ship with Visual Studio:
  • IntelliSense
  • Object Explorer
  • Automatically generated class diagrams
  • ...

Example

This example retrieves and prints the latest game build number.

var service = new ServiceManager();
var build   = service.GetBuild();

Console.WriteLine("The current build number is: {0}", build.BuildId);

Service Errors

Many service endpoints require that you specify one or more identifiers or filters for the object(s) that should be retrieved. Invalid parameters typically result in a service error. These errors can be handled by catching the ServiceException that is thrown.

var service = new ServiceManager();
try
{
    // Send an item_details request with garbage value -2147483648
    var item = service.GetItemDetails(int.MinValue);
}
catch (ServiceException exception)
{
    Console.WriteLine("Error: {0}", exception.Message);
}

Error: invalid item_id

Important: service error message are always in English.

Last edited Sep 17, 2014 at 8:53 PM by StevenLiekens, version 7