public async Task DeliverAsync(string goods)
        {
            var rand = new Random();

            foreach (var good in goods.Split(','))
            {
                var randomNumber = rand.Next(1, 1000);

                // notify about delivery start
                var startDeliveryNotification = new DeliveryStartNotification(good);
                _notificationActor.Tell(startDeliveryNotification);
                // deliver goods
                var deliveryData = new DeliveryGoods(new string[] { good });
                var result       = await _deliveryActor.Ask <DeliveryResult>(deliveryData);

                // notify about delivery finish
                var delivaryFinishNotification = new DeliveryFinishNotification(good, result.ShipId,
                                                                                (NotificationApi.TransportType)result.TransportType, result.DeliveryDate, result.IsSuccess);

                _notificationActor.Tell(delivaryFinishNotification);

                var msg = result.IsSuccess
                ? $"{good} is delivered to {result.Address} by {result.TransportType} {result.ShipId} at {result.DeliveryDate} successfully"
                : $"{good} delivery to {result.Address} by {result.TransportType} {result.ShipId} at {result.DeliveryDate} was failed";

                await _deliveryHub.SendMessageAsync(msg);
            }
        }
Beispiel #2
0
        public void NotifyAboutDeliveryFinish(DeliveryFinishNotification data)
        {
            var path = Configurator.GetValue <string>("ReportPath");
            var msg  = data.IsSuccess
                ? $"{data.Good} are delivered by {data.TransportType} {data.ShipId} successfully"
                : $"Delivery of {data.Good} by {data.TransportType} {data.ShipId} was failed";

            File.AppendAllLines(path, new[] { msg });
        }