Skip to content

Commit 9bdecb9

Browse files
authored
gui2: object dictionary rewrite (#182)
* gui2 object dictionary rewrite
1 parent 4c80424 commit 9bdecb9

File tree

12 files changed

+398
-119
lines changed

12 files changed

+398
-119
lines changed

EDSEditorGUI2/Mapper/ProtobufferViewModelMapper.cs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,58 @@ public static ViewModels.Device MapFromProtobuffer(CanOpenDevice source)
1919
.ForMember(dest => dest.CreatedBy, opt => opt.MapFrom(src => src.CreatedBy))
2020
.ForMember(dest => dest.ModificationTime, opt => opt.MapFrom(src => src.ModificationTime))
2121
.ForMember(dest => dest.ModifiedBy, opt => opt.MapFrom(src => src.ModifiedBy));
22+
cfg.CreateMap<Google.Protobuf.Collections.MapField<string, OdObject>, ViewModels.ObjectDictionary>().ConvertUsing<ODConverter>();
2223
cfg.CreateMap<CanOpenDevice, ViewModels.Device>()
2324
.ForMember(dest => dest.FileInfo, opt => opt.MapFrom(src => src.FileInfo))
2425
.ForMember(dest => dest.DeviceInfo, opt => opt.MapFrom(src => src.DeviceInfo))
2526
.ForMember(dest => dest.DeviceCommissioning, opt => opt.MapFrom(src => src.DeviceCommissioning))
26-
.ForPath(dest => dest.Objects.Data, opt => opt.MapFrom(src => src.Objects));
27-
27+
.ForMember(dest => dest.Objects, opt => opt.MapFrom(src => src.Objects));
2828
cfg.CreateMap<CanOpen_DeviceInfo, ViewModels.DeviceInfo>();
2929
cfg.CreateMap<CanOpen_DeviceCommissioning, ViewModels.DeviceCommissioning>();
30-
cfg.CreateMap<OdObject, ViewModels.OdObject>();
31-
3230
});
3331
config.AssertConfigurationIsValid();
3432
var mapper = config.CreateMapper();
3533
var result = mapper.Map<ViewModels.Device>(source);
3634
return result;
3735
}
36+
public class ODConverter : ITypeConverter<Google.Protobuf.Collections.MapField<string, OdObject>, ViewModels.ObjectDictionary>,
37+
ITypeConverter< ViewModels.ObjectDictionary, Google.Protobuf.Collections.MapField<string, OdObject>>
38+
{
39+
public ViewModels.ObjectDictionary Convert(Google.Protobuf.Collections.MapField<string, OdObject> source, ViewModels.ObjectDictionary destination, ResolutionContext context)
40+
{
41+
var config = new MapperConfiguration(cfg =>
42+
{
43+
cfg.CreateMap<OdObject, ViewModels.OdObject>();
44+
cfg.CreateMap<OdSubObject, ViewModels.OdSubObject>();
45+
});
46+
config.AssertConfigurationIsValid();
47+
var mapper = config.CreateMapper();
48+
49+
destination = [];
50+
foreach (var item in source)
51+
{
52+
destination.Add(item.Key, mapper.Map<ViewModels.OdObject>(item.Value));
53+
}
54+
return destination;
55+
}
56+
public Google.Protobuf.Collections.MapField<string, OdObject> Convert(ViewModels.ObjectDictionary source, Google.Protobuf.Collections.MapField<string, OdObject> destination, ResolutionContext context)
57+
{
58+
var config = new MapperConfiguration(cfg =>
59+
{
60+
cfg.CreateMap<ViewModels.OdObject, OdObject>();
61+
cfg.CreateMap<ViewModels.OdSubObject, OdSubObject>();
62+
});
63+
config.AssertConfigurationIsValid();
64+
var mapper = config.CreateMapper();
65+
66+
destination = [];
67+
foreach (var item in source)
68+
{
69+
destination.Add(item.Key, mapper.Map<OdObject>(item.Value));
70+
}
71+
return destination;
72+
}
73+
}
3874

3975
public static CanOpenDevice MapToProtobuffer(ViewModels.Device source)
4076
{

EDSEditorGUI2/ViewModels/Device.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public Device()
1818
private DeviceCommissioning _deviceCommissioning = new();
1919

2020
[ObservableProperty]
21-
private DeviceOD _objects = new();
21+
private ObjectDictionary _objects = new();
2222

2323
public void OnClickCommand()
2424
{

EDSEditorGUI2/ViewModels/DeviceOD.cs

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)