Skip to content

Commit

Permalink
Update NJS, fix some problems, v2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
RicoSuter committed Feb 25, 2019
1 parent a53f1f8 commit 03cbd04
Show file tree
Hide file tree
Showing 14 changed files with 472 additions and 179 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,3 +10,4 @@
/src/UpgradeLog.htm
/src/VisualJsonEditor.sln.GhostDoc.xml
/src/VisualJsonEditor/VisualJsonEditor.previous.nugetreferenceswitcher
/src/.vs/
574 changes: 421 additions & 153 deletions src/VisualJsonEditor.Installer/Generated.wxs

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions src/VisualJsonEditor/Controls/JsonEditor.xaml
Expand Up @@ -20,6 +20,7 @@
<myConverters:IndexConverter x:Key="IndexConverter" />
<myConverters:TimeConverter x:Key="TimeConverter" />
<myConverters:DateConverter x:Key="DateConverter" />
<myConverters:DateTimeConverter x:Key="DateTimeConverter" />
<myConverters:DecimalUpDownRangeConverter x:Key="DecimalUpDownRangeConverter" />
<myConverters:IntegerUpDownRangeConverter x:Key="IntegerUpDownRangeConverter" />
</UserControl.Resources>
Expand Down Expand Up @@ -51,9 +52,7 @@
<TextBlock Text="{Binding Schema.Description}" Margin="0,0,0,4"
Visibility="{Binding Schema.Description, Converter={StaticResource VisibilityConverter}}" />
<xctk:DateTimePicker Margin="0,0,0,8" TextAlignment="Left" AutoCloseCalendar="True"
Value="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource DateConverter}}" />
<!--<TextBox Margin="0,0,0,8" ui:UndoRedoCommandManager.DisableUndoRedo="True"
Text="{Binding Value, Converter={StaticResource DateConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />-->
Value="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource DateTimeConverter}}" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="DateTemplate">
Expand All @@ -64,8 +63,6 @@
<xctk:DateTimePicker Margin="0,0,0,8" TextAlignment="Left" Format="LongDate"
TimePickerVisibility="Collapsed" TimeFormat="Custom" AutoCloseCalendar="True"
Value="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource DateConverter}}" />
<!--<TextBox Margin="0,0,0,8" ui:UndoRedoCommandManager.DisableUndoRedo="True"
Text="{Binding Value, Converter={StaticResource DateConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />-->
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="TimeTemplate">
Expand Down
4 changes: 2 additions & 2 deletions src/VisualJsonEditor/Controls/JsonEditor.xaml.cs
Expand Up @@ -47,7 +47,7 @@ private void OnAddArrayObject(object sender, RoutedEventArgs e)
property.Value = new ObservableCollection<JsonTokenModel>();

var list = (ObservableCollection<JsonTokenModel>)property.Value;
var schema = property.Schema.ActualPropertySchema.Item.ActualSchema;
var schema = property.Schema.ActualSchema.Item.ActualSchema;

var obj = !schema.Type.HasFlag(JsonObjectType.Object) && !schema.Type.HasFlag(JsonObjectType.Array) ?
(JsonTokenModel)new JsonValueModel { Schema = schema } : JsonObjectModel.FromSchema(schema);
Expand All @@ -67,7 +67,7 @@ private void OnCreateObject(object sender, RoutedEventArgs e)
var property = (JsonPropertyModel)((CheckBox)sender).Tag;
if (property.Parent[property.Name] == null)
{
property.Parent[property.Name] = JsonObjectModel.FromSchema(property.Schema.ActualPropertySchema);
property.Parent[property.Name] = JsonObjectModel.FromSchema(property.Schema.ActualSchema);
property.RaisePropertyChanged<JsonPropertyModel>(i => i.HasValue);
}
}
Expand Down
Expand Up @@ -26,7 +26,7 @@ public override DataTemplate SelectTemplate(object item, DependencyObject contai

JsonSchema4 schema = null;
if (item is JsonPropertyModel)
schema = ((JsonPropertyModel)item).Schema.ActualPropertySchema;
schema = ((JsonPropertyModel)item).Schema.ActualSchema;
else if (item is JsonTokenModel)
schema = ((JsonTokenModel)item).Schema.ActualSchema;
else if (item == null)
Expand Down
2 changes: 1 addition & 1 deletion src/VisualJsonEditor/Converters/DateConverter.cs
Expand Up @@ -24,7 +24,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
return (value as DateTime?)?.ToString("yyyy-MM-dd");
}
}
}
30 changes: 30 additions & 0 deletions src/VisualJsonEditor/Converters/DateTimeConverter.cs
@@ -0,0 +1,30 @@
//-----------------------------------------------------------------------
// <copyright file="DateConverter.cs" company="Visual JSON Editor">
// Copyright (c) Rico Suter. All rights reserved.
// </copyright>
// <license>http://visualjsoneditor.codeplex.com/license</license>
// <author>Rico Suter, mail@rsuter.com</author>
//-----------------------------------------------------------------------

using System;
using System.Globalization;
using System.Windows.Data;

