diff --git a/Main/Program.cs b/Main/Program.cs index 0cb61f649ae22d30247c61b31350164273d6719e..5a405e7a83434d593f7d504fa78a1622719af4d3 100644 --- a/Main/Program.cs +++ b/Main/Program.cs @@ -48,7 +48,7 @@ namespace Main // Define sensors data list of SensorDataContract var dataList = new[] { - new SensorDataContract + new SensorDataWriteContract { Quantity = "Voltage", Value = "120", @@ -56,7 +56,7 @@ namespace Main DataType = SensorDataType.Decimal, Index = 0, }, - new SensorDataContract + new SensorDataWriteContract { Quantity = "Frequency", Value = "1", @@ -64,7 +64,7 @@ namespace Main DataType = SensorDataType.Decimal, Index = 0, }, - new SensorDataContract + new SensorDataWriteContract { Quantity = "OK parts", Value = "600", @@ -75,7 +75,7 @@ namespace Main }; // Create sensor contract with specific data - SensorContract sensor = new SensorContract + SensorWriteContract sensor = new SensorWriteContract { Login = "buffer", SensorData = dataList.ToArray(), diff --git a/README.md b/README.md index 7a52bf1d5a18d97c12e62c8069a9aaebb5bb25e8..618141f0576622b369c5465841538bd90a687d1a 100644 --- a/README.md +++ b/README.md @@ -270,6 +270,9 @@ await devkitConnector.AddSensorData(sensorContracts); * `Post(string subUrl, object body)` * `Patch(string subUrl, object body)` * `Delete(string subUrl)` +* **Paths** + * `GetPaths()` - Get all paths + * `GetPath(id)` - Get path by ID ## Future features - **protobuffers** serialization diff --git a/SDK/Connection/V3/Areas.cs b/SDK/Connection/V3/Areas.cs index c764679dd8003e751fbdac27a7e41e1ff3572545..f0469415235415b190a1a2544706e29f562d1dac 100644 --- a/SDK/Connection/V3/Areas.cs +++ b/SDK/Connection/V3/Areas.cs @@ -18,7 +18,7 @@ namespace SDK return await GetRequest<AreaContract>(subUrl); } - public async Task<AreaContract> AddArea(AreaContract area) + public async Task<AreaContract> AddArea(AreaWriteContract area) { string subUrl = Address.UrlCombine(Address.Areas); return await PostRequest<AreaContract>(subUrl, area); diff --git a/SDK/Connection/V3/Beacons.cs b/SDK/Connection/V3/Beacons.cs index 4f7400f2d6789af95fb6847b4b24e9450989790e..982192346209e054aa91cfc0edbdfc62dec74f4c 100644 --- a/SDK/Connection/V3/Beacons.cs +++ b/SDK/Connection/V3/Beacons.cs @@ -23,17 +23,12 @@ namespace SDK return response; } - public async Task<BeaconContract> AddBeacon(BeaconContract beaconContract) + public async Task<BeaconContract> AddBeacon(BeaconWriteContract beaconContract) { string subUrl = Address.UrlCombine(Address.Beacons); - var response = await PostRequest<AddBeaconResponseContract>(subUrl, beaconContract); + var response = await PostRequest<BeaconContract>(subUrl, beaconContract); - if (response.ErrorMessage != null) - { - throw new ServerResponseException(ServerResponseException.message + " " + response.ErrorMessage); - } - - return (BeaconContract)response; + return response; } public async Task UpdateBeacon(int id, object changes) diff --git a/SDK/Connection/V3/Devices.cs b/SDK/Connection/V3/Devices.cs index 1036ddbc43f71e3dd1b31059ac443451897dc3c7..88abc3f423f0b6c37719892aa30ec9f21c50c01f 100644 --- a/SDK/Connection/V3/Devices.cs +++ b/SDK/Connection/V3/Devices.cs @@ -50,7 +50,7 @@ namespace SDK return response; } - public async Task<DeviceContract> AddDevice(DeviceContract deviceContract) + public async Task<DeviceContract> AddDevice(DeviceWriteContract deviceContract) { string subUrl = Address.UrlCombine(Address.Devices); return await PostRequest<DeviceContract>(subUrl, deviceContract); diff --git a/SDK/Connection/V3/Layers.cs b/SDK/Connection/V3/Layers.cs index 181c47089d1fc9c36652b3177bb24cfb9182c092..a384e7b446ebef2a1d2895234ac5f2eee35d955e 100644 --- a/SDK/Connection/V3/Layers.cs +++ b/SDK/Connection/V3/Layers.cs @@ -24,14 +24,6 @@ namespace SDK return response; } - public async Task<LayerContract[]> GetNoGoLayers(string deviceLogin, string queryString = "") - { - string subUrl = Address.UrlCombine(Address.LayersNoGo, deviceLogin, queryString); - var response = await GetRequest<LayerContract[]>(subUrl); - - return response; - } - public async Task<LayerContract[]> GetLocalizationLayers(string deviceLogin, string queryString = "") { string subUrl = Address.UrlCombine(Address.Layerslocalization, deviceLogin, queryString); @@ -40,15 +32,7 @@ namespace SDK return response; } - public async Task<LayerContract[]> GetLocalizationLayers(LoginContract loginContract, string queryString = "") - { - string subUrl = Address.UrlCombine(Address.Layerslocalization, queryString); - var response = await PostRequest<LayerContract[]>(subUrl, loginContract); - - return response; - } - - public async Task<LayerContract> AddLayer(LayerContract layer) + public async Task<LayerContract> AddLayer(LayerWriteContract layer) { string subUrl = Address.UrlCombine(Address.Layers); var response = await PostRequest<LayerContract>(subUrl, layer); diff --git a/SDK/Connection/V3/Log.cs b/SDK/Connection/V3/Log.cs index faf38e03149471d3b2249cf0c053780154f2944f..c6db1c467f24d663f5908d8c80cc93644fb210e1 100644 --- a/SDK/Connection/V3/Log.cs +++ b/SDK/Connection/V3/Log.cs @@ -7,7 +7,7 @@ namespace SDK { public partial class DevkitConnectorV3 { - public async Task<LogContract> AddLog(LogContract logContract) + public async Task<LogContract> AddLog(LogWriteContract logContract) { string subUrl = Address.UrlCombine(Address.LogAdd); return await PostRequest<LogContract>(subUrl, logContract); diff --git a/SDK/Connection/V3/Paths.cs b/SDK/Connection/V3/Paths.cs new file mode 100644 index 0000000000000000000000000000000000000000..78abea7c30b12992a8d3d5ca5eb187ce32718b35 --- /dev/null +++ b/SDK/Connection/V3/Paths.cs @@ -0,0 +1,21 @@ +using SDK.Models; +using System; +using System.Threading.Tasks; + +namespace SDK +{ + public partial class DevkitConnectorV3 + { + public async Task<PathContract[]> GetPaths(string queryString = "") + { + string subUrl = Address.UrlCombine(Address.Paths, queryString); + return await GetRequest<PathContract[]>(subUrl); + } + + public async Task<PathContract> GetPath(int id, string queryString = "") + { + string subUrl = Address.UrlCombine(Address.Paths, Convert.ToString(id), queryString); + return await GetRequest<PathContract>(subUrl); + } + } +} \ No newline at end of file diff --git a/SDK/Connection/V3/Quantities.cs b/SDK/Connection/V3/Quantities.cs index 6cdae78165987722136434f6c8f3ab6d5ab74ecf..bd19070b6fdbdad5695443acf8754ade4440cf8b 100644 --- a/SDK/Connection/V3/Quantities.cs +++ b/SDK/Connection/V3/Quantities.cs @@ -18,7 +18,7 @@ namespace SDK return await GetRequest<QuantityContract>(subUrl); } - public async Task<QuantityContract> AddQuantity(QuantityContract Quantity) + public async Task<QuantityContract> AddQuantity(QuantityWriteContract Quantity) { string subUrl = Address.UrlCombine(Address.Quantities); return await PostRequest<QuantityContract>(subUrl, Quantity); @@ -27,7 +27,7 @@ namespace SDK public async Task UpdateQuantity(QuantityContract Quantity) { string subUrl = Address.UrlCombine(Address.Quantities, Convert.ToString(Quantity.Id)); - await PatchRequest<QuantityContract>(subUrl, Quantity); + await PatchRequest(subUrl, Quantity); } public async Task DeleteQuantity(int id) diff --git a/SDK/Connection/V3/Sectors.cs b/SDK/Connection/V3/Sectors.cs index a1b539103602aeced2ff1fa706279c43a479fe36..0f0cde87ae97c94a61907a75b8da9d5ada255836 100644 --- a/SDK/Connection/V3/Sectors.cs +++ b/SDK/Connection/V3/Sectors.cs @@ -25,17 +25,12 @@ namespace SDK return response; } - public async Task<SectorContract> AddSector(SectorContract sectorContract) + public async Task<SectorContract> AddSector(SectorWriteContract sectorContract) { string subUrl = Address.UrlCombine(Address.Sectors); - var response = await PostRequest<AddSectorResponseContract>(subUrl, sectorContract); + var response = await PostRequest<SectorContract>(subUrl, sectorContract); - if (response.ErrorMessage != null) - { - throw new ServerResponseException(ServerResponseException.message + " " + response.ErrorMessage); - } - - return (SectorContract)response; + return response; } public async Task UpdateSector(int id, object changes) diff --git a/SDK/Connection/V3/Sensors.cs b/SDK/Connection/V3/Sensors.cs index e3903a4c6f367ea4c6b624cf4f2d9107c0c2a0f5..28571f5850a13f7bfab065bb86acc6fa6dc27d37 100644 --- a/SDK/Connection/V3/Sensors.cs +++ b/SDK/Connection/V3/Sensors.cs @@ -31,7 +31,7 @@ namespace SDK return response; } - public async Task<SensorContract> AddSensor(SensorContract sensorContract) + public async Task<SensorContract> AddSensor(SensorWriteContract sensorContract) { string subUrl = Address.UrlCombine(Address.Sensors); var response = await PostRequest<AddSensorResponseContract>(subUrl, sensorContract); @@ -53,7 +53,7 @@ namespace SDK string subUrl = Address.UrlCombine(Address.Sensors, Convert.ToString(id)); await DeleteRequest(subUrl); } - public async Task<PostResponseContract[]> AddSensorData(SensorContract[] sensors) + public async Task<PostResponseContract[]> AddSensorData(SensorWriteContract[] sensors) { string subUrl = Address.UrlCombine(Address.SensorsAddDataBatch); var response = await PostRequest<AddSensorDataResponseContract[]>(subUrl, sensors); @@ -82,7 +82,7 @@ namespace SDK return response; } - public async Task<PostResponseContract> AddSensorData(SensorDataContract[] sensorData) + public async Task<PostResponseContract> AddSensorData(SensorDataWriteContract[] sensorData) { string subUrl = Address.UrlCombine(Address.SensorsAddData); var response = await PostRequest<SensorDataResponseContract[]>(subUrl, sensorData); //AddSensorDataResponseContract diff --git a/SDK/Connection/V3/Shifts.cs b/SDK/Connection/V3/Shifts.cs index 1a6ec6fdfc0074b08c02d7d0ea1db695506d6732..60f7fc272289748088a4cb0cf75d17b2ae2681b4 100644 --- a/SDK/Connection/V3/Shifts.cs +++ b/SDK/Connection/V3/Shifts.cs @@ -26,7 +26,7 @@ namespace SDK return response; } - public async Task<ShiftContract> AddShift(ShiftContract shiftContract) + public async Task<ShiftContract> AddShift(ShiftWriteContract shiftContract) { string subUrl = Address.UrlCombine(Address.Shifts); var response = await PostRequest<AddShiftResponseContract>(subUrl, shiftContract); diff --git a/SDK/Contracts/Communication/AddBeaconResponseContract.cs b/SDK/Contracts/Communication/AddBeaconResponseContract.cs deleted file mode 100644 index 3265af3ed18cba0debf6f40c3dc26d07f8ada916..0000000000000000000000000000000000000000 --- a/SDK/Contracts/Communication/AddBeaconResponseContract.cs +++ /dev/null @@ -1,72 +0,0 @@ -using SDK.Communication; -using SDK.Models; - -namespace SDK.Contracts.Communication -{ - public class AddBeaconResponseContract : PostResponseContract - { - public int Id { get; set; } - - public int? SectorId { get; set; } - - public int BranchId { get; set; } - - public string Mac { get; set; } - - public double? X { get; set; } - - public double? Y { get; set; } - - public double? Z { get; set; } - - public string Title { get; set; } - - public bool Active { get; set; } - - public bool Position { get; set; } - - public int? TypeId { get; set; } - - public bool Geofence { get; set; } - - public double? GeofenceRange { get; set; } - - public string Cluster { get; set; } - - public long? LastTimeOnline { get; set; } - - public bool UseGps { get; set; } - - public string CFUUID { get; set; } - - public long Created { get; set; } - - public long Update { get; set; } - - public static explicit operator BeaconContract(AddBeaconResponseContract addBeaconResponseContract) - { - return new BeaconContract - { - Id = addBeaconResponseContract.Id, - SectorId = addBeaconResponseContract.SectorId, - BranchId = addBeaconResponseContract.BranchId, - Mac = addBeaconResponseContract.Mac, - X = addBeaconResponseContract.X, - Y = addBeaconResponseContract.Y, - Z = addBeaconResponseContract.Z, - Title = addBeaconResponseContract.Title, - Active = addBeaconResponseContract.Active, - Position = addBeaconResponseContract.Position, - TypeId = addBeaconResponseContract.TypeId, - Geofence = addBeaconResponseContract.Geofence, - GeofenceRange = addBeaconResponseContract.GeofenceRange, - Cluster = addBeaconResponseContract.Cluster, - LastTimeOnline = addBeaconResponseContract.LastTimeOnline, - UseGps = addBeaconResponseContract.UseGps, - CFUUID = addBeaconResponseContract.CFUUID, - Created = addBeaconResponseContract.Created, - Update = addBeaconResponseContract.Update, - }; - } - } -} diff --git a/SDK/Contracts/Communication/AddLogContract.cs b/SDK/Contracts/Communication/AddLogContract.cs index 8d054706781672863a2a8a5f5cf3ad265b1020dd..cc2589898c474c9f15838b4f3b3e3dc4fdbf7fcb 100644 --- a/SDK/Contracts/Communication/AddLogContract.cs +++ b/SDK/Contracts/Communication/AddLogContract.cs @@ -1,6 +1,7 @@ using SDK.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Runtime.Serialization; using System.Text; @@ -32,4 +33,34 @@ namespace SDK.Contracts.Communication [DataMember(Order = 8)] public string Login { get; set; } } + + public class LogWriteContract + { + /// <summary> + /// If not provided, make sure to provide <b>Login</b> property, which is the <i>Login</i> of the <i>Account</i> + /// you want to associate this <i>Log</i> with. The system will find its AccountId. + /// </summary> + [DataMember(Order = 1)] + public int? AccountId { get; set; } + + [DataMember(Order = 2)] + [StringLength(5000)] + public string Message { get; set; } + + [DataMember(Order = 3)] + [StringLength(20)] + public string Level { get; set; } + + /// <summary> + /// Provide a unix miliseconds UTC value. If not provided, current time will be used. + /// </summary> + [DataMember(Order = 4)] + public long? Timestamp { get; set; } + + /// <summary> + /// If <b>AccountId</b> is not provided, this property is used to find the <i>Account</i> to associate this <i>Log</i> with. + /// </summary> + [DataMember(Order = 5)] + public string Login { get; set; } + } } diff --git a/SDK/Contracts/Communication/AddSectorResponseContract.cs b/SDK/Contracts/Communication/AddSectorResponseContract.cs deleted file mode 100644 index 09d9471b478240ed95c03a41776fd4c07b783353..0000000000000000000000000000000000000000 --- a/SDK/Contracts/Communication/AddSectorResponseContract.cs +++ /dev/null @@ -1,61 +0,0 @@ -using SDK.Communication; -using SDK.Models; -using System; - -namespace SDK.Contracts.Communication -{ - class AddSectorResponseContract : PostResponseContract - { - public int Id { get; set; } - - public Guid Guid { get; set; } - - public int BranchId { get; set; } - - public string Title { get; set; } - - public float BarrierWidth { get; set; } - - public float BarrierHeight { get; set; } - - public float SectorWidth { get; set; } - - public float SectorHeight { get; set; } - - public long Modified { get; set; } - - public string Configuration { get; set; } - - public GpsItemContract[] GpsItems { get; set; } - - public AreaContract[] Areas { get; set; } - - public BarrierContract[] Barriers { get; set; } - - public BeaconContract[] Beacons { get; set; } - - public SensorContract[] Sensors { get; set; } - - public static explicit operator SectorContract(AddSectorResponseContract addSectorResponseContract) - { - return new SectorContract - { - Id = addSectorResponseContract.Id, - Guid = addSectorResponseContract.Guid, - BranchId = addSectorResponseContract.BranchId, - Title = addSectorResponseContract.Title, - BarrierHeight = addSectorResponseContract.BarrierHeight, - BarrierWidth = addSectorResponseContract.BarrierWidth, - SectorWidth = addSectorResponseContract.SectorWidth, - SectorHeight = addSectorResponseContract.SectorHeight, - Modified = addSectorResponseContract.Modified, - Configuration = addSectorResponseContract.Configuration, - GpsItems = addSectorResponseContract.GpsItems, - Areas = addSectorResponseContract.Areas, - Barriers = addSectorResponseContract.Barriers, - Beacons = addSectorResponseContract.Beacons, - Sensors = addSectorResponseContract.Sensors - }; - } - } -} diff --git a/SDK/Contracts/Data/AccountContract.cs b/SDK/Contracts/Data/AccountContract.cs index ef120943f137c55a5366996897febce8bdf6dc54..b0cadea61c2e5d45e023216b2ce0a9add2976a7d 100644 --- a/SDK/Contracts/Data/AccountContract.cs +++ b/SDK/Contracts/Data/AccountContract.cs @@ -1,7 +1,11 @@ -namespace SDK.Contracts.Data +using System.ComponentModel.DataAnnotations; + +namespace SDK.Contracts.Data { public class AccountContract { + [Required] + [StringLength(255)] public string Login { get; set; } //public string Password { get; set; } diff --git a/SDK/Contracts/Data/AreaContract.cs b/SDK/Contracts/Data/AreaContract.cs index d52338e619ed1366bbe9bbca0158ea901fa398b4..1e2db0e6f7f2b94582972dba8ea967714c90c407 100644 --- a/SDK/Contracts/Data/AreaContract.cs +++ b/SDK/Contracts/Data/AreaContract.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel.DataAnnotations; namespace SDK.Models { @@ -26,6 +27,23 @@ namespace SDK.Models public long Updated { get; set; } public string ExternalId { get; set; } + + public static explicit operator AreaWriteContract(AreaContract contract) + { + return new AreaWriteContract + { + Title = contract.Title, + Created = contract.Created, + Updated = contract.Updated, + ExternalId = contract.ExternalId, + Description = contract.Description, + Coordinates = contract.Coordinates, + Color = contract.Color, + LayerId = contract.LayerId, + SectorId = contract.SectorId, + Guid = contract.Guid, + }; + } } public class PointContract @@ -34,4 +52,32 @@ namespace SDK.Models public double Y { get; set; } } + + public class AreaWriteContract + { + public Guid Guid { get; set; } + + [Required] + public string Title { get; set; } + + public int SectorId { get; set; } + + public int? LayerId { get; set; } + + [StringLength(25)] + public string Color { get; set; } + + public PointContract[] Coordinates { get; set; } + + public string Description { get; set; } + + public long Created { get; set; } + + public long Updated { get; set; } + + public int? TargetBranchId { get; set; } + + [StringLength(25)] + public string ExternalId { get; set; } + } } diff --git a/SDK/Contracts/Data/BeaconContract.cs b/SDK/Contracts/Data/BeaconContract.cs index fa166e6fa7a3d7b13f5eb13b96005062532a29c6..f6ceb1e89781bb1936aa9d74ff6f574284801fed 100644 --- a/SDK/Contracts/Data/BeaconContract.cs +++ b/SDK/Contracts/Data/BeaconContract.cs @@ -1,4 +1,7 @@ -namespace SDK.Models +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; + +namespace SDK.Models { public class BeaconContract { @@ -40,4 +43,40 @@ public long Update { get; set; } } + + public class BeaconWriteContract + { + public int? SectorId { get; set; } + + [Required] + [StringLength(17)] + public string Mac { get; set; } + + public float? X { get; set; } + + public float? Y { get; set; } + + public float? Z { get; set; } + + [Required] + [StringLength(50)] + public string Title { get; set; } + + public bool Active { get; set; } + + public int? TypeId { get; set; } + + public bool Position { get; set; } + + public bool Geofence { get; set; } + + public float? GeofenceRange { get; set; } + + [StringLength(10)] + public string Cluster { get; set; } + + public long? LastTimeOnline { get; set; } + + public bool UseGps { get; set; } + } } diff --git a/SDK/Contracts/Data/DeviceContract.cs b/SDK/Contracts/Data/DeviceContract.cs index 1dd9d4d4bfb65a5f6b3cd9d187cfaf26a0ee14e8..107208521d90086a98bc6b6bb33609d3ca39b951 100644 --- a/SDK/Contracts/Data/DeviceContract.cs +++ b/SDK/Contracts/Data/DeviceContract.cs @@ -1,5 +1,8 @@ using Core.Enum; using SDK.Contracts.Data; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SDK.Models { @@ -48,5 +51,80 @@ namespace SDK.Models public bool Geofence { get; set; } public float? GeofenceRange { get; set; } + + public static explicit operator DeviceWriteContract(DeviceContract contract) + { + return new DeviceWriteContract + { + Title = contract.Title, + Note = contract.Note, + Mac = contract.Mac, + SectorId = contract.SectorId, + LastTimeOnline = contract.LastTimeOnline, + X = (float)contract.X, + Y = (float)contract.Y, + AppVersion = contract.AppVersion, + IsMoving = contract.IsMoving, + FallStatus = contract.FallStatus, + Battery = contract.Battery, + DeviceTypeId = contract.DeviceTypeId, + Position = contract.Position, + Geofence = contract.Geofence, + GeofenceRange = contract.GeofenceRange, + Login = contract.Login, + }; + } + } + + public class DeviceWriteContract : AccountContract + { + [StringLength(17)] + public string Mac { get; set; } + + public int? SectorId { get; set; } + + [Required] + [StringLength(50)] + public string Title { get; set; } + + public string Note { get; set; } + + public long? LastTimeOnline { get; set; } + + public float? X { get; set; } + + public float? Y { get; set; } + + public float? Z { get; set; } + + [StringLength(17)] + public string AppVersion { get; set; } + + public bool IsMoving { get; set; } + + public FallType FallStatus { get; set; } + + public float? Battery { get; set; } + + public int? DeviceTypeId { get; set; } + + public bool Position { get; set; } + + public bool Geofence { get; set; } + + public float? GeofenceRange { get; set; } + + public string Password { get; set; } + /// <summary> + /// An array of <b>Layer Ids</b> that are NoGo Layers for this <b>Device</b>. + /// </summary> + public HashSet<int> Layers { get; set; } + + [StringLength(17)] + public string DeviceStatus { get; set; } + + public long? Heartbeat { get; set; } + + public string Color { get; set; } } } diff --git a/SDK/Contracts/Data/LayerContract.cs b/SDK/Contracts/Data/LayerContract.cs index 4716d3eb04a6093a265a0c15e45bc0522e1a0a53..f77364f7c3e4e04994c41d3e038a0701e0647ef0 100644 --- a/SDK/Contracts/Data/LayerContract.cs +++ b/SDK/Contracts/Data/LayerContract.cs @@ -1,4 +1,8 @@ using SDK.Models; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Runtime.Serialization; namespace SDK.Contracts.Data { @@ -26,5 +30,60 @@ namespace SDK.Contracts.Data public bool IsNoGo { get; set; } public string ExternalId { get; set; } + + public static explicit operator LayerWriteContract(LayerContract contract) + { + return new LayerWriteContract + { + Title = contract.Title, + Created = contract.Created, + Icon = contract.Icon, + Visible = contract.Visible, + Localization = contract.Localization, + Updated = contract.Updated, + ExternalId = contract.ExternalId, + Areas = contract.Areas.Select(area => area.Id).ToHashSet(), + Paths = contract.Devices.Select(device => device.Id).ToHashSet(), + }; + } + } + + public class LayerWriteContract + { + [Required] + [StringLength(255)] + public string Title { get; set; } + + public string Icon { get; set; } + + public bool Visible { get; set; } + + public bool Localization { get; set; } + + public long Created { get; set; } + + public long Updated { get; set; } + /// <summary> + /// An array of <b>Area Ids</b> to associate with this <b>Layer</b>. + /// </summary> + public HashSet<int> Areas { get; set; } + + /// <summary> + /// An array of <b>Device Ids</b> to associate with this <b>Layer</b>. + /// </summary> + public HashSet<int> Devices { get; set; } + + /// <summary> + /// An array of <b>Path Ids</b> to associate with this <b>Layer</b>. + /// </summary> + public HashSet<int> Paths { get; set; } + + /// <summary> + /// An array of <b>Layer Ids</b> that are children of this <b>Layer</b>. + /// </summary> + public HashSet<int> Children { get; set; } + + [StringLength(255)] + public string ExternalId { get; set; } } } diff --git a/SDK/Contracts/Data/LoginContract.cs b/SDK/Contracts/Data/LoginContract.cs deleted file mode 100644 index 3fa8f4b8aecea61ca5f301fe6c80d95e97217e55..0000000000000000000000000000000000000000 --- a/SDK/Contracts/Data/LoginContract.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SDK.Contracts.Data -{ - public class LoginContract - { - public string Login { get; set; } - } -} diff --git a/SDK/Contracts/Data/PathContract.cs b/SDK/Contracts/Data/PathContract.cs new file mode 100644 index 0000000000000000000000000000000000000000..b74bc6ba87f0714e483e0e29faeefa1f5f04d391 --- /dev/null +++ b/SDK/Contracts/Data/PathContract.cs @@ -0,0 +1,47 @@ +using System; + +namespace SDK.Models +{ + public class PathContract + { + public int Id { get; set; } + + public Guid Guid { get; set; } + + public string Title { get; set; } + + public int SectorId { get; set; } + + + public int BranchId { get; set; } + + + public int? LayerId { get; set; } + + + public string Color { get; set; } + + public PathPointContract[] PathPoints { get; set; } + + public string Description { get; set; } + + public long Created { get; set; } + + public long Updated { get; set; } + } + + public class PathPointContract + { + public int Id { get; set; } + + public int PathId { get; set; } + + public int BranchId { get; set; } + + public int Index { get; set; } + + public float X { get; set; } + + public float Y { get; set; } + } +} \ No newline at end of file diff --git a/SDK/Contracts/Data/QuantityContract.cs b/SDK/Contracts/Data/QuantityContract.cs index 5433bd2377cc60bd9495c44f38dda5771bd0b9e6..bf7086ed722c80d3b64d430e80e97229aa096968 100644 --- a/SDK/Contracts/Data/QuantityContract.cs +++ b/SDK/Contracts/Data/QuantityContract.cs @@ -18,6 +18,15 @@ namespace SDK.Models [DataMember(Order = 4)] public RangeContract Range { get; set; } + + public static explicit operator QuantityWriteContract(QuantityContract contract) + { + return new QuantityWriteContract + { + Title = contract.Title, + Range = contract.Range, + }; + } } [DataContract] @@ -44,4 +53,15 @@ namespace SDK.Models [DataMember(Order = 2)] public string value { get; set; } } + + public class QuantityWriteContract + { + [DataMember(Order = 1)] + [Required] + [StringLength(255)] + public string Title { get; set; } + + [DataMember(Order = 2)] + public RangeContract Range { get; set; } + } } diff --git a/SDK/Contracts/Data/SectorContract.cs b/SDK/Contracts/Data/SectorContract.cs index 50b77a40864dcf998b6630747fc704c843f7b0f1..d944755fd4b54e979b60157bf9892584a1a810da 100644 --- a/SDK/Contracts/Data/SectorContract.cs +++ b/SDK/Contracts/Data/SectorContract.cs @@ -1,4 +1,7 @@ using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SDK.Models { @@ -33,6 +36,8 @@ namespace SDK.Models public BeaconContract[] Beacons { get; set; } public SensorContract[] Sensors { get; set; } + + public int? Floor { get; set; } } public class BarrierContract @@ -60,4 +65,56 @@ namespace SDK.Models public double Longitude { get; set; } } + + public class SectorWriteContract + { + public Guid Guid { get; set; } + + [Required] + [StringLength(50)] + public string Title { get; set; } + + public float BarrierHeight { get; set; } + + public float BarrierWidth { get; set; } + + public float SectorWidth { get; set; } + + public float SectorHeight { get; set; } + + public long Modified { get; set; } + + /// <summary> + /// An Array of <b>GpsItem Ids</b> that are in this sector. + /// </summary> + public HashSet<int> GpsItems { get; set; } + + /// <summary> + /// An Array of <b>Area Ids</b> that are in this sector. + /// </summary> + public HashSet<int> Areas { get; set; } + + /// <summary> + /// An Array of <b>Barrier Ids</b> that are in this sector. + /// </summary> + public HashSet<int> Barriers { get; set; } + + /// <summary> + /// An Array of <b>Beacon Ids</b> that are in this sector. + /// </summary> + public HashSet<int> Beacons { get; set; } + + /// <summary> + /// An Array of <b>Sensor Ids</b> that are in this sector. + /// </summary> + public HashSet<int> Sensors { get; set; } + + public string Configuration { get; set; } + /// <summary> + /// An Array of <b>Path Ids</b> that are in this sector. + /// </summary> + public HashSet<int> Paths { get; set; } + + public int? Floor { get; set; } + } } diff --git a/SDK/Contracts/Data/SensorContract.cs b/SDK/Contracts/Data/SensorContract.cs index 277a0a88c5fcec87dd0b5d7d6fec3dd77464c201..f600141ec73cf3c16e13c990979da9b4c45dfe0a 100644 --- a/SDK/Contracts/Data/SensorContract.cs +++ b/SDK/Contracts/Data/SensorContract.cs @@ -1,4 +1,6 @@ using SDK.Contracts.Data; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SDK.Models { @@ -25,4 +27,36 @@ namespace SDK.Models public int? AreaId { get; set; } public string ExternalId { get; set; } } + + public class SensorWriteContract : AccountContract + { + [Required] + [StringLength(50)] + public string Title { get; set; } + + [StringLength(17)] + public string Mac { get; set; } + + public string Note { get; set; } + + public float? X { get; set; } + + public float? Y { get; set; } + + public float? Battery { get; set; } + + public int? SectorId { get; set; } + + public SensorDataWriteContract[] SensorData { get; set; } + + public int? AreaId { get; set; } + + public string Password { get; set; } + + [StringLength(25)] + public string Color { get; set; } + + [StringLength(50)] + public string ExternalId { get; set; } + } } diff --git a/SDK/Contracts/Data/SensorDataContract.cs b/SDK/Contracts/Data/SensorDataContract.cs index 328ecbe1373c3e49e4759d7e554a362cc199b09b..640c43eea9fae08d69558193bf9cdb8d5600d34b 100644 --- a/SDK/Contracts/Data/SensorDataContract.cs +++ b/SDK/Contracts/Data/SensorDataContract.cs @@ -1,4 +1,6 @@ using SDK.Enum; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SDK.Models { @@ -24,4 +26,31 @@ namespace SDK.Models public RangeContract Range { get; set; } } + + public class SensorDataWriteContract + { + [Required] + [StringLength(255)] + public string Quantity { get; set; } + + [Required] + [StringLength(1000)] + public string Value { get; set; } + + [StringLength(15)] + public string Unit { get; set; } + + [Required] + public SensorDataType DataType { get; set; } + + public long Timestamp { get; set; } + + public RangeContract Range { get; set; } + + public int Index { get; set; } + + public bool VisibleInApp { get; set; } + + public int SensorId { get; set; } + } } diff --git a/SDK/Contracts/Data/ShiftContract.cs b/SDK/Contracts/Data/ShiftContract.cs index fe4cc98d7632c5f77c24da9c5300a6354661ddca..2f708922c759c5842a62bffaf78c3aae7b91ba74 100644 --- a/SDK/Contracts/Data/ShiftContract.cs +++ b/SDK/Contracts/Data/ShiftContract.cs @@ -1,4 +1,7 @@ -namespace SDK.Contracts.Data +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; + +namespace SDK.Contracts.Data { public class ShiftContract { @@ -11,5 +14,26 @@ public long StartTime { get; set; } public long StopTime { get; set; } + + public static explicit operator ShiftWriteContract(ShiftContract contract) + { + return new ShiftWriteContract + { + Title = contract.Title, + StartTime = contract.StartTime, + StopTime = contract.StopTime, + }; + } + } + + public class ShiftWriteContract + { + [Required] + [StringLength(255)] + public string Title { get; set; } + + public long StartTime { get; set; } + + public long StopTime { get; set; } } } diff --git a/SDK/Exceptions/ExceptionContent.cs b/SDK/Exceptions/ExceptionContent.cs deleted file mode 100644 index 27be96e0dbbc933472003596da50973785028d85..0000000000000000000000000000000000000000 --- a/SDK/Exceptions/ExceptionContent.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace SDK.Exceptions -{ - public class ExceptionContent - { - public string Code { get; set; } - public string Message { get; set; } - } -} diff --git a/SDK/Helpers/Address.cs b/SDK/Helpers/Address.cs index 16c08ad034425c4ba52a10e48fcb338270690583..2e85813253b5330de5ae107eef3a9f8962fccf79 100644 --- a/SDK/Helpers/Address.cs +++ b/SDK/Helpers/Address.cs @@ -50,6 +50,8 @@ namespace SDK.Models public const string LogAdd = "logs"; + public const string Paths = "paths/"; + public const string Sectors = "sectors/"; public const string Sensors = "sensors/"; diff --git a/SDK/SDK.csproj b/SDK/SDK.csproj index b7429ea3831cf20fac4e627b6e37c5a515ae0e2e..59235ec182a5147d99dc1ed6a3ea5e684d9de14d 100644 --- a/SDK/SDK.csproj +++ b/SDK/SDK.csproj @@ -13,7 +13,7 @@ <TargetFrameworks Condition="'$(TargetFrameworkOverride)' != ''">$(TargetFrameworkOverride)</TargetFrameworks> <AssemblyVersion>2021.6.28.25</AssemblyVersion> <FileVersion>2021.6.28.25</FileVersion> - <Version>5.7.0</Version> + <Version>5.8.0</Version> <GeneratePackageOnBuild>true</GeneratePackageOnBuild> </PropertyGroup> diff --git a/Test/Test/TestData/Paths.cs b/Test/Test/TestData/Paths.cs new file mode 100644 index 0000000000000000000000000000000000000000..6da71dfb653ba0bd40c0ad96fccf467d836ab6cd --- /dev/null +++ b/Test/Test/TestData/Paths.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using SDK.Models; + +namespace Test.TestData +{ + public static class Paths + { + public static readonly Guid TestPathId1 = new Guid("11111111-1111-1111-1111-111111111111"); + public static readonly Guid TestPathId2 = new Guid("22222222-2222-2222-2222-222222222222"); + + public static PathContract GetTestPath(Guid guid) => new PathContract + { + Id = 1, + Title = $"Test Path 1", + Description = "A test path for unit testing", + BranchId = 1, + SectorId = 1, + LayerId = 1, + Guid = guid, + PathPoints = new [] + { + new PathPointContract + { + Id = 1, + X = 0, + Y = 0, + }, + new PathPointContract + { + Id = 2, + X = 10, + Y = 10, + } + } + }; + + public static IEnumerable<PathContract> GetTestPaths() + { + return new List<PathContract> + { + GetTestPath(TestPathId1), + GetTestPath(TestPathId2) + }; + } + } +} diff --git a/Test/Test/V3/Areas.cs b/Test/Test/V3/Areas.cs index 076800e9cb6a7436061abdcf332e9df28d4689a0..7edb16de7a577ee3c45d4e3017083fbac2d992ad 100644 --- a/Test/Test/V3/Areas.cs +++ b/Test/Test/V3/Areas.cs @@ -47,7 +47,7 @@ namespace Test.V3 server.Given(Request.Create().WithPath(PATH_BASE + AREAS).UsingPost()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); - AreaContract response = await devkitConnector.AddArea(bodyContent); + AreaContract response = await devkitConnector.AddArea((AreaWriteContract)bodyContent); Assert.IsInstanceOfType(response, typeof(AreaContract)); } diff --git a/Test/Test/V3/Devices.cs b/Test/Test/V3/Devices.cs index 472750a38d8f9dcd3f2d2774a31e0c6e7789f7fe..0046c4b7cdc9bdba8f2afb6ea908b58bc92355fd 100644 --- a/Test/Test/V3/Devices.cs +++ b/Test/Test/V3/Devices.cs @@ -1,4 +1,5 @@ using Core.Enum; +using Microsoft.AspNetCore.Mvc; using Microsoft.VisualStudio.TestTools.UnitTesting; using SDK.Contracts.Communication; using SDK.Contracts.Data; @@ -20,10 +21,10 @@ namespace Test.V3 [TestMethod] public async Task GetDevices_ErrorHandling_ShouldThrowsException() { - var bodyContent = new ExceptionContent + var bodyContent = new ProblemDetails { - Code = "10", - Message = "Error" + Title = "Specify the Error from Type property more.", + Detail = "How to solve error." }; server.Reset(); @@ -87,7 +88,7 @@ namespace Test.V3 server.Given(Request.Create().WithPath(PATH_BASE + DEVICES).UsingPost()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); - DeviceContract response = await devkitConnector.AddDevice(bodyContent); + DeviceContract response = await devkitConnector.AddDevice((DeviceWriteContract)bodyContent); Assert.IsInstanceOfType(response, typeof(DeviceContract)); } diff --git a/Test/Test/V3/Layers.cs b/Test/Test/V3/Layers.cs index 7e536cc5745e5b5b8a4759d147e0124644a74505..12c1d3f49da89e38b2d240efe324333bb6c3b2ed 100644 --- a/Test/Test/V3/Layers.cs +++ b/Test/Test/V3/Layers.cs @@ -25,20 +25,6 @@ namespace Test.V3 Assert.IsInstanceOfType(response, typeof(LayerContract[])); } - [TestCategory("Layer")] - [TestMethod] - public async Task GetNoGoLayersForDevice_ShouldReturnLayers() - { - var deviceLogin = "device1"; - - server.Given(Request.Create().WithPath(PATH_BASE + LAYERS + $"/device/{deviceLogin}").UsingGet()) - .RespondWith(Response.Create().WithStatusCode(200) - .WithBodyAsJson(TestData.Layers.GetLayers())); - - var response = await devkitConnector.GetNoGoLayers(deviceLogin); - Assert.IsInstanceOfType(response, typeof(LayerContract[])); - } - [TestCategory("Layer")] [TestMethod] public async Task GetLayers_ShouldReturnLayers() @@ -72,7 +58,7 @@ namespace Test.V3 .RespondWith(Response.Create().WithStatusCode(200) .WithBodyAsJson(layer)); - var response = await devkitConnector.AddLayer(layer); + var response = await devkitConnector.AddLayer((LayerWriteContract) layer); Assert.IsInstanceOfType(response, typeof(LayerContract)); } diff --git a/Test/Test/V3/Log.cs b/Test/Test/V3/Log.cs index b934e4bf8c06768dd66ad9e381cabd1ad2c2a13c..075a298d45d70374419a94b7642f361f358be64f 100644 --- a/Test/Test/V3/Log.cs +++ b/Test/Test/V3/Log.cs @@ -15,7 +15,7 @@ namespace Test.V3 [TestMethod] public async Task PostLog_ShouldReturnLogContract() { - var bodyContent = new LogContract() + var bodyContent = new LogWriteContract() { Login = "login", AccountId = 1, diff --git a/Test/Test/V3/Paths.cs b/Test/Test/V3/Paths.cs new file mode 100644 index 0000000000000000000000000000000000000000..a0bd4965ab9073663cbcf6fd75e0cde87ec6a9e3 --- /dev/null +++ b/Test/Test/V3/Paths.cs @@ -0,0 +1,44 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SDK.Models; +using System; +using System.Threading.Tasks; +using WireMock.RequestBuilders; +using WireMock.ResponseBuilders; + +namespace Test.V3 +{ + [TestClass] + public class Paths : Requests + { + const string PATHS = "paths"; + + [TestCategory("Path")] + [TestMethod] + public async Task GetPaths_ShouldReturnPaths() + { + var bodyContent = TestData.Paths.GetTestPaths(); + + server.Given(Request.Create().WithPath(PATH_BASE + PATHS).UsingGet()) + .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); + + var response = await devkitConnector.GetPaths(); + + Assert.IsInstanceOfType(response, typeof(PathContract[])); + } + + [TestCategory("Path")] + [TestMethod] + public async Task GetPath_ShouldReturnPath() + { + const int pathId = 1; + var bodyContent = TestData.Paths.GetTestPath(TestData.Paths.TestPathId1); + + server.Given(Request.Create().WithPath(PATH_BASE + PATHS + "/" + pathId).UsingGet()) + .RespondWith(Response.Create().WithStatusCode(200) + .WithBodyAsJson(bodyContent)); + + var response = await devkitConnector.GetPath(pathId); + Assert.IsInstanceOfType(response, typeof(PathContract)); + } + } +} diff --git a/Test/Test/V3/Quantities.cs b/Test/Test/V3/Quantities.cs index 9eadc3c12b1bc09f9a714ce3cae11bfd2f728e5d..bfbbd2bccd1e9f7cf045215780a3b94144a405e3 100644 --- a/Test/Test/V3/Quantities.cs +++ b/Test/Test/V3/Quantities.cs @@ -48,7 +48,7 @@ namespace Test.V3 server.Given(Request.Create().WithPath(PATH_BASE + QUANTITIES).UsingPost()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); - QuantityContract response = await devkitConnector.AddQuantity(bodyContent); + QuantityContract response = await devkitConnector.AddQuantity((QuantityWriteContract)bodyContent); Assert.IsInstanceOfType(response, typeof(QuantityContract)); } diff --git a/Test/Test/V3/Shifts.cs b/Test/Test/V3/Shifts.cs index 824ac50a344a35496899f256130f2176e231e6a4..51e8f5d0743def81ca097e4295fb91e16c496175 100644 --- a/Test/Test/V3/Shifts.cs +++ b/Test/Test/V3/Shifts.cs @@ -48,7 +48,7 @@ namespace Test.V3 server.Given(Request.Create().WithPath(PATH_BASE + SHIFTS).UsingPost()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); - ShiftContract response = await devkitConnector.AddShift(bodyContent); + ShiftContract response = await devkitConnector.AddShift((ShiftWriteContract)bodyContent); Assert.IsInstanceOfType(response, typeof(ShiftContract)); }