Repository navigation
Workspace and WorkspaceViewModel Serialization - #7953
Conversation
| /// we should add it to recent files. Otherwise leave it.</param> | ||
| /// <returns></returns> | ||
| public override bool Save(string newPath, bool isBackup = false) | ||
| public override void Save(string newPath, bool isBackup = false) |
There was a problem hiding this comment.
API Change. WorkspaceModel.Save now returns void.
| /// by looking it up in the CustomNodeManager. | ||
| /// </summary> | ||
| public class NodeModelConverter : JsonConverter | ||
| public class NodeReadConverter : JsonConverter |
There was a problem hiding this comment.
Potential API Change. Need to check if these converters were included in 1.3.
| public static string ToJson(this WorkspaceModel workspace, LibraryServices libraryServices, | ||
| EngineController engineController, DynamoScheduler scheduler, NodeFactory factory, | ||
| bool isTestMode, bool verboseLogging, CustomNodeManager manager) | ||
| public static string ToJson(this WorkspaceModel workspace) |
There was a problem hiding this comment.
API Change. The SerializationExtensions class has been added to provide the WorkspaceModel.ToJson(...) extension method.
| public event Action WorkspaceSaved; | ||
| protected virtual void OnWorkspaceSaved() | ||
| public event Action Saved; | ||
| internal virtual void OnSaved() |
There was a problem hiding this comment.
API change. The WorkspaceModel.WorkspaceSaved event is now WorkspaceModel.Saved.
| /// we should add it to recent files. Otherwise leave it.</param> | ||
| public virtual bool Save(string newPath, bool isBackup = false) | ||
| /// <exception cref="ArgumentNullException">Thrown when the file path is null.</exception> | ||
| public virtual void Save(string filePath, bool isBackup = false) |
There was a problem hiding this comment.
API change. Save now returns void. An Exception is thrown if an error occurs.
| /// <param name="path">The path to save to</param> | ||
| /// <param name="ws">workspace to save</param> | ||
| /// <param name="isBackup">indicate saving for backup</param> | ||
| public bool SaveWorkspace(string path, WorkspaceModel ws, bool isBackup = false) |
There was a problem hiding this comment.
API change. DynamoModel.SaveWorkspace(...) has been removed. Use WorkspaceModel.Save(...) instead.
| /// </summary> | ||
| /// <param name="viewModel"></param> | ||
| /// <returns>A JSON string representing the WorkspaceViewModel</returns> | ||
| public static string ToJson(this WorkspaceViewModel viewModel) |
There was a problem hiding this comment.
API change. WorkspaceViewModel.ToJson(...) has been added.
| /// </summary> | ||
| /// <param name="newPath">The path to save to</param> | ||
| /// <param name="isBackup">Indicates whether saved workspace is backup or not. If it's not backup, | ||
| /// <param name="filePath">The path the file.</param> |
| OnSaved(); | ||
| } | ||
|
|
||
| OnSaved(); |
There was a problem hiding this comment.
The OnSaved() in if seems redundant
There was a problem hiding this comment.
Good catch. This is a mistake.
| string fn = "ruthlessTurtles.dyn"; | ||
| string path = Path.Combine(TempFolder, fn); | ||
| CurrentDynamoModel.SaveWorkspace(path, CurrentDynamoModel.CurrentWorkspace); | ||
| CurrentDynamoModel.CurrentWorkspace.Save(path); |
There was a problem hiding this comment.
This was done to make multiple home workspaces easier in the future.
|
Restarting |
|
@ikeough Looks like there are a few minor build errors after merging with master branch: |
| /// construction and should not be serialized. | ||
| /// </summary> | ||
| public class WorkspaceConverter : JsonConverter | ||
| public class WorkspaceReadConverter : JsonConverter |
There was a problem hiding this comment.
Hey @ikeough I'm curious what the advantage was for splitting the converters into two?
There was a problem hiding this comment.
@mjkkirschner It's not being split in two. The workspace serialization doesn't need to use this converter. Trying to do so required references to dynamo model objects like the scheduler, which is not allowed in workspace. I removed this converter from the logic in ToJson(...), and changed the name to make it explicit that it's a converter for reading only.
Purpose
This PR adds two different modes for
Workspaceserialization:DynamoViewModelwhich in turn callsCurrentSpaceViewModel.Save. TheWorkspaceViewModelserialization first callsWorkspaceModel.ToJson(...), then injects theViewproperty whose value is the serialization of theWorkspaceViewModelinto the resulting json. Then the json is saved to the file.WorkspaceModel.SavethenWorkspaceModel.ToJsonis called, and the results are written directly to the file.A number of API changes have been made and are called out in comments below.
Declarations
Check these if you believe they are true
*.resxfilesReviewers
@QilongTang