Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AGD-1882] Support storing user defined graph documentation #11444

Merged
Show file tree
Hide file tree
Changes from 5 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
25 changes: 25 additions & 0 deletions src/DynamoCore/Graph/Workspaces/SerializationConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,19 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist

ws.NodeLibraryDependencies = nodeLibraryDependencies.ToList();
ws.ExtensionData = GetExtensionData(serializer, obj);
if (obj.TryGetValue(nameof(WorkspaceModel.Thumbnail), StringComparison.OrdinalIgnoreCase, out JToken thumbnail))
ws.Thumbnail = thumbnail.ToString();

if (obj.TryGetValue(nameof(WorkspaceModel.GraphDocumentationURL), StringComparison.OrdinalIgnoreCase, out JToken helpLink))
{
if (Uri.TryCreate(helpLink.ToString(), UriKind.Absolute, out Uri uri))
ws.GraphDocumentationURL = uri;
}


if (obj.TryGetValue(nameof(WorkspaceModel.Author), StringComparison.OrdinalIgnoreCase, out JToken author))
ws.Author = author.ToString();


return ws;
}
Expand Down Expand Up @@ -771,6 +784,18 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
writer.WritePropertyName(WorkspaceReadConverter.EXTENSION_WORKSPACE_DATA);
serializer.Serialize(writer, ws.ExtensionData);

// Thumbnail
writer.WritePropertyName(nameof(WorkspaceModel.Thumbnail));
writer.WriteValue(ws.Thumbnail);

// GraphDocumentaionLink
writer.WritePropertyName(nameof(WorkspaceModel.GraphDocumentationURL));
writer.WriteValue(ws.GraphDocumentationURL);

// Graph Author
writer.WritePropertyName(nameof(WorkspaceModel.Author));
writer.WriteValue(ws.Author);

if (engine != null)
{
// Bindings
Expand Down
42 changes: 42 additions & 0 deletions src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ internal int CurrentPasteOffset
private DateTime lastSaved;
private string author = "None provided";
private string description;
private string thumbnail;
Copy link
Member

@mjkkirschner mjkkirschner Mar 18, 2021

Choose a reason for hiding this comment

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

before this gets merged- a quick thought, do all of these new properties make sense on both home workspaces and custom node workspaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tbh I hadn't considered that this also affected the CN workspace. Most of these probably don't make sense on the CN, maybe the Author is okay, but not sure i see the need for the others.

@nate-peters @saintentropy, any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, just noticed that its the same with the new ExtensionWorkspaceData not sure that makes sense in the CN workspace either?

private Uri graphDocumentationURL;
private bool hasUnsavedChanges;
private bool isReadOnly;
private readonly List<NodeModel> nodes;
Expand Down Expand Up @@ -724,6 +726,46 @@ public string Description
}
}

/// <summary>
/// Link to documentation page for this workspace
/// </summary>
public Uri GraphDocumentationURL
{
get { return graphDocumentationURL; }
set
{
if (graphDocumentationURL == value)
return;

graphDocumentationURL = value;
RaisePropertyChanged(nameof(GraphDocumentationURL));
}
}


/// <summary>
/// Workspace thumbnail as Base64 string.
/// Returns null if provide value is not Base64 encoded.
/// </summary>
public string Thumbnail
{
get { return thumbnail; }
set
{
try
{
// if value is not a valid Base64 string this will throw, and we return null.
byte[] data = Convert.FromBase64String(value);
thumbnail = value;
RaisePropertyChanged(nameof(Thumbnail));
}
catch
{
return;
}
}
}

/// <summary>
/// List of user defined data from extensions and view extensions stored in the graph
/// </summary>
Expand Down
30 changes: 30 additions & 0 deletions test/DynamoCoreTests/Graph/Workspaces/WorkspaceModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,35 @@ public void UpdateModelValueInvalidParameters()
Assert.AreEqual(Resources.ModelNotFoundError, ex3.Message);

}

[Test]
public void CanStoreBase64EncodedImageInThumbnailProperty()
{
// Arrange
var imagePath = Path.Combine(TestDirectory, @"DynamoCoreTests\Graph\Workspaces\thumbnailTestImage.png");
Assert.That(File.Exists(imagePath));

// Act
byte[] imageArray = System.IO.File.ReadAllBytes(imagePath);
string base64ImageRepresentation = Convert.ToBase64String(imageArray);
this.CurrentDynamoModel.CurrentWorkspace.Thumbnail = base64ImageRepresentation;

// Assert
Assert.NotNull(base64ImageRepresentation);
Assert.AreEqual(this.CurrentDynamoModel.CurrentWorkspace.Thumbnail, base64ImageRepresentation);
}

[Test]
public void WillNotStoreInvalidBase64StringInThumbnailProperty()
{
// Arrange
var invalidImagePath = "GenericString";

// Act
this.CurrentDynamoModel.CurrentWorkspace.Thumbnail = invalidImagePath;

// Assert
Assert.IsNull(this.CurrentDynamoModel.CurrentWorkspace.Thumbnail);
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.