예제 #1
0
        public override async Task <Result> ReceiveAsync(EventData <PowerSourceChangeData> @event)
        {
            var data = @event.Value;

            if (data.RobotId == new Guid(88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
            {
                throw new DivideByZeroException("The mystery 88 guid can't be divided by zero.");
            }

            var robot = await _mgr.GetAsync(data.RobotId);

            if (robot == null)
            {
                return(Result.DataNotFound());
            }

            robot.AcceptChanges();
            robot.PowerSource = data.PowerSource;
            if (robot.IsChanged)
            {
                await _mgr.UpdateAsync(robot, data.RobotId);
            }

            Logger.LogInformation("A trace message to prove it works!");

            if (GetOriginatingData() == null)
            {
                Logger.LogError("There should always be originating data!");
            }

            return(Result.Success());
        }
예제 #2
0
        public override async Task <Result> ReceiveAsync(EventData <string> @event)
        {
            _log.LogInformation("A trace message to prove it works!");

            if (@event.Key is Guid id)
            {
                var robot = await _mgr.GetAsync(id);

                if (robot == null)
                {
                    return(Result.DataNotFound());
                }

                robot.AcceptChanges();
                robot.PowerSource = @event.Value;
                if (robot.IsChanged)
                {
                    await _mgr.UpdateAsync(robot, id);
                }

                return(Result.Success());
            }
            else
            {
                return(Result.InvalidData($"Key '{@event.Key}' must be a GUID.", ResultHandling.ContinueWithAudit));
            }
        }
예제 #3
0
 public override Task <proto.Robot> Get(proto.RobotGetRequest request, ServerCallContext context)
 {
     return(new GrpcService <proto.Robot>(context, async() =>
     {
         var __req = request ?? new proto.RobotGetRequest();
         var __result = await _manager.GetAsync(Transformers.GuidToStringConverter.ConvertToSrce(__req.Id));
         return _mapper.Map <Robot, proto.Robot>(__result !) !;
     }, operationType: OperationType.Read, statusCode: HttpStatusCode.OK, alternateStatusCode: HttpStatusCode.NotFound).ExecuteAsync());
예제 #4
0
 public IActionResult Get(Guid id)
 {
     return(new WebApiGet <Robot?>(this, () => _manager.GetAsync(id),
                                   operationType: OperationType.Read, statusCode: HttpStatusCode.OK, alternateStatusCode: HttpStatusCode.NotFound));
 }