aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2019-12-20 21:34:50 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2019-12-20 21:34:50 +0200
commit76cdf188e28544cd5056c30f35d77590d9a79cae (patch)
treee83b12220517378e4499dc47c6261f8862f37f46 /Software/Visual_Studio
parent5cb75f4b026a7842171369f58f5aba1c9678f60f (diff)
downloadTango-76cdf188e28544cd5056c30f35d77590d9a79cae.tar.gz
Tango-76cdf188e28544cd5056c30f35d77590d9a79cae.zip
Improvements to ActionLogs.
Implemented ActionLogs for hw comparison.
Diffstat (limited to 'Software/Visual_Studio')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs26
-rw-r--r--Software/Visual_Studio/Tango.BL/ActionLogs/DefaultActionLogComparer.cs21
-rw-r--r--Software/Visual_Studio/Tango.BL/ActionLogs/DefaultActionLogManager.cs5
-rw-r--r--Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsItemsRecipeDTO.cs6
-rw-r--r--Software/Visual_Studio/Tango.BL/DTO/HardwareBlowerDTO.cs7
-rw-r--r--Software/Visual_Studio/Tango.BL/DTO/HardwareBreakSensorDTO.cs7
-rw-r--r--Software/Visual_Studio/Tango.BL/DTO/HardwareDancerDTO.cs7
-rw-r--r--Software/Visual_Studio/Tango.BL/DTO/HardwareMotorDTO.cs7
-rw-r--r--Software/Visual_Studio/Tango.BL/DTO/HardwarePidControlDTO.cs7
-rw-r--r--Software/Visual_Studio/Tango.BL/DTO/HardwareSpeedSensorDTO.cs7
-rw-r--r--Software/Visual_Studio/Tango.BL/DTO/HardwareVersionDTO.cs22
-rw-r--r--Software/Visual_Studio/Tango.BL/DTO/HardwareWinderDTO.cs7
-rw-r--r--Software/Visual_Studio/Tango.BL/DTO/LiquidTypesRmlDTO.cs6
-rw-r--r--Software/Visual_Studio/Tango.BL/ObservableDTOPropertyAttribute.cs14
-rw-r--r--Software/Visual_Studio/Tango.BL/ObservableEntityDTO.cs15
-rw-r--r--Software/Visual_Studio/Tango.BL/Tango.BL.csproj3
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/BL/DTO_TST.cs12
17 files changed, 170 insertions, 9 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
index 9a80eb9d9..7c95ce270 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
@@ -16,6 +16,9 @@ using Tango.Core.ExtensionMethods;
using Tango.MachineStudio.HardwareDesigner.Views;
using Microsoft.Win32;
using System.IO;
+using Tango.BL.ActionLogs;
+using Tango.MachineStudio.Common.Authentication;
+using Tango.BL.DTO;
namespace Tango.MachineStudio.HardwareDesigner.ViewModels
{
@@ -24,6 +27,9 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
private INotificationProvider _notification;
private bool _isNew;
private ObservablesContext _db;
+ private IActionLogManager _actionLogManager;
+ private IAuthenticationProvider _authentication;
+ private HardwareVersionDTO _hwBeforeSave;
private HardwareVersion _selectedVersion;
public HardwareVersion SelectedVersion
@@ -45,6 +51,8 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
get { return _selectedHardwareObject; }
set
{
+ _selectedHardwareObject = null;
+ RaisePropertyChangedAuto();
_selectedHardwareObject = value;
RaisePropertyChangedAuto();
RaisePropertyChanged(nameof(SelectedHardwareObjectTypeName));
@@ -113,9 +121,11 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
public RelayCommand ImportHardwareVersionCommand { get; set; }
- public MainViewVM(INotificationProvider notification)
+ public MainViewVM(INotificationProvider notification, IActionLogManager actionLogManager, IAuthenticationProvider authentication)
{
_notification = notification;
+ _actionLogManager = actionLogManager;
+ _authentication = authentication;
CurrentVersion = new HardwareVersion();
@@ -337,6 +347,8 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
});
CurrentVersion.HardwareBreakSensors = CurrentVersion.HardwareBreakSensors.OrderBy(x => x.HardwareBreakSensorType.Code).ToSynchronizedObservableCollection();
+
+ _hwBeforeSave = HardwareVersionDTO.FromObservable(CurrentVersion);
});
}
@@ -391,6 +403,8 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
_db.HardwareVersions.Add(CurrentVersion);
_db.SaveChanges();
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.HardwareVersionCreated, _authentication.CurrentUser, CurrentVersion.Name, CurrentVersion, "New hardware version created using Machine Studio.");
+
RefreshVersions();
InvokeUI(() =>
@@ -420,6 +434,11 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
{
CurrentVersion.LastUpdated = DateTime.UtcNow;
_db.SaveChanges();
+
+ var dtoAfter = HardwareVersionDTO.FromObservable(CurrentVersion);
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.HardwareVersionSaved, _authentication.CurrentUser, CurrentVersion.Name, _hwBeforeSave, dtoAfter, "Hardware Version saved using Machine Studio.");
+ _hwBeforeSave = dtoAfter;
+
RefreshVersions();
InvokeUI(() =>
@@ -461,6 +480,9 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
cloned.Version = HardwareVersions.Max(x => x.Version) + 1;
_db.HardwareVersions.Add(cloned);
_db.SaveChanges();
+
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.HardwareVersionCreated, _authentication.CurrentUser, cloned.Name, cloned, "New hardware version created (cloned) using Machine Studio.");
+
RefreshVersions();
InvokeUI(() =>
@@ -496,6 +518,8 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
await CurrentVersion.DeleteCascadeAsync(_db);
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.HardwareVersionDeleted, _authentication.CurrentUser, CurrentVersion.Name, _hwBeforeSave, "Hardware version deleted using Machine Studio.", true);
+
await Task.Factory.StartNew(() =>
{
SelectedVersion = null;
diff --git a/Software/Visual_Studio/Tango.BL/ActionLogs/DefaultActionLogComparer.cs b/Software/Visual_Studio/Tango.BL/ActionLogs/DefaultActionLogComparer.cs
index b6c028137..0b29dcc8c 100644
--- a/Software/Visual_Studio/Tango.BL/ActionLogs/DefaultActionLogComparer.cs
+++ b/Software/Visual_Studio/Tango.BL/ActionLogs/DefaultActionLogComparer.cs
@@ -108,6 +108,10 @@ namespace Tango.BL.ActionLogs
{
IList beforeCollection = null;
IList afterCollection = null;
+ ActionLogDifference listDiff = new ActionLogDifference()
+ {
+ Name = prop.Name
+ };
if (before != null)
{
@@ -119,18 +123,22 @@ namespace Tango.BL.ActionLogs
afterCollection = prop.GetValue(after) as IList;
}
+ int listCount = 0;
+
if (beforeCollection != null && afterCollection == null)
{
for (int i = 0; i < beforeCollection.Count; i++)
{
- Compare(AddChildDiff(diff, GetActionLogName(beforeCollection[i], prop.Name)), beforeCollection[i], null, scannedObjects);
+ listCount++;
+ Compare(AddChildDiff(listDiff, GetActionLogName(beforeCollection[i], prop.Name)), beforeCollection[i], null, scannedObjects);
}
}
else if (beforeCollection == null && afterCollection != null)
{
for (int i = 0; i < afterCollection.Count; i++)
{
- Compare(AddChildDiff(diff, GetActionLogName(afterCollection[i], prop.Name)), null, afterCollection[i], scannedObjects);
+ listCount++;
+ Compare(AddChildDiff(listDiff, GetActionLogName(afterCollection[i], prop.Name)), null, afterCollection[i], scannedObjects);
}
}
@@ -140,9 +148,16 @@ namespace Tango.BL.ActionLogs
{
var beforeItem = i < beforeCollection.Count ? beforeCollection[i] : null;
var afterItem = i < afterCollection.Count ? afterCollection[i] : null;
- Compare(AddChildDiff(diff, GetActionLogName(beforeItem, prop.Name)), beforeItem, afterItem, scannedObjects);
+
+ listCount++;
+ Compare(AddChildDiff(listDiff, GetActionLogName(beforeItem, prop.Name)), beforeItem, afterItem, scannedObjects);
}
}
+
+ if (listCount > 0)
+ {
+ diff.Children.Add(listDiff);
+ }
}
}
}
diff --git a/Software/Visual_Studio/Tango.BL/ActionLogs/DefaultActionLogManager.cs b/Software/Visual_Studio/Tango.BL/ActionLogs/DefaultActionLogManager.cs
index b8f427e3a..0f5d6bd51 100644
--- a/Software/Visual_Studio/Tango.BL/ActionLogs/DefaultActionLogManager.cs
+++ b/Software/Visual_Studio/Tango.BL/ActionLogs/DefaultActionLogManager.cs
@@ -108,6 +108,8 @@ namespace Tango.BL.ActionLogs
{
ActionLogDifference diff = new ActionLogDifference();
+ bool insertWhenNoDifference = false;
+
if (ActionLogComparer != null)
{
try
@@ -116,10 +118,11 @@ namespace Tango.BL.ActionLogs
}
catch (Exception ex)
{
+ insertWhenNoDifference = true;
LogManager.Log(ex, $"Error while comparing for action log '{type}'.");
}
- if (diff.Children.Count > 0)
+ if (diff.Children.Count > 0 || insertWhenNoDifference)
{
InsertLog(type, userGuid, relatedObjectName, GetRelatedObjectGuid(relatedObjectBefore, relatedObjectAfter), diff, message);
}
diff --git a/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsItemsRecipeDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsItemsRecipeDTO.cs
index 34b061df8..06979a3bb 100644
--- a/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsItemsRecipeDTO.cs
+++ b/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsItemsRecipeDTO.cs
@@ -4,14 +4,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.BL.Entities;
namespace Tango.BL.DTO
{
public class ColorCatalogsItemsRecipeDTO : ColorCatalogsItemsRecipeDTOBase
{
+ [ObservableDTOProperty(MapsTo = nameof(ColorCatalogsItemsRecipe.Rml) + "." + nameof(ColorCatalogsItemsRecipe.Rml.Name))]
+ public String RmlName { get; set; }
+
protected override string OnGetActionLogName()
{
- return $"Color Recipe for RML '{RmlGuid}'";
+ return $"Color Recipe for RML '{(RmlName != null ? RmlName : RmlGuid)}'";
}
}
}
diff --git a/Software/Visual_Studio/Tango.BL/DTO/HardwareBlowerDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/HardwareBlowerDTO.cs
index be8a50ca1..85d5ef9f7 100644
--- a/Software/Visual_Studio/Tango.BL/DTO/HardwareBlowerDTO.cs
+++ b/Software/Visual_Studio/Tango.BL/DTO/HardwareBlowerDTO.cs
@@ -4,11 +4,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.BL.Entities;
namespace Tango.BL.DTO
{
public class HardwareBlowerDTO : HardwareBlowerDTOBase
{
+ [ObservableDTOProperty(MapsTo = nameof(HardwareBlower.HardwareBlowerType) + "." + nameof(HardwareBlower.HardwareBlowerType.Description))]
+ public String HardwareBlowerTypeDescription { get; set; }
+ protected override string OnGetActionLogName()
+ {
+ return $"Blower '{HardwareBlowerTypeDescription}'";
+ }
}
}
diff --git a/Software/Visual_Studio/Tango.BL/DTO/HardwareBreakSensorDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/HardwareBreakSensorDTO.cs
index 968070be0..1b1790a4d 100644
--- a/Software/Visual_Studio/Tango.BL/DTO/HardwareBreakSensorDTO.cs
+++ b/Software/Visual_Studio/Tango.BL/DTO/HardwareBreakSensorDTO.cs
@@ -4,11 +4,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.BL.Entities;
namespace Tango.BL.DTO
{
public class HardwareBreakSensorDTO : HardwareBreakSensorDTOBase
{
+ [ObservableDTOProperty(MapsTo = nameof(HardwareBreakSensor.HardwareBreakSensorType) + "." + nameof(HardwareBreakSensor.HardwareBreakSensorType.Description))]
+ public String HardwareBreakSensorTypeDescription { get; set; }
+ protected override string OnGetActionLogName()
+ {
+ return $"Break Sensor '{HardwareBreakSensorTypeDescription}'";
+ }
}
}
diff --git a/Software/Visual_Studio/Tango.BL/DTO/HardwareDancerDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/HardwareDancerDTO.cs
index 1963ae9d7..2527a3e45 100644
--- a/Software/Visual_Studio/Tango.BL/DTO/HardwareDancerDTO.cs
+++ b/Software/Visual_Studio/Tango.BL/DTO/HardwareDancerDTO.cs
@@ -4,11 +4,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.BL.Entities;
namespace Tango.BL.DTO
{
public class HardwareDancerDTO : HardwareDancerDTOBase
{
+ [ObservableDTOProperty(MapsTo = nameof(HardwareDancer.HardwareDancerType) + "." + nameof(HardwareDancer.HardwareDancerType.Description))]
+ public String HardwareDancerTypeDescription { get; set; }
+ protected override string OnGetActionLogName()
+ {
+ return $"Dancer '{HardwareDancerTypeDescription}'";
+ }
}
}
diff --git a/Software/Visual_Studio/Tango.BL/DTO/HardwareMotorDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/HardwareMotorDTO.cs
index 41d53bf2a..cc1147f4c 100644
--- a/Software/Visual_Studio/Tango.BL/DTO/HardwareMotorDTO.cs
+++ b/Software/Visual_Studio/Tango.BL/DTO/HardwareMotorDTO.cs
@@ -4,11 +4,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.BL.Entities;
namespace Tango.BL.DTO
{
public class HardwareMotorDTO : HardwareMotorDTOBase
{
+ [ObservableDTOProperty(MapsTo = nameof(HardwareMotor.HardwareMotorType) + "." + nameof(HardwareMotor.HardwareMotorType.Description))]
+ public String HardwareMotorTypeDescription { get; set; }
+ protected override string OnGetActionLogName()
+ {
+ return $"Motor '{HardwareMotorTypeDescription}'";
+ }
}
}
diff --git a/Software/Visual_Studio/Tango.BL/DTO/HardwarePidControlDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/HardwarePidControlDTO.cs
index bd6e344a7..d65b5d68f 100644
--- a/Software/Visual_Studio/Tango.BL/DTO/HardwarePidControlDTO.cs
+++ b/Software/Visual_Studio/Tango.BL/DTO/HardwarePidControlDTO.cs
@@ -4,11 +4,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.BL.Entities;
namespace Tango.BL.DTO
{
public class HardwarePidControlDTO : HardwarePidControlDTOBase
{
+ [ObservableDTOProperty(MapsTo = nameof(HardwarePidControl.HardwarePidControlType) + "." + nameof(HardwarePidControl.HardwarePidControlType.Description))]
+ public String HardwarePidControlTypeDescription { get; set; }
+ protected override string OnGetActionLogName()
+ {
+ return $"PID Control '{HardwarePidControlTypeDescription}'";
+ }
}
}
diff --git a/Software/Visual_Studio/Tango.BL/DTO/HardwareSpeedSensorDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/HardwareSpeedSensorDTO.cs
index 14eae14ae..88145cce4 100644
--- a/Software/Visual_Studio/Tango.BL/DTO/HardwareSpeedSensorDTO.cs
+++ b/Software/Visual_Studio/Tango.BL/DTO/HardwareSpeedSensorDTO.cs
@@ -4,11 +4,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.BL.Entities;
namespace Tango.BL.DTO
{
public class HardwareSpeedSensorDTO : HardwareSpeedSensorDTOBase
{
+ [ObservableDTOProperty(MapsTo = nameof(HardwareSpeedSensor.HardwareSpeedSensorType) + "." + nameof(HardwareSpeedSensor.HardwareSpeedSensorType.Description))]
+ public String HardwareSpeedSensorTypeDescription { get; set; }
+ protected override string OnGetActionLogName()
+ {
+ return $"Speed Sensor '{HardwareSpeedSensorTypeDescription}'";
+ }
}
}
diff --git a/Software/Visual_Studio/Tango.BL/DTO/HardwareVersionDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/HardwareVersionDTO.cs
index 55065b301..36681162b 100644
--- a/Software/Visual_Studio/Tango.BL/DTO/HardwareVersionDTO.cs
+++ b/Software/Visual_Studio/Tango.BL/DTO/HardwareVersionDTO.cs
@@ -9,6 +9,28 @@ namespace Tango.BL.DTO
{
public class HardwareVersionDTO : HardwareVersionDTOBase
{
+ public List<HardwareBlowerDTO> HardwareBlowers { get; set; }
+ public List<HardwareBreakSensorDTO> HardwareBreakSensors { get; set; }
+ public List<HardwareDancerDTO> HardwareDancers { get; set; }
+ public List<HardwareMotorDTO> HardwareMotors { get; set; }
+ public List<HardwarePidControlDTO> HardwarePidControls { get; set; }
+ public List<HardwareSpeedSensorDTO> HardwareSpeedSensors { get; set; }
+ public List<HardwareWinderDTO> HardwareWinders { get; set; }
+ public HardwareVersionDTO()
+ {
+ HardwareBlowers = new List<HardwareBlowerDTO>();
+ HardwareBreakSensors = new List<HardwareBreakSensorDTO>();
+ HardwareDancers = new List<HardwareDancerDTO>();
+ HardwareMotors = new List<HardwareMotorDTO>();
+ HardwarePidControls = new List<HardwarePidControlDTO>();
+ HardwareSpeedSensors = new List<HardwareSpeedSensorDTO>();
+ HardwareWinders = new List<HardwareWinderDTO>();
+ }
+
+ protected override string OnGetActionLogName()
+ {
+ return $"Hardware Version '{Name} v{Version}'";
+ }
}
}
diff --git a/Software/Visual_Studio/Tango.BL/DTO/HardwareWinderDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/HardwareWinderDTO.cs
index a65d81791..c84c4eeaf 100644
--- a/Software/Visual_Studio/Tango.BL/DTO/HardwareWinderDTO.cs
+++ b/Software/Visual_Studio/Tango.BL/DTO/HardwareWinderDTO.cs
@@ -4,11 +4,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.BL.Entities;
namespace Tango.BL.DTO
{
public class HardwareWinderDTO : HardwareWinderDTOBase
{
+ [ObservableDTOProperty(MapsTo = nameof(HardwareWinder.HardwareWinderType) + "." + nameof(HardwareWinder.HardwareWinderType.Description))]
+ public String HardwareWinderTypeDescription { get; set; }
+ protected override string OnGetActionLogName()
+ {
+ return $"Winder '{HardwareWinderTypeDescription}'";
+ }
}
}
diff --git a/Software/Visual_Studio/Tango.BL/DTO/LiquidTypesRmlDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/LiquidTypesRmlDTO.cs
index 2366b9727..e7d940ca4 100644
--- a/Software/Visual_Studio/Tango.BL/DTO/LiquidTypesRmlDTO.cs
+++ b/Software/Visual_Studio/Tango.BL/DTO/LiquidTypesRmlDTO.cs
@@ -4,16 +4,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.BL.Entities;
namespace Tango.BL.DTO
{
public class LiquidTypesRmlDTO : LiquidTypesRmlDTOBase
{
- public LiquidTypeDTO LiquidType { get; set; }
+ [ObservableDTOProperty(MapsTo = nameof(LiquidTypesRml.LiquidType) + "." + nameof(LiquidTypesRml.LiquidType.Name))]
+ public String LiquidTypeName { get; set; }
protected override string OnGetActionLogName()
{
- return this.LiquidType != null ? $"Liquid Factor '{LiquidType.Name}'" : $"Liquid Factor '{Guid}'";
+ return LiquidTypeName != null ? $"Liquid Factor '{LiquidTypeName}'" : $"Liquid Factor '{Guid}'";
}
}
}
diff --git a/Software/Visual_Studio/Tango.BL/ObservableDTOPropertyAttribute.cs b/Software/Visual_Studio/Tango.BL/ObservableDTOPropertyAttribute.cs
new file mode 100644
index 000000000..48e07c271
--- /dev/null
+++ b/Software/Visual_Studio/Tango.BL/ObservableDTOPropertyAttribute.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.BL
+{
+ [AttributeUsage(AttributeTargets.Property)]
+ public class ObservableDTOPropertyAttribute : Attribute
+ {
+ public String MapsTo { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.BL/ObservableEntityDTO.cs b/Software/Visual_Studio/Tango.BL/ObservableEntityDTO.cs
index ee8d2f40f..4c5ca6ae4 100644
--- a/Software/Visual_Studio/Tango.BL/ObservableEntityDTO.cs
+++ b/Software/Visual_Studio/Tango.BL/ObservableEntityDTO.cs
@@ -1,12 +1,14 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.ActionLogs;
using Tango.BL.ValueObjects;
+using Tango.Core.ExtensionMethods;
namespace Tango.BL
{
@@ -72,6 +74,19 @@ namespace Tango.BL
prop.SetValue(dto, collection);
}
}
+ else if (prop.GetCustomAttribute<ObservableDTOPropertyAttribute>() != null)
+ {
+ var att = prop.GetCustomAttribute<ObservableDTOPropertyAttribute>();
+
+ try
+ {
+ prop.SetValue(dto, observable.GetPropertyValueByPath(att.MapsTo));
+ }
+ catch
+ {
+ Debug.WriteLine($"Error mapping '{typeof(DTO).Name}.{prop.PropertyType}' to '{typeof(T)}.{att.MapsTo}'.");
+ }
+ }
}
return dto;
diff --git a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj
index fb8ec84a3..5c599bb5e 100644
--- a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj
+++ b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj
@@ -384,6 +384,7 @@
<Compile Include="Enumerations\JobSource.cs" />
<Compile Include="Enumerations\TangoUpdateStatuses.cs" />
<Compile Include="IObservableEntityDTO.cs" />
+ <Compile Include="ObservableDTOPropertyAttribute.cs" />
<Compile Include="ObservableEntityDTO.cs" />
<Compile Include="Enumerations\DancerTypes.cs" />
<Compile Include="Enumerations\EditingStates.cs" />
@@ -591,7 +592,7 @@
</Target>
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" />
+ <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
</VisualStudio>
</ProjectExtensions>
</Project> \ No newline at end of file
diff --git a/Software/Visual_Studio/Tango.UnitTesting/BL/DTO_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/BL/DTO_TST.cs
index 58a05ee83..a574f7ea0 100644
--- a/Software/Visual_Studio/Tango.UnitTesting/BL/DTO_TST.cs
+++ b/Software/Visual_Studio/Tango.UnitTesting/BL/DTO_TST.cs
@@ -38,5 +38,17 @@ namespace Tango.UnitTesting.BL
Assert.IsTrue(configDTO.Equals(config));
}
}
+
+ [TestMethod]
+ public void DTOPropertyAttribute_Is_Working()
+ {
+ using (ObservablesContext db = ObservablesContext.CreateDefault())
+ {
+ var hwBlower = db.HardwareBlowers.Include(x => x.HardwareBlowerType).First();
+ var dto = HardwareBlowerDTO.FromObservable(hwBlower);
+
+ Assert.AreEqual(dto.HardwareBlowerTypeDescription, hwBlower.HardwareBlowerType.Description);
+ }
+ }
}
}