diff --git a/src/Artemis.Core/Models/Profile/DataModel/DataModelPath.cs b/src/Artemis.Core/Models/Profile/DataModel/DataModelPath.cs index 1feeee83f..c6cdc9c40 100644 --- a/src/Artemis.Core/Models/Profile/DataModel/DataModelPath.cs +++ b/src/Artemis.Core/Models/Profile/DataModel/DataModelPath.cs @@ -18,20 +18,30 @@ namespace Artemis.Core private readonly LinkedList _segments; /// - /// Creates a new instance of the class + /// Creates a new instance of the class pointing directly to the target /// /// The target at which this path starts - /// A string representation of the + public DataModelPath(object target) + { + Target = target ?? throw new ArgumentNullException(nameof(target)); + Path = ""; + + _segments = new LinkedList(); + Initialize(Path); + } + + /// + /// Creates a new instance of the class pointing to the provided path + /// + /// The target at which this path starts + /// A point-separated path public DataModelPath(object target, string path) { Target = target ?? throw new ArgumentNullException(nameof(target)); Path = path ?? throw new ArgumentNullException(nameof(path)); - if (string.IsNullOrWhiteSpace(Path)) - throw new ArgumentException("Path cannot be empty"); - _segments = new LinkedList(); - Initialize(path); + Initialize(Path); } /// @@ -40,7 +50,7 @@ namespace Artemis.Core public object Target { get; } /// - /// Gets a string representation of the + /// Gets the point-separated path associated with this /// public string Path { get; } @@ -106,7 +116,7 @@ namespace Artemis.Core /// public override string ToString() { - return Path; + return string.IsNullOrWhiteSpace(Path) ? "this" : Path; } private void Initialize(string path) @@ -114,12 +124,16 @@ namespace Artemis.Core DataModelPathSegment startSegment = new DataModelPathSegment(this, "target", "target"); startSegment.Node = _segments.AddFirst(startSegment); - string[] segments = path.Split("."); - for (int index = 0; index < segments.Length; index++) + // On an empty path don't bother processing segments + if (!string.IsNullOrWhiteSpace(path)) { - string identifier = segments[index]; - LinkedListNode node = _segments.AddLast(new DataModelPathSegment(this, identifier, string.Join('.', segments.Take(index + 1)))); - node.Value.Node = node; + string[] segments = path.Split("."); + for (int index = 0; index < segments.Length; index++) + { + string identifier = segments[index]; + LinkedListNode node = _segments.AddLast(new DataModelPathSegment(this, identifier, string.Join('.', segments.Take(index + 1)))); + node.Value.Node = node; + } } ParameterExpression parameter = Expression.Parameter(typeof(object), "t"); diff --git a/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelVisualizationViewModel.cs b/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelVisualizationViewModel.cs index 3b19720d8..744982273 100644 --- a/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelVisualizationViewModel.cs +++ b/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelVisualizationViewModel.cs @@ -39,12 +39,12 @@ namespace Artemis.UI.Shared public DataModelPath DataModelPath { get; } public string Path => DataModelPath?.Path; - public int Depth { get; set; } + public int Depth { get; private set; } public DataModel DataModel { get => _dataModel; - set => SetAndNotify(ref _dataModel, value); + protected set => SetAndNotify(ref _dataModel, value); } public DataModelPropertyAttribute PropertyDescription @@ -140,12 +140,15 @@ namespace Artemis.UI.Shared public DataModelVisualizationViewModel GetChildByPath(Guid dataModelGuid, string propertyPath) { - if (DataModel.PluginInfo.Guid != dataModelGuid) - return null; - if (propertyPath == null) - return null; - if (Path.StartsWith(propertyPath)) - return null; + if (!IsRootViewModel) + { + if (DataModel.PluginInfo.Guid != dataModelGuid) + return null; + if (propertyPath == null) + return null; + if (Path.StartsWith(propertyPath, StringComparison.OrdinalIgnoreCase)) + return null; + } // Ensure children are populated by requesting an update if (!IsVisualizationExpanded) @@ -191,7 +194,7 @@ namespace Artemis.UI.Shared // Add missing static children foreach (PropertyInfo propertyInfo in modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { - string childPath = Path != null ? $"{Path}.{propertyInfo.Name}" : propertyInfo.Name; + string childPath = AppendToPath(propertyInfo.Name); if (Children.Any(c => c.Path != null && c.Path.Equals(childPath))) continue; if (propertyInfo.GetCustomAttribute() != null) @@ -210,7 +213,7 @@ namespace Artemis.UI.Shared hiddenProperties = DataModel.GetHiddenProperties(); foreach (PropertyInfo hiddenProperty in hiddenProperties) { - string childPath = Path != null ? $"{Path}.{hiddenProperty.Name}" : hiddenProperty.Name; + string childPath = AppendToPath(hiddenProperty.Name); DataModelVisualizationViewModel toRemove = Children.FirstOrDefault(c => c.Path != null && c.Path == childPath); if (toRemove != null) Children.Remove(toRemove); @@ -226,7 +229,7 @@ namespace Artemis.UI.Shared { foreach (KeyValuePair kvp in dataModel.DynamicDataModels) { - string childPath = Path != null ? $"{Path}.{kvp.Key}" : kvp.Key; + string childPath = AppendToPath(kvp.Key); if (Children.Any(c => c.Path != null && c.Path.Equals(childPath))) continue; @@ -277,6 +280,11 @@ namespace Artemis.UI.Shared return null; } + private string AppendToPath(string toAppend) + { + return !string.IsNullOrEmpty(Path) ? $"{Path}.{toAppend}" : toAppend; + } + private void RequestUpdate() { Parent?.RequestUpdate(); @@ -294,10 +302,4 @@ namespace Artemis.UI.Shared #endregion } - - public enum DataModelConditionSide - { - Left, - Right - } } \ No newline at end of file diff --git a/src/Artemis.UI.Shared/Services/DataModelUIService.cs b/src/Artemis.UI.Shared/Services/DataModelUIService.cs index 62f385157..efeab96c2 100644 --- a/src/Artemis.UI.Shared/Services/DataModelUIService.cs +++ b/src/Artemis.UI.Shared/Services/DataModelUIService.cs @@ -34,7 +34,7 @@ namespace Artemis.UI.Shared.Services { DataModelPropertiesViewModel viewModel = new DataModelPropertiesViewModel(null, null, null); foreach (DataModel dataModelExpansion in _dataModelService.GetDataModels()) - viewModel.Children.Add(new DataModelPropertiesViewModel(dataModelExpansion, viewModel, null)); + viewModel.Children.Add(new DataModelPropertiesViewModel(dataModelExpansion, viewModel, new DataModelPath(dataModelExpansion))); // Update to populate children viewModel.Update(this);