瀏覽代碼

backup old @Workbench, add new casted @Workbench. Fix JsonDocumentExt.Diff

Dalibor Votruba 2 年之前
父節點
當前提交
89f036a352

+ 93 - 93
@Workbench/@Workbench.csproj → @Legacy/@Workbench/@Workbench.csproj

@@ -1,94 +1,94 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
-  <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProjectGuid>{60DDDF9B-507A-4665-8A5B-1F670005727F}</ProjectGuid>
-    <OutputType>Exe</OutputType>
-    <RootNamespace>_Workbench</RootNamespace>
-    <AssemblyName>%40Workbench</AssemblyName>
-    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
-    <FileAlignment>512</FileAlignment>
-    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
-    <Deterministic>true</Deterministic>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <PlatformTarget>AnyCPU</PlatformTarget>
-    <DebugSymbols>true</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
-    <OutputPath>bin\Debug\</OutputPath>
-    <DefineConstants>DEBUG;TRACE</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
-    <PlatformTarget>AnyCPU</PlatformTarget>
-    <DebugType>pdbonly</DebugType>
-    <Optimize>true</Optimize>
-    <OutputPath>bin\Release\</OutputPath>
-    <DefineConstants>TRACE</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
-    <SignAssembly>true</SignAssembly>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
-    <AssemblyOriginatorKeyFile>quadarax_strong_name_key.pfx</AssemblyOriginatorKeyFile>
-  </PropertyGroup>
-  <PropertyGroup>
-    <SignAssembly>true</SignAssembly>
-  </PropertyGroup>
-  <PropertyGroup>
-    <AssemblyOriginatorKeyFile>quadarax_strong_name_key.pfx</AssemblyOriginatorKeyFile>
-  </PropertyGroup>
-  <ItemGroup>
-    <Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
-      <HintPath>..\Infrastructure\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
-    </Reference>
-    <Reference Include="QDR.FND.Common, Version=1.0.0.7, Culture=neutral, PublicKeyToken=60b8fdcb29a015db, processorArchitecture=MSIL">
-      <HintPath>..\Infrastructure\packages\Quadarax.Foundation.Common.1.0.0.7\lib\net472\QDR.FND.Common.dll</HintPath>
-    </Reference>
-    <Reference Include="StructureMap, Version=4.7.0.0, Culture=neutral, processorArchitecture=MSIL">
-      <HintPath>..\Infrastructure\packages\StructureMap.4.7.1\lib\net45\StructureMap.dll</HintPath>
-    </Reference>
-    <Reference Include="System" />
-    <Reference Include="System.Core" />
-    <Reference Include="System.Xml.Linq" />
-    <Reference Include="System.Data.DataSetExtensions" />
-    <Reference Include="Microsoft.CSharp" />
-    <Reference Include="System.Data" />
-    <Reference Include="System.Net.Http" />
-    <Reference Include="System.Xml" />
-  </ItemGroup>
-  <ItemGroup>
-    <Compile Include="Layers\DefaultBusinessLayer.cs" />
-    <Compile Include="Layers\DefaultDataLayer.cs" />
-    <Compile Include="Layers\DefaultGlobalLayer.cs" />
-    <Compile Include="Layers\Modules\IModBuss.cs" />
-    <Compile Include="Layers\Modules\IModData.cs" />
-    <Compile Include="Layers\Modules\IModGlobal.cs" />
-    <Compile Include="Layers\Modules\ModBusiness.cs" />
-    <Compile Include="Layers\Modules\ModData.cs" />
-    <Compile Include="Layers\Modules\ModGlobal.cs" />
-    <Compile Include="Layers\Modules\Module.cs" />
-    <Compile Include="Program.cs" />
-    <Compile Include="Properties\AssemblyInfo.cs" />
-    <Compile Include="Layers\TestLayers.cs" />
-  </ItemGroup>
-  <ItemGroup>
-    <None Include="App.config" />
-    <None Include="packages.config" />
-    <None Include="quadarax_strong_name_key.pfx" />
-  </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\Infrastructure\Infrastructure.csproj">
-      <Project>{9b070374-98a3-4122-85dd-cf5ab5e4b503}</Project>
-      <Name>Infrastructure</Name>
-    </ProjectReference>
-  </ItemGroup>
-  <ItemGroup />
-  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{60DDDF9B-507A-4665-8A5B-1F670005727F}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>_Workbench</RootNamespace>
+    <AssemblyName>%40Workbench</AssemblyName>
+    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+    <Deterministic>true</Deterministic>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
+    <SignAssembly>true</SignAssembly>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
+    <AssemblyOriginatorKeyFile>quadarax_strong_name_key.pfx</AssemblyOriginatorKeyFile>
+  </PropertyGroup>
+  <PropertyGroup>
+    <SignAssembly>true</SignAssembly>
+  </PropertyGroup>
+  <PropertyGroup>
+    <AssemblyOriginatorKeyFile>quadarax_strong_name_key.pfx</AssemblyOriginatorKeyFile>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
+      <HintPath>..\Infrastructure\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
+    </Reference>
+    <Reference Include="QDR.FND.Common, Version=1.0.0.7, Culture=neutral, PublicKeyToken=60b8fdcb29a015db, processorArchitecture=MSIL">
+      <HintPath>..\Infrastructure\packages\Quadarax.Foundation.Common.1.0.0.7\lib\net472\QDR.FND.Common.dll</HintPath>
+    </Reference>
+    <Reference Include="StructureMap, Version=4.7.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <HintPath>..\Infrastructure\packages\StructureMap.4.7.1\lib\net45\StructureMap.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Layers\DefaultBusinessLayer.cs" />
+    <Compile Include="Layers\DefaultDataLayer.cs" />
+    <Compile Include="Layers\DefaultGlobalLayer.cs" />
+    <Compile Include="Layers\Modules\IModBuss.cs" />
+    <Compile Include="Layers\Modules\IModData.cs" />
+    <Compile Include="Layers\Modules\IModGlobal.cs" />
+    <Compile Include="Layers\Modules\ModBusiness.cs" />
+    <Compile Include="Layers\Modules\ModData.cs" />
+    <Compile Include="Layers\Modules\ModGlobal.cs" />
+    <Compile Include="Layers\Modules\Module.cs" />
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Layers\TestLayers.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+    <None Include="packages.config" />
+    <None Include="quadarax_strong_name_key.pfx" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\Infrastructure\Infrastructure.csproj">
+      <Project>{9b070374-98a3-4122-85dd-cf5ab5e4b503}</Project>
+      <Name>Infrastructure</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup />
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 0 - 0
@Workbench/App.config → @Legacy/@Workbench/App.config


