Skip to content

Commit

Permalink
[Synapse] - Fixed deserialization error when create Pipeline/Dataset/…
Browse files Browse the repository at this point in the history
…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 <dongwwa@microsoft.com>
  • Loading branch information
idear1203 and Dongwei Wang authored Dec 15, 2020
1 parent 91f1b75 commit 83d920a
Show file tree
Hide file tree
Showing 265 changed files with 59 additions and 22,929 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public override void ExecuteCmdlet()

private void WriteToFile(PSNotebookResource notebook)
{
string json = JsonConvert.SerializeObject(notebook.Properties, Formatting.Indented);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(notebook.Properties, Formatting.Indented);
File.WriteAllText(Path.Combine(this.OutputFolder, notebook.Name + ".ipynb"), json);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.Azure.Commands.Synapse.Models;
using Microsoft.Azure.Commands.Synapse.Properties;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Management.Automation;
Expand Down Expand Up @@ -80,11 +79,17 @@ public override void ExecuteCmdlet()
this.WorkspaceName = this.WorkspaceObject.Name;
}

if (!this.IsParameterBound(c => c.Name))
{
string path = this.TryResolvePath(DefinitionFile);
this.Name = Path.GetFileNameWithoutExtension(path);
}

if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.SettingSynapseNotebook, this.Name, this.WorkspaceName)))
{
string rawJsonContent = SynapseAnalyticsClient.ReadJsonFileContent(this.TryResolvePath(DefinitionFile));
PSNotebook pSNotebook = JsonConvert.DeserializeObject<PSNotebook>(rawJsonContent);
NotebookResource notebookResource = new NotebookResource(pSNotebook.ToSdkObject());
Notebook notebook = JsonConvert.DeserializeObject<Notebook>(rawJsonContent);
NotebookResource notebookResource = new NotebookResource(this.Name, notebook);

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

if (!this.IsParameterBound(c => c.Name))
{
string path = this.TryResolvePath(DefinitionFile);
this.Name = Path.GetFileNameWithoutExtension(path);
}
WriteObject(new PSNotebookResource(SynapseAnalyticsClient.CreateOrUpdateNotebook(this.Name, notebookResource), this.WorkspaceName));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
using Microsoft.Azure.Commands.Synapse.Models;
using Microsoft.Azure.Commands.Synapse.Properties;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using JsonConvert = Newtonsoft.Json.JsonConvert;

namespace Microsoft.Azure.Commands.Synapse
{
Expand Down
42 changes: 42 additions & 0 deletions src/Synapse/Synapse/Common/JsonConvert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.IO;
using System.Reflection;
using System.Text.Json;

namespace Microsoft.Azure.Commands.Synapse.Common
{
internal static class JsonConvert
{
internal static T DeserializeObject<T>(string rawJsonContent)
{
var document = JsonDocument.Parse(rawJsonContent);
MethodInfo deserializer = typeof(T).GetMethod($"Deserialize{typeof(T).Name}", BindingFlags.NonPublic | BindingFlags.Static);
return (T) deserializer.Invoke(null, new object[] { document.RootElement });
}

internal static string SerializeObject(object obj)
{
// TODO: in future, we might consider to add option to allow users to specify JSON writer options.
using (MemoryStream memoryStream = new MemoryStream())
using (Utf8JsonWriter writer = new Utf8JsonWriter(memoryStream, new JsonWriterOptions { Indented = true }))
{
SerializeObject(obj, writer);
return memoryStream.ToString();
}
}

internal static void SerializeObject(object obj, string outputPath)
{
using (FileStream writeStream = File.Open(outputPath, FileMode.Create))
using (Utf8JsonWriter writer = new Utf8JsonWriter(writeStream))
{
SerializeObject(obj, writer);
}
}

internal static void SerializeObject(object obj, Utf8JsonWriter writer)
{
MethodInfo serializer = obj.GetType().GetMethod("Write", BindingFlags.NonPublic);
serializer.Invoke(obj, new object[] { writer });
}
}
}
44 changes: 0 additions & 44 deletions src/Synapse/Synapse/Models/Activity/PSActivityPolicy.cs

This file was deleted.

76 changes: 0 additions & 76 deletions src/Synapse/Synapse/Models/Activity/PSAppendVariableActivity.cs

This file was deleted.

This file was deleted.

Loading

0 comments on commit 83d920a

Please sign in to comment.