public async Task <bool> AddOrUpdateVehicleAsync(VehicleInfo vehicle, CancellationToken cancellationToken) { if (vehicle == null) { throw new ArgumentNullException(nameof(vehicle)); } bool result = false; if (!string.IsNullOrWhiteSpace(vehicle.Plate)) { using (var tx = this.StateManager.CreateTransaction()) { await this.vehiclesDictionary.SetAsync(tx, vehicle.Plate, vehicle, TimeSpan.FromSeconds(5), cancellationToken); await tx.CommitAsync(); result = true; } try { var vehicleProxy = this.actorFactory.Create <IVehicleActor>(new ActorId(vehicle.Plate), new Uri(UriConstants.VehicleActorUri)); await vehicleProxy.UpdateVehicleInfoAsync(vehicle.ToVehicleActorVehicleInfo(), cancellationToken); } catch {} } return(result); }
public async Task <bool> UpdateVehicleStateAsync(string plate, VehicleState newState, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(plate)) { throw new ArgumentException(nameof(plate)); } bool result = false; using (var tx = this.StateManager.CreateTransaction()) { var tryVehicle = await this.vehiclesDictionary.TryGetValueAsync(tx, plate, TimeSpan.FromSeconds(5), cancellationToken); if (tryVehicle.HasValue) { var newVehicle = new VehicleInfo(tryVehicle.Value); newVehicle.State = newState; await this.vehiclesDictionary.SetAsync(tx, plate, newVehicle, TimeSpan.FromSeconds(5), cancellationToken); await tx.CommitAsync(); result = true; } } return(result); }
public static VehicleData FromServiceInterfacesInfo(VehiclesServiceInterfaces.VehicleInfo vehicleInfo) { if (vehicleInfo == null) { throw new ArgumentNullException(nameof(vehicleInfo)); } return(new VehicleData() { Brand = vehicleInfo.Brand, DailyCost = vehicleInfo.DailyCost, Model = vehicleInfo.Model, }); }
public override async Task ExecuteAsync(IEnumerable <string> args) { var vehicle = new iRentCar.VehiclesService.Interfaces.VehicleInfo() { Brand = this.brand, DailyCost = this.dailyCost, Model = this.model, Plate = this.plate, State = this.state }; var response = await VehiclesServiceProxy.Instance.AddOrUpdateVehicleAsync(vehicle, default(CancellationToken)); Console.WriteLine($"AddOrUpdateVehicleAsync --> {response}"); WriteMessage(null); }
public async Task <VehicleInfo> GetVehicleByPlateAsync(string plate, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(plate)) { throw new ArgumentException(nameof(plate)); } VehicleInfo vehicle = null; using (var tx = this.StateManager.CreateTransaction()) { var tryVehicle = await this.vehiclesDictionary.TryGetValueAsync(tx, plate, TimeSpan.FromSeconds(5), cancellationToken); if (tryVehicle.HasValue) { vehicle = tryVehicle.Value; } } return(vehicle); }
public static iRentCar.VehicleActor.Interfaces.VehicleInfo ToVehicleActorVehicleInfo(this VehicleInfo info) { if (info == null) { throw new NullReferenceException(nameof(info)); } return(new iRentCar.VehicleActor.Interfaces.VehicleInfo() { Brand = info.Brand, CurrentRent = null, DailyCost = info.DailyCost, Model = info.Model, Plate = info.Plate, State = info.State.ToVehicleActorVehicleState() }); }
private IVehiclesService CreateServiceProxy(VehicleInfo vehicle) { var partitionKey = new ServicePartitionKey(vehicle.PartitionKey); return(ServiceProxy.Create <IVehiclesService>(serviceUri, partitionKey)); }