+ 0 - 0
@Workbench/Layers/DefaultBusinessLayer.cs → @Legacy/@Workbench/Layers/DefaultBusinessLayer.cs


+ 0 - 0
@Workbench/Layers/DefaultDataLayer.cs → @Legacy/@Workbench/Layers/DefaultDataLayer.cs


+ 0 - 0
@Workbench/Layers/DefaultGlobalLayer.cs → @Legacy/@Workbench/Layers/DefaultGlobalLayer.cs


+ 0 - 0
@Workbench/Layers/Modules/IModBuss.cs → @Legacy/@Workbench/Layers/Modules/IModBuss.cs


+ 0 - 0
@Workbench/Layers/Modules/IModData.cs → @Legacy/@Workbench/Layers/Modules/IModData.cs


+ 0 - 0
@Workbench/Layers/Modules/IModGlobal.cs → @Legacy/@Workbench/Layers/Modules/IModGlobal.cs


+ 0 - 0
@Workbench/Layers/Modules/ModBusiness.cs → @Legacy/@Workbench/Layers/Modules/ModBusiness.cs


+ 0 - 0
@Workbench/Layers/Modules/ModData.cs → @Legacy/@Workbench/Layers/Modules/ModData.cs


+ 0 - 0
@Workbench/Layers/Modules/ModGlobal.cs → @Legacy/@Workbench/Layers/Modules/ModGlobal.cs


