Compare commits
43 Commits
master
...
version_1_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68de09c109 | ||
|
|
578b88cea2 | ||
|
|
69e86bfa26 | ||
| c9269aaf3a | |||
| 92d7efd34d | |||
| 94e0c1e647 | |||
| 19d84b4417 | |||
| eb50590684 | |||
| f5921180cf | |||
| 33f782346b | |||
| 042949ec60 | |||
| ca1d71a846 | |||
| 74101d9939 | |||
| a0b2d5ba9c | |||
| 88ab87c9ee | |||
| 52ec413761 | |||
| 006aa541cd | |||
| 52d5467b85 | |||
| 63654bdcf9 | |||
| bdab0dc286 | |||
| 9e8109225a | |||
| fc9d38c3c1 | |||
| 85ca1368a2 | |||
| 3e6439433e | |||
| 5b56c677ef | |||
| cf2d7759de | |||
| 390852ce4f | |||
| 499065bdb7 | |||
| 79be291113 | |||
| 3b6c480cc6 | |||
| 35e2d8296b | |||
| 9328318468 | |||
| ee021510c8 | |||
| 1725376623 | |||
| afdd538a3b | |||
| 4f1902984b | |||
| 55a612fd0c | |||
| 820de792a5 | |||
| 8c2e276d1c | |||
| e5bfed2ff6 | |||
| e157cd1cb0 | |||
| 474e9ce719 | |||
| e61b334f02 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -54,3 +54,6 @@ obj
|
|||||||
*.user
|
*.user
|
||||||
ManagerService/bin
|
ManagerService/bin
|
||||||
ManagerService/obj
|
ManagerService/obj
|
||||||
|
ManagerService/resources
|
||||||
|
ManagerService/configurations
|
||||||
|
ManagerService/service-data
|
||||||
|
|||||||
@ -22,20 +22,25 @@ namespace Manager.Framework.Business
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Authenticate(string email, string password)
|
public void TestPassword(string email, string userPassword, string password)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(email))
|
if (string.IsNullOrWhiteSpace(email))
|
||||||
{
|
{
|
||||||
_logger.LogError($"Authenticate error: No e-mail provided");
|
_logger.LogError($"Authenticate error: No e-mail provided");
|
||||||
throw new UnauthorizedAccessException("Authentication error");
|
throw new UnauthorizedAccessException("Authentication error");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(password))
|
if (string.IsNullOrEmpty(password))
|
||||||
{
|
{
|
||||||
_logger.LogError($"Authenticate error: No password provided");
|
_logger.LogError($"Authenticate error: No password provided");
|
||||||
throw new UnauthorizedAccessException("Authentication error");
|
throw new UnauthorizedAccessException("Authentication error");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
if (!PasswordUtils.Compare(userPassword, password, PasswordsPepper))
|
||||||
|
{
|
||||||
|
_logger.LogError($"Authenticate error: passwords doesn't match");
|
||||||
|
throw new UnauthorizedAccessException("Authentication error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -8,9 +8,19 @@ namespace Manager.Interfaces.DTO
|
|||||||
{
|
{
|
||||||
public string id { get; set; }
|
public string id { get; set; }
|
||||||
public string label { get; set; }
|
public string label { get; set; }
|
||||||
|
public List<TranslationDTO> title { get; set; }
|
||||||
|
public string imageId { get; set; } // == ResourceId
|
||||||
|
public string imageSource { get; set; } // == Image url
|
||||||
public string primaryColor { get; set; }
|
public string primaryColor { get; set; }
|
||||||
public string secondaryColor { get; set; }
|
public string secondaryColor { get; set; }
|
||||||
public List<string> languages { get; set; } // fr, en, de, nl => Sélection dans une liste déjà établie dans l'application !
|
public List<string> languages { get; set; } // fr, en, de, nl => Sélection dans une liste déjà établie dans l'application !
|
||||||
public DateTime dateCreation { get; set; }
|
public DateTime dateCreation { get; set; }
|
||||||
|
public bool isMobile { get; set; } // MyVisit - True if for mobile (MyVisit)
|
||||||
|
public bool isTablet { get; set; }
|
||||||
|
public bool isOffline { get; set; } // MyVisit - True if MyVisit is full offline
|
||||||
|
/*public string latitude { get; set; } // MyVisit - latitude of visit ? (MyVisit)
|
||||||
|
public string longitude { get; set; } // MyVisit - True if for mobile (MyVisit)*/
|
||||||
|
public string instanceId { get; set; }
|
||||||
|
public List<string> sectionIds { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@ namespace Manager.Interfaces.DTO
|
|||||||
public bool connected{ get; set; }
|
public bool connected{ get; set; }
|
||||||
public DateTime dateCreation{ get; set; }
|
public DateTime dateCreation{ get; set; }
|
||||||
public DateTime dateUpdate { get; set; }
|
public DateTime dateUpdate { get; set; }
|
||||||
|
public string instanceId { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DeviceDetailDTO : DeviceDTO
|
public class DeviceDetailDTO : DeviceDTO
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using DevExpress.Xpo;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Manager.Interfaces.DTO
|
namespace Manager.Interfaces.DTO
|
||||||
|
|||||||
13
Manager.Interfaces/DTO/InstanceDTO.cs
Normal file
13
Manager.Interfaces/DTO/InstanceDTO.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Manager.Interfaces.DTO
|
||||||
|
{
|
||||||
|
public class InstanceDTO
|
||||||
|
{
|
||||||
|
public string id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
public DateTime dateCreation { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -10,7 +10,8 @@ namespace Manager.Interfaces.DTO
|
|||||||
public string id { get; set; }
|
public string id { get; set; }
|
||||||
public ResourceType type { get; set; }
|
public ResourceType type { get; set; }
|
||||||
public string label { get; set; }
|
public string label { get; set; }
|
||||||
public DateTime dateCreation { get; set; }
|
|
||||||
public string data { get; set; }
|
public string data { get; set; }
|
||||||
|
public DateTime dateCreation { get; set; }
|
||||||
|
public string instanceId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,5 +20,11 @@ namespace Manager.Interfaces.DTO
|
|||||||
public string data { get; set; } // == Include section type info
|
public string data { get; set; } // == Include section type info
|
||||||
public DateTime dateCreation { get; set; } // == Include section type info
|
public DateTime dateCreation { get; set; } // == Include section type info
|
||||||
public int order { get; set; } // Order to show
|
public int order { get; set; } // Order to show
|
||||||
|
public string instanceId { get; set; }
|
||||||
|
public string latitude { get; set; } // MyVisit - Use to launch automatic content when current location is near
|
||||||
|
public string longitude { get; set; } // MyVisit - Use to launch automatic content when current location is near
|
||||||
|
public int? meterZoneGPS { get; set; } // MyVisit - Nbr of meters of the zone to launch content
|
||||||
|
public bool isBeacon { get; set; } // MyVisit - True if section use beacon, false otherwise
|
||||||
|
public int? beaconId { get; set; } // MyVisit - Beacon' identifier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
Manager.Interfaces/DTO/SubSection/ArticleDTO.cs
Normal file
16
Manager.Interfaces/DTO/SubSection/ArticleDTO.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using Manager.Interfaces.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Manager.Interfaces.DTO
|
||||||
|
{
|
||||||
|
public class ArticleDTO
|
||||||
|
{
|
||||||
|
public List<TranslationDTO> content { get; set; }
|
||||||
|
public bool isContentTop { get; set; } // MyVisit - True if content is displayed at top, false otherwise
|
||||||
|
public List<TranslationDTO> audioIds { get; set; }
|
||||||
|
public bool isReadAudioAuto { get; set; } // MyVisit - True for audio play when open the article / false otherwise
|
||||||
|
public List<ImageDTO> images { get; set; } // Will check if ok or if we need need type of image (simpler)
|
||||||
|
}
|
||||||
|
}
|
||||||
38
Manager.Interfaces/DTO/SubSection/QuizzDTO.cs
Normal file
38
Manager.Interfaces/DTO/SubSection/QuizzDTO.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Manager.Interfaces.DTO
|
||||||
|
{
|
||||||
|
public class QuizzDTO
|
||||||
|
{
|
||||||
|
public List<QuestionDTO> questions { get; set; }
|
||||||
|
public LevelDTO bad_level { get; set; }
|
||||||
|
public LevelDTO medium_level { get; set; }
|
||||||
|
public LevelDTO good_level { get; set; }
|
||||||
|
public LevelDTO great_level { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class QuestionDTO
|
||||||
|
{
|
||||||
|
public List<TranslationDTO> label { get; set; }
|
||||||
|
public List<ResponseDTO> responses { get; set; }
|
||||||
|
public string resourceId { get; set; } // question image
|
||||||
|
public string source { get; set; }
|
||||||
|
public int order { get; set; } // Order to show
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ResponseDTO
|
||||||
|
{
|
||||||
|
public List<TranslationDTO> label { get; set; }
|
||||||
|
public bool isGood { get; set; }
|
||||||
|
public int order { get; set; } // Order to show
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LevelDTO
|
||||||
|
{
|
||||||
|
public List<TranslationDTO> label { get; set; }
|
||||||
|
public string resourceId { get; set; } // level result image
|
||||||
|
public string source { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -10,5 +10,6 @@ namespace Manager.Interfaces.DTO
|
|||||||
public string token_type { get; set; }
|
public string token_type { get; set; }
|
||||||
public int expires_in { get; set; }
|
public int expires_in { get; set; }
|
||||||
public DateTimeOffset expiration { get; set; }
|
public DateTimeOffset expiration { get; set; }
|
||||||
|
public string instanceId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DevExpress.Xpo" Version="20.1.8" />
|
|
||||||
<PackageReference Include="MongoDB.Bson" Version="2.12.1" />
|
<PackageReference Include="MongoDB.Bson" Version="2.12.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
using MongoDB.Bson.Serialization.Attributes;
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Manager.Interfaces.Models
|
namespace Manager.Interfaces.Models
|
||||||
@ -19,6 +20,16 @@ namespace Manager.Interfaces.Models
|
|||||||
[BsonRequired]
|
[BsonRequired]
|
||||||
public string Label { get; set; }
|
public string Label { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Title")]
|
||||||
|
[BsonRequired]
|
||||||
|
public List<TranslationDTO> Title { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("ImageId")]
|
||||||
|
public string ImageId { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("ImageSource")]
|
||||||
|
public string ImageSource { get; set; }
|
||||||
|
|
||||||
[BsonElement("PrimaryColor")]
|
[BsonElement("PrimaryColor")]
|
||||||
public string PrimaryColor { get; set; }
|
public string PrimaryColor { get; set; }
|
||||||
|
|
||||||
@ -31,16 +42,37 @@ namespace Manager.Interfaces.Models
|
|||||||
[BsonElement("DateCreation")]
|
[BsonElement("DateCreation")]
|
||||||
public DateTime DateCreation { get; set; }
|
public DateTime DateCreation { get; set; }
|
||||||
|
|
||||||
public ConfigurationDTO ToDTO()
|
[BsonElement("IsMobile")]
|
||||||
|
public bool IsMobile { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("IsTablet")]
|
||||||
|
public bool IsTablet { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("IsOffline")]
|
||||||
|
public bool IsOffline { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("InstanceId")]
|
||||||
|
[BsonRequired]
|
||||||
|
public string InstanceId { get; set; }
|
||||||
|
|
||||||
|
public ConfigurationDTO ToDTO(List<string> sectionIds)
|
||||||
{
|
{
|
||||||
return new ConfigurationDTO()
|
return new ConfigurationDTO()
|
||||||
{
|
{
|
||||||
id = Id,
|
id = Id,
|
||||||
label = Label,
|
label = Label,
|
||||||
|
title = Title,
|
||||||
|
imageId = ImageId,
|
||||||
|
imageSource = ImageSource,
|
||||||
dateCreation = DateCreation,
|
dateCreation = DateCreation,
|
||||||
primaryColor = PrimaryColor,
|
primaryColor = PrimaryColor,
|
||||||
languages = Languages,
|
languages = Languages,
|
||||||
secondaryColor = SecondaryColor
|
secondaryColor = SecondaryColor,
|
||||||
|
isMobile = IsMobile,
|
||||||
|
isTablet = IsTablet,
|
||||||
|
isOffline = IsOffline,
|
||||||
|
instanceId = InstanceId,
|
||||||
|
sectionIds = sectionIds
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,12 +81,20 @@ namespace Manager.Interfaces.Models
|
|||||||
{
|
{
|
||||||
id = Id,
|
id = Id,
|
||||||
label = Label,
|
label = Label,
|
||||||
|
title= Title,
|
||||||
|
imageId = ImageId,
|
||||||
|
imageSource = ImageSource,
|
||||||
dateCreation = DateCreation,
|
dateCreation = DateCreation,
|
||||||
primaryColor = PrimaryColor,
|
primaryColor = PrimaryColor,
|
||||||
languages = Languages,
|
languages = Languages,
|
||||||
secondaryColor = SecondaryColor,
|
secondaryColor = SecondaryColor,
|
||||||
|
isMobile = IsMobile,
|
||||||
|
isTablet = IsTablet,
|
||||||
|
isOffline = IsOffline,
|
||||||
sections = sections,
|
sections = sections,
|
||||||
resources = resources
|
resources = resources,
|
||||||
|
instanceId = InstanceId,
|
||||||
|
sectionIds = sections.Select(s => s.id).ToList()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,6 +60,9 @@ namespace Manager.Interfaces.Models
|
|||||||
[BsonElement("LastConnectionLevel")]
|
[BsonElement("LastConnectionLevel")]
|
||||||
public DateTime LastConnectionLevel { get; set; }
|
public DateTime LastConnectionLevel { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("InstanceId")]
|
||||||
|
[BsonRequired]
|
||||||
|
public string InstanceId { get; set; }
|
||||||
|
|
||||||
public DeviceDTO ToDTO()
|
public DeviceDTO ToDTO()
|
||||||
{
|
{
|
||||||
@ -74,7 +77,8 @@ namespace Manager.Interfaces.Models
|
|||||||
configuration = Configuration,
|
configuration = Configuration,
|
||||||
configurationId = ConfigurationId,
|
configurationId = ConfigurationId,
|
||||||
dateUpdate = DateUpdate,
|
dateUpdate = DateUpdate,
|
||||||
dateCreation = DateCreation
|
dateCreation = DateCreation,
|
||||||
|
instanceId = InstanceId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +99,8 @@ namespace Manager.Interfaces.Models
|
|||||||
batteryLevel = BatteryLevel,
|
batteryLevel = BatteryLevel,
|
||||||
lastBatteryLevel = LastBatteryLevel,
|
lastBatteryLevel = LastBatteryLevel,
|
||||||
dateUpdate = DateUpdate,
|
dateUpdate = DateUpdate,
|
||||||
dateCreation = DateCreation
|
dateCreation = DateCreation,
|
||||||
|
instanceId = InstanceId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
Manager.Interfaces/Models/Instance.cs
Normal file
36
Manager.Interfaces/Models/Instance.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using Manager.Interfaces.DTO;
|
||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Manager.Interfaces.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Instance Information
|
||||||
|
/// </summary>
|
||||||
|
public class Instance
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Name")]
|
||||||
|
[BsonRequired]
|
||||||
|
public string Name { get; set; } // UNIQUE !..
|
||||||
|
|
||||||
|
[BsonElement("DateCreation")]
|
||||||
|
public DateTime DateCreation { get; set; }
|
||||||
|
|
||||||
|
public InstanceDTO ToDTO()
|
||||||
|
{
|
||||||
|
return new InstanceDTO()
|
||||||
|
{
|
||||||
|
id = Id,
|
||||||
|
name = Name,
|
||||||
|
dateCreation = DateCreation
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -27,19 +27,20 @@ namespace Manager.Interfaces.Models
|
|||||||
[BsonElement("DateCreation")]
|
[BsonElement("DateCreation")]
|
||||||
public DateTime DateCreation { get; set; }
|
public DateTime DateCreation { get; set; }
|
||||||
|
|
||||||
[BsonElement("Data")]
|
[BsonElement("InstanceId")]
|
||||||
[BsonRequired]
|
[BsonRequired]
|
||||||
public string Data { get; set; }
|
public string InstanceId { get; set; }
|
||||||
|
|
||||||
public ResourceDTO ToDTO(bool isExport = false)
|
public ResourceDTO ToDTO(string data = null) //
|
||||||
{
|
{
|
||||||
return new ResourceDTO()
|
return new ResourceDTO()
|
||||||
{
|
{
|
||||||
id = Id,
|
id = Id,
|
||||||
label = Label,
|
label = Label,
|
||||||
type = Type,
|
type = Type,
|
||||||
data = isExport ? Data : null,
|
data = data,
|
||||||
dateCreation = DateCreation
|
dateCreation = DateCreation,
|
||||||
|
instanceId = InstanceId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,6 +50,7 @@ namespace Manager.Interfaces.Models
|
|||||||
Image,
|
Image,
|
||||||
Video,
|
Video,
|
||||||
ImageUrl,
|
ImageUrl,
|
||||||
VideoUrl
|
VideoUrl,
|
||||||
|
Audio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
31
Manager.Interfaces/Models/ResourceData.cs
Normal file
31
Manager.Interfaces/Models/ResourceData.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using Manager.Interfaces.DTO;
|
||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Manager.Interfaces.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Resource Information
|
||||||
|
/// </summary>
|
||||||
|
public class ResourceData
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Data")]
|
||||||
|
[BsonRequired]
|
||||||
|
public string Data { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("ResourceId")]
|
||||||
|
[BsonRequired]
|
||||||
|
public string ResourceId { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("InstanceId")]
|
||||||
|
[BsonRequired]
|
||||||
|
public string InstanceId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -61,6 +61,25 @@ namespace Manager.Interfaces.Models
|
|||||||
[BsonRequired]
|
[BsonRequired]
|
||||||
public string Data { get; set; } // Json encapsulated section info
|
public string Data { get; set; } // Json encapsulated section info
|
||||||
|
|
||||||
|
[BsonElement("InstanceId")]
|
||||||
|
[BsonRequired]
|
||||||
|
public string InstanceId { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("IsBeacon")]
|
||||||
|
public bool IsBeacon { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("BeaconId")]
|
||||||
|
public int? BeaconId { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Latitude")]
|
||||||
|
public string Latitude { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Longitude")]
|
||||||
|
public string Longitude { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("MeterZoneGPS")]
|
||||||
|
public int? MeterZoneGPS { get; set; }
|
||||||
|
|
||||||
public SectionDTO ToDTO()
|
public SectionDTO ToDTO()
|
||||||
{
|
{
|
||||||
return new SectionDTO()
|
return new SectionDTO()
|
||||||
@ -77,7 +96,13 @@ namespace Manager.Interfaces.Models
|
|||||||
isSubSection = IsSubSection,
|
isSubSection = IsSubSection,
|
||||||
parentId = ParentId,
|
parentId = ParentId,
|
||||||
data = Data,
|
data = Data,
|
||||||
dateCreation = DateCreation
|
dateCreation = DateCreation,
|
||||||
|
instanceId = InstanceId,
|
||||||
|
isBeacon = IsBeacon,
|
||||||
|
beaconId = BeaconId,
|
||||||
|
latitude = Latitude,
|
||||||
|
longitude = Longitude,
|
||||||
|
meterZoneGPS = MeterZoneGPS,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,6 +113,8 @@ namespace Manager.Interfaces.Models
|
|||||||
Slider,
|
Slider,
|
||||||
Video,
|
Video,
|
||||||
Web,
|
Web,
|
||||||
Menu
|
Menu,
|
||||||
|
Quizz,
|
||||||
|
Article
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,6 +38,10 @@ namespace Manager.Interfaces.Models
|
|||||||
[BsonElement("DateCreation")]
|
[BsonElement("DateCreation")]
|
||||||
public DateTime DateCreation { get; set; }
|
public DateTime DateCreation { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("InstanceId")]
|
||||||
|
[BsonRequired]
|
||||||
|
public string InstanceId { get; set; }
|
||||||
|
|
||||||
public UserDetailDTO ToDTO()
|
public UserDetailDTO ToDTO()
|
||||||
{
|
{
|
||||||
return new UserDetailDTO()
|
return new UserDetailDTO()
|
||||||
|
|||||||
@ -51,16 +51,16 @@ namespace ManagerService.Service.Controllers
|
|||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
email = "test@email.be";
|
email = "test@email.be";
|
||||||
password = "W/7aj4NB60i3YFKJq50pbw=="; // password = "kljqsdkljqsd";
|
password = "kljqsdkljqsd"; // password = "kljqsdkljqsd"; // W/7aj4NB60i3YFKJq50pbw==
|
||||||
#endif
|
#endif
|
||||||
var token = _tokensService.Authenticate(email.ToLower(), password);
|
|
||||||
|
|
||||||
// Set user token ?
|
// Set user token ?
|
||||||
var user = _UserDatabaseService.GetByEmail(email.ToLower());
|
var user = _UserDatabaseService.GetByEmail(email.ToLower());
|
||||||
|
|
||||||
if (user == null)
|
if (user == null)
|
||||||
throw new KeyNotFoundException("User not found");
|
throw new KeyNotFoundException("User not found");
|
||||||
|
|
||||||
|
var token = _tokensService.Authenticate(user, password);
|
||||||
|
|
||||||
MqttClientService.SetServices(_DeviceDatabaseService, _ConfigurationDatabaseService);
|
MqttClientService.SetServices(_DeviceDatabaseService, _ConfigurationDatabaseService);
|
||||||
|
|
||||||
return new OkObjectResult(token);
|
return new OkObjectResult(token);
|
||||||
|
|||||||
@ -1,13 +1,18 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Manager.Helpers;
|
||||||
using Manager.Interfaces.DTO;
|
using Manager.Interfaces.DTO;
|
||||||
using Manager.Interfaces.Models;
|
using Manager.Interfaces.Models;
|
||||||
using Manager.Services;
|
using Manager.Services;
|
||||||
|
using ManagerService.Helpers;
|
||||||
using ManagerService.Service.Services;
|
using ManagerService.Service.Services;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Mqtt.Client.AspNetCore.Services;
|
using Mqtt.Client.AspNetCore.Services;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@ -23,32 +28,46 @@ namespace ManagerService.Controllers
|
|||||||
private ConfigurationDatabaseService _configurationService;
|
private ConfigurationDatabaseService _configurationService;
|
||||||
private SectionDatabaseService _sectionService;
|
private SectionDatabaseService _sectionService;
|
||||||
private ResourceDatabaseService _resourceService;
|
private ResourceDatabaseService _resourceService;
|
||||||
|
private ResourceDataDatabaseService _resourceDataService;
|
||||||
private DeviceDatabaseService _deviceService;
|
private DeviceDatabaseService _deviceService;
|
||||||
private readonly ILogger<ConfigurationController> _logger;
|
private readonly ILogger<ConfigurationController> _logger;
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
|
||||||
public ConfigurationController(ILogger<ConfigurationController> logger, ConfigurationDatabaseService configurationService, SectionDatabaseService sectionService, ResourceDatabaseService resourceService, DeviceDatabaseService deviceService)
|
public ConfigurationController(IConfiguration configuration, ILogger<ConfigurationController> logger, ConfigurationDatabaseService configurationService, SectionDatabaseService sectionService, ResourceDatabaseService resourceService, ResourceDataDatabaseService resourceDataService, DeviceDatabaseService deviceService)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_configuration = configuration;
|
||||||
_configurationService = configurationService;
|
_configurationService = configurationService;
|
||||||
_sectionService = sectionService;
|
_sectionService = sectionService;
|
||||||
_resourceService = resourceService;
|
_resourceService = resourceService;
|
||||||
|
_resourceDataService = resourceDataService;
|
||||||
_deviceService = deviceService;
|
_deviceService = deviceService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a list of all configuration (summary)
|
/// Get a list of all configuration (summary)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="id">id instance</param>
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[ProducesResponseType(typeof(List<ConfigurationDTO>), 200)]
|
[ProducesResponseType(typeof(List<ConfigurationDTO>), 200)]
|
||||||
[ProducesResponseType(typeof(string), 500)]
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ObjectResult Get()
|
public ObjectResult Get([FromQuery] string instanceId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<Configuration> configurations = _configurationService.GetAll();
|
List<Configuration> configurations = _configurationService.GetAll(instanceId);
|
||||||
|
|
||||||
return new OkObjectResult(configurations.Select(r => r.ToDTO()));
|
List<ConfigurationDTO> configurationDTOs = new List<ConfigurationDTO>();
|
||||||
|
|
||||||
|
foreach(var configuration in configurations)
|
||||||
|
{
|
||||||
|
List<string> sectionIds = _sectionService.GetAllIdsFromConfiguration(configuration.Id);
|
||||||
|
ConfigurationDTO configurationDTO = configuration.ToDTO(sectionIds);
|
||||||
|
configurationDTOs.Add(configurationDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new OkObjectResult(configurationDTOs.OrderBy(c => c.dateCreation));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -75,7 +94,9 @@ namespace ManagerService.Controllers
|
|||||||
if (configuration == null)
|
if (configuration == null)
|
||||||
throw new KeyNotFoundException("This configuration was not found");
|
throw new KeyNotFoundException("This configuration was not found");
|
||||||
|
|
||||||
return new OkObjectResult(configuration.ToDTO());
|
List<string> sectionIds = _sectionService.GetAllIdsFromConfiguration(id);
|
||||||
|
|
||||||
|
return new OkObjectResult(configuration.ToDTO(sectionIds));
|
||||||
}
|
}
|
||||||
catch (KeyNotFoundException ex)
|
catch (KeyNotFoundException ex)
|
||||||
{
|
{
|
||||||
@ -105,15 +126,27 @@ namespace ManagerService.Controllers
|
|||||||
|
|
||||||
// Todo add some verification ?
|
// Todo add some verification ?
|
||||||
Configuration configuration = new Configuration();
|
Configuration configuration = new Configuration();
|
||||||
|
configuration.InstanceId = newConfiguration.instanceId;
|
||||||
configuration.Label = newConfiguration.label;
|
configuration.Label = newConfiguration.label;
|
||||||
|
configuration.Title = new List<TranslationDTO>();
|
||||||
|
configuration.ImageId = newConfiguration.imageId;
|
||||||
|
configuration.ImageSource = newConfiguration.imageSource;
|
||||||
configuration.PrimaryColor = newConfiguration.primaryColor;
|
configuration.PrimaryColor = newConfiguration.primaryColor;
|
||||||
configuration.SecondaryColor = newConfiguration.secondaryColor;
|
configuration.SecondaryColor = newConfiguration.secondaryColor;
|
||||||
configuration.Languages = new List<string> { "FR", "NL", "EN", "DE" }; // by default all languages
|
|
||||||
|
configuration.Languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>();
|
||||||
|
|
||||||
|
//configuration.Languages = new List<string> { "FR", "NL", "EN", "DE" }; // by default all languages
|
||||||
|
configuration.Title = LanguageInit.Init("Title", configuration.Languages);
|
||||||
|
|
||||||
configuration.DateCreation = DateTime.Now;
|
configuration.DateCreation = DateTime.Now;
|
||||||
|
configuration.IsMobile = newConfiguration.isMobile;
|
||||||
|
configuration.IsTablet = newConfiguration.isTablet;
|
||||||
|
configuration.IsOffline = newConfiguration.isOffline;
|
||||||
|
|
||||||
Configuration configurationCreated = _configurationService.Create(configuration);
|
Configuration configurationCreated = _configurationService.Create(configuration);
|
||||||
|
|
||||||
return new OkObjectResult(configurationCreated.ToDTO());
|
return new OkObjectResult(configurationCreated.ToDTO(new List<string>())); // Empty list
|
||||||
}
|
}
|
||||||
catch (ArgumentNullException ex)
|
catch (ArgumentNullException ex)
|
||||||
{
|
{
|
||||||
@ -152,16 +185,25 @@ namespace ManagerService.Controllers
|
|||||||
throw new KeyNotFoundException("Configuration does not exist");
|
throw new KeyNotFoundException("Configuration does not exist");
|
||||||
|
|
||||||
// Todo add some verification ?
|
// Todo add some verification ?
|
||||||
|
configuration.InstanceId = updatedConfiguration.instanceId;
|
||||||
configuration.Label = updatedConfiguration.label;
|
configuration.Label = updatedConfiguration.label;
|
||||||
|
configuration.Title = updatedConfiguration.title;
|
||||||
|
configuration.ImageId = updatedConfiguration.imageId;
|
||||||
|
configuration.ImageSource = updatedConfiguration.imageSource;
|
||||||
configuration.PrimaryColor = updatedConfiguration.primaryColor;
|
configuration.PrimaryColor = updatedConfiguration.primaryColor;
|
||||||
configuration.SecondaryColor = updatedConfiguration.secondaryColor;
|
configuration.SecondaryColor = updatedConfiguration.secondaryColor;
|
||||||
configuration.Languages = updatedConfiguration.languages;
|
configuration.Languages = updatedConfiguration.languages;
|
||||||
|
configuration.IsMobile = updatedConfiguration.isMobile;
|
||||||
|
configuration.IsTablet = updatedConfiguration.isTablet;
|
||||||
|
configuration.IsOffline = updatedConfiguration.isOffline;
|
||||||
|
|
||||||
Configuration configurationModified = _configurationService.Update(updatedConfiguration.id, configuration);
|
Configuration configurationModified = _configurationService.Update(updatedConfiguration.id, configuration);
|
||||||
|
|
||||||
MqttClientService.PublishMessage($"config/{configurationModified.Id}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
// TODO HANDLE MqttClientService.PublishMessage($"config/{configurationModified.Id}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
||||||
|
|
||||||
|
List<string> sectionIds = _sectionService.GetAllIdsFromConfiguration(configuration.Id);
|
||||||
|
|
||||||
return new OkObjectResult(configurationModified.ToDTO());
|
return new OkObjectResult(configurationModified.ToDTO(sectionIds));
|
||||||
}
|
}
|
||||||
catch (ArgumentNullException ex)
|
catch (ArgumentNullException ex)
|
||||||
{
|
{
|
||||||
@ -209,7 +251,7 @@ namespace ManagerService.Controllers
|
|||||||
_deviceService.Update(device.Id, device);
|
_deviceService.Update(device.Id, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
MqttClientService.PublishMessage($"config/{id}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true, isDeleted = true }));
|
// TODO MqttClientService.PublishMessage($"config/{id}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true, isDeleted = true }));
|
||||||
|
|
||||||
return new ObjectResult("The configuration has been deleted") { StatusCode = 202 };
|
return new ObjectResult("The configuration has been deleted") { StatusCode = 202 };
|
||||||
|
|
||||||
@ -228,17 +270,19 @@ namespace ManagerService.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Export a configuration
|
/// Export a configuration
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">Id of configuration to export</param>
|
/// <param name="id">Id of configuration to export</param>
|
||||||
[ProducesResponseType(typeof(ExportConfigurationDTO), 200)]
|
/// <param name="language">Language to export</param>
|
||||||
|
[AllowAnonymous]
|
||||||
|
[ProducesResponseType(typeof(FileContentResult), 200)]
|
||||||
[ProducesResponseType(typeof(string), 400)]
|
[ProducesResponseType(typeof(string), 400)]
|
||||||
[ProducesResponseType(typeof(string), 404)]
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
[ProducesResponseType(typeof(string), 500)]
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
[HttpGet("{id}/export")]
|
[HttpGet("{id}/export")]
|
||||||
public ObjectResult Export(string id)
|
public ActionResult Export(string id, [FromQuery] string language)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -246,16 +290,43 @@ namespace ManagerService.Controllers
|
|||||||
throw new ArgumentNullException("Configuration param is null");
|
throw new ArgumentNullException("Configuration param is null");
|
||||||
|
|
||||||
Configuration configuration = _configurationService.GetById(id);
|
Configuration configuration = _configurationService.GetById(id);
|
||||||
|
|
||||||
if (configuration == null)
|
if (configuration == null)
|
||||||
throw new KeyNotFoundException("Configuration does not exist");
|
throw new KeyNotFoundException("Configuration does not exist");
|
||||||
|
|
||||||
List<SectionDTO> sectionDTOs = _sectionService.GetAllFromConfiguration(configuration.Id).Select(s => s.ToDTO()).ToList();
|
List<SectionDTO> sectionDTOs = _sectionService.GetAllFromConfiguration(configuration.Id).Select(s => s.ToDTO()).ToList();
|
||||||
List<ResourceDTO> resourceDTOs = new List<ResourceDTO>();
|
List<string> resourceIds = new List<string>();
|
||||||
|
|
||||||
|
var mimeType = "application/json";
|
||||||
|
|
||||||
|
string currentDirectory = System.IO.Directory.GetCurrentDirectory();
|
||||||
|
Console.WriteLine($"currentDirectory: {currentDirectory}");
|
||||||
|
currentDirectory = Path.Combine(currentDirectory, "service-data");
|
||||||
|
System.IO.Directory.CreateDirectory(currentDirectory.ToString());
|
||||||
|
Console.WriteLine($"createdDiretory: {currentDirectory}");
|
||||||
|
#if RELEASE
|
||||||
|
//Console.WriteLine($"currentDirectory: {Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}");
|
||||||
|
//currentDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "service-data");
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
var resourcesDirectory = Path.Combine(currentDirectory, "resources");
|
||||||
|
System.IO.Directory.CreateDirectory(resourcesDirectory.ToString());
|
||||||
|
Console.WriteLine($"resourcesDirectory: {resourcesDirectory}");
|
||||||
|
|
||||||
|
var configurationsDirectory = Path.Combine(currentDirectory, "configurations");
|
||||||
|
System.IO.Directory.CreateDirectory(configurationsDirectory.ToString());
|
||||||
|
Console.WriteLine($"configurationsDirectory: {configurationsDirectory}");
|
||||||
|
|
||||||
|
if (configuration.ImageId != null)
|
||||||
|
{
|
||||||
|
addResourceIdToList(resourceIds, configuration.ImageId);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var section in sectionDTOs)
|
foreach (var section in sectionDTOs)
|
||||||
{
|
{
|
||||||
if (section.imageId != null) {
|
if (section.imageId != null) {
|
||||||
addResourceToList(resourceDTOs, section.imageId);
|
addResourceIdToList(resourceIds, section.imageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (section.type) {
|
switch (section.type) {
|
||||||
@ -263,14 +334,14 @@ namespace ManagerService.Controllers
|
|||||||
MapDTO mapDTO = JsonConvert.DeserializeObject<MapDTO>(section.data);
|
MapDTO mapDTO = JsonConvert.DeserializeObject<MapDTO>(section.data);
|
||||||
if (mapDTO.iconResourceId != null)
|
if (mapDTO.iconResourceId != null)
|
||||||
{
|
{
|
||||||
addResourceToList(resourceDTOs, mapDTO.iconResourceId);
|
addResourceIdToList(resourceIds, mapDTO.iconResourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var point in mapDTO.points) {
|
foreach (var point in mapDTO.points) {
|
||||||
foreach (var image in point.images) {
|
foreach (var image in point.images) {
|
||||||
if (image.imageResourceId != null)
|
if (image.imageResourceId != null)
|
||||||
{
|
{
|
||||||
addResourceToList(resourceDTOs, image.imageResourceId);
|
addResourceIdToList(resourceIds, image.imageResourceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,7 +353,65 @@ namespace ManagerService.Controllers
|
|||||||
{
|
{
|
||||||
if (image.resourceId != null)
|
if (image.resourceId != null)
|
||||||
{
|
{
|
||||||
addResourceToList(resourceDTOs, image.resourceId);
|
addResourceIdToList(resourceIds, image.resourceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SectionType.Quizz:
|
||||||
|
QuizzDTO quizzDTO = JsonConvert.DeserializeObject<QuizzDTO>(section.data);
|
||||||
|
foreach (var question in quizzDTO.questions)
|
||||||
|
{
|
||||||
|
if (question.resourceId != null)
|
||||||
|
{
|
||||||
|
addResourceIdToList(resourceIds, question.resourceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (quizzDTO.bad_level != null)
|
||||||
|
{
|
||||||
|
if (quizzDTO.bad_level.resourceId != null)
|
||||||
|
{
|
||||||
|
addResourceIdToList(resourceIds, quizzDTO.bad_level.resourceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (quizzDTO.medium_level != null)
|
||||||
|
{
|
||||||
|
if (quizzDTO.medium_level.resourceId != null)
|
||||||
|
{
|
||||||
|
addResourceIdToList(resourceIds, quizzDTO.medium_level.resourceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (quizzDTO.good_level != null)
|
||||||
|
{
|
||||||
|
if (quizzDTO.good_level.resourceId != null)
|
||||||
|
{
|
||||||
|
addResourceIdToList(resourceIds, quizzDTO.good_level.resourceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (quizzDTO.great_level != null)
|
||||||
|
{
|
||||||
|
if (quizzDTO.great_level.resourceId != null)
|
||||||
|
{
|
||||||
|
addResourceIdToList(resourceIds, quizzDTO.great_level.resourceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SectionType.Article:
|
||||||
|
ArticleDTO articleDTO = JsonConvert.DeserializeObject<ArticleDTO>(section.data);
|
||||||
|
foreach (var image in articleDTO.images)
|
||||||
|
{
|
||||||
|
if (image.resourceId != null)
|
||||||
|
{
|
||||||
|
addResourceIdToList(resourceIds, image.resourceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If not a language is used for export in manager, if one is the myvisit app
|
||||||
|
var audios = language != null ? articleDTO.audioIds.Where(a => a.language == language) : articleDTO.audioIds;
|
||||||
|
foreach (var audio in audios)
|
||||||
|
{
|
||||||
|
if (audio.value != null)
|
||||||
|
{
|
||||||
|
addResourceIdToList(resourceIds, audio.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -294,20 +423,183 @@ namespace ManagerService.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new OkObjectResult(configuration.ToExportDTO(sectionDTOs, resourceDTOs));
|
if (language == null)
|
||||||
|
{
|
||||||
|
// EXPORT IN ZIP
|
||||||
|
getResourceDTOFromIds(resourcesDirectory, resourceIds);
|
||||||
|
|
||||||
|
ExportConfigurationDTO toDownload = configuration.ToExportDTO(sectionDTOs, null); // intentionnaly putting null to get only data
|
||||||
|
string jsonString = JsonConvert.SerializeObject(toDownload);
|
||||||
|
|
||||||
|
var fileBytes = Encoding.UTF8.GetBytes(jsonString);
|
||||||
|
|
||||||
|
var configFileMainTitle = $"config-{configuration.Label.Trim().Replace(" ", "_")}.json";
|
||||||
|
string configFileMainData = Path.Combine(configurationsDirectory, configFileMainTitle);
|
||||||
|
|
||||||
|
// Create the file.
|
||||||
|
createFile(configFileMainData, fileBytes);
|
||||||
|
|
||||||
|
byte[] exportFile = FileHelper.CreateZipArchive(currentDirectory);
|
||||||
|
|
||||||
|
var fileName0 = $"{configuration.Label.Trim().Replace(" ", "_")}";
|
||||||
|
|
||||||
|
return File(exportFile, "application/zip", $"{fileName0}_{DateTime.Now:yyyyMMdd}.zip");
|
||||||
|
}
|
||||||
|
|
||||||
|
var fileName = $"{configuration.Label.Trim().Replace(" ","_")}.json";
|
||||||
|
string configFile = Path.Combine(configurationsDirectory, fileName);
|
||||||
|
|
||||||
|
if (!System.IO.File.Exists(configFile))
|
||||||
|
{
|
||||||
|
|
||||||
|
List<ResourceDTO> resourceDTOs = getResourceDTOFromIds(resourcesDirectory, resourceIds);
|
||||||
|
|
||||||
|
ExportConfigurationDTO toDownload = configuration.ToExportDTO(sectionDTOs, resourceDTOs);
|
||||||
|
string jsonString = JsonConvert.SerializeObject(toDownload);
|
||||||
|
|
||||||
|
var fileBytes = Encoding.UTF8.GetBytes(jsonString);
|
||||||
|
|
||||||
|
// Create the file.
|
||||||
|
createFile(configFile, fileBytes);
|
||||||
|
|
||||||
|
return new FileContentResult(fileBytes, mimeType)
|
||||||
|
{
|
||||||
|
FileDownloadName = fileName
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Get file from folder
|
||||||
|
//byte[] readText = System.IO.File.ReadAllBytes(configFile);
|
||||||
|
byte[] readText;
|
||||||
|
using (var stream = new FileStream(configFile, FileMode.Open, FileAccess.Read))
|
||||||
|
{
|
||||||
|
var buffer = new byte[4096];
|
||||||
|
using (var ms = new MemoryStream())
|
||||||
|
{
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
|
||||||
|
{
|
||||||
|
ms.Write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
readText = ms.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string exportInString = Encoding.UTF8.GetString(readText);
|
||||||
|
|
||||||
|
//string exportInString = Encoding.UTF8.GetString(readText);
|
||||||
|
|
||||||
|
ExportConfigurationDTO exportConfigurationFromFile = JsonConvert.DeserializeObject<ExportConfigurationDTO>(exportInString);
|
||||||
|
|
||||||
|
// Get all ids that are not in the existing file
|
||||||
|
List<string> resourceIdsToDownload = resourceIds.Where(r => !exportConfigurationFromFile.resources.Select(r => r.id).Distinct().ToList().Contains(r)).ToList();
|
||||||
|
|
||||||
|
List<ResourceDTO> resourceDTOs = getResourceDTOFromIds(resourcesDirectory, resourceIdsToDownload);
|
||||||
|
|
||||||
|
exportConfigurationFromFile.resources.AddRange(resourceDTOs);
|
||||||
|
|
||||||
|
//exportConfigurationFromFile.resources.AddRange(exportConfigurationFromFile.resources.Distinct());
|
||||||
|
ExportConfigurationDTO exportWithAll = configuration.ToExportDTO(sectionDTOs, exportConfigurationFromFile.resources);
|
||||||
|
string jsonStringWithAll = JsonConvert.SerializeObject(exportWithAll);
|
||||||
|
|
||||||
|
ExportConfigurationDTO toDownload = configuration.ToExportDTO(sectionDTOs, exportConfigurationFromFile.resources.Where(r => resourceIds.Contains(r.id)).ToList()); //Only download from resourceIds (only language ask (or not)
|
||||||
|
|
||||||
|
string jsonString = JsonConvert.SerializeObject(toDownload);
|
||||||
|
readText = Encoding.UTF8.GetBytes(jsonString);
|
||||||
|
|
||||||
|
// Check if difference
|
||||||
|
if (exportInString != jsonStringWithAll)
|
||||||
|
{
|
||||||
|
// Delete file
|
||||||
|
System.IO.File.Delete(configFile);
|
||||||
|
|
||||||
|
var fileBytes = Encoding.UTF8.GetBytes(jsonStringWithAll);
|
||||||
|
|
||||||
|
// Recreate file with new content
|
||||||
|
createFile(configFile, fileBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FileContentResult(readText, mimeType)
|
||||||
|
{
|
||||||
|
FileDownloadName = fileName
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (ArgumentNullException ex)
|
catch (ArgumentNullException ex)
|
||||||
{
|
{
|
||||||
return new BadRequestObjectResult(ex.Message) { };
|
return null;
|
||||||
|
//return new BadRequestObjectResult(ex.Message) { };
|
||||||
}
|
}
|
||||||
catch (KeyNotFoundException ex)
|
catch (KeyNotFoundException ex)
|
||||||
{
|
{
|
||||||
return new NotFoundObjectResult(ex.Message) { };
|
return null;
|
||||||
|
//return new NotFoundObjectResult(ex.Message) { };
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
Console.WriteLine($"Error: {ex.Message}");
|
||||||
|
return null;
|
||||||
|
//return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ResourceDTO> getResourceDTOFromIds(string resourcesDirectory, List<string> resourceIds)
|
||||||
|
{
|
||||||
|
List<ResourceDTO> resourceDTOs = new List<ResourceDTO>();
|
||||||
|
|
||||||
|
foreach (var resourceId in resourceIds)
|
||||||
|
{
|
||||||
|
string resourceFile = Path.Combine(resourcesDirectory, resourceId)+".json";
|
||||||
|
if (System.IO.File.Exists(resourceFile))
|
||||||
|
{
|
||||||
|
// FILE EXIST, JUST GET IT FROM FILE
|
||||||
|
byte[] readText = System.IO.File.ReadAllBytes(resourceFile);
|
||||||
|
string resourceInString = Encoding.UTF8.GetString(readText);
|
||||||
|
ResourceDTO resourceDTO = JsonConvert.DeserializeObject<ResourceDTO>(resourceInString);
|
||||||
|
resourceDTOs.Add(resourceDTO);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// FILE DO NOT EXIST
|
||||||
|
Resource resource = _resourceService.GetById(resourceId);
|
||||||
|
ResourceData resourceData = _resourceDataService.GetByResourceId(resourceId);
|
||||||
|
|
||||||
|
if (resource != null && resourceData != null && !resourceDTOs.Any(r => r.id == resource.Id)) // Check if file already exist
|
||||||
|
{
|
||||||
|
resourceDTOs.Add(resource.ToDTO(resourceData.Data));
|
||||||
|
|
||||||
|
// Put resource in resources folder
|
||||||
|
string resourceJsonString = JsonConvert.SerializeObject(resource.ToDTO(resourceData.Data));
|
||||||
|
byte[] resourceBytes = Encoding.UTF8.GetBytes(resourceJsonString);
|
||||||
|
|
||||||
|
createFile(resourceFile, resourceBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourceDTOs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createFile(String fileName, byte[] fileBytes)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (FileStream fs = System.IO.File.Create(fileName))
|
||||||
|
{
|
||||||
|
|
||||||
|
Console.WriteLine($"Try to create file at : {fileName}");
|
||||||
|
|
||||||
|
// Add some information to the file.
|
||||||
|
fs.Write(fileBytes, 0, fileBytes.Length);
|
||||||
|
|
||||||
|
Console.WriteLine($"Created file: {fileName}");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"An error occured during file creation: {fileName} - {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,11 +626,24 @@ namespace ManagerService.Controllers
|
|||||||
|
|
||||||
configuration = new Configuration();
|
configuration = new Configuration();
|
||||||
configuration.Id = exportConfiguration.id;
|
configuration.Id = exportConfiguration.id;
|
||||||
|
configuration.InstanceId = exportConfiguration.instanceId;
|
||||||
configuration.Label = exportConfiguration.label;
|
configuration.Label = exportConfiguration.label;
|
||||||
|
configuration.Title = exportConfiguration.title;
|
||||||
|
configuration.ImageId = exportConfiguration.imageId;
|
||||||
|
configuration.ImageSource = exportConfiguration.imageSource;
|
||||||
|
|
||||||
|
if (configuration.ImageId != null)
|
||||||
|
{
|
||||||
|
createResource(exportConfiguration.resources.Where(r => r.id == configuration.ImageId).FirstOrDefault());
|
||||||
|
}
|
||||||
|
|
||||||
configuration.DateCreation = exportConfiguration.dateCreation;
|
configuration.DateCreation = exportConfiguration.dateCreation;
|
||||||
configuration.PrimaryColor = exportConfiguration.primaryColor;
|
configuration.PrimaryColor = exportConfiguration.primaryColor;
|
||||||
configuration.SecondaryColor = exportConfiguration.secondaryColor;
|
configuration.SecondaryColor = exportConfiguration.secondaryColor;
|
||||||
configuration.Languages = exportConfiguration.languages;
|
configuration.Languages = exportConfiguration.languages;
|
||||||
|
configuration.IsMobile = exportConfiguration.isMobile;
|
||||||
|
configuration.IsTablet = exportConfiguration.isTablet;
|
||||||
|
configuration.IsOffline = exportConfiguration.isOffline;
|
||||||
|
|
||||||
_configurationService.Create(configuration);
|
_configurationService.Create(configuration);
|
||||||
|
|
||||||
@ -346,6 +651,7 @@ namespace ManagerService.Controllers
|
|||||||
{
|
{
|
||||||
Section newSection = new Section();
|
Section newSection = new Section();
|
||||||
newSection.Id = section.id;
|
newSection.Id = section.id;
|
||||||
|
newSection.InstanceId = section.instanceId;
|
||||||
newSection.Label = section.label;
|
newSection.Label = section.label;
|
||||||
newSection.Title = section.title;
|
newSection.Title = section.title;
|
||||||
newSection.Description = section.description;
|
newSection.Description = section.description;
|
||||||
@ -358,6 +664,11 @@ namespace ManagerService.Controllers
|
|||||||
newSection.ParentId = section.parentId;
|
newSection.ParentId = section.parentId;
|
||||||
newSection.Data = section.data;
|
newSection.Data = section.data;
|
||||||
newSection.DateCreation = section.dateCreation;
|
newSection.DateCreation = section.dateCreation;
|
||||||
|
newSection.IsBeacon = section.isBeacon;
|
||||||
|
newSection.BeaconId = section.beaconId;
|
||||||
|
newSection.Latitude = section.latitude;
|
||||||
|
newSection.Longitude = section.longitude;
|
||||||
|
newSection.MeterZoneGPS = section.meterZoneGPS;
|
||||||
|
|
||||||
if (newSection.ImageId != null)
|
if (newSection.ImageId != null)
|
||||||
{
|
{
|
||||||
@ -397,6 +708,54 @@ namespace ManagerService.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SectionType.Quizz:
|
||||||
|
QuizzDTO quizzDTO = JsonConvert.DeserializeObject<QuizzDTO>(section.data);
|
||||||
|
foreach (var question in quizzDTO.questions)
|
||||||
|
{
|
||||||
|
if (question.resourceId != null)
|
||||||
|
{
|
||||||
|
createResource(exportConfiguration.resources.Where(r => r.id == question.resourceId).FirstOrDefault());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (quizzDTO.bad_level != null)
|
||||||
|
{
|
||||||
|
if(quizzDTO.bad_level.resourceId != null)
|
||||||
|
{
|
||||||
|
createResource(exportConfiguration.resources.Where(r => r.id == quizzDTO.bad_level.resourceId).FirstOrDefault());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (quizzDTO.medium_level != null)
|
||||||
|
{
|
||||||
|
if (quizzDTO.medium_level.resourceId != null)
|
||||||
|
{
|
||||||
|
createResource(exportConfiguration.resources.Where(r => r.id == quizzDTO.medium_level.resourceId).FirstOrDefault());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (quizzDTO.good_level != null)
|
||||||
|
{
|
||||||
|
if (quizzDTO.good_level.resourceId != null)
|
||||||
|
{
|
||||||
|
createResource(exportConfiguration.resources.Where(r => r.id == quizzDTO.good_level.resourceId).FirstOrDefault());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (quizzDTO.great_level != null)
|
||||||
|
{
|
||||||
|
if (quizzDTO.great_level.resourceId != null)
|
||||||
|
{
|
||||||
|
createResource(exportConfiguration.resources.Where(r => r.id == quizzDTO.great_level.resourceId).FirstOrDefault());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SectionType.Article:
|
||||||
|
ArticleDTO articleDTO = JsonConvert.DeserializeObject<ArticleDTO>(section.data);
|
||||||
|
foreach (var image in articleDTO.images)
|
||||||
|
{
|
||||||
|
if (image.resourceId != null)
|
||||||
|
{
|
||||||
|
createResource(exportConfiguration.resources.Where(r => r.id == image.resourceId).FirstOrDefault());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case SectionType.Menu:
|
case SectionType.Menu:
|
||||||
case SectionType.Web:
|
case SectionType.Web:
|
||||||
case SectionType.Video:
|
case SectionType.Video:
|
||||||
@ -432,25 +791,32 @@ namespace ManagerService.Controllers
|
|||||||
{
|
{
|
||||||
Resource resource = new Resource();
|
Resource resource = new Resource();
|
||||||
resource.Id = resourceExport.id;
|
resource.Id = resourceExport.id;
|
||||||
|
resource.InstanceId = resourceExport.instanceId;
|
||||||
resource.Type = resourceExport.type;
|
resource.Type = resourceExport.type;
|
||||||
resource.Label = resourceExport.label;
|
resource.Label = resourceExport.label;
|
||||||
resource.DateCreation = resourceExport.dateCreation;
|
resource.DateCreation = resourceExport.dateCreation;
|
||||||
resource.Data = resourceExport.data;
|
//resource.Data = resourceExport.data;
|
||||||
|
|
||||||
|
ResourceData resourceData = new ResourceData();
|
||||||
|
resourceData.ResourceId = resourceExport.id;
|
||||||
|
resourceData.InstanceId = resourceExport.instanceId;
|
||||||
|
resourceData.Data = resourceExport.data;
|
||||||
|
|
||||||
if (!_resourceService.IsExist(resourceExport.id))
|
if (!_resourceService.IsExist(resourceExport.id))
|
||||||
_resourceService.Create(resource);
|
_resourceService.Create(resource);
|
||||||
|
|
||||||
|
if (!_resourceDataService.IsExist(resourceExport.id))
|
||||||
|
_resourceDataService.Create(resourceData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ResourceDTO> addResourceToList(List<ResourceDTO> resourceDTOs, string resourceId) {
|
private List<string> addResourceIdToList(List<string> resourceIds, string resourceId) {
|
||||||
if (!resourceDTOs.Select(r => r.id).Contains(resourceId)) {
|
if (!resourceIds.Contains(resourceId))
|
||||||
Resource resource = _resourceService.GetById(resourceId);
|
{
|
||||||
|
resourceIds.Add(resourceId);
|
||||||
if (resource != null) {
|
|
||||||
resourceDTOs.Add(resource.ToDTO(true));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return resourceDTOs;
|
|
||||||
|
return resourceIds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,14 +37,15 @@ namespace ManagerService.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a list of all devices
|
/// Get a list of all devices
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="id">id instance</param>
|
||||||
[ProducesResponseType(typeof(List<DeviceDTO>), 200)]
|
[ProducesResponseType(typeof(List<DeviceDTO>), 200)]
|
||||||
[ProducesResponseType(typeof(string), 500)]
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ObjectResult Get()
|
public ObjectResult Get([FromQuery] string instanceId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<Device> devices = _deviceService.GetAll();
|
List<Device> devices = _deviceService.GetAll(instanceId);
|
||||||
|
|
||||||
return new OkObjectResult(devices.Select(d => d.ToDTO()));
|
return new OkObjectResult(devices.Select(d => d.ToDTO()));
|
||||||
}
|
}
|
||||||
@ -121,6 +122,7 @@ namespace ManagerService.Controllers
|
|||||||
device.DateCreation = DateTime.Now;
|
device.DateCreation = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
device.InstanceId = newDevice.instanceId;
|
||||||
device.Name = newDevice.name;
|
device.Name = newDevice.name;
|
||||||
device.Configuration = configuration.Label;
|
device.Configuration = configuration.Label;
|
||||||
device.ConfigurationId = newDevice.configurationId;
|
device.ConfigurationId = newDevice.configurationId;
|
||||||
@ -178,6 +180,7 @@ namespace ManagerService.Controllers
|
|||||||
|
|
||||||
// Todo add some verification ?
|
// Todo add some verification ?
|
||||||
device.Name = updatedDevice.name;
|
device.Name = updatedDevice.name;
|
||||||
|
device.InstanceId = updatedDevice.instanceId;
|
||||||
device.Identifier = updatedDevice.identifier;
|
device.Identifier = updatedDevice.identifier;
|
||||||
device.IpAddressWLAN = updatedDevice.ipAddressWLAN;
|
device.IpAddressWLAN = updatedDevice.ipAddressWLAN;
|
||||||
device.IpAddressETH = updatedDevice.ipAddressETH;
|
device.IpAddressETH = updatedDevice.ipAddressETH;
|
||||||
@ -239,7 +242,7 @@ namespace ManagerService.Controllers
|
|||||||
|
|
||||||
Device deviceModified = _deviceService.Update(device.Id, device);
|
Device deviceModified = _deviceService.Update(device.Id, device);
|
||||||
|
|
||||||
MqttClientService.PublishMessage($"player/{device.Id}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
// TODO MqttClientService.PublishMessage($"player/{device.Id}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
||||||
|
|
||||||
return new OkObjectResult(deviceModified.ToDTO());
|
return new OkObjectResult(deviceModified.ToDTO());
|
||||||
}
|
}
|
||||||
|
|||||||
216
ManagerService/Controllers/InstanceController.cs
Normal file
216
ManagerService/Controllers/InstanceController.cs
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Manager.Framework.Business;
|
||||||
|
using Manager.Interfaces.DTO;
|
||||||
|
using Manager.Interfaces.Models;
|
||||||
|
using Manager.Services;
|
||||||
|
using ManagerService.Service.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NSwag.Annotations;
|
||||||
|
|
||||||
|
namespace ManagerService.Controllers
|
||||||
|
{
|
||||||
|
[Authorize] // TODO Add ROLES (Roles = "Admin")
|
||||||
|
[ApiController, Route("api/[controller]")]
|
||||||
|
[OpenApiTag("Instance", Description = "Instance management")]
|
||||||
|
public class InstanceController : ControllerBase
|
||||||
|
{
|
||||||
|
private InstanceDatabaseService _instanceService;
|
||||||
|
private UserDatabaseService _userService;
|
||||||
|
private readonly ILogger<InstanceController> _logger;
|
||||||
|
private readonly ProfileLogic _profileLogic;
|
||||||
|
|
||||||
|
public InstanceController(ILogger<InstanceController> logger, InstanceDatabaseService instanceService, UserDatabaseService userService, ProfileLogic profileLogic)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_instanceService = instanceService;
|
||||||
|
_userService = userService;
|
||||||
|
_profileLogic = profileLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a list of instance
|
||||||
|
/// </summary>
|
||||||
|
[ProducesResponseType(typeof(List<Instance>), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
|
[HttpGet]
|
||||||
|
public ObjectResult Get()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<Instance> instances = _instanceService.GetAll();
|
||||||
|
|
||||||
|
return new OkObjectResult(instances);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a specific instance
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">id instance</param>
|
||||||
|
[ProducesResponseType(typeof(InstanceDTO), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public ObjectResult GetDetail(string id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Instance instance = _instanceService.GetById(id);
|
||||||
|
|
||||||
|
if (instance == null)
|
||||||
|
throw new KeyNotFoundException("This instance was not found");
|
||||||
|
|
||||||
|
return new OkObjectResult(instance.ToDTO());
|
||||||
|
}
|
||||||
|
catch (KeyNotFoundException ex)
|
||||||
|
{
|
||||||
|
return new NotFoundObjectResult(ex.Message) {};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create an instance
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="newInstance">New instance info</param>
|
||||||
|
//[AllowAnonymous]
|
||||||
|
[ProducesResponseType(typeof(InstanceDTO), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 400)]
|
||||||
|
[ProducesResponseType(typeof(string), 409)]
|
||||||
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
|
[HttpPost]
|
||||||
|
public ObjectResult CreateInstance([FromBody] Instance newInstance)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (newInstance == null)
|
||||||
|
throw new ArgumentNullException("instance param is null");
|
||||||
|
|
||||||
|
newInstance.DateCreation = DateTime.Now;
|
||||||
|
|
||||||
|
List<Instance> instances = _instanceService.GetAll();
|
||||||
|
|
||||||
|
if (instances.Select(i => i.Name).Contains(newInstance.Name))
|
||||||
|
throw new InvalidOperationException("This name is already used");
|
||||||
|
|
||||||
|
Instance instanceCreated = _instanceService.Create(newInstance);
|
||||||
|
|
||||||
|
return new OkObjectResult(instanceCreated.ToDTO());
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
return new BadRequestObjectResult(ex.Message) {};
|
||||||
|
}
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
return new ConflictObjectResult(ex.Message) {};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update an instance
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="updatedinstance">instance to update</param>
|
||||||
|
[ProducesResponseType(typeof(InstanceDTO), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 400)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
|
[HttpPut]
|
||||||
|
public ObjectResult Updateinstance([FromBody] Instance updatedInstance)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (updatedInstance == null)
|
||||||
|
throw new ArgumentNullException("instance param is null");
|
||||||
|
|
||||||
|
Instance instance = _instanceService.GetById(updatedInstance.Id);
|
||||||
|
|
||||||
|
if (instance == null)
|
||||||
|
throw new KeyNotFoundException("instance does not exist");
|
||||||
|
|
||||||
|
Instance instanceModified = _instanceService.Update(updatedInstance.Id, instance);
|
||||||
|
|
||||||
|
return new OkObjectResult(instanceModified.ToDTO());
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
return new BadRequestObjectResult(ex.Message) {};
|
||||||
|
}
|
||||||
|
catch (KeyNotFoundException ex)
|
||||||
|
{
|
||||||
|
return new NotFoundObjectResult(ex.Message) {};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete an instance
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Id of instance to delete</param>
|
||||||
|
[ProducesResponseType(typeof(string), 202)]
|
||||||
|
[ProducesResponseType(typeof(string), 400)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public ObjectResult DeleteInstance(string id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (id == null)
|
||||||
|
throw new ArgumentNullException("instance param is null");
|
||||||
|
|
||||||
|
Instance instance = _instanceService.GetById(id);
|
||||||
|
|
||||||
|
// Delete all user in instance
|
||||||
|
List<User> users = _userService.GetByInstanceId(instance.Id);
|
||||||
|
|
||||||
|
foreach(var user in users)
|
||||||
|
{
|
||||||
|
_userService.Remove(user.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (instance == null)
|
||||||
|
throw new KeyNotFoundException("instance does not exist");
|
||||||
|
|
||||||
|
_instanceService.Remove(id);
|
||||||
|
|
||||||
|
return new ObjectResult("The instance has been deleted") { StatusCode = 202 };
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
return new BadRequestObjectResult(ex.Message) { };
|
||||||
|
}
|
||||||
|
catch (KeyNotFoundException ex)
|
||||||
|
{
|
||||||
|
return new NotFoundObjectResult(ex.Message) { };
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,6 +11,7 @@ using System.Threading.Tasks;
|
|||||||
using Manager.Interfaces.DTO;
|
using Manager.Interfaces.DTO;
|
||||||
using Manager.Interfaces.Models;
|
using Manager.Interfaces.Models;
|
||||||
using Manager.Services;
|
using Manager.Services;
|
||||||
|
using ManagerService.Helpers;
|
||||||
using ManagerService.Service.Services;
|
using ManagerService.Service.Services;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@ -26,29 +27,61 @@ namespace ManagerService.Controllers
|
|||||||
public class ResourceController : ControllerBase
|
public class ResourceController : ControllerBase
|
||||||
{
|
{
|
||||||
private ResourceDatabaseService _resourceService;
|
private ResourceDatabaseService _resourceService;
|
||||||
|
private ResourceDataDatabaseService _resourceDataService;
|
||||||
private SectionDatabaseService _sectionService;
|
private SectionDatabaseService _sectionService;
|
||||||
|
private ConfigurationDatabaseService _configurationService;
|
||||||
private readonly ILogger<ResourceController> _logger;
|
private readonly ILogger<ResourceController> _logger;
|
||||||
|
|
||||||
public ResourceController(ILogger<ResourceController> logger, ResourceDatabaseService resourceService, SectionDatabaseService sectionService)
|
private static int MaxWidth = 1024;
|
||||||
|
private static int MaxHeight = 1024;
|
||||||
|
|
||||||
|
public ResourceController(ILogger<ResourceController> logger, ResourceDatabaseService resourceService, ResourceDataDatabaseService resourceDataService, SectionDatabaseService sectionService, ConfigurationDatabaseService configurationService)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_resourceService = resourceService;
|
_resourceService = resourceService;
|
||||||
|
_resourceDataService = resourceDataService;
|
||||||
_sectionService = sectionService;
|
_sectionService = sectionService;
|
||||||
|
_configurationService = configurationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a list of all resources (summary)
|
/// Get a list of all resources (summary)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="id">id instance</param>
|
||||||
|
/// <param name="types">types of resource</param>
|
||||||
[ProducesResponseType(typeof(List<ResourceDTO>), 200)]
|
[ProducesResponseType(typeof(List<ResourceDTO>), 200)]
|
||||||
[ProducesResponseType(typeof(string), 500)]
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ObjectResult Get()
|
public ObjectResult Get([FromQuery] string instanceId, [FromQuery] List<ResourceType> types)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<Resource> resources = _resourceService.GetAll();
|
if (instanceId == null)
|
||||||
|
throw new ArgumentNullException("InstanceId needed");
|
||||||
|
List<Resource> resources = new List<Resource>();
|
||||||
|
if (types.Count > 0)
|
||||||
|
{
|
||||||
|
resources = _resourceService.GetAllByType(instanceId, types);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
resources = _resourceService.GetAll(instanceId);
|
||||||
|
}
|
||||||
|
|
||||||
return new OkObjectResult(resources.Select(r => r.ToDTO(r.Type == ResourceType.ImageUrl)));
|
List<ResourceDTO> resourceDTOs = new List<ResourceDTO>();
|
||||||
|
foreach(var resource in resources)
|
||||||
|
{
|
||||||
|
ResourceDTO resourceDTO = new ResourceDTO();
|
||||||
|
resourceDTO = resource.ToDTO();
|
||||||
|
if(resource.Type == ResourceType.ImageUrl)
|
||||||
|
{
|
||||||
|
var resourceData = _resourceDataService.GetByResourceId(resource.Id);
|
||||||
|
resourceDTO.data = resourceData != null ? resourceData.Data : null;
|
||||||
|
}
|
||||||
|
resourceDTOs.Add(resourceDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new OkObjectResult(resourceDTOs.OrderByDescending(r => r.dateCreation));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -56,7 +89,6 @@ namespace ManagerService.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a specific resource
|
/// Get a specific resource
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -74,8 +106,40 @@ namespace ManagerService.Controllers
|
|||||||
|
|
||||||
if (resource == null)
|
if (resource == null)
|
||||||
throw new KeyNotFoundException("This resource was not found");
|
throw new KeyNotFoundException("This resource was not found");
|
||||||
|
|
||||||
|
ResourceDTO resourceDTO = new ResourceDTO();
|
||||||
|
resourceDTO = resource.ToDTO();
|
||||||
|
ResourceData resourceData = _resourceDataService.GetByResourceId(id);
|
||||||
|
resourceDTO.data = resourceData.Data;
|
||||||
|
/*if (resource.Type == ResourceType.ImageUrl)
|
||||||
|
{
|
||||||
|
var resourceData = _resourceDataService.GetByResourceId(resource.Id);
|
||||||
|
resourceDTO.data = resourceData != null ? resourceData.Data : null;
|
||||||
|
}*/
|
||||||
|
|
||||||
return new OkObjectResult(resource.ToDTO(resource.Type == ResourceType.ImageUrl));
|
// RESIZE IMAGE
|
||||||
|
|
||||||
|
/*byte[] imageBytes = Convert.FromBase64String(resourceData.Data);
|
||||||
|
|
||||||
|
using (MemoryStream originalImageMemoryStream = new MemoryStream(imageBytes))
|
||||||
|
{
|
||||||
|
using (Image image = Image.FromStream(originalImageMemoryStream))
|
||||||
|
{
|
||||||
|
var width = image.Width;
|
||||||
|
var height = image.Height;
|
||||||
|
|
||||||
|
if (image.Width > MaxWidth || image.Height > MaxHeight)
|
||||||
|
{
|
||||||
|
Size newSize = ImageResizer.ResizeKeepAspect(image.Size, MaxWidth, MaxHeight);
|
||||||
|
byte[] resizedImage = ImageResizer.ResizeImage(image, newSize.Width, newSize.Height, image.Width, image.Height);
|
||||||
|
|
||||||
|
resourceData.Data = Convert.ToBase64String(resizedImage);
|
||||||
|
ResourceData resourceModified = _resourceDataService.Update(resourceData.Id, resourceData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
return new OkObjectResult(resourceDTO);
|
||||||
}
|
}
|
||||||
catch (KeyNotFoundException ex)
|
catch (KeyNotFoundException ex)
|
||||||
{
|
{
|
||||||
@ -101,19 +165,46 @@ namespace ManagerService.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Resource resource = _resourceService.GetById(id);
|
Resource resource = _resourceService.GetById(id);
|
||||||
|
ResourceData resourceData = _resourceDataService.GetByResourceId(id);
|
||||||
|
|
||||||
if (resource == null)
|
if (resource == null || resourceData == null)
|
||||||
throw new KeyNotFoundException("This resource was not found");
|
throw new KeyNotFoundException("This resource was not found");
|
||||||
|
|
||||||
var file = Convert.FromBase64String(resource.Data);
|
var file = Convert.FromBase64String(resourceData.Data);
|
||||||
|
|
||||||
|
// RESIZE IMAGE
|
||||||
|
|
||||||
|
/*using (MemoryStream originalImageMemoryStream = new MemoryStream(file))
|
||||||
|
{
|
||||||
|
using (Image image = Image.FromStream(originalImageMemoryStream))
|
||||||
|
{
|
||||||
|
var width = image.Width;
|
||||||
|
var height = image.Height;
|
||||||
|
|
||||||
|
if(image.Width > MaxWidth || image.Height > MaxHeight)
|
||||||
|
{
|
||||||
|
Size newSize = ImageResizer.ResizeKeepAspect(image.Size, MaxWidth, MaxHeight);
|
||||||
|
byte[] resizedImage = ImageResizer.ResizeImage(image, newSize.Width, newSize.Height, image.Width, image.Height);
|
||||||
|
|
||||||
|
resourceData.Data = Convert.ToBase64String(resizedImage);
|
||||||
|
ResourceData resourceModified = _resourceDataService.Update(resourceData.Id, resourceData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
if (resource.Type == ResourceType.Image)
|
if (resource.Type == ResourceType.Image)
|
||||||
{
|
{
|
||||||
return new FileContentResult(file, "image/png");
|
return new FileContentResult(file, "image/png")
|
||||||
|
{
|
||||||
|
FileDownloadName = resource.Label + ".png"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if (resource.Type == ResourceType.Video)
|
if (resource.Type == ResourceType.Video || resource.Type == ResourceType.Audio)
|
||||||
{
|
{
|
||||||
return new FileContentResult(file, "application/octet-stream");
|
return new FileContentResult(file, "application/octet-stream")
|
||||||
|
{
|
||||||
|
FileDownloadName = resource.Type == ResourceType.Audio ? resource.Label + ".mp3" : resource.Label + ".mp4",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return new FileContentResult(file, "image/png");
|
return new FileContentResult(file, "image/png");
|
||||||
@ -135,16 +226,14 @@ namespace ManagerService.Controllers
|
|||||||
[ProducesResponseType(typeof(string), 404)]
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
[ProducesResponseType(typeof(string), 500)]
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
[HttpPost("upload"), DisableRequestSizeLimit]
|
[HttpPost("upload"), DisableRequestSizeLimit]
|
||||||
public IActionResult Upload([FromForm] string label, [FromForm] string type) // Create but with local //[FromBody] ResourceDetailDTO uploadResource
|
public IActionResult Upload([FromForm] string label, [FromForm] string type, [FromForm] string instanceId) // Create but with local //[FromBody] ResourceDetailDTO uploadResource
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (label == null || type == null)
|
if (label == null || type == null || instanceId == null)
|
||||||
throw new ArgumentNullException("One of resource params is null");
|
throw new ArgumentNullException("One of resource params is null");
|
||||||
ResourceDTO uploadResource = new ResourceDTO();
|
|
||||||
uploadResource.type = (ResourceType) Enum.Parse(typeof(ResourceType), type);
|
|
||||||
uploadResource.label = label;
|
|
||||||
|
|
||||||
|
var resourceType = (ResourceType)Enum.Parse(typeof(ResourceType), type);
|
||||||
List<Resource> resources = new List<Resource>();
|
List<Resource> resources = new List<Resource>();
|
||||||
|
|
||||||
foreach (var file in Request.Form.Files)
|
foreach (var file in Request.Form.Files)
|
||||||
@ -152,23 +241,42 @@ namespace ManagerService.Controllers
|
|||||||
if (file.Length > 0)
|
if (file.Length > 0)
|
||||||
{
|
{
|
||||||
var stringResult = "";
|
var stringResult = "";
|
||||||
if (file.Length > 0)
|
double fileSizeibMbs = (double) ((double)file.Length) / (1024*1024);
|
||||||
|
if (fileSizeibMbs <= 1.5 || resourceType == ResourceType.Image)
|
||||||
{
|
{
|
||||||
using (var ms = new MemoryStream())
|
using (var ms = new MemoryStream())
|
||||||
{
|
{
|
||||||
file.CopyTo(ms);
|
file.CopyTo(ms);
|
||||||
var fileBytes = ms.ToArray();
|
var fileBytes = ms.ToArray();
|
||||||
|
if (resourceType == ResourceType.Image)
|
||||||
|
{
|
||||||
|
bool isFort = instanceId == "633ee379d9405f32f166f047"; // If fort saint heribert, TODO add watermark in configuration and model
|
||||||
|
|
||||||
|
if(isFort) // TODO We need to know for which purpose (mobile or tablet)
|
||||||
|
{
|
||||||
|
fileBytes = ImageHelper.ResizeAndAddWatermark(fileBytes, isFort, MaxWidth, MaxHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
stringResult = Convert.ToBase64String(fileBytes);
|
stringResult = Convert.ToBase64String(fileBytes);
|
||||||
}
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
throw new FileLoadException(message: "Fichier inexistant ou trop volumineux (max 4Mb)");
|
||||||
}
|
}
|
||||||
// Todo add some verification ?
|
// Todo add some verification ?
|
||||||
Resource resource = new Resource();
|
Resource resource = new Resource();
|
||||||
resource.Label = uploadResource.label;
|
resource.Label = label;
|
||||||
resource.Type = uploadResource.type;
|
resource.Type = resourceType;
|
||||||
resource.DateCreation = DateTime.Now;
|
resource.DateCreation = DateTime.Now;
|
||||||
resource.Data = stringResult;
|
resource.InstanceId = instanceId;
|
||||||
Resource resourceCreated = _resourceService.Create(resource);
|
Resource resourceCreated = _resourceService.Create(resource);
|
||||||
resources.Add(resourceCreated);
|
resources.Add(resourceCreated);
|
||||||
|
|
||||||
|
ResourceData resourceData = new ResourceData();
|
||||||
|
resourceData.Data = stringResult;
|
||||||
|
resourceData.ResourceId = resourceCreated.Id;
|
||||||
|
resourceData.InstanceId = stringResult;
|
||||||
|
ResourceData resourceDataCreated = _resourceDataService.Create(resourceData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok(resources.Select(r => r.ToDTO()));
|
return Ok(resources.Select(r => r.ToDTO()));
|
||||||
@ -177,6 +285,10 @@ namespace ManagerService.Controllers
|
|||||||
{
|
{
|
||||||
return new BadRequestObjectResult(ex.Message) { };
|
return new BadRequestObjectResult(ex.Message) { };
|
||||||
}
|
}
|
||||||
|
catch (FileLoadException ex)
|
||||||
|
{
|
||||||
|
return new BadRequestObjectResult(ex.Message) { };
|
||||||
|
}
|
||||||
catch (InvalidOperationException ex)
|
catch (InvalidOperationException ex)
|
||||||
{
|
{
|
||||||
return new ConflictObjectResult(ex.Message) { };
|
return new ConflictObjectResult(ex.Message) { };
|
||||||
@ -205,14 +317,25 @@ namespace ManagerService.Controllers
|
|||||||
|
|
||||||
// Todo add some verification ?
|
// Todo add some verification ?
|
||||||
Resource resource = new Resource();
|
Resource resource = new Resource();
|
||||||
|
resource.InstanceId = newResource.instanceId;
|
||||||
resource.Label = newResource.label;
|
resource.Label = newResource.label;
|
||||||
resource.Type = newResource.type;
|
resource.Type = newResource.type;
|
||||||
resource.DateCreation = DateTime.Now;
|
resource.DateCreation = DateTime.Now;
|
||||||
resource.Data = newResource.data;
|
//resource.Data = newResource.data;
|
||||||
|
resource.InstanceId = newResource.instanceId;
|
||||||
|
|
||||||
Resource resourceCreated = _resourceService.Create(resource);
|
Resource resourceCreated = _resourceService.Create(resource);
|
||||||
|
|
||||||
return new OkObjectResult(resourceCreated.ToDTO(resource.Type == ResourceType.ImageUrl));
|
if(resource.Type == ResourceType.ImageUrl || resource.Type == ResourceType.VideoUrl)
|
||||||
|
{
|
||||||
|
ResourceData resourceData = new ResourceData();
|
||||||
|
resourceData.Data = newResource.data;
|
||||||
|
resourceData.ResourceId = resourceCreated.Id;
|
||||||
|
resourceData.InstanceId = newResource.instanceId;
|
||||||
|
ResourceData resourceDataCreated = _resourceDataService.Create(resourceData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new OkObjectResult(resourceCreated.ToDTO()); // WITHOUT DATA
|
||||||
}
|
}
|
||||||
catch (ArgumentNullException ex)
|
catch (ArgumentNullException ex)
|
||||||
{
|
{
|
||||||
@ -251,9 +374,10 @@ namespace ManagerService.Controllers
|
|||||||
throw new KeyNotFoundException("Resource does not exist");
|
throw new KeyNotFoundException("Resource does not exist");
|
||||||
|
|
||||||
// Todo add some verification ?
|
// Todo add some verification ?
|
||||||
|
resource.InstanceId = updatedResource.instanceId;
|
||||||
resource.Label = updatedResource.label;
|
resource.Label = updatedResource.label;
|
||||||
resource.Type = updatedResource.type;
|
resource.Type = updatedResource.type;
|
||||||
resource.Data = updatedResource.data;
|
//resource.Data = updatedResource.data; // NOT ALLOWED
|
||||||
|
|
||||||
Resource resourceModified = _resourceService.Update(updatedResource.id, resource);
|
Resource resourceModified = _resourceService.Update(updatedResource.id, resource);
|
||||||
|
|
||||||
@ -290,12 +414,24 @@ namespace ManagerService.Controllers
|
|||||||
if (id == null)
|
if (id == null)
|
||||||
throw new ArgumentNullException("Resource param is null");
|
throw new ArgumentNullException("Resource param is null");
|
||||||
|
|
||||||
if (!_resourceService.IsExist(id))
|
var ressource = _resourceService.GetById(id);
|
||||||
|
var ressourceData = _resourceDataService.GetByResourceId(id);
|
||||||
|
if (ressource == null)
|
||||||
throw new KeyNotFoundException("Resource does not exist");
|
throw new KeyNotFoundException("Resource does not exist");
|
||||||
|
|
||||||
|
|
||||||
|
foreach (var configuration in _configurationService.GetAll(ressource.InstanceId))
|
||||||
|
{
|
||||||
|
if (configuration.ImageId == id)
|
||||||
|
{
|
||||||
|
configuration.ImageId = null;
|
||||||
|
configuration.ImageSource = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Delete all resource occurence
|
// Delete all resource occurence
|
||||||
foreach (var section in _sectionService.GetAll())
|
foreach (var section in _sectionService.GetAll(ressource.InstanceId))
|
||||||
{
|
{
|
||||||
if (section.ImageId == id)
|
if (section.ImageId == id)
|
||||||
{
|
{
|
||||||
@ -329,12 +465,55 @@ namespace ManagerService.Controllers
|
|||||||
sliderDTO.images = imagesToKeep;
|
sliderDTO.images = imagesToKeep;
|
||||||
section.Data = JsonConvert.SerializeObject(sliderDTO);
|
section.Data = JsonConvert.SerializeObject(sliderDTO);
|
||||||
break;
|
break;
|
||||||
|
case SectionType.Quizz:
|
||||||
|
QuizzDTO quizzDTO = JsonConvert.DeserializeObject<QuizzDTO>(section.Data);
|
||||||
|
foreach (var question in quizzDTO.questions)
|
||||||
|
{
|
||||||
|
question.source = question.resourceId == id ? null : question.source;
|
||||||
|
question.resourceId = question.resourceId == id ? null : question.resourceId;
|
||||||
|
}
|
||||||
|
if (quizzDTO.bad_level != null) {
|
||||||
|
quizzDTO.bad_level.source = quizzDTO.bad_level.resourceId == id ? null : quizzDTO.bad_level.source;
|
||||||
|
quizzDTO.bad_level.resourceId = quizzDTO.bad_level.resourceId == id ? null : quizzDTO.bad_level.resourceId;
|
||||||
|
}
|
||||||
|
if (quizzDTO.medium_level != null)
|
||||||
|
{
|
||||||
|
quizzDTO.medium_level.source = quizzDTO.medium_level.resourceId == id ? null : quizzDTO.medium_level.source;
|
||||||
|
quizzDTO.medium_level.resourceId = quizzDTO.medium_level.resourceId == id ? null : quizzDTO.medium_level.resourceId;
|
||||||
|
}
|
||||||
|
if (quizzDTO.good_level != null)
|
||||||
|
{
|
||||||
|
quizzDTO.good_level.source = quizzDTO.good_level.resourceId == id ? null : quizzDTO.good_level.source;
|
||||||
|
quizzDTO.good_level.resourceId = quizzDTO.good_level.resourceId == id ? null : quizzDTO.good_level.resourceId;
|
||||||
|
}
|
||||||
|
if (quizzDTO.great_level != null)
|
||||||
|
{
|
||||||
|
quizzDTO.great_level.source = quizzDTO.great_level.resourceId == id ? null : quizzDTO.great_level.source;
|
||||||
|
quizzDTO.great_level.resourceId = quizzDTO.great_level.resourceId == id ? null : quizzDTO.great_level.resourceId;
|
||||||
|
}
|
||||||
|
section.Data = JsonConvert.SerializeObject(quizzDTO);
|
||||||
|
break;
|
||||||
|
case SectionType.Article:
|
||||||
|
ArticleDTO articleDTO = JsonConvert.DeserializeObject<ArticleDTO>(section.Data);
|
||||||
|
List<ImageDTO> imagesArticleToKeep = new List<ImageDTO>();
|
||||||
|
foreach (var image in articleDTO.images)
|
||||||
|
{
|
||||||
|
if (image.resourceId != id)
|
||||||
|
imagesArticleToKeep.Add(image);
|
||||||
|
}
|
||||||
|
articleDTO.images = imagesArticleToKeep;
|
||||||
|
section.Data = JsonConvert.SerializeObject(articleDTO);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_sectionService.Update(section.Id, section);
|
_sectionService.Update(section.Id, section);
|
||||||
}
|
}
|
||||||
|
|
||||||
_resourceService.Remove(id);
|
_resourceService.Remove(id);
|
||||||
|
if (ressourceData != null)
|
||||||
|
{
|
||||||
|
_resourceDataService.Remove(ressourceData.Id);
|
||||||
|
}
|
||||||
|
|
||||||
return new ObjectResult("The resource has been deleted") { StatusCode = 202 };
|
return new ObjectResult("The resource has been deleted") { StatusCode = 202 };
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
using Manager.Interfaces.DTO;
|
using Manager.Helpers;
|
||||||
|
using Manager.Interfaces.DTO;
|
||||||
using Manager.Interfaces.Models;
|
using Manager.Interfaces.Models;
|
||||||
using Manager.Services;
|
using Manager.Services;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Mqtt.Client.AspNetCore.Services;
|
using Mqtt.Client.AspNetCore.Services;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@ -21,10 +23,12 @@ namespace ManagerService.Controllers
|
|||||||
private SectionDatabaseService _sectionService;
|
private SectionDatabaseService _sectionService;
|
||||||
private ConfigurationDatabaseService _configurationService;
|
private ConfigurationDatabaseService _configurationService;
|
||||||
private readonly ILogger<SectionController> _logger;
|
private readonly ILogger<SectionController> _logger;
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
|
||||||
public SectionController(ILogger<SectionController> logger, SectionDatabaseService sectionService, ConfigurationDatabaseService configurationService)
|
public SectionController(IConfiguration configuration, ILogger<SectionController> logger, SectionDatabaseService sectionService, ConfigurationDatabaseService configurationService)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_configuration = configuration;
|
||||||
_sectionService = sectionService;
|
_sectionService = sectionService;
|
||||||
_configurationService = configurationService;
|
_configurationService = configurationService;
|
||||||
}
|
}
|
||||||
@ -32,14 +36,35 @@ namespace ManagerService.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a list of all section (summary)
|
/// Get a list of all section (summary)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="id">id instance</param>
|
||||||
[ProducesResponseType(typeof(List<SectionDTO>), 200)]
|
[ProducesResponseType(typeof(List<SectionDTO>), 200)]
|
||||||
[ProducesResponseType(typeof(string), 500)]
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ObjectResult Get()
|
public ObjectResult Get([FromQuery] string instanceId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<Section> sections = _sectionService.GetAll();
|
List<Section> sections = _sectionService.GetAll(instanceId);
|
||||||
|
|
||||||
|
|
||||||
|
/* CLEAN ARTICLE AUDIO - Init new field AudioIds */
|
||||||
|
|
||||||
|
/*foreach (var article in sections.Where(s => s.Type == SectionType.Article))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ArticleDTO articleDTO = JsonConvert.DeserializeObject<ArticleDTO>(article.Data);
|
||||||
|
List<string> languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>();
|
||||||
|
articleDTO.audioIds = LanguageInit.Init("Audio", languages, true);
|
||||||
|
article.Data = JsonConvert.SerializeObject(articleDTO); // Include all info from specific section as JSON
|
||||||
|
|
||||||
|
Section sectionModified = _sectionService.Update(article.Id, article);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
return new OkObjectResult(sections.Select(r => r.ToDTO()));
|
return new OkObjectResult(sections.Select(r => r.ToDTO()));
|
||||||
}
|
}
|
||||||
@ -205,6 +230,35 @@ namespace ManagerService.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get all section with beacon
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="instanceId">Instance id</param>
|
||||||
|
[AllowAnonymous]
|
||||||
|
[ProducesResponseType(typeof(List<SectionDTO>), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
|
[HttpGet("beacons/{instanceId}")]
|
||||||
|
public ObjectResult GetAllBeaconsForInstance(string instanceId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<Section> sections = _sectionService.GetAll(instanceId);
|
||||||
|
|
||||||
|
sections = sections.Where(s => s.IsBeacon && s.BeaconId != null).ToList();
|
||||||
|
|
||||||
|
return new OkObjectResult(sections.Select(s => s.ToDTO()));
|
||||||
|
}
|
||||||
|
catch (KeyNotFoundException ex)
|
||||||
|
{
|
||||||
|
return new NotFoundObjectResult(ex.Message) { };
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new section
|
/// Create a new section
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -229,6 +283,7 @@ namespace ManagerService.Controllers
|
|||||||
|
|
||||||
// Todo add some verification ?
|
// Todo add some verification ?
|
||||||
Section section = new Section();
|
Section section = new Section();
|
||||||
|
section.InstanceId = newSection.instanceId;
|
||||||
section.Label = newSection.label;
|
section.Label = newSection.label;
|
||||||
section.ImageId = newSection.imageId;
|
section.ImageId = newSection.imageId;
|
||||||
section.ImageSource = newSection.imageSource;
|
section.ImageSource = newSection.imageSource;
|
||||||
@ -240,40 +295,59 @@ namespace ManagerService.Controllers
|
|||||||
section.Title = new List<TranslationDTO>();
|
section.Title = new List<TranslationDTO>();
|
||||||
section.Description = new List<TranslationDTO>();
|
section.Description = new List<TranslationDTO>();
|
||||||
section.Order = _sectionService.GetAllFromConfiguration(newSection.configurationId).Count;
|
section.Order = _sectionService.GetAllFromConfiguration(newSection.configurationId).Count;
|
||||||
|
section.IsBeacon = newSection.isBeacon;
|
||||||
|
section.BeaconId = newSection.beaconId;
|
||||||
|
section.Latitude = newSection.latitude;
|
||||||
|
section.Longitude = newSection.longitude;
|
||||||
|
section.MeterZoneGPS = newSection.meterZoneGPS;
|
||||||
|
|
||||||
// Preparation
|
// Preparation
|
||||||
List<string> languages = new List<string> { "FR", "NL", "EN", "DE" };//_configurationService.GetById(newSection.ConfigurationId).Languages;
|
List<string> languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>();
|
||||||
|
|
||||||
|
var contentArticle = new List<TranslationDTO>();
|
||||||
|
|
||||||
var mapDTO = new MapDTO(); // For menu dto
|
var mapDTO = new MapDTO(); // For menu dto
|
||||||
var sliderDTO = new SliderDTO(); // For menu dto
|
var sliderDTO = new SliderDTO(); // For menu dto
|
||||||
|
|
||||||
foreach (var language in languages)
|
section.Title = LanguageInit.Init("Title", languages);
|
||||||
|
section.Description = LanguageInit.Init("Description", languages);
|
||||||
|
contentArticle = LanguageInit.Init("Content", languages);
|
||||||
|
|
||||||
|
/*foreach (var language in languages)
|
||||||
{
|
{
|
||||||
TranslationDTO title = new TranslationDTO();
|
TranslationDTO title = new TranslationDTO();
|
||||||
TranslationDTO description = new TranslationDTO();
|
TranslationDTO description = new TranslationDTO();
|
||||||
|
TranslationDTO content = new TranslationDTO();
|
||||||
title.language = language.ToUpper();
|
title.language = language.ToUpper();
|
||||||
description.language = language.ToUpper();
|
description.language = language.ToUpper();
|
||||||
|
content.language = language.ToUpper();
|
||||||
switch (language.ToUpper())
|
switch (language.ToUpper())
|
||||||
{
|
{
|
||||||
case "FR":
|
case "FR":
|
||||||
title.value = "Titre en français";
|
title.value = "Titre en français";
|
||||||
description.value = "Description en français";
|
description.value = "Description en français";
|
||||||
|
content.value = "Contenu en français";
|
||||||
break;
|
break;
|
||||||
case "EN":
|
case "EN":
|
||||||
title.value = "Title in english";
|
title.value = "Title in english";
|
||||||
description.value = "Description en anglais";
|
description.value = "Description en anglais";
|
||||||
|
content.value = "Contenu en anglais";
|
||||||
break;
|
break;
|
||||||
case "NL":
|
case "NL":
|
||||||
title.value = "Titre in dutch";
|
title.value = "Titre in dutch";
|
||||||
description.value = "Description en néerlandais";
|
description.value = "Description en néerlandais";
|
||||||
|
content.value = "Contenu en néerlandais";
|
||||||
break;
|
break;
|
||||||
case "DE":
|
case "DE":
|
||||||
title.value = "Titre en allemand";
|
title.value = "Titre en allemand";
|
||||||
description.value = "Description en allemand";
|
description.value = "Description en allemand";
|
||||||
|
content.value = "Contenu en allemand";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
section.Title.Add(title);
|
section.Title.Add(title);
|
||||||
section.Description.Add(description);
|
section.Description.Add(description);
|
||||||
}
|
contentArticle.Add(content);
|
||||||
|
}*/
|
||||||
|
|
||||||
section.Title = section.Title.OrderBy(t => t.language).ToList();
|
section.Title = section.Title.OrderBy(t => t.language).ToList();
|
||||||
section.Description = section.Description.OrderBy(d => d.language).ToList();
|
section.Description = section.Description.OrderBy(d => d.language).ToList();
|
||||||
@ -333,6 +407,19 @@ namespace ManagerService.Controllers
|
|||||||
menuDTO.Sections.Add(section1DTO);*/
|
menuDTO.Sections.Add(section1DTO);*/
|
||||||
section.Data = JsonConvert.SerializeObject(menuDTO); // Include all info from specific section as JSON
|
section.Data = JsonConvert.SerializeObject(menuDTO); // Include all info from specific section as JSON
|
||||||
break;
|
break;
|
||||||
|
case SectionType.Quizz:
|
||||||
|
QuizzDTO quizzDTO = new QuizzDTO();
|
||||||
|
quizzDTO.questions = new List<QuestionDTO>();
|
||||||
|
section.Data = JsonConvert.SerializeObject(quizzDTO); // Include all info from specific section as JSON
|
||||||
|
break;
|
||||||
|
case SectionType.Article:
|
||||||
|
ArticleDTO articleDTO = new ArticleDTO();
|
||||||
|
articleDTO.images = new List<ImageDTO>();
|
||||||
|
articleDTO.content = contentArticle;
|
||||||
|
articleDTO.audioIds = LanguageInit.Init("Audio", languages, true);
|
||||||
|
|
||||||
|
section.Data = JsonConvert.SerializeObject(articleDTO); // Include all info from specific section as JSON
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Section sectionCreated = _sectionService.Create(section);
|
Section sectionCreated = _sectionService.Create(section);
|
||||||
@ -427,6 +514,7 @@ namespace ManagerService.Controllers
|
|||||||
throw new KeyNotFoundException("Section does not exist");
|
throw new KeyNotFoundException("Section does not exist");
|
||||||
|
|
||||||
// Todo add some verification ?
|
// Todo add some verification ?
|
||||||
|
section.InstanceId = updatedSection.instanceId;
|
||||||
section.Label = updatedSection.label;
|
section.Label = updatedSection.label;
|
||||||
section.Title = updatedSection.title;
|
section.Title = updatedSection.title;
|
||||||
section.Description = updatedSection.description;
|
section.Description = updatedSection.description;
|
||||||
@ -437,10 +525,15 @@ namespace ManagerService.Controllers
|
|||||||
section.IsSubSection = updatedSection.isSubSection;
|
section.IsSubSection = updatedSection.isSubSection;
|
||||||
section.ParentId = updatedSection.parentId;
|
section.ParentId = updatedSection.parentId;
|
||||||
section.Data = updatedSection.data;
|
section.Data = updatedSection.data;
|
||||||
|
section.IsBeacon = updatedSection.isBeacon;
|
||||||
|
section.BeaconId = updatedSection.beaconId;
|
||||||
|
section.Latitude = updatedSection.latitude;
|
||||||
|
section.Longitude = updatedSection.longitude;
|
||||||
|
section.MeterZoneGPS = updatedSection.meterZoneGPS;
|
||||||
|
|
||||||
Section sectionModified = _sectionService.Update(updatedSection.id, section);
|
Section sectionModified = _sectionService.Update(updatedSection.id, section);
|
||||||
|
|
||||||
MqttClientService.PublishMessage($"config/{sectionModified.ConfigurationId}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
// TODO MqttClientService.PublishMessage($"config/{sectionModified.ConfigurationId}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
||||||
|
|
||||||
return new OkObjectResult(sectionModified.ToDTO());
|
return new OkObjectResult(sectionModified.ToDTO());
|
||||||
}
|
}
|
||||||
@ -489,7 +582,7 @@ namespace ManagerService.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (updatedSectionsOrder.Count > 0) {
|
if (updatedSectionsOrder.Count > 0) {
|
||||||
MqttClientService.PublishMessage($"config/{updatedSectionsOrder[0].configurationId}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
// TODO MqttClientService.PublishMessage($"config/{updatedSectionsOrder[0].configurationId}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ObjectResult("Sections order has been successfully modified") { StatusCode = 200 };
|
return new ObjectResult("Sections order has been successfully modified") { StatusCode = 200 };
|
||||||
@ -606,5 +699,25 @@ namespace ManagerService.Controllers
|
|||||||
{
|
{
|
||||||
return new ObjectResult("PlayerMessageDTO") { StatusCode = 200 };
|
return new ObjectResult("PlayerMessageDTO") { StatusCode = 200 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Useless, just to generate dto code
|
||||||
|
/// </summary>
|
||||||
|
[ProducesResponseType(typeof(QuizzDTO), 200)]
|
||||||
|
[HttpGet("QuizzDTO")]
|
||||||
|
public ObjectResult GetQuizzDTO()
|
||||||
|
{
|
||||||
|
return new ObjectResult("QuizzDTO") { StatusCode = 200 };
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Useless, just to generate dto code
|
||||||
|
/// </summary>
|
||||||
|
[ProducesResponseType(typeof(ArticleDTO), 200)]
|
||||||
|
[HttpGet("ArticleDTO")]
|
||||||
|
public ObjectResult GetArticleDTO()
|
||||||
|
{
|
||||||
|
return new ObjectResult("ArticleDTO") { StatusCode = 200 };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,7 +86,7 @@ namespace ManagerService.Controllers
|
|||||||
/// Create an user
|
/// Create an user
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="newUser">New user info</param>
|
/// <param name="newUser">New user info</param>
|
||||||
[AllowAnonymous]
|
//[AllowAnonymous]
|
||||||
[ProducesResponseType(typeof(UserDetailDTO), 200)]
|
[ProducesResponseType(typeof(UserDetailDTO), 200)]
|
||||||
[ProducesResponseType(typeof(string), 400)]
|
[ProducesResponseType(typeof(string), 400)]
|
||||||
[ProducesResponseType(typeof(string), 409)]
|
[ProducesResponseType(typeof(string), 409)]
|
||||||
@ -99,6 +99,9 @@ namespace ManagerService.Controllers
|
|||||||
if (newUser == null)
|
if (newUser == null)
|
||||||
throw new ArgumentNullException("User param is null");
|
throw new ArgumentNullException("User param is null");
|
||||||
|
|
||||||
|
if (newUser.InstanceId == null)
|
||||||
|
throw new ArgumentNullException("InstanceId is null");
|
||||||
|
|
||||||
newUser.Token = _tokenService.GenerateToken(newUser.Email).ToString();
|
newUser.Token = _tokenService.GenerateToken(newUser.Email).ToString();
|
||||||
newUser.DateCreation = DateTime.Now;
|
newUser.DateCreation = DateTime.Now;
|
||||||
|
|
||||||
|
|||||||
26
ManagerService/Dockerfile
Normal file
26
ManagerService/Dockerfile
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
|
||||||
|
RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev
|
||||||
|
WORKDIR /app
|
||||||
|
EXPOSE 80
|
||||||
|
VOLUME ["/etc/managerservice"]
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||||
|
WORKDIR /src
|
||||||
|
COPY ["ManagerService/ManagerService.csproj", "ManagerService/"]
|
||||||
|
COPY ["Manager.Interfaces/Manager.Interfaces.csproj", "Manager.Interfaces/"]
|
||||||
|
COPY ["Manager.Framework/Manager.Framework.csproj", "Manager.Framework/"]
|
||||||
|
RUN dotnet restore "ManagerService/ManagerService.csproj"
|
||||||
|
COPY . .
|
||||||
|
WORKDIR "/src/ManagerService"
|
||||||
|
RUN dotnet build "ManagerService.csproj" -c Release -o /app/build
|
||||||
|
|
||||||
|
FROM build AS publish
|
||||||
|
RUN dotnet publish "ManagerService.csproj" -c Release -o /app/publish
|
||||||
|
|
||||||
|
FROM base AS final
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=publish /app/publish .
|
||||||
|
RUN mkdir -p /app/service-data
|
||||||
|
ENTRYPOINT ["dotnet", "ManagerService.dll"]
|
||||||
28
ManagerService/Helpers/FileHelper.cs
Normal file
28
ManagerService/Helpers/FileHelper.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
|
||||||
|
namespace ManagerService.Helpers
|
||||||
|
{
|
||||||
|
public class FileHelper
|
||||||
|
{
|
||||||
|
public static byte[] CreateZipArchive(string configurationFolder)
|
||||||
|
{
|
||||||
|
byte[] archiveFiles;
|
||||||
|
using (var archiveStream = new MemoryStream())
|
||||||
|
{
|
||||||
|
using (var archive = new ZipArchive(archiveStream, ZipArchiveMode.Create, true))
|
||||||
|
{
|
||||||
|
var di = new DirectoryInfo(configurationFolder);
|
||||||
|
foreach (var file in di.EnumerateFiles("*.*", SearchOption.AllDirectories))
|
||||||
|
{
|
||||||
|
archive.CreateEntryFromFile(file.FullName, file.Name);
|
||||||
|
//file.Delete();
|
||||||
|
}
|
||||||
|
//di.Delete();
|
||||||
|
}
|
||||||
|
archiveFiles = archiveStream.ToArray();
|
||||||
|
}
|
||||||
|
return archiveFiles;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
125
ManagerService/Helpers/ImageHelper.cs
Normal file
125
ManagerService/Helpers/ImageHelper.cs
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace ManagerService.Helpers
|
||||||
|
{
|
||||||
|
public static class ImageHelper
|
||||||
|
{
|
||||||
|
|
||||||
|
public static Size ResizeKeepAspect(this Size src, int maxWidth, int maxHeight, bool enlarge = false)
|
||||||
|
{
|
||||||
|
maxWidth = enlarge ? maxWidth : Math.Min(maxWidth, src.Width);
|
||||||
|
maxHeight = enlarge ? maxHeight : Math.Min(maxHeight, src.Height);
|
||||||
|
|
||||||
|
decimal rnd = Math.Min(maxWidth / (decimal)src.Width, maxHeight / (decimal)src.Height);
|
||||||
|
return new Size((int)Math.Round(src.Width * rnd), (int)Math.Round(src.Height * rnd));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TO Byte[] or Image type
|
||||||
|
public static dynamic ResizeImage(Image image,
|
||||||
|
/* note changed names */
|
||||||
|
int canvasWidth, int canvasHeight,
|
||||||
|
/* new */
|
||||||
|
int originalWidth, int originalHeight, bool isImage = false)
|
||||||
|
{
|
||||||
|
byte[] convertedToBytes;
|
||||||
|
|
||||||
|
System.Drawing.Image thumbnail =
|
||||||
|
new Bitmap(canvasWidth, canvasHeight); // changed parm names
|
||||||
|
System.Drawing.Graphics graphic =
|
||||||
|
System.Drawing.Graphics.FromImage(thumbnail);
|
||||||
|
|
||||||
|
graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
|
graphic.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
|
graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||||
|
graphic.CompositingQuality = CompositingQuality.HighQuality;
|
||||||
|
|
||||||
|
/* ------------------ new code --------------- */
|
||||||
|
|
||||||
|
// Figure out the ratio
|
||||||
|
double ratioX = (double)canvasWidth / (double)originalWidth;
|
||||||
|
double ratioY = (double)canvasHeight / (double)originalHeight;
|
||||||
|
// use whichever multiplier is smaller
|
||||||
|
double ratio = ratioX < ratioY ? ratioX : ratioY;
|
||||||
|
|
||||||
|
// now we can get the new height and width
|
||||||
|
int newHeight = Convert.ToInt32(originalHeight * ratio);
|
||||||
|
int newWidth = Convert.ToInt32(originalWidth * ratio);
|
||||||
|
|
||||||
|
// Now calculate the X,Y position of the upper-left corner
|
||||||
|
// (one of these will always be zero)
|
||||||
|
int posX = Convert.ToInt32((canvasWidth - (originalWidth * ratio)) / 2);
|
||||||
|
int posY = Convert.ToInt32((canvasHeight - (originalHeight * ratio)) / 2);
|
||||||
|
|
||||||
|
graphic.Clear(Color.White); // white padding
|
||||||
|
graphic.DrawImage(image, posX, posY, newWidth, newHeight);
|
||||||
|
|
||||||
|
/* ------------- end new code ---------------- */
|
||||||
|
|
||||||
|
System.Drawing.Imaging.ImageCodecInfo[] info =
|
||||||
|
ImageCodecInfo.GetImageEncoders();
|
||||||
|
EncoderParameters encoderParameters;
|
||||||
|
encoderParameters = new EncoderParameters(1);
|
||||||
|
encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality,
|
||||||
|
100L);
|
||||||
|
|
||||||
|
if (isImage)
|
||||||
|
{
|
||||||
|
return thumbnail;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (MemoryStream updatedImageMemorySteam = new MemoryStream())
|
||||||
|
{
|
||||||
|
thumbnail.Save(updatedImageMemorySteam, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||||
|
convertedToBytes = updatedImageMemorySteam.ToArray();
|
||||||
|
}
|
||||||
|
return convertedToBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] ResizeAndAddWatermark(Byte[] bytes, bool watermark, int maxWidth, int maxHeight)
|
||||||
|
{
|
||||||
|
byte[] convertedToBytes;
|
||||||
|
|
||||||
|
using (MemoryStream originalImageMemoryStream = new MemoryStream(bytes))
|
||||||
|
{
|
||||||
|
using (Image image = Image.FromStream(originalImageMemoryStream))
|
||||||
|
{
|
||||||
|
Image currentImage = image;
|
||||||
|
|
||||||
|
if (image.Width > maxWidth || image.Height > maxHeight)
|
||||||
|
{
|
||||||
|
Size newSize = ResizeKeepAspect(image.Size, maxWidth, maxHeight);
|
||||||
|
Image resizedImage = ImageHelper.ResizeImage(image, newSize.Width, newSize.Height, image.Width, image.Height, true);
|
||||||
|
currentImage = resizedImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(watermark)
|
||||||
|
{
|
||||||
|
Font font = new Font("Arial", 25, FontStyle.Italic, GraphicsUnit.Pixel);
|
||||||
|
Color color = Color.DarkBlue;
|
||||||
|
Point point = new Point(currentImage.Width /2, (int)Math.Round(currentImage.Height - currentImage.Height * 0.1));
|
||||||
|
SolidBrush brush = new SolidBrush(color);
|
||||||
|
using (Graphics graphics = Graphics.FromImage(currentImage))
|
||||||
|
{
|
||||||
|
StringFormat stringFormat = new StringFormat();
|
||||||
|
stringFormat.Alignment = StringAlignment.Center;
|
||||||
|
stringFormat.LineAlignment = StringAlignment.Center;
|
||||||
|
graphics.DrawString("fortsaintheribert.be", font, brush, point, stringFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
using (MemoryStream updatedImageMemorySteam = new MemoryStream())
|
||||||
|
{
|
||||||
|
currentImage.Save(updatedImageMemorySteam, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||||
|
convertedToBytes = updatedImageMemorySteam.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return convertedToBytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
27
ManagerService/Helpers/LanguageInit.cs
Normal file
27
ManagerService/Helpers/LanguageInit.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Manager.Interfaces.DTO;
|
||||||
|
using Manager.Interfaces.Models;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
|
||||||
|
namespace Manager.Helpers
|
||||||
|
{
|
||||||
|
public class LanguageInit
|
||||||
|
{
|
||||||
|
public static List<TranslationDTO> Init(string label, List<string> languages, bool toNull = false)
|
||||||
|
{
|
||||||
|
List<TranslationDTO> translations = new List<TranslationDTO>();
|
||||||
|
|
||||||
|
foreach (var language in languages)
|
||||||
|
{
|
||||||
|
var value = toNull ? null : $"{language} - {label}";
|
||||||
|
translations.Add(new TranslationDTO() { language = language.ToUpper(), value = value });
|
||||||
|
}
|
||||||
|
return translations;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,12 +1,23 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
|
<UserSecretsId>d2e1a747-e204-4b43-bf93-abbd19c46417</UserSecretsId>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
<DefineConstants>$(DefineConstants)TRACE;RELEASE</DefineConstants>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
|
<DefineConstants>$(DefineConstants)TRACE;RELEASE</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.2" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.2" />
|
||||||
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.10.0" />
|
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.10.0" />
|
||||||
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
|
||||||
<PackageReference Include="MongoDB.Driver" Version="2.12.1" />
|
<PackageReference Include="MongoDB.Driver" Version="2.12.1" />
|
||||||
<PackageReference Include="MQTTnet.AspNetCore" Version="3.0.13" />
|
<PackageReference Include="MQTTnet.AspNetCore" Version="3.0.13" />
|
||||||
<PackageReference Include="NSwag.AspNetCore" Version="13.10.8" />
|
<PackageReference Include="NSwag.AspNetCore" Version="13.10.8" />
|
||||||
|
|||||||
@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
|
||||||
|
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||||
|
-->
|
||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<WebPublishMethod>Custom</WebPublishMethod>
|
||||||
|
<DockerPublish>true</DockerPublish>
|
||||||
|
<RegistryUrl>https://registry.unov.be</RegistryUrl>
|
||||||
|
<UserName>admin</UserName>
|
||||||
|
<PublishImageTag>version_1_0</PublishImageTag>
|
||||||
|
<PublishProvider>ContainerRegistry</PublishProvider>
|
||||||
|
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||||
|
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||||
|
<ProjectGuid>042e0bc4-8dcf-4eec-8420-c71aa85d4d99</ProjectGuid>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
||||||
|
<SelfContained>false</SelfContained>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
|
||||||
|
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||||
|
-->
|
||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<WebPublishMethod>Custom</WebPublishMethod>
|
||||||
|
<DockerPublish>true</DockerPublish>
|
||||||
|
<RegistryUrl>https://registry.unov.be</RegistryUrl>
|
||||||
|
<UserName />
|
||||||
|
<PublishImageTag>version_1_0</PublishImageTag>
|
||||||
|
<PublishProvider>ContainerRegistry</PublishProvider>
|
||||||
|
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||||
|
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||||
|
<ProjectGuid>042e0bc4-8dcf-4eec-8420-c71aa85d4d99</ProjectGuid>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||||
"iisSettings": {
|
"iisSettings": {
|
||||||
"windowsAuthentication": false,
|
"windowsAuthentication": false,
|
||||||
"anonymousAuthentication": true,
|
"anonymousAuthentication": true,
|
||||||
@ -7,15 +8,14 @@
|
|||||||
"sslPort": 0
|
"sslPort": 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"IIS Express": {
|
"IIS Express": {
|
||||||
"commandName": "IISExpress",
|
"commandName": "IISExpress",
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"launchUrl": "swagger",
|
"launchUrl": "swagger",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_URLS": "http://*:5000/",
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_URLS": "http://*:5000/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ManagerService": {
|
"ManagerService": {
|
||||||
@ -26,6 +26,22 @@
|
|||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
},
|
},
|
||||||
"applicationUrl": "https://localhost:5001;http://localhost:5000"
|
"applicationUrl": "https://localhost:5001;http://localhost:5000"
|
||||||
|
},
|
||||||
|
"WSL": {
|
||||||
|
"commandName": "WSL2",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "https://localhost:5001/weatherforecast",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
|
"ASPNETCORE_URLS": "https://localhost:5001;http://localhost:5000"
|
||||||
|
},
|
||||||
|
"distributionName": ""
|
||||||
|
},
|
||||||
|
"Docker": {
|
||||||
|
"commandName": "Docker",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
|
||||||
|
"publishAllPorts": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18,9 +18,9 @@ namespace Manager.Services
|
|||||||
var database = client.GetDatabase("TabletDb");
|
var database = client.GetDatabase("TabletDb");
|
||||||
_Configurations = database.GetCollection<Configuration>("Configurations");
|
_Configurations = database.GetCollection<Configuration>("Configurations");
|
||||||
}
|
}
|
||||||
public List<Configuration> GetAll()
|
public List<Configuration> GetAll(string instanceId)
|
||||||
{
|
{
|
||||||
return _Configurations.Find(d => true).ToList();
|
return _Configurations.Find(d => d.InstanceId == instanceId).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Configuration GetById(string id)
|
public Configuration GetById(string id)
|
||||||
|
|||||||
@ -19,9 +19,9 @@ namespace Manager.Services
|
|||||||
_Devices = database.GetCollection<Device>("Devices");
|
_Devices = database.GetCollection<Device>("Devices");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Device> GetAll()
|
public List<Device> GetAll(string instanceId)
|
||||||
{
|
{
|
||||||
return _Devices.Find(d => true).ToList();
|
return _Devices.Find(d => d.InstanceId == instanceId).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Device> GetAllConnected()
|
public List<Device> GetAllConnected()
|
||||||
|
|||||||
59
ManagerService/Services/InstanceDatabaseService.cs
Normal file
59
ManagerService/Services/InstanceDatabaseService.cs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Manager.Interfaces.Models;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
|
||||||
|
namespace Manager.Services
|
||||||
|
{
|
||||||
|
public class InstanceDatabaseService
|
||||||
|
{
|
||||||
|
private readonly IMongoCollection<Instance> _Instances;
|
||||||
|
|
||||||
|
public InstanceDatabaseService(IConfiguration config)
|
||||||
|
{
|
||||||
|
var client = new MongoClient(config.GetConnectionString("TabletDb"));
|
||||||
|
var database = client.GetDatabase("TabletDb");
|
||||||
|
_Instances = database.GetCollection<Instance>("Instances");
|
||||||
|
}
|
||||||
|
public List<Instance> GetAll()
|
||||||
|
{
|
||||||
|
return _Instances.Find(m => true).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instance GetByName(string name)
|
||||||
|
{
|
||||||
|
return _Instances.Find<Instance>(i => i.Name == name).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instance GetById(string id)
|
||||||
|
{
|
||||||
|
return _Instances.Find<Instance>(i => i.Id == id).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsExist(string id)
|
||||||
|
{
|
||||||
|
return _Instances.Find<Instance>(i => i.Id == id).FirstOrDefault() != null ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instance Create(Instance instance)
|
||||||
|
{
|
||||||
|
_Instances.InsertOne(instance);
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instance Update(string id, Instance instanceIn)
|
||||||
|
{
|
||||||
|
_Instances.ReplaceOne(instance => instance.Id == id, instanceIn);
|
||||||
|
return instanceIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Remove(string id)
|
||||||
|
{
|
||||||
|
_Instances.DeleteOne(instance => instance.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
64
ManagerService/Services/ResourceDataDatabaseService.cs
Normal file
64
ManagerService/Services/ResourceDataDatabaseService.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Manager.Interfaces.Models;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
|
||||||
|
namespace Manager.Services
|
||||||
|
{
|
||||||
|
public class ResourceDataDatabaseService
|
||||||
|
{
|
||||||
|
private readonly IMongoCollection<ResourceData> _ResourcesData;
|
||||||
|
|
||||||
|
public ResourceDataDatabaseService(IConfiguration config)
|
||||||
|
{
|
||||||
|
var client = new MongoClient(config.GetConnectionString("TabletDb"));
|
||||||
|
var database = client.GetDatabase("TabletDb");
|
||||||
|
_ResourcesData = database.GetCollection<ResourceData>("ResourcesData");
|
||||||
|
}
|
||||||
|
public List<ResourceData> GetAll(string instanceId)
|
||||||
|
{
|
||||||
|
return _ResourcesData.Find(r => r.InstanceId == instanceId).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceData GetById(string id)
|
||||||
|
{
|
||||||
|
return _ResourcesData.Find<ResourceData>(r => r.Id == id).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceData GetByResourceId(string id)
|
||||||
|
{
|
||||||
|
return _ResourcesData.Find<ResourceData>(r => r.ResourceId == id).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsExist(string id)
|
||||||
|
{
|
||||||
|
return _ResourcesData.Find<ResourceData>(r => r.Id == id).FirstOrDefault() != null ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsExistResourceId(string id)
|
||||||
|
{
|
||||||
|
return _ResourcesData.Find<ResourceData>(r => r.ResourceId == id).FirstOrDefault() != null ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceData Create(ResourceData resource)
|
||||||
|
{
|
||||||
|
_ResourcesData.InsertOne(resource);
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceData Update(string id, ResourceData resourceIn)
|
||||||
|
{
|
||||||
|
_ResourcesData.ReplaceOne(r => r.Id == id, resourceIn);
|
||||||
|
return resourceIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Remove(string id)
|
||||||
|
{
|
||||||
|
_ResourcesData.DeleteOne(r => r.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -18,14 +18,14 @@ namespace Manager.Services
|
|||||||
var database = client.GetDatabase("TabletDb");
|
var database = client.GetDatabase("TabletDb");
|
||||||
_Resources = database.GetCollection<Resource>("Resources");
|
_Resources = database.GetCollection<Resource>("Resources");
|
||||||
}
|
}
|
||||||
public List<Resource> GetAll()
|
public List<Resource> GetAll(string instanceId)
|
||||||
{
|
{
|
||||||
return _Resources.Find(r => true).ToList();
|
return _Resources.Find(r => r.InstanceId == instanceId).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Resource GetByType(ResourceType type)
|
public List<Resource> GetAllByType(string instanceId, List<ResourceType> types)
|
||||||
{
|
{
|
||||||
return _Resources.Find<Resource>(r => r.Type == type).FirstOrDefault();
|
return _Resources.Find<Resource>(r => r.InstanceId == instanceId && types.Contains(r.Type)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Resource GetById(string id)
|
public Resource GetById(string id)
|
||||||
|
|||||||
@ -19,9 +19,9 @@ namespace Manager.Services
|
|||||||
_Sections = database.GetCollection<Section>("Sections");
|
_Sections = database.GetCollection<Section>("Sections");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Section> GetAll()
|
public List<Section> GetAll(string instanceId)
|
||||||
{
|
{
|
||||||
return _Sections.Find(s => !s.IsSubSection).ToList();
|
return _Sections.Find(s => !s.IsSubSection && s.InstanceId == instanceId).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Section> GetAllFromConfiguration(string configurationId)
|
public List<Section> GetAllFromConfiguration(string configurationId)
|
||||||
@ -29,6 +29,11 @@ namespace Manager.Services
|
|||||||
return _Sections.Find(s => !s.IsSubSection && s.ConfigurationId == configurationId).ToList();
|
return _Sections.Find(s => !s.IsSubSection && s.ConfigurationId == configurationId).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<string> GetAllIdsFromConfiguration(string configurationId)
|
||||||
|
{
|
||||||
|
return _Sections.Find(s => !s.IsSubSection && s.ConfigurationId == configurationId).ToList().Select(s => s.Id).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
public List<Section> GetAllSubSection(string parentId)
|
public List<Section> GetAllSubSection(string parentId)
|
||||||
{
|
{
|
||||||
return _Sections.Find(s => s.IsSubSection && s.ParentId == parentId).ToList();
|
return _Sections.Find(s => s.IsSubSection && s.ParentId == parentId).ToList();
|
||||||
|
|||||||
@ -51,17 +51,16 @@ namespace ManagerService.Service.Services
|
|||||||
/// <param name="email">Email</param>
|
/// <param name="email">Email</param>
|
||||||
/// <param name="password">Password</param>
|
/// <param name="password">Password</param>
|
||||||
/// <returns>Token DTO in case of success</returns>
|
/// <returns>Token DTO in case of success</returns>
|
||||||
public TokenDTO Authenticate(string email, string password)
|
public TokenDTO Authenticate(User user, string password)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var claims = new List<System.Security.Claims.Claim>();
|
var claims = new List<System.Security.Claims.Claim>();
|
||||||
var expiration = DateTime.UtcNow.AddMinutes(_tokenSettings.AccessTokenExpiration);
|
var expiration = DateTime.UtcNow.AddMinutes(_tokenSettings.AccessTokenExpiration);
|
||||||
|
|
||||||
// Todo nothing good here..
|
_profileLogic.TestPassword(user.Email, user.Password, password);
|
||||||
var profile = _profileLogic.Authenticate(email, password);
|
|
||||||
|
|
||||||
claims.Add(new Claim(ClaimTypes.Email, email));
|
claims.Add(new Claim(ClaimTypes.Email, user.Email));
|
||||||
|
|
||||||
// TODO: add refresh token support
|
// TODO: add refresh token support
|
||||||
|
|
||||||
@ -80,17 +79,18 @@ namespace ManagerService.Service.Services
|
|||||||
expires_in = _tokenSettings.AccessTokenExpiration * 60,
|
expires_in = _tokenSettings.AccessTokenExpiration * 60,
|
||||||
expiration = new DateTimeOffset(token.ValidTo),
|
expiration = new DateTimeOffset(token.ValidTo),
|
||||||
token_type = "Bearer",
|
token_type = "Bearer",
|
||||||
scope = Security.Scope
|
scope = Security.Scope,
|
||||||
|
instanceId = user.InstanceId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch (UnauthorizedAccessException ex)
|
catch (UnauthorizedAccessException ex)
|
||||||
{
|
{
|
||||||
_logger?.LogError(ex, $"Authenticate error for user '{email}': unauthorized access");
|
_logger?.LogError(ex, $"Authenticate error for user '{user.Email}': unauthorized access");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger?.LogError(ex, $"Authenticate error for user '{email}': {ex.Message}");
|
_logger?.LogError(ex, $"Authenticate error for user '{user.Email}': {ex.Message}");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,22 +20,27 @@ namespace Manager.Services
|
|||||||
}
|
}
|
||||||
public List<User> GetAll()
|
public List<User> GetAll()
|
||||||
{
|
{
|
||||||
return _Users.Find(m => true).ToList();
|
return _Users.Find(u => true).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public User GetByEmail(string email)
|
public User GetByEmail(string email)
|
||||||
{
|
{
|
||||||
return _Users.Find<User>(m => m.Email == email).FirstOrDefault();
|
return _Users.Find<User>(u => u.Email == email).FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public User GetById(string id)
|
public User GetById(string id)
|
||||||
{
|
{
|
||||||
return _Users.Find<User>(m => m.Id == id).FirstOrDefault();
|
return _Users.Find<User>(u => u.Id == id).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<User> GetByInstanceId(string id)
|
||||||
|
{
|
||||||
|
return _Users.Find<User>(u => u.InstanceId == id).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsExist(string id)
|
public bool IsExist(string id)
|
||||||
{
|
{
|
||||||
return _Users.Find<User>(d => d.Id == id).FirstOrDefault() != null ? true : false;
|
return _Users.Find<User>(u => u.Id == id).FirstOrDefault() != null ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User Create(User user)
|
public User Create(User user)
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using Manager.Framework.Business;
|
using Manager.Framework.Business;
|
||||||
using Manager.Framework.Models;
|
using Manager.Framework.Models;
|
||||||
|
using Manager.Helpers;
|
||||||
using Manager.Interfaces.Models;
|
using Manager.Interfaces.Models;
|
||||||
using Manager.Services;
|
using Manager.Services;
|
||||||
using ManagerService.Extensions;
|
using ManagerService.Extensions;
|
||||||
@ -40,7 +41,7 @@ namespace ManagerService
|
|||||||
{
|
{
|
||||||
Configuration = configuration;
|
Configuration = configuration;
|
||||||
|
|
||||||
MapConfiguration();
|
//MapConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IConfiguration Configuration { get; }
|
public IConfiguration Configuration { get; }
|
||||||
@ -132,14 +133,17 @@ namespace ManagerService
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddMqttClientHostedService();
|
//services.AddMqttClientHostedService();
|
||||||
services.AddScoped(typeof(ProfileLogic));
|
services.AddScoped(typeof(ProfileLogic));
|
||||||
services.AddScoped<TokensService>();
|
services.AddScoped<TokensService>();
|
||||||
services.AddScoped<UserDatabaseService>();
|
services.AddScoped<UserDatabaseService>();
|
||||||
services.AddScoped<SectionDatabaseService>();
|
services.AddScoped<SectionDatabaseService>();
|
||||||
services.AddScoped<ConfigurationDatabaseService>();
|
services.AddScoped<ConfigurationDatabaseService>();
|
||||||
services.AddScoped<ResourceDatabaseService>();
|
services.AddScoped<ResourceDatabaseService>();
|
||||||
|
services.AddScoped<ResourceDataDatabaseService>();
|
||||||
|
services.AddScoped<LanguageInit>();
|
||||||
services.AddScoped<DeviceDatabaseService>();
|
services.AddScoped<DeviceDatabaseService>();
|
||||||
|
services.AddScoped<InstanceDatabaseService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
@ -151,11 +155,12 @@ namespace ManagerService
|
|||||||
|
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
{
|
{
|
||||||
//app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
app.UseExceptionHandler(HandleError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseExceptionHandler(HandleError);
|
||||||
|
|
||||||
|
//app.UseHttpsRedirection();
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
{
|
{
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
//"TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017" //DEV
|
//"TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017" //DEV
|
||||||
//"TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017" //PROD - Thomas
|
//"TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017", //PROD - Thomas
|
||||||
"TabletDb": "mongodb://admin:mdlf2021!@localhost:27017" //PROD
|
//"TabletDb": "mongodb://admin:MioTech4ever!@192.168.31.140:27017" //PROD - Thomas
|
||||||
|
//"TabletDb": "mongodb://admin:mdlf2021!@localhost:27017" //PROD MDLF
|
||||||
|
"TabletDb": "mongodb://admin:MyMuseum2022!@51.77.222.154:27017" //PROD MyMuseum
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
@ -33,5 +35,6 @@
|
|||||||
"UserName": "admin",
|
"UserName": "admin",
|
||||||
"Password": "mdlf2021!"
|
"Password": "mdlf2021!"
|
||||||
},
|
},
|
||||||
"Urls": "http://localhost:5002"
|
"SupportedLanguages": [ "FR", "NL", "EN", "DE", "IT", "ES", "PL", "CN", "AR", "UK" ]
|
||||||
|
//"Urls": "http://[::]:80"
|
||||||
}
|
}
|
||||||
|
|||||||
1
RELEASE/Version 1.4/changelog.txt
Normal file
1
RELEASE/Version 1.4/changelog.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Ajout du quizz
|
||||||
BIN
RELEASE/Version 1.4/netcoreapp3.1/DevExpress.Data.v20.1.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/DevExpress.Data.v20.1.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/DevExpress.Xpo.v20.1.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/DevExpress.Xpo.v20.1.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/DnsClient.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/DnsClient.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/MQTTnet.AspNetCore.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/MQTTnet.AspNetCore.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/MQTTnet.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/MQTTnet.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/Manager.Framework.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/Manager.Framework.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/Manager.Framework.pdb
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/Manager.Framework.pdb
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/Manager.Interfaces.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/Manager.Interfaces.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/Manager.Interfaces.pdb
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/Manager.Interfaces.pdb
Normal file
Binary file not shown.
6684
RELEASE/Version 1.4/netcoreapp3.1/ManagerService.deps.json
Normal file
6684
RELEASE/Version 1.4/netcoreapp3.1/ManagerService.deps.json
Normal file
File diff suppressed because it is too large
Load Diff
BIN
RELEASE/Version 1.4/netcoreapp3.1/ManagerService.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/ManagerService.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/ManagerService.pdb
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/ManagerService.pdb
Normal file
Binary file not shown.
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"runtimeOptions": {
|
||||||
|
"additionalProbingPaths": [
|
||||||
|
"C:\\Users\\thoma\\.dotnet\\store\\|arch|\\|tfm|",
|
||||||
|
"C:\\Users\\thoma\\.nuget\\packages"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"runtimeOptions": {
|
||||||
|
"tfm": "netcoreapp3.1",
|
||||||
|
"framework": {
|
||||||
|
"name": "Microsoft.AspNetCore.App",
|
||||||
|
"version": "3.1.0"
|
||||||
|
},
|
||||||
|
"configProperties": {
|
||||||
|
"System.GC.Server": true,
|
||||||
|
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
|
||||||
|
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/MongoDB.Bson.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/MongoDB.Bson.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/MongoDB.Driver.Core.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/MongoDB.Driver.Core.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/MongoDB.Driver.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/MongoDB.Driver.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/MongoDB.Libmongocrypt.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/MongoDB.Libmongocrypt.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/NJsonSchema.Yaml.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/NJsonSchema.Yaml.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/NJsonSchema.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/NJsonSchema.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/NSwag.Annotations.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/NSwag.Annotations.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/NSwag.AspNetCore.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/NSwag.AspNetCore.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/NSwag.Core.Yaml.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/NSwag.Core.Yaml.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/NSwag.Core.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/NSwag.Core.dll
Normal file
Binary file not shown.
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/NSwag.Generation.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/NSwag.Generation.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/Namotion.Reflection.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/Namotion.Reflection.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/Newtonsoft.Json.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/Newtonsoft.Json.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/Scrypt.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/Scrypt.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/SharpCompress.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/SharpCompress.dll
Normal file
Binary file not shown.
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/System.Data.SqlClient.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/System.Data.SqlClient.dll
Normal file
Binary file not shown.
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/System.Drawing.Common.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/System.Drawing.Common.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/System.ServiceModel.Http.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/System.ServiceModel.Http.dll
Normal file
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/System.ServiceModel.NetTcp.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/System.ServiceModel.NetTcp.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
RELEASE/Version 1.4/netcoreapp3.1/System.ServiceModel.dll
Normal file
BIN
RELEASE/Version 1.4/netcoreapp3.1/System.ServiceModel.dll
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user