| | | 1 | | using LGDXRobotCloud.Data.DbContexts; |
| | | 2 | | using LGDXRobotCloud.Data.Entities; |
| | | 3 | | using LGDXRobotCloud.Utilities.Enums; |
| | | 4 | | using Microsoft.EntityFrameworkCore; |
| | | 5 | | |
| | | 6 | | namespace LGDXRobotCloud.Data.Services; |
| | | 7 | | |
| | 0 | 8 | | public record WaypointData(string Name, double X, double Y, double Rotation); |
| | | 9 | | |
| | | 10 | | public class DataSeeder(LgdxContext context) |
| | | 11 | | { |
| | | 12 | | private readonly LgdxContext _context = context ?? throw new ArgumentNullException(nameof(context)); |
| | | 13 | | |
| | | 14 | | private readonly List<WaypointData> waypoints = [ |
| | | 15 | | new WaypointData("Waypoint 1", 1.5, 0.5, 0), |
| | | 16 | | new WaypointData("Waypoint 2", 1.5, 2.5, 0), |
| | | 17 | | new WaypointData("Waypoint 3", 1.5, 4.5, 0), |
| | | 18 | | new WaypointData("Waypoint 4", 1.5, 6.5, 0), |
| | | 19 | | new WaypointData("Waypoint 5", 1.5, 8.5, 0), |
| | | 20 | | new WaypointData("Waypoint 6", 6.5, 8.5, 3.14159265), |
| | | 21 | | new WaypointData("Waypoint 7", 6.5, 6.5, 3.14159265), |
| | | 22 | | new WaypointData("Waypoint 8", 6.5, 4.5, 3.14159265), |
| | | 23 | | new WaypointData("Waypoint 9", 6.5, 2.5, 3.14159265), |
| | | 24 | | new WaypointData("Waypoint 10",6.5, 0.5, 0), |
| | | 25 | | ]; |
| | | 26 | | |
| | | 27 | | public async Task Seed() |
| | | 28 | | { |
| | | 29 | | // Realm |
| | | 30 | | var realm = await _context.Realms.FirstOrDefaultAsync(); |
| | | 31 | | realm!.Resolution = 0.05; |
| | | 32 | | realm.OriginX = -0.951; |
| | | 33 | | realm.OriginY = -1.11; |
| | | 34 | | |
| | | 35 | | // Waypoint |
| | | 36 | | foreach (var waypoint in waypoints) |
| | | 37 | | { |
| | | 38 | | var wp = new Waypoint |
| | | 39 | | { |
| | | 40 | | Name = waypoint.Name, |
| | | 41 | | X = waypoint.X, |
| | | 42 | | Y = waypoint.Y, |
| | | 43 | | Rotation = waypoint.Rotation, |
| | | 44 | | RealmId = realm.Id |
| | | 45 | | }; |
| | | 46 | | await _context.Waypoints.AddAsync(wp); |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | // Flow |
| | | 50 | | var flow = new Flow |
| | | 51 | | { |
| | | 52 | | Name = "Flow 1", |
| | | 53 | | FlowDetails = [new FlowDetail |
| | | 54 | | { |
| | | 55 | | ProgressId = (int)ProgressState.Moving, |
| | | 56 | | AutoTaskNextControllerId = (int)AutoTaskNextController.Robot, |
| | | 57 | | }] |
| | | 58 | | }; |
| | | 59 | | await _context.Flows.AddAsync(flow); |
| | | 60 | | |
| | | 61 | | // Robots |
| | | 62 | | var robots = new List<Robot> |
| | | 63 | | { |
| | | 64 | | new() { |
| | | 65 | | Id = Guid.Parse("0198276e-97f7-7dd1-982e-56ea02c6d921"), |
| | | 66 | | Name = "Robot1", |
| | | 67 | | RealmId = realm.Id, |
| | | 68 | | IsProtectingHardwareSerialNumber = false, |
| | | 69 | | }, |
| | | 70 | | new (){ |
| | | 71 | | Id = Guid.Parse("0198276e-e868-733b-b9e7-d67c0ab84afd"), |
| | | 72 | | Name = "Robot2", |
| | | 73 | | RealmId = realm.Id, |
| | | 74 | | IsProtectingHardwareSerialNumber = false, |
| | | 75 | | } |
| | | 76 | | }; |
| | | 77 | | |
| | | 78 | | var robotChassisInfo = new List<RobotChassisInfo> |
| | | 79 | | { |
| | | 80 | | new (){ |
| | | 81 | | RobotTypeId = (int)LgdxRobotType.LGDXRobot2Classic, |
| | | 82 | | BatteryCount = 2, |
| | | 83 | | BatteryMaxVoltage = 12.0, |
| | | 84 | | BatteryMinVoltage = 10.0, |
| | | 85 | | ChassisLengthX = 1.0, |
| | | 86 | | ChassisLengthY = 1.0, |
| | | 87 | | ChassisWheelCount = 4, |
| | | 88 | | ChassisWheelRadius = 0.1, |
| | | 89 | | }, |
| | | 90 | | new (){ |
| | | 91 | | RobotTypeId = (int)LgdxRobotType.LGDXRobot2Classic, |
| | | 92 | | BatteryCount = 2, |
| | | 93 | | BatteryMaxVoltage = 12.0, |
| | | 94 | | BatteryMinVoltage = 10.0, |
| | | 95 | | ChassisLengthX = 1.0, |
| | | 96 | | ChassisLengthY = 1.0, |
| | | 97 | | ChassisWheelCount = 4, |
| | | 98 | | ChassisWheelRadius = 0.1, |
| | | 99 | | } |
| | | 100 | | }; |
| | | 101 | | robots[0].RobotChassisInfo = robotChassisInfo[0]; |
| | | 102 | | robots[1].RobotChassisInfo = robotChassisInfo[1]; |
| | | 103 | | |
| | | 104 | | var robotCertificate = new List<RobotCertificate> { |
| | | 105 | | new() { |
| | | 106 | | Thumbprint = "DD53D5856E815B10B9B04B0D85B3BA5A622C184A", |
| | | 107 | | ThumbprintBackup = string.Empty, |
| | | 108 | | NotBefore = DateTime.UtcNow, |
| | | 109 | | NotAfter = DateTime.UtcNow.AddYears(100), |
| | | 110 | | }, |
| | | 111 | | new() { |
| | | 112 | | Thumbprint = "08970F71CED907B1064FA3AD43F82992900FA905", |
| | | 113 | | ThumbprintBackup = string.Empty, |
| | | 114 | | NotBefore = DateTime.UtcNow, |
| | | 115 | | NotAfter = DateTime.UtcNow.AddYears(100), |
| | | 116 | | } |
| | | 117 | | }; |
| | | 118 | | robots[0].RobotCertificate = robotCertificate[0]; |
| | | 119 | | robots[1].RobotCertificate = robotCertificate[1]; |
| | | 120 | | |
| | | 121 | | await _context.Robots.AddRangeAsync(robots); |
| | | 122 | | |
| | | 123 | | await _context.SaveChangesAsync(); |
| | | 124 | | } |
| | | 125 | | } |