Skip to content
Permalink
Browse files

Update NJS, fix some problems, v2.5

  • Loading branch information...
RSuter committed Feb 25, 2019
1 parent a53f1f8 commit 03cbd040c62141af4b7002d40cc6ff1135fc9d64
@@ -10,3 +10,4 @@
/src/UpgradeLog.htm
/src/VisualJsonEditor.sln.GhostDoc.xml
/src/VisualJsonEditor/VisualJsonEditor.previous.nugetreferenceswitcher
/src/.vs/

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -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>
@@ -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">
@@ -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">
@@ -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);
@@ -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);
}
}
@@ -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)
@@ -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");
}
}
}
@@ -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;
}
}
}
@@ -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();
@@ -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)
@@ -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;
@@ -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;

@@ -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));
});
}
@@ -18,4 +18,4 @@
ResourceDictionaryLocation.SourceAssembly
)]

[assembly: AssemblyVersion("2.4.*")]
[assembly: AssemblyVersion("2.5.*")]
@@ -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": {
@@ -61,11 +61,6 @@
},
"List": {
"type": "array",
"required": [
"Abc",
"Def",
"Geh"
],
"items": {
"type": "object",
"properties": {
@@ -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">
@@ -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" />
@@ -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.
You can’t perform that action at this time.