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