public MasonViewModel(ViewModel parent, JObject resource, BuilderContext context) : base(parent) { MainProperty = new ResourcePropertyViewModel(this, resource, "ROOT", new ResourceViewModel(this, resource, context)); Subscribe <SourceChangedEventArgs>(e => Source = e.Source); // Extract meta title for window title and top-level property name if (resource[MasonProperties.Meta] != null && resource[MasonProperties.Meta][MasonProperties.MetaProperties.Title] != null) { string title = resource[MasonProperties.Meta][MasonProperties.MetaProperties.Title].Value <string>(); if (!string.IsNullOrEmpty(title)) { MainProperty.Name = title; Publish(new TitleChangedEventArgs { Title = title }); } } else { Publish(new TitleChangedEventArgs { Title = "Unnamed resource" }); } Source = resource.ToString(); }
public ResourceViewModel(ViewModel parent, JObject resource, BuilderContext context) : base(parent, resource) { Properties = new ObservableCollection <ViewModel>(); JObject namespaces = resource.SelectToken(MasonProperties.Namespaces) as JObject; if (namespaces != null) { BuildNamespaces(namespaces, context); } foreach (var pair in resource) { if (pair.Key == MasonProperties.Namespaces && pair.Value is JObject) { // Ignore - it has been handled } else if (pair.Key == MasonProperties.Controls && pair.Value is JObject) { ControlsJsonValue = pair.Value; Controls = new ObservableCollection <ControlViewModel>( pair.Value.Children().OfType <JProperty>().Select(n => BuildControlElement(this, n.Name, n.Value as JObject, context)).Where(n => n != null)); } else if (pair.Key == MasonProperties.Meta && pair.Value is JObject) { MetaJsonValue = pair.Value; Description = GetValue <string>(pair.Value, MasonProperties.MetaProperties.Description); JToken metaControlsProperty = pair.Value[MasonProperties.Controls]; if (metaControlsProperty is JObject) { MetaControlsJsonValue = metaControlsProperty; MetaControls = new ObservableCollection <ControlViewModel>( metaControlsProperty.Children().OfType <JProperty>().Select(l => BuildControlElement(this, l.Name, l.Value as JObject, context))); } } else if (pair.Key == MasonProperties.Error && pair.Value is JObject) { ResourcePropertyViewModel error = new ResourcePropertyViewModel(this, pair.Value, pair.Key, new ResourceViewModel(this, (JObject)pair.Value, context)); error.IsError = true; Properties.Add(error); } else { Properties.Add(CreatePropertiesRecursively(pair.Key, pair.Value, context)); } } if (Controls == null) { Controls = new ObservableCollection <ControlViewModel>(); } }
public ResourceViewModel(ViewModel parent, JObject resource, BuilderContext context) : base(parent, resource) { Properties = new ObservableCollection<ViewModel>(); JObject namespaces = resource.SelectToken(MasonProperties.Namespaces) as JObject; if (namespaces != null) BuildNamespaces(namespaces, context); foreach (var pair in resource) { if (pair.Key == MasonProperties.Namespaces && pair.Value is JObject) { // Ignore - it has been handled } else if (pair.Key == MasonProperties.Controls && pair.Value is JObject) { ControlsJsonValue = pair.Value; Controls = new ObservableCollection<ControlViewModel>( pair.Value.Children().OfType<JProperty>().Select(n => BuildControlElement(this, n.Name, n.Value as JObject, context)).Where(n => n != null)); } else if (pair.Key == MasonProperties.Meta && pair.Value is JObject) { MetaJsonValue = pair.Value; Description = GetValue<string>(pair.Value, MasonProperties.MetaProperties.Description); JToken metaControlsProperty = pair.Value[MasonProperties.Controls]; if (metaControlsProperty is JObject) { MetaControlsJsonValue = metaControlsProperty; MetaControls = new ObservableCollection<ControlViewModel>( metaControlsProperty.Children().OfType<JProperty>().Select(l => BuildControlElement(this, l.Name, l.Value as JObject, context))); } } else if (pair.Key == MasonProperties.Error && pair.Value is JObject) { ResourcePropertyViewModel error = new ResourcePropertyViewModel(this, pair.Value, pair.Key, new ResourceViewModel(this, (JObject)pair.Value, context)); error.IsError = true; Properties.Add(error); } else { Properties.Add(CreatePropertiesRecursively(pair.Key, pair.Value, context)); } } if (Controls == null) Controls = new ObservableCollection<ControlViewModel>(); }
public MasonViewModel(ViewModel parent, JObject resource, BuilderContext context) : base(parent) { MainProperty = new ResourcePropertyViewModel(this, resource, "ROOT", new ResourceViewModel(this, resource, context)); Subscribe<SourceChangedEventArgs>(e => Source = e.Source); // Extract meta title for window title and top-level property name if (resource[MasonProperties.Meta] != null && resource[MasonProperties.Meta][MasonProperties.MetaProperties.Title] != null) { string title = resource[MasonProperties.Meta][MasonProperties.MetaProperties.Title].Value<string>(); if (!string.IsNullOrEmpty(title)) { MainProperty.Name = title; Publish(new TitleChangedEventArgs { Title = title }); } } else { Publish(new TitleChangedEventArgs { Title = "Unnamed resource" }); } Source = resource.ToString(); }