namespace VisualJsonEditor.Converters
{
public class DateTimeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return null;

return value is DateTime ? value : DateTime.Parse(value.ToString());
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
}
2 changes: 1 addition & 1 deletion src/VisualJsonEditor/Models/JsonDocumentModel.cs
Expand Up @@ -116,7 +116,7 @@ public static Task<JsonDocumentModel> LoadAsync(string filePath, string schemaPa
{
return Task.Run(() =>
{
var schema = JsonSchema4.FromJsonAsync(File.ReadAllText(schemaPath, Encoding.UTF8)).GetAwaiter().GetResult();
var schema = JsonSchema4.FromFileAsync(schemaPath).GetAwaiter().GetResult();
var data = JsonObjectModel.FromJson(File.ReadAllText(filePath, Encoding.UTF8), schema);
var document = new JsonDocumentModel();
Expand Down
10 changes: 5 additions & 5 deletions src/VisualJsonEditor/Models/JsonObjectModel.cs
Expand Up @@ -33,7 +33,7 @@ public static JsonObjectModel FromSchema(JsonSchema4 schema)
var obj = new JsonObjectModel();
foreach (var property in schema.Properties)
{
var propertySchema = property.Value.ActualPropertySchema;
var propertySchema = property.Value.ActualSchema;
if (propertySchema.Type.HasFlag(JsonObjectType.Object))
{
if (property.Value.IsRequired)
Expand Down Expand Up @@ -76,7 +76,7 @@ public static JsonObjectModel FromJson(JObject obj, JsonSchema4 schema)
var result = new JsonObjectModel();
foreach (var property in schema.Properties)
{
var propertySchema = property.Value.ActualPropertySchema;
var propertySchema = property.Value.ActualSchema;
if (propertySchema.Type.HasFlag(JsonObjectType.Array))
{
var propertyItemSchema = propertySchema.Item != null ? propertySchema.Item.ActualSchema : null;
Expand Down Expand Up @@ -118,7 +118,7 @@ public static JsonObjectModel FromJson(JObject obj, JsonSchema4 schema)

private static object GetDefaultValue(KeyValuePair<string, JsonProperty> property)
{
var propertySchema = property.Value.ActualPropertySchema;
var propertySchema = property.Value.ActualSchema;
if (propertySchema.Default != null)
return propertySchema.Default;

Expand Down Expand Up @@ -189,8 +189,8 @@ public Task<string> ValidateAsync()
{
return Task.Run(() =>
{
var obj = JToken.ReadFrom(new JsonTextReader(new StringReader(ToJson())));
var errors = Schema.Validate(obj);
var json = ToJson();
var errors = Schema.Validate(json);
return string.Join("\n", ConvertErrors(errors, string.Empty));
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/VisualJsonEditor/Properties/AssemblyInfo.cs
Expand Up @@ -18,4 +18,4 @@
ResourceDictionaryLocation.SourceAssembly
)]

[assembly: AssemblyVersion("2.4.*")]
[assembly: AssemblyVersion("2.5.*")]
2 changes: 1 addition & 1 deletion src/VisualJsonEditor/Samples/Sample.json
Expand Up @@ -3,7 +3,7 @@
"BoolValue": false,
"NumberValue": 2.3,
"DateTimeValue": "2014-08-13T21:00:00",
"DateValue": "2014-08-14T00:00:00",
"DateValue": "2014-08-14",
"TimeValue": "02:00:00",
"IntegerValue": 1,
"Test": {
Expand Down
5 changes: 0 additions & 5 deletions src/VisualJsonEditor/Samples/Sample.schema.json
Expand Up @@ -61,11 +61,6 @@
},
"List": {
"type": "array",
"required": [
"Abc",
"Def",
"Geh"
],
"items": {
"type": "object",
"properties": {
Expand Down
8 changes: 5 additions & 3 deletions src/VisualJsonEditor/VisualJsonEditor.csproj
Expand Up @@ -59,15 +59,16 @@
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NJsonSchema, Version=9.2.5.0, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.9.2.5\lib\net45\NJsonSchema.dll</HintPath>
<Private>True</Private>
<Reference Include="NJsonSchema, Version=9.13.19.0, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.9.13.19\lib\net45\NJsonSchema.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Data" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Windows.Controls.Ribbon" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand Down Expand Up @@ -116,6 +117,7 @@
</ApplicationDefinition>
<Compile Include="Controls\ExpandingGroupBox.cs" />
<Compile Include="Converters\DateConverter.cs" />
<Compile Include="Converters\DateTimeConverter.cs" />
<Compile Include="Converters\DecimalUpDownRangeConverter.cs" />
<Compile Include="Converters\IndexConverter.cs" />
<Compile Include="Converters\IntegerConverter.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/VisualJsonEditor/packages.config
Expand Up @@ -6,5 +6,5 @@
<package id="MyToolkit" version="2.5.16" targetFramework="net45" />
<package id="MyToolkit.Extended" version="2.5.16" targetFramework="net45" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="NJsonSchema" version="9.2.5" targetFramework="net45" />
<package id="NJsonSchema" version="9.13.19" targetFramework="net45" />
</packages>

0 comments on commit 03cbd04

Please sign in to comment.