Skip to content

Locations

Locations are a hierarchical representation of the different places in a vessel, or shore-side.

For example, an entire Deck, a Fire zone, a Cabin, etc.

Locations can be as granular as decided, for example Drawers and Cabinets.

Integration

The Location Services offers some messages that can be published, as well as some events that another services can consume to keep up to date with new and updated locations.

First of all, we need a reference to the Locations.Application.Contracts project, as it's shown below:

XML
<ProjectReference Include="$(ServicesPath)Locations\ITsynch.Suite.Locations.Application.Contracts\ITsynch.Suite.Locations.Application.Contracts.csproj" />

Messages

From your module, you are able to request two different Location's actions, wait for their response and then continue:

Create or update a Location:

C#
var correlationId = NewId.NextGuid();
var displayName = "DECK 1";
var code = "D01";

var client = this.ServiceProvider.GetRequiredService<IRequestClient<CreateOrUpdateLocation>>();

var locationCreated = (await client.GetResponse<LocationUpdated>(new
{
    CorrelationId = correlationId,
    DisplayName = displayName,
    Code = code,
    ParentLocationId = (Guid?)null
})).Message;

You can set the ParentLocationId while you are creating the Location. Take into account that the ParentLocation must be created before its "child".

Events

On the other hand, you can consume the different Location's events and perform the actions you need to do in your project.

Location Updated:

C#
using ITsynch.Suite.Locations.Application;
using MassTransit;
using System.Threading.Tasks;

namespace ITsynch.Suite.Example.Application
{
    public class LocationUpdatedConsumer : IConsumer<LocationUpdated>
    {
        public LocationUpdatedConsumer()
        {
        }

        public async Task Consume(ConsumeContext<LocationUpdated> context)
        {
            // do some stuff
        }
    }
}

This event has all the Location's information, including LocationNamePath. This property contains the entire Location hierarchy, from the root Location to the Location itself.

Note

LocationUpdated event is published when a Location is updated but also when a Location is created.