aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs
blob: 88f14fa098adc1a4362b371a35eacc1963246547 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.BL.Entities;
using Tango.MachineStudio.Common;
using System.Data.Entity;
using Tango.MachineStudio.Catalogs.Contracts;
using Tango.MachineStudio.Common.Notifications;
using Tango.Core.Commands;
using Tango.BL.Builders;
using Tango.Documents;
using Microsoft.Win32;
using Tango.Core.Helpers;
using System.IO;
using Tango.MachineStudio.Catalogs.Excel;
using Tango.BL.ActionLogs;
using Tango.MachineStudio.Common.Authentication;
using Tango.BL.Enumerations;
using Tango.BL.DTO;

namespace Tango.MachineStudio.Catalogs.ViewModels
{
    public class MainViewVM : StudioViewModel<IMainView>
    {
        private ObservablesContext _catalogsContext;
        private ObservablesContext _activeCatalogContext;
        private INotificationProvider _notification;
        private IActionLogManager _actionLogManager;
        private IAuthenticationProvider _authentication;
        private ColorCatalogDTO _catalogBeforeSave;

        #region Properties

        private ObservableCollection<ColorCatalog> _catalogs;
        /// <summary>
        /// Gets or sets the catalogs.
        /// </summary>
        public ObservableCollection<ColorCatalog> Catalogs
        {
            get { return _catalogs; }
            set { _catalogs = value; RaisePropertyChangedAuto(); }
        }

