public LocationController(
     IServiceLocation serviceLocation,
     ILocationMapper locationMapper,
     IUrlHelper urlHelper
     )
 {
     this.serviceLocation = serviceLocation;
     this.locationMapper  = locationMapper;
     this.urlHelper       = urlHelper;
 }
Exemple #2
0
 void PostMessage(HostCommunicator sender, IServiceLocation target, object message)
 {
     message = new ServiceMessage
     {
         SenderId = sender.Id,
         TargetId = ((ServiceLocation)target).Id,
         Body = message
     };
     var json = JsonConvert.SerializeObject(message, new JsonSerializerSettings
     {
         TypeNameHandling = TypeNameHandling.All
     });
     var msg = Encoding.UTF8.GetBytes(json);
     udpClient.Send(msg, msg.Length, ((ServiceLocation)target).EndPoint);
 }
Exemple #3
0
        public TInterface Build(IServiceLocation <TInterface> location)
        {
            var resolver = _stubResolver;
            var handler  = _stubHandler
                           .Address(location.Address !)
                           .Port(location.Port)
                           .Meta(location.Meta !)
                           .Tags(location.Tags !);

            var stub     = resolver.Resolve <TInterface>();
            var instance = (TInterface)Activator.CreateInstance(stub,
                                                                $"{location.Address!.TrimEnd('/')!}{(location.Port == null ? ":" + location.Port : "")}",
                                                                _factory.CreateClient());

            if (!(instance is IStub))
            {
                throw new ArgumentException();
            }

            ((IStub)instance).UseHandler(handler);

            return(instance);
        }
Exemple #4
0
 protected virtual async Task OnMessageReceived(IServiceLocation sender, object message)
 {
 }
Exemple #5
0
 async Task HandleMessage(IServiceLocation sender, EntityMovedMessage message)
 {
     if (EntityMoved != null) EntityMoved(message);
 }
Exemple #6
0
 async Task HandleMessage(IServiceLocation sender, EntityCreatedMessage message)
 {
     if (EntityCreated != null) EntityCreated(message.EntityId);
 }
Exemple #7
0
 protected override async Task OnMessageReceived(IServiceLocation sender, object message)
 {
     await HandleMessage(sender, (dynamic)message);
 }
Exemple #8
0
 public void DoHandleMessageReceived(IServiceLocation sender, object message)
 {
     messageQueue.Add(new Message { Sender = sender, Content = message });
 }
Exemple #9
0
 public void PostMessage(IServiceLocation target, object message)
 {
     host.PostMessage(this, target, message);
 }