+ 0 - 0
@Workbench/Layers/Modules/Module.cs → @Legacy/@Workbench/Layers/Modules/Module.cs


+ 0 - 0
@Workbench/Layers/TestLayers.cs → @Legacy/@Workbench/Layers/TestLayers.cs


+ 0 - 0
@Workbench/Program.cs → @Legacy/@Workbench/Program.cs


+ 0 - 0
@Workbench/Properties/AssemblyInfo.cs → @Legacy/@Workbench/Properties/AssemblyInfo.cs


+ 0 - 0
@Workbench/packages.config → @Legacy/@Workbench/packages.config


+ 0 - 0
@Workbench/quadarax_strong_name_key.pfx → @Legacy/@Workbench/quadarax_strong_name_key.pfx


+ 14 - 0
@Workbench/JsonDocument/JsonDocument.csproj

@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net7.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\..\qdr.fnd.core\qdr.fnd.core.csproj" />
+  </ItemGroup>
+
+</Project>

+ 36 - 0
@Workbench/JsonDocument/JsonDocument.sln

@@ -0,0 +1,36 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.7.34031.279
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonDocument", "JsonDocument.csproj", "{6C051D9E-E896-4E04-A456-3961F870D976}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Qdr.Fnd", "Qdr.Fnd", "{8BBFC68B-D225-45DD-BCDF-E64E9AFE2C07}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "qdr.fnd.core", "..\..\qdr.fnd.core\qdr.fnd.core.csproj", "{F431407D-713C-4A68-B617-59D5DC635803}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{6C051D9E-E896-4E04-A456-3961F870D976}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{6C051D9E-E896-4E04-A456-3961F870D976}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{6C051D9E-E896-4E04-A456-3961F870D976}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{6C051D9E-E896-4E04-A456-3961F870D976}.Release|Any CPU.Build.0 = Release|Any CPU
+		{F431407D-713C-4A68-B617-59D5DC635803}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{F431407D-713C-4A68-B617-59D5DC635803}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{F431407D-713C-4A68-B617-59D5DC635803}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{F431407D-713C-4A68-B617-59D5DC635803}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(NestedProjects) = preSolution
+		{F431407D-713C-4A68-B617-59D5DC635803} = {8BBFC68B-D225-45DD-BCDF-E64E9AFE2C07}
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {B96D4ABA-E7CE-46E0-913E-67149F3A5292}
+	EndGlobalSection
+EndGlobal

+ 20 - 0
@Workbench/JsonDocument/Program.cs

@@ -0,0 +1,20 @@
+// See https://aka.ms/new-console-template for more information
+
+using System.Text.Json;
+using Quadarax.Foundation.Core.Json.Extensions;
+
+Console.WriteLine("Hello, World!");
+
+var data1 = "{\"Name\" : \"Dalibor Votruba\", \"Age\" : 23, \"IsGood\" : false}";
+var data2 = "{\"Name\" : \"Dalibor Votruba\", \"Age\" : 43, \"IsGood\" : false}";
+var data3 = "{\"Name\" : \"Daliborx Votruba\", \"IsGood\" : true}";
+
+
+var json1 = JsonDocument.Parse(data1);
+var json2 = JsonDocument.Parse(data2);
+var json3 = JsonDocument.Parse(data3);
+
+var res1 = json1.Diff(json2);
+var res2 = json1.Diff(json3);
+
+Console.ReadKey();

+ 91 - 0
qdr.fnd.core/Json/Extensions/JsonDocumentExt.cs

@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Text.Json;
+
+namespace Quadarax.Foundation.Core.Json.Extensions
+{
+    public static class JsonDocumentExt
+    {
+
+        public static IDictionary<string, DiffOccurrence> Diff(this JsonDocument src, JsonDocument trg)
+        {
+            if (src == null) throw new ArgumentNullException(nameof(src));
+            if (trg == null) throw new ArgumentNullException(nameof(trg));
+
+            var result = new Dictionary<string, DiffOccurrence>();
+
+            var srcEnumerator = src.RootElement.EnumerateObject();
+            var trgEnumerator = trg.RootElement.EnumerateObject();
+            while (srcEnumerator.MoveNext())
+            {
+                var srcProperty = srcEnumerator.Current;
+                var trgProperty = Find(srcProperty.Name, trgEnumerator.GetEnumerator());
+
+                if (trgProperty == null)
+                    result.Add(srcProperty.Name, new DiffOccurrence(srcProperty.Name, DiffTypeEnum.TrgMissing, srcProperty.Value.GetRawText(), null));
+                else if (!string.Equals(srcProperty.Value.GetRawText(), trgProperty.Value.Value.GetRawText(),StringComparison.InvariantCultureIgnoreCase))
+                        result.Add(srcProperty.Name, new DiffOccurrence(srcProperty.Name, DiffTypeEnum.Different, srcProperty.Value.GetRawText(), trgProperty.Value.Value.GetRawText()));
+            }
+
+            while (trgEnumerator.MoveNext())
+            {
+                var trgProperty = trgEnumerator.Current;
+                var srcProperty = Find(trgProperty.Name, srcEnumerator.GetEnumerator());
+                if (srcProperty == null)
+                {
+                    result.Add(trgProperty.Name, new DiffOccurrence(trgProperty.Name, DiffTypeEnum.SrcMissing, null, trgProperty.Value.ToString()));
+                }
+            }
+
+            return result;
+        }
+
+        private static JsonProperty? Find(string name, IEnumerator<JsonProperty> enumerator)
+        {
+            while (enumerator.MoveNext())
+            {
+                var property = enumerator.Current;
+                if (property.Name.Equals(name,StringComparison.InvariantCultureIgnoreCase))
+                    return property;
+            }
+            return null;
+        }
+
+        #region *** Nested classes ***
+
+        public class DiffOccurrence
+        {
+            public string Name { get; private set; }
+            public DiffTypeEnum DiffType { get; private set; }
+            public string? SrcValue { get; private set; }
+            public string? TrgValue { get; private set; }
+
+            public DiffOccurrence(string name, DiffTypeEnum diffType, string? srcValue, string? trgValue)
+            {
+                if (string.IsNullOrEmpty(name))
+                    throw new ArgumentNullException(nameof(name));
+                Name = name;
+                DiffType = diffType;
+                SrcValue = srcValue;
+                TrgValue = trgValue;
+            }
+            
+            public override string ToString()
+            {
+                var sb = new StringBuilder();
+                sb.Append("Name=").Append(Name).Append(";DiffType=").Append(DiffType);
+                return sb.ToString();
+            }
+        }
+
+        public enum DiffTypeEnum
+        {
+            SrcMissing,
+            TrgMissing,
+            Different
+        }
+
+        #endregion
+    }
+}

+ 2 - 1
qdr.fnd.core/releasenotes.md

@@ -2,11 +2,12 @@
 Ordered by version descending
 
 ## 0.0.2.0
-Date:__27.9.2023__
+Date:__30.9.2023__
 - extends Thread/LoopWorker to support external ansync iteration body expression
 - fix Thread/ContiguousWorker to support external ansync iteration body expression
 - add Thread/BasicWorkerContext and extends IWorkerContext to stores CancellationToken
 - extends Thread/AbstractWorker to work with default IWorkerContext, make public AbstractWorker.Context
+- add Json/Extensions/JsonDocumentExt.Diff function to compare two JsonDocument
 - fix quality CA
 - minor fixes
 ---