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

DYN-4034 : open file from json content #12671

Merged
merged 5 commits into from
Mar 11, 2022
Merged

Conversation

BogdanZavu
Copy link
Contributor

@BogdanZavu BogdanZavu commented Mar 4, 2022

Purpose

Allow a workspace to be created from json content.
In Generative Design, we often work with multiple variants of the same graph for which currently we save a file on disk.
We want to avoid this as it is more efficient t work with the file content directly.

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated

Reviewers

@mjkkirschner @saintentropy

FYIs

@@ -1870,7 +1885,7 @@ private void SetPeriodicEvaluation(WorkspaceModel ws)
CustomNodeManager,
this.LinterManager);

workspace.FileName = filePath;
workspace.FileName = String.IsNullOrEmpty(filePath) ? "" : filePath;
Copy link
Member

Choose a reason for hiding this comment

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

what affect does this have? Isn't workspace.FileName going to end up being null "" or filepath in all cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just wanted to avoid having workspace.FileName set to null and set it to empty string instead so that I can mimic the exact FIleName setting of a new Home unsaved dyn file.

@@ -1852,7 +1864,10 @@ private void SetPeriodicEvaluation(WorkspaceModel ws)
bool forceManualExecutionMode,
out WorkspaceModel workspace)
{
CustomNodeManager.AddUninitializedCustomNodesInPath(Path.GetDirectoryName(filePath), IsTestMode);
if (!String.IsNullOrEmpty(filePath))
Copy link
Member

Choose a reason for hiding this comment

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

I guess this is good to do, though unnecessary as ScanNodeHeadersInDirectory already checks the directory exists and logs something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, will remove

@mjkkirschner
Copy link
Member

Looks good @BogdanZavu -

  • just one a few small comments,
  • and some code that I think is from another PR.
  • Can we also add a test for the method - that loads some JSON from a string, and asserts the graph is loaded correctly?

@saintentropy
Copy link
Contributor

LGTM @BogdanZavu with test from Mike's comment

@@ -1852,7 +1864,10 @@ private void SetPeriodicEvaluation(WorkspaceModel ws)
bool forceManualExecutionMode,
out WorkspaceModel workspace)
{
CustomNodeManager.AddUninitializedCustomNodesInPath(Path.GetDirectoryName(filePath), IsTestMode);
if (!string.IsNullOrEmpty(filePath))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this check back because Path.GetDirectoryName throws when filePath is null.

{
// Log file open action and the number of nodes in the opened workspace
Dynamo.Logging.Analytics.TrackFileOperationEvent(
dynamoModel.CurrentWorkspace.Name,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we use something else here since Name will be an empty string ?

Copy link
Member

Choose a reason for hiding this comment

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

does this match the implementation/result for disk based file open?

Copy link
Member

Choose a reason for hiding this comment

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

ah, I see, the other uses filepath - maybe something that notes this is in memory open.

@BogdanZavu
Copy link
Contributor Author

@mjkkirschner @saintentropy I added a command as well to be more inline with the regular OpenFileCommand and to benefit from the AskForSave utility on the Dynamo side. Please take another look

@@ -144,6 +144,9 @@ internal static RecordableCommand Deserialize(XmlElement element)
case "OpenFileCommand":
command = OpenFileCommand.DeserializeCore(element);
break;
case "OpenFileFromJsonCommand":
Copy link
Member

Choose a reason for hiding this comment

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

can you use nameof?

errorMsgString = String.Format(Resources.MessageUnkownErrorOpeningFile, "Json file content");
}
model.Logger.LogNotification("Dynamo", commandString, errorMsgString, e.ToString());
System.Windows.MessageBox.Show(errorMsgString);
Copy link
Member

Choose a reason for hiding this comment

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

I think we want to use the new themed dialog box where possible - @QilongTang @RobertGlobant20 can you point to an example of this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -1541,17 +1633,42 @@ private bool CanOpen(object parameters)
return PathHelper.IsValidPath(filePath);
}

private bool CanOpenFromJson(object parameters)
Copy link
Member

Choose a reason for hiding this comment

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

what about reusing this helper?

public static bool isValidJson(string path, out string fileContents, out Exception ex)

Copy link
Contributor

Choose a reason for hiding this comment

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

Please reuse the helper, I put a lot of thoughts into it.. Feel free to update as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -52,6 +52,8 @@ private static void RegisterDebugModes()

internal static void LoadDebugModesStatusFromConfig(string configPath)
{
if (!File.Exists(configPath)) return;
Copy link
Member

Choose a reason for hiding this comment

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

👍

@BogdanZavu BogdanZavu merged commit d5bc36b into DynamoDS:master Mar 11, 2022
@BogdanZavu BogdanZavu deleted the DYN-4034 branch March 11, 2022 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants