Skip to content

Workspace and WorkspaceViewModel Serialization - #7953

Merged
ikeough merged 21 commits into
DynamoDS:masterfrom
ikeough:QNTM-687-a
Jun 13, 2017
Merged

ikeough merged 21 commits into
DynamoDS:masterfrom
ikeough:QNTM-687-a

Conversation

@ikeough

@ikeough ikeough commented Jun 12, 2017 •

Copy link
Copy Markdown
Contributor

Purpose

This PR adds two different modes for Workspace serialization:

  • If serialization is requested from the UI, it goes through DynamoViewModel which in turn calls CurrentSpaceViewModel.Save. The WorkspaceViewModel serialization first calls WorkspaceModel.ToJson(...), then injects the View property whose value is the serialization of the WorkspaceViewModel into the resulting json. Then the json is saved to the file.
  • If serialization is requested using WorkspaceModel.Save then WorkspaceModel.ToJson is 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

  • The code base 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. (One existing regression remains)
  • Snapshot of UI changes, if any. n/a
  • Changes to the API follow Semantic Versioning, and are documented in the API Changes document.

Reviewers

@QilongTang

/// 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)

@ikeough ikeough Jun 12, 2017 •

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.

API Change. WorkspaceModel.Save now returns void.

/// by looking it up in the CustomNodeManager.
/// </summary>
public class NodeModelConverter : JsonConverter
public class NodeReadConverter : JsonConverter

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.

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)

@ikeough ikeough Jun 12, 2017 •

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.

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()

@ikeough ikeough Jun 12, 2017 •

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.

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)

@ikeough ikeough Jun 12, 2017 •

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.

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)

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.

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)

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.

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>

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.

The path of the file

OnSaved();
}

OnSaved();

@QilongTang QilongTang Jun 12, 2017 •

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.

The OnSaved() in if seems redundant

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.

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);

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.

Neat

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.

This was done to make multiple home workspaces easier in the future.

@QilongTang

Copy link
Copy Markdown
Contributor

Restarting EngOps Build to make sure Dynamo builds, other than that the changes looks good

@QilongTang

Copy link
Copy Markdown
Contributor

@ikeough Looks like there are a few minor build errors after merging with master branch:
Graph\Workspaces\SerializationConverters.cs(203,39): error CS1002: ; expected [E:\Builds\Dynamo_master\Dynamo\src\DynamoCore\DynamoCore.csproj]
Graph\Workspaces\SerializationConverters.cs(279,38): error CS1002: ; expected [E:\Builds\Dynamo_master\Dynamo\src\DynamoCore\DynamoCore.csproj]

/// construction and should not be serialized.
/// </summary>
public class WorkspaceConverter : JsonConverter
public class WorkspaceReadConverter : JsonConverter

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey @ikeough I'm curious what the advantage was for splitting the converters into two?

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.

@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.

@ikeough ikeough added this to the 2.0 milestone Jun 13, 2017
@ikeough
ikeough merged commit cef50a7 into DynamoDS:master Jun 13, 2017
@ikeough
ikeough deleted the QNTM-687-a branch June 13, 2017 17:22
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.

3 participants