Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, default);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feature default literal is not available in C# 7.0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. Fixed.

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