Skip to content

Commit 83d920a

Browse files
idear1203Dongwei Wang
andauthored
[Synapse] - Fixed deserialization error when create Pipeline/Dataset/Trigger through DefinitionFile (#13721)
* Remove using Newtonsoft.Json and JsonObject * update client and cmdlets * Remove more Newtonsoft annotation * remove ToSdkObject and SetProperties * update artifacts client * Remove JsonProperty * remove unused sub-classes * remove internal properties * Update artifacts dependency version * Fix the default literal issue Co-authored-by: Dongwei Wang <[email protected]>
1 parent 91f1b75 commit 83d920a

File tree

265 files changed

+59
-22929
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

265 files changed

+59
-22929
lines changed

src/Synapse/Synapse/Commands/DataPlaneCommands/Artifact/Notebooks/ExportAzureSynapseNotebook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public override void ExecuteCmdlet()
8888

8989
private void WriteToFile(PSNotebookResource notebook)
9090
{
91-
string json = JsonConvert.SerializeObject(notebook.Properties, Formatting.Indented);
91+
string json = Newtonsoft.Json.JsonConvert.SerializeObject(notebook.Properties, Formatting.Indented);
9292
File.WriteAllText(Path.Combine(this.OutputFolder, notebook.Name + ".ipynb"), json);
9393
}
9494
}

src/Synapse/Synapse/Commands/DataPlaneCommands/Artifact/Notebooks/SetAzureSynapseNotebook.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Microsoft.Azure.Commands.Synapse.Models;
66
using Microsoft.Azure.Commands.Synapse.Properties;
77
using Microsoft.WindowsAzure.Commands.Utilities.Common;
8-
using Newtonsoft.Json;
98
using System;
109
using System.IO;
1110
using System.Management.Automation;
@@ -80,11 +79,17 @@ public override void ExecuteCmdlet()
8079
this.WorkspaceName = this.WorkspaceObject.Name;
8180
}
8281

82+
if (!this.IsParameterBound(c => c.Name))
83+
{
84+
string path = this.TryResolvePath(DefinitionFile);
85+
this.Name = Path.GetFileNameWithoutExtension(path);
86+
}
87+
8388
if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.SettingSynapseNotebook, this.Name, this.WorkspaceName)))
8489
{
8590
string rawJsonContent = SynapseAnalyticsClient.ReadJsonFileContent(this.TryResolvePath(DefinitionFile));
86-
PSNotebook pSNotebook = JsonConvert.DeserializeObject<PSNotebook>(rawJsonContent);
87-
NotebookResource notebookResource = new NotebookResource(pSNotebook.ToSdkObject());
91+
Notebook notebook = JsonConvert.DeserializeObject<Notebook>(rawJsonContent);
92+
NotebookResource notebookResource = new NotebookResource(this.Name, notebook);
8893

8994
if (this.IsParameterBound(c => c.SparkPoolName))
9095
{
@@ -115,11 +120,6 @@ public override void ExecuteCmdlet()
115120
notebookResource.Properties.SessionProperties = new NotebookSessionProperties(options["memory"] + "g", (int)options["cores"], options["memory"] + "g", (int)options["cores"], (int)options["nodeCount"]);
116121
}
117122

118-
if (!this.IsParameterBound(c => c.Name))
119-
{
120-
string path = this.TryResolvePath(DefinitionFile);
121-
this.Name = Path.GetFileNameWithoutExtension(path);
122-
}
123123
WriteObject(new PSNotebookResource(SynapseAnalyticsClient.CreateOrUpdateNotebook(this.Name, notebookResource), this.WorkspaceName));
124124
}
125125
}

src/Synapse/Synapse/Commands/DataPlaneCommands/Artifact/PipelineRuns/InvokeAzureSynapsePipeline.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
using Microsoft.Azure.Commands.Synapse.Models;
44
using Microsoft.Azure.Commands.Synapse.Properties;
55
using Microsoft.WindowsAzure.Commands.Utilities.Common;
6-
using Newtonsoft.Json;
76
using System;
87
using System.Collections;
98
using System.Collections.Generic;
109
using System.Linq;
1110
using System.Management.Automation;
11+
using JsonConvert = Newtonsoft.Json.JsonConvert;
1212

1313
namespace Microsoft.Azure.Commands.Synapse
1414
{
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.IO;
2+
using System.Reflection;
3+
using System.Text.Json;
4+
5+
namespace Microsoft.Azure.Commands.Synapse.Common
6+
{
7+
internal static class JsonConvert
8+
{
9+
internal static T DeserializeObject<T>(string rawJsonContent)
10+
{
11+
var document = JsonDocument.Parse(rawJsonContent);
12+
MethodInfo deserializer = typeof(T).GetMethod($"Deserialize{typeof(T).Name}", BindingFlags.NonPublic | BindingFlags.Static);
13+
return (T) deserializer.Invoke(null, new object[] { document.RootElement });
14+
}
15+
16+
internal static string SerializeObject(object obj)
17+
{
18+
// TODO: in future, we might consider to add option to allow users to specify JSON writer options.
19+
using (MemoryStream memoryStream = new MemoryStream())
20+
using (Utf8JsonWriter writer = new Utf8JsonWriter(memoryStream, new JsonWriterOptions { Indented = true }))
21+
{
22+
SerializeObject(obj, writer);
23+
return memoryStream.ToString();
24+
}
25+
}
26+
27+
internal static void SerializeObject(object obj, string outputPath)
28+
{
29+
using (FileStream writeStream = File.Open(outputPath, FileMode.Create))
30+
using (Utf8JsonWriter writer = new Utf8JsonWriter(writeStream))
31+
{
32+
SerializeObject(obj, writer);
33+
}
34+
}
35+
36+
internal static void SerializeObject(object obj, Utf8JsonWriter writer)
37+
{
38+
MethodInfo serializer = obj.GetType().GetMethod("Write", BindingFlags.NonPublic);
39+
serializer.Invoke(obj, new object[] { writer });
40+
}
41+
}
42+
}

src/Synapse/Synapse/Models/Activity/PSActivityPolicy.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/Synapse/Synapse/Models/Activity/PSAppendVariableActivity.cs

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/Synapse/Synapse/Models/Activity/PSAzureDataExplorerCommandActivity.cs

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)