        private ColorCatalog _selectedCatalog;
        /// <summary>
        /// Gets or sets the selected catalog.
        /// </summary>
        public ColorCatalog SelectedCatalog
        {
            get { return _selectedCatalog; }
            set { _selectedCatalog = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
        }

        private ColorCatalog _activeCatalog;
        /// <summary>
        /// Gets or sets the active catalog.
        /// </summary>
        public ColorCatalog ActiveCatalog
        {
            get { return _activeCatalog; }
            set { _activeCatalog = value; RaisePropertyChangedAuto(); }
        }

        private ColorCatalogsGroup _selectedGroup;
        /// <summary>
        /// Gets or sets the selected group.
        /// </summary>
        public ColorCatalogsGroup SelectedGroup
        {
            get { return _selectedGroup; }
            set { _selectedGroup = value; RaisePropertyChangedAuto(); }
        }

        private ColorCatalogsItem _selectedItem;
        /// <summary>
        /// Gets or sets the selected item.
        /// </summary>
        public ColorCatalogsItem SelectedItem
        {
            get { return _selectedItem; }
            set { _selectedItem = value; RaisePropertyChangedAuto(); }
        }

        private List<Rml> _rmls;
        /// <summary>
        /// Gets or sets the RMLS.
        /// </summary>
        public List<Rml> RMLS
        {
            get { return _rmls; }
            set { _rmls = value; RaisePropertyChangedAuto(); }
        }

        #endregion

        #region Commands

        /// <summary>
        /// Gets or sets the new catalog command.
        /// </summary>
        public RelayCommand NewCatalogCommand { get; set; }

        /// <summary>
        /// Gets or sets the delete catalog command.
        /// </summary>
        public RelayCommand DeleteCatalogCommand { get; set; }

        /// <summary>
        /// Gets or sets the edit catalog command.
        /// </summary>
        public RelayCommand EditCatalogCommand { get; set; }

        /// <summary>
        /// Gets or sets the back to catalogs command.
        /// </summary>
        public RelayCommand BackToCatalogsCommand { get; set; }

        /// <summary>
        /// Gets or sets the save active catalog command.
        /// </summary>
        public RelayCommand SaveActiveCatalogCommand { get; set; }

        /// <summary>
        /// Gets or sets the export excel command.
        /// </summary>
        public RelayCommand ExportExcelCommand { get; set; }

        /// <summary>
        /// Gets or sets the import excel command.
        /// </summary>
        public RelayCommand ImportExcelCommand { get; set; }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewVM"/> class.
        /// </summary>
        public MainViewVM()
        {
            Catalogs = new ObservableCollection<ColorCatalog>();

            EditCatalogCommand = new RelayCommand(EditSelectedCatalog, () => SelectedCatalog != null);
            NewCatalogCommand = new RelayCommand(CreateNewCatalog);
            DeleteCatalogCommand = new RelayCommand(DeleteSelectedCatalog, () => SelectedCatalog != null);
            BackToCatalogsCommand = new RelayCommand(BackToCatalogs);
            SaveActiveCatalogCommand = new RelayCommand(SaveActiveCatalog);
            ExportExcelCommand = new RelayCommand(ExportCatalogToExcel);
            ImportExcelCommand = new RelayCommand(ImportCatalogFromExcel);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewVM"/> class.
        /// </summary>
        /// <param name="notificationProvider">The notification provider.</param>
        public MainViewVM(INotificationProvider notificationProvider, IActionLogManager actionLogManager, IAuthenticationProvider authenticationProvider) : this()
        {
            _actionLogManager = actionLogManager;
            _notification = notificationProvider;
            _authentication = authenticationProvider;
        }

        #endregion

        #region Edit / Delete / Create Catalog

        public async Task LoadCatalogs()
        {
            using (_notification.PushTaskItem("Loading color catalogs..."))
            {
                IsFree = false;

                if (_catalogsContext != null)
                {
                    _catalogsContext.Dispose();
                }

                _catalogsContext = ObservablesContext.CreateDefault();

                Catalogs = (await _catalogsContext.ColorCatalogs.Include(x => x.ColorCatalogsGroups.Select(g => g.ColorCatalogsItems)).ToListAsync()).ToSynchronizedObservableCollection();
                SelectedCatalog = null;

                IsFree = true;
            }
        }

        public async void EditSelectedCatalog()
        {
            if (SelectedCatalog != null)
            {
                using (_notification.PushTaskItem("Loading selected catalog..."))
                {
                    try
                    {
                        IsFree = false;

                        if (_activeCatalogContext != null)
                        {
                            _activeCatalogContext.Dispose();
                        }

                        _activeCatalogContext = ObservablesContext.CreateDefault();

                        ActiveCatalog = await new CatalogBuilder(_activeCatalogContext).Set(SelectedCatalog.Guid).WithGroups().WithItems().WithRecipes().BuildAsync();
                        SelectedGroup = ActiveCatalog.ColorCatalogsGroups.FirstOrDefault();
                        RMLS = await _activeCatalogContext.Rmls.ToListAsync();

                        if (SelectedGroup != null)
                        {
                            SelectedItem = SelectedGroup.ColorCatalogsItems.FirstOrDefault();
                        }

                        _catalogBeforeSave = ColorCatalogDTO.FromObservable(ActiveCatalog);

                        View.NavigateTo(CatalogsNavigationView.CatalogView);
                    }
                    catch (Exception ex)
                    {
                        _notification.ShowError($"An error occurred while trying to load the selected catalog.\n{ex.Message}");
                        LogManager.Log(ex, $"Error loading selected catalog '{SelectedCatalog.Name}'.");
                    }
                    finally
                    {
                        IsFree = true;
                    }
                }
            }
        }

        private async void DeleteSelectedCatalog()
        {
            if (SelectedCatalog != null)
            {
                if (_notification.ShowQuestion("Are you sure you want to delete the selected catalog ?"))
                {
                    using (_notification.PushTaskItem("Deleting selected catalog..."))
                    {
                        try
                        {
                            IsFree = false;
                            await SelectedCatalog.DeleteCascadeAsync(_catalogsContext);
                            _actionLogManager.InsertLog(ActionLogType.CatalogDeleted, _authentication.CurrentUser, SelectedCatalog.Name, SelectedCatalog, "Catalog deleted using Machine Studio.", false);
                            Catalogs.Remove(SelectedCatalog);
                            SelectedCatalog = null;
                        }
                        catch (Exception ex)
                        {
                            _notification.ShowError($"An error occurred while trying to delete the selected catalog.\n{ex.Message}");
                            LogManager.Log(ex, $"Error deleting catalog {SelectedCatalog.Name}.");
                        }
                        finally
                        {
                            IsFree = true;
                        }
                    }
                }
            }
        }

        private async void CreateNewCatalog()
        {
            String name = _notification.ShowTextInput("Please enter a catalog name", "Catalog name");
            if (!String.IsNullOrWhiteSpace(name))
            {
                using (_notification.PushTaskItem("Generating catalog..."))
                {
                    try
                    {
                        IsFree = false;
                        ColorCatalog newCatalog = new ColorCatalog();
                        newCatalog.Name = name;
                        newCatalog.Description = name;
                        newCatalog.Company = "Twine";
                        _catalogsContext.ColorCatalogs.Add(newCatalog);
                        await _catalogsContext.SaveChangesAsync();
                        _actionLogManager.InsertLog(ActionLogType.CatalogCreated, _authentication.CurrentUser, newCatalog.Name, newCatalog, "Catalog created using Machine Studio.");
                        SelectedCatalog = newCatalog;
                        EditSelectedCatalog();
                    }
                    catch (Exception ex)
                    {
                        _notification.ShowError($"An error occurred while trying to create the catalog.\n{ex.Message}");
                        LogManager.Log(ex, $"Error creating new catalog.");
                    }
                    finally
                    {
                        IsFree = true;
                    }
                }
            }
        }

        public void OnGroupDeleted(ColorCatalogsGroup group)
        {
            group.Delete(_activeCatalogContext);
        }

        public void OnItemDeleted(ColorCatalogsItem item)
        {
            item.Delete(_activeCatalogContext);
        }

        public void OnRecipeDeleted(ColorCatalogsItemsRecipe recipe)
        {
            recipe.Delete(_activeCatalogContext);
        }

        private async void SaveActiveCatalog()
        {
            if (ActiveCatalog != null)
            {
                using (_notification.PushTaskItem("Updating catalog..."))
                {
                    try
                    {
                        IsFree = false;

                        //Validate color codes.
                        var duplicateCodes = ActiveCatalog
                            .ColorCatalogsGroups
                            .SelectMany(x => x.ColorCatalogsItems)
                            .GroupBy(x => x.Code)
                            .Where(x => x.Count() > 1)
                            .Select(x => x.First().Code)
                            .ToList();

                        if (duplicateCodes.Count > 0)
                        {
                            throw new InvalidOperationException($"Duplicate color codes found:\n{String.Join(Environment.NewLine, duplicateCodes)}");
                        }

                        //Validate color names.
                        var duplicateNames = ActiveCatalog
                            .ColorCatalogsGroups
                            .SelectMany(x => x.ColorCatalogsItems)
                            .GroupBy(x => x.Name)
                            .Where(x => x.Count() > 1)
                            .Select(x => x.First().Name)
                            .ToList();

                        if (duplicateNames.Count > 0)
                        {
                            throw new InvalidOperationException($"Duplicate color names found:\n{String.Join(Environment.NewLine, duplicateNames)}");
                        }

                        ActiveCatalog.LastUpdated = DateTime.UtcNow;
                        await _activeCatalogContext.SaveChangesAsync();

                        var activeCatalogDTO = ColorCatalogDTO.FromObservable(ActiveCatalog);
                        _actionLogManager.InsertLog(ActionLogType.CatalogSaved, _authentication.CurrentUser, _catalogBeforeSave.Name, _catalogBeforeSave, activeCatalogDTO, "Catalog saved using Machine Studio.");
                        _catalogBeforeSave = activeCatalogDTO;

                        await LoadCatalogs();

                        _notification.ShowInfo("Catalog updated successfully.");
                    }
                    catch (Exception ex)
                    {
                        _notification.ShowError($"An error occurred while trying to update the catalog.\n{ex.Message}");
                        LogManager.Log(ex, $"Error updating catalog {ActiveCatalog.Name}.");
                    }
                    finally
                    {
                        IsFree = true;
                    }
                }
            }
        }

        private void BackToCatalogs()
        {
            View.NavigateTo(CatalogsNavigationView.CatalogsView);
        }

        #endregion

        #region Export / Import Excel

        public void ExportCatalogToExcel()
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "Excel Documents|*.xlsx";
            if (dlg.ShowDialog().Value)
            {
                using (_notification.PushTaskItem("Exporting catalog to file..."))
                {
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            IsFree = false;

                            Stream stream = null;
                            bool dispose = false;
                            String file = AssemblyHelper.GetCurrentAssemblyFolder() + "\\Templates\\ExportTemplate.xlsx";

                            if (File.Exists(file))
                            {
                                stream = File.OpenRead(file);
                                dispose = true;
                            }
                            else
                            {
                                stream = EmbeddedResourceHelper.GetEmbeddedResourceStream("Tango.MachineStudio.Catalogs.Templates.ExportTemplate.xlsx");
                            }

                            byte[] data = new byte[stream.Length];
                            stream.Read(data, 0, data.Length);
                            File.WriteAllBytes(dlg.FileName, data);

                            if (dispose)
                            {
                                stream.Dispose();
                            }

                            ExcelWriter writer = new ExcelWriter(dlg.FileName);

                            List<Media> medias = RMLS.Select(x => new Media()
                            {
                                MediaName = x.Name,
                            }).ToList();

                            writer.WriteData(medias, "RML");

                            List<ColorGroup> groups = ActiveCatalog.ColorCatalogsGroups.Select(x => new ColorGroup()
                            {
                                GroupColor = x.Color,
                                GroupName = x.Name,
                                GroupIndex = x.GroupIndex,
                            }).ToList();

                            writer.WriteData(groups, "Groups");

                            List<ColorItem> items = ActiveCatalog.ColorCatalogsGroups.SelectMany(x => x.ColorCatalogsItems).Select(x => new ColorItem()
                            {

                                ItemColor = x.Color,
                                Group = x.ColorCatalogsGroup.Name,
                                Code = x.Code,
                                Name = x.Name,
                                ItemIndex = x.ItemIndex,
                                Red = x.Red,
                                Green = x.Green,
                                Blue = x.Blue,
                                L = x.L,
                                A = x.A,
                                B = x.B,
                                Cyan = x.Cyan,
                                Magenta = x.Magenta,
                                Yellow = x.Yellow,
                                Black = x.Black,
                                BlueExtra = x.BlueExtra,
                                NavyExtra = x.NavyExtra,
                                OrangeExtra = x.OrangeExtra,
                                RedExtra = x.RedExtra,
                                RubineExtra = x.RubineExtra,
                                VioletExtra = x.VioletExtra,
                                Region = x.ProcessParametersTableIndex,

                            }).ToList();

                            writer.WriteData(items, "Colors");

                            List<ColorRecipe> recipes = ActiveCatalog.ColorCatalogsGroups.SelectMany(x => x.ColorCatalogsItems).SelectMany(x => x.ColorCatalogsItemsRecipes).Select(x => new ColorRecipe()
                            {

                                R_Color = x.ColorCatalogsItem.Color,
                                R_Name = x.ColorCatalogsItem.Name,
                                R_Media = x.Rml.Name,
                                R_Cyan = x.Cyan,
                                R_Magenta = x.Magenta,
                                R_Yellow = x.Yellow,
                                R_Black = x.Black,
                                R_Region = x.ProcessParametersTableIndex,


                            }).ToList();

                            writer.WriteData(recipes, "Recipes");

                            writer.Dispose();

                            InvokeUI(() =>
                            {
                                _notification.ShowInfo("Catalog exported successfully.");
                            });
                        }
                        catch (Exception ex)
                        {
                            LogManager.Log(ex, $"Error exporting color catalog to {dlg.FileName}");

                            InvokeUI(() =>
                            {
                                _notification.ShowError($"An error occurred while trying to export the catalog. Make sure the selected excel file is closed and data is valid.\n{ex.FlattenMessage()}");
                            });
                        }
                        finally
                        {
                            IsFree = true;
                        }
                    });
                }
            }
        }

        public void ImportCatalogFromExcel()
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "Excel Documents|*.xlsx";
            if (dlg.ShowDialog().Value)
            {
                using (_notification.PushTaskItem("Merging catalog from file..."))
                {
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            ExcelReader reader = new ExcelReader(dlg.FileName);
                            var groups = reader.GetData<ColorGroup>("Groups");
                            reader.Dispose();

                            reader = new ExcelReader(dlg.FileName);
                            var colors = reader.GetData<ColorItem>("Colors");
                            reader.Dispose();

                            reader = new ExcelReader(dlg.FileName);
                            var recipes = reader.GetData<ColorRecipe>("Recipes");
                            reader.Dispose();

                            foreach (var group in groups)
                            {
                                ColorCatalogsGroup existinGroup = ActiveCatalog.ColorCatalogsGroups.SingleOrDefault(x => x.Name == group.GroupName);

                                bool inserting = false;
                                if (existinGroup == null)
                                {
                                    existinGroup = new ColorCatalogsGroup();
                                    inserting = true;
                                }

                                existinGroup.Name = group.GroupName;
                                existinGroup.GroupIndex = group.GroupIndex;

                                if (inserting)
                                {
                                    ActiveCatalog.ColorCatalogsGroups.Add(existinGroup);
                                }
                            }

                            foreach (var item in colors)
                            {
                                var existinItem = ActiveCatalog.ColorCatalogsGroups.SelectMany(x => x.ColorCatalogsItems).SingleOrDefault(x => x.Code == item.Code);
                                var group = ActiveCatalog.ColorCatalogsGroups.SingleOrDefault(x => x.Name == item.Group);

                                bool inserting = false;

                                if (existinItem == null)
                                {
                                    existinItem = new ColorCatalogsItem();
                                    inserting = true;
                                }
                                else
                                {
                                    if (existinItem.ColorCatalogsGroup != group)
                                    {
                                        existinItem.ColorCatalogsGroup.ColorCatalogsItems.Remove(existinItem);
                                        group.ColorCatalogsItems.Add(existinItem);
                                    }
                                }

                                existinItem.ColorCatalogsGroup = group;
                                existinItem.Code = item.Code;
                                existinItem.Name = item.Name;
                                existinItem.ItemIndex = item.ItemIndex;
                                existinItem.Red = item.Red;
                                existinItem.Green = item.Green;
                                existinItem.Blue = item.Blue;
                                existinItem.L = item.L;
                                existinItem.A = item.A;
                                existinItem.B = item.B;
                                existinItem.Cyan = item.Cyan;
                                existinItem.Magenta = item.Magenta;
                                existinItem.Yellow = item.Yellow;
                                existinItem.Black = item.Black;
                                existinItem.BlueExtra = item.BlueExtra;
                                existinItem.NavyExtra = item.NavyExtra;
                                existinItem.OrangeExtra = item.OrangeExtra;
                                existinItem.RedExtra = item.RedExtra;
                                existinItem.RubineExtra = item.RubineExtra;
                                existinItem.VioletExtra = item.VioletExtra;
                                existinItem.ProcessParametersTableIndex = item.Region;

                                if (inserting)
                                {
                                    _activeCatalogContext.ColorCatalogsItems.Add(existinItem);
                                }
                            }

                            foreach (var recipe in recipes)
                            {
                                var existingRecipe = ActiveCatalog.ColorCatalogsGroups.SelectMany(x => x.ColorCatalogsItems).SelectMany(x => x.ColorCatalogsItemsRecipes).SingleOrDefault(x => x.ColorCatalogsItem.Name == recipe.R_Name && x.Rml.Name == recipe.R_Media);

                                bool inserting = false;

                                if (existingRecipe == null)
                                {
                                    existingRecipe = new ColorCatalogsItemsRecipe();
                                    existingRecipe.Rml = RMLS.SingleOrDefault(x => x.Name == recipe.R_Media);
                                    existingRecipe.ColorCatalogsItem = ActiveCatalog.ColorCatalogsGroups.SelectMany(x => x.ColorCatalogsItems).SingleOrDefault(x => x.Name == recipe.R_Name);
                                    inserting = true;
                                }

                                existingRecipe.Cyan = recipe.R_Cyan;
                                existingRecipe.Magenta = recipe.R_Magenta;
                                existingRecipe.Yellow = recipe.R_Yellow;
                                existingRecipe.Black = recipe.R_Black;
                                existingRecipe.ProcessParametersTableIndex = recipe.R_Region;

                                if (inserting)
                                {
                                    _activeCatalogContext.ColorCatalogsItemsRecipes.Add(existingRecipe);
                                }
                            }

                            InvokeUI(() =>
                            {
                                _notification.ShowInfo("Catalog imported successfully.");
                            });
                        }
                        catch (Exception ex)
                        {
                            LogManager.Log(ex, $"Error importing color catalog to {dlg.FileName}");

                            InvokeUI(() =>
                            {
                                _notification.ShowError($"An error occurred while trying to merge the catalog. Please check your data.\n{ex.FlattenMessage()}");
                            });
                        }
                        finally
                        {
                            IsFree = true;
                        }
                    });
                }
            }
        }

        #endregion

        #region Application Ready

        public async override void OnApplicationReady()
        {
            await LoadCatalogs();
        }

        #endregion
    }
}