From e30ebfcd266458b457f7e5f8101c9302a04032c1 Mon Sep 17 00:00:00 2001 From: Michael Kirschner Date: Wed, 17 Jul 2024 20:15:49 -0400 Subject: [PATCH 1/2] do not use TypeNameHandling.Auto when deserializing (#15390) --- .editorconfig | 5 ++ src/DynamoCore/DynamoCore.csproj | 4 ++ src/DynamoCore/Graph/Nodes/DummyNode.cs | 4 +- .../Graph/Workspaces/WorkspaceModel.cs | 6 +-- src/DynamoCore/Models/DynamoModel.cs | 2 +- src/DynamoCore/Models/RecordableCommands.cs | 53 ------------------- src/DynamoCore/PublicAPI.Unshipped.txt | 1 - .../Watch3D/HelixWatch3DViewModel.cs | 2 +- .../Models/RecordableCommandsTest.cs | 22 +++----- 9 files changed, 22 insertions(+), 77 deletions(-) diff --git a/.editorconfig b/.editorconfig index ab40da7cb8e..90cf6ec6a8b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,6 +10,11 @@ end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true +dotnet_diagnostic.CA2327.severity = error +dotnet_diagnostic.CA2329.severity = error +dotnet_diagnostic.CA2330.severity = error +dotnet_diagnostic.CA2328.severity = error +dotnet_diagnostic.CA2326.severity = warning [*.tt] insert_final_newline = false diff --git a/src/DynamoCore/DynamoCore.csproj b/src/DynamoCore/DynamoCore.csproj index 305c7db289e..9a8babf22fe 100644 --- a/src/DynamoCore/DynamoCore.csproj +++ b/src/DynamoCore/DynamoCore.csproj @@ -181,4 +181,8 @@ + + true + All + diff --git a/src/DynamoCore/Graph/Nodes/DummyNode.cs b/src/DynamoCore/Graph/Nodes/DummyNode.cs index cdb6e214c12..5f9cd437aee 100644 --- a/src/DynamoCore/Graph/Nodes/DummyNode.cs +++ b/src/DynamoCore/Graph/Nodes/DummyNode.cs @@ -1,4 +1,4 @@ -using Autodesk.DesignScript.Runtime; +using Autodesk.DesignScript.Runtime; using Dynamo.Core; using Dynamo.Engine; using Dynamo.Graph.Nodes.NodeLoaders; @@ -546,7 +546,7 @@ internal NodeModel GetNodeModelForDummyNode(string json, LibraryServices library Console.WriteLine(args.ErrorContext.Error); }, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - TypeNameHandling = TypeNameHandling.Auto, + TypeNameHandling = TypeNameHandling.None, Formatting = Newtonsoft.Json.Formatting.Indented, Culture = CultureInfo.InvariantCulture, Converters = new List{ diff --git a/src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs b/src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs index e447d1e2431..bc856d3685b 100644 --- a/src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs +++ b/src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs @@ -70,7 +70,7 @@ static internal ExtraWorkspaceViewInfo ExtraWorkspaceViewInfoFromJson(string jso Console.WriteLine(args.ErrorContext.Error); }, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - TypeNameHandling = TypeNameHandling.Auto, + TypeNameHandling = TypeNameHandling.None, Formatting = Newtonsoft.Json.Formatting.Indented, Culture = CultureInfo.InvariantCulture }; @@ -2289,7 +2289,7 @@ public static WorkspaceModel FromJson(string json, LibraryServices libraryServic Console.WriteLine(args.ErrorContext.Error); }, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - TypeNameHandling = TypeNameHandling.Auto, + TypeNameHandling = TypeNameHandling.None, Formatting = Newtonsoft.Json.Formatting.Indented, Culture = CultureInfo.InvariantCulture, Converters = new List{ @@ -2326,7 +2326,7 @@ public static WorkspaceModel FromJson(string json, LibraryServices libraryServic Console.WriteLine(args.ErrorContext.Error); }, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - TypeNameHandling = TypeNameHandling.Auto, + TypeNameHandling = TypeNameHandling.None, Formatting = Newtonsoft.Json.Formatting.Indented, Culture = CultureInfo.InvariantCulture, Converters = new List{ diff --git a/src/DynamoCore/Models/DynamoModel.cs b/src/DynamoCore/Models/DynamoModel.cs index c9897a9f28e..e233387a79f 100644 --- a/src/DynamoCore/Models/DynamoModel.cs +++ b/src/DynamoCore/Models/DynamoModel.cs @@ -2118,7 +2118,7 @@ static private DynamoPreferencesData DynamoPreferencesDataFromJson(string json) Console.WriteLine(args.ErrorContext.Error); }, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - TypeNameHandling = TypeNameHandling.Auto, + TypeNameHandling = TypeNameHandling.None, Formatting = Newtonsoft.Json.Formatting.Indented, Culture = CultureInfo.InvariantCulture }; diff --git a/src/DynamoCore/Models/RecordableCommands.cs b/src/DynamoCore/Models/RecordableCommands.cs index c866aeb5eea..33250cac9ed 100644 --- a/src/DynamoCore/Models/RecordableCommands.cs +++ b/src/DynamoCore/Models/RecordableCommands.cs @@ -31,24 +31,6 @@ public abstract class RecordableCommand // See property for more details. protected bool redundant = false; - /// - /// Settings that is used for serializing commands - /// - protected static JsonSerializerSettings jsonSettings; - - /// - /// Initialize commands serializing settings - /// - static RecordableCommand() - { - jsonSettings = new JsonSerializerSettings() - { - TypeNameHandling = TypeNameHandling.Objects, - ContractResolver = new CamelCasePropertyNamesContractResolver(), - Culture = CultureInfo.InvariantCulture - }; - } - #endregion #region Public Class Operational Methods @@ -109,18 +91,6 @@ internal XmlElement Serialize(XmlDocument document) return element; } - /// - /// This method serializes the RecordableCommand object in the json form. - /// The resulting string contains command type name and all the - /// arguments that are required by this command. - /// - /// The string can be used for reconstructing RecordableCommand - /// using Deserialize method - internal string Serialize() - { - return JsonConvert.SerializeObject(this, jsonSettings); - } - /// /// Call this static method to reconstruct a RecordableCommand-derived /// object given an XmlElement that was previously saved with Serialize @@ -220,29 +190,6 @@ internal static RecordableCommand Deserialize(XmlElement element) throw new ArgumentException(message); } - /// - /// Call this static method to reconstruct a RecordableCommand from json - /// string that contains command name - name of corresponding class inherited - /// from RecordableCommand, - and all the arguments that are required by this - /// command. - /// - /// Json string that contains command name and all - /// its arguments. - /// Reconstructed RecordableCommand - internal static RecordableCommand Deserialize(string jsonString) - { - RecordableCommand command = null; - try - { - command = JsonConvert.DeserializeObject(jsonString, jsonSettings) as RecordableCommand; - command.IsInPlaybackMode = true; - return command; - } - catch - { - throw new ApplicationException("Invalid jsonString for creating RecordableCommand"); - } - } #endregion #region Public Command Properties diff --git a/src/DynamoCore/PublicAPI.Unshipped.txt b/src/DynamoCore/PublicAPI.Unshipped.txt index cfa65c57d11..6a7e843509b 100644 --- a/src/DynamoCore/PublicAPI.Unshipped.txt +++ b/src/DynamoCore/PublicAPI.Unshipped.txt @@ -2723,7 +2723,6 @@ static Dynamo.Models.DynamoModel.IsTestMode.set -> void static Dynamo.Models.DynamoModel.ModelBasedRecordableCommand.DeserializeGuid(System.Xml.XmlElement element, Dynamo.Utilities.XmlElementHelper helper) -> System.Collections.Generic.IEnumerable static Dynamo.Models.DynamoModel.OnRequestDispatcherBeginInvoke(System.Action action) -> void static Dynamo.Models.DynamoModel.OnRequestDispatcherInvoke(System.Action action) -> void -static Dynamo.Models.DynamoModel.RecordableCommand.jsonSettings -> Newtonsoft.Json.JsonSerializerSettings static Dynamo.Models.DynamoModel.RequestDispatcherBeginInvoke -> Dynamo.Models.ActionHandler static Dynamo.Models.DynamoModel.RequestDispatcherInvoke -> Dynamo.Models.ActionHandler static Dynamo.Models.DynamoModel.SetUICulture(string locale) -> void diff --git a/src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs b/src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs index c9dea063d99..00dbb0f6cf5 100644 --- a/src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs @@ -794,7 +794,7 @@ protected override void OnWorkspaceOpening(object obj) Console.WriteLine(args.ErrorContext.Error); }, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - TypeNameHandling = TypeNameHandling.Auto, + TypeNameHandling = TypeNameHandling.None, Formatting = Newtonsoft.Json.Formatting.Indented, Culture = CultureInfo.InvariantCulture }; diff --git a/test/DynamoCoreTests/Models/RecordableCommandsTest.cs b/test/DynamoCoreTests/Models/RecordableCommandsTest.cs index 3c6c1fa30d5..64d42783272 100644 --- a/test/DynamoCoreTests/Models/RecordableCommandsTest.cs +++ b/test/DynamoCoreTests/Models/RecordableCommandsTest.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Xml; @@ -53,12 +53,12 @@ public void TestRecordableCommand() //The tag passed as parameter is null, then it will raise an exception later var cmd = new Mock(null); var pausePlaybackCommand = new DynamoModel.PausePlaybackCommand(20); - + var xmldoc= new XmlDocument(); //Act - var xmlElements = pausePlaybackCommand.Serialize(); - + var xmlElements = pausePlaybackCommand.Serialize(xmldoc); + //Assert - Assert.IsNotNull(JToken.Parse(xmlElements));//Verify that the json serialized is valid + Assert.IsNotNull(xmlElements); //This will execute the exception section in RecordableCommand(string tag), because tag is null Assert.Throws(() => executive.ExecuteCommand(cmd.Object, "TestRecordable", "ExtensionTests")); @@ -92,8 +92,7 @@ public void TestRecordableCommandDeserialize() XmlDocument xmlDocument = new XmlDocument(); XmlElement elementAddPresetCommand = AddPresetCommand.Serialize(xmlDocument); - var jsonAddPresetCommand = AddPresetCommand.Serialize(); - + var xmlAddPresetCommand = AddPresetCommand.Serialize(xmlDocument); var helper = new XmlElementHelper(elementAddPresetCommand); Guid gWorkspace = Guid.NewGuid(); @@ -109,12 +108,6 @@ public void TestRecordableCommandDeserialize() var deserializedAddPresetCommand = DynamoModel.RecordableCommand.Deserialize(elementAddPresetCommand); var deserializedApplyPresetCommand = DynamoModel.RecordableCommand.Deserialize(elementApplyPresetCommand); - //This will execute the overloaded Deserialize method (the one receiving a string as parameter) - var deserializedFromJson = DynamoModel.RecordableCommand.Deserialize(jsonAddPresetCommand); - - //This will generate a invalid json string, so when it's deserialized will raise an exception - jsonAddPresetCommand = jsonAddPresetCommand.Replace('{', '<'); - //This is a fake command so when it's deserialized will raise an exception XmlElement elemTest = xmlDocument.CreateElement("TestCommand"); Assert.Throws(() => DynamoModel.RecordableCommand.Deserialize(elemTest)); @@ -123,9 +116,6 @@ public void TestRecordableCommandDeserialize() //This will check that the Deserialized commands are valid Assert.IsNotNull(deserializedAddPresetCommand); Assert.IsNotNull(deserializedApplyPresetCommand); - Assert.IsNotNull(deserializedFromJson); - Assert.Throws(() => DynamoModel.RecordableCommand.Deserialize(jsonAddPresetCommand)); - } } From 3c17f6b6276800e83d20661e3586ee65874100ff Mon Sep 17 00:00:00 2001 From: Aabishkar KC Date: Thu, 18 Jul 2024 15:00:37 -0400 Subject: [PATCH 2/2] Update issue_type_predicter.yml (#15398) --- .github/workflows/issue_type_predicter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/issue_type_predicter.yml b/.github/workflows/issue_type_predicter.yml index 552eed7b3cb..afb215b8532 100644 --- a/.github/workflows/issue_type_predicter.yml +++ b/.github/workflows/issue_type_predicter.yml @@ -89,7 +89,7 @@ jobs: - name: Run Issues Type Predicter if: env.analysis_response == 'Valid' run: | - echo "is_wish_list="$(dotnet run -p ./IssuesTypePredicter/IssuesTypePredicterML.ConsoleApp/IssuesTypePredicterML.ConsoleApp.csproj -v q "${{ env.issue_json_string }}")"" >> $GITHUB_ENV + echo "is_wish_list="$(dotnet run --project ./IssuesTypePredicter/IssuesTypePredicterML.ConsoleApp/IssuesTypePredicterML.ConsoleApp.csproj -v q "${{ env.issue_json_string }}")"" >> $GITHUB_ENV # If the is_wish_list variable contains 1, label the issue as "Wishlist" - name: Label issue as 'Wishlist'