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-1819 ExportExcel Write as String Option #11291

Merged
merged 10 commits into from
Dec 11, 2020

Conversation

StudioLE
Copy link
Contributor

Purpose

JIRA: DYN-1819

Issues: DynamoDS/DynamoWishlist#13

Added an additional writeAsString parameter to the Data.ExportExcel node. This parameter defaults to false ensuring the existing behaviour is preserved. When set to true the NumberFormat for the written range is set to text, therefore preserving the string rather than letting Excel automatically determine the format.

Behaviour before:
DYN-1819-Export-Excel-Before

Behaviour after writeAsString: false:
DYN-1819-Export-Excel-After-False

Behaviour after writeAsString: true:
DYN-1819-Export-Excel-After-True

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 @QilongTang @mmisol

FYIs

@Amoursol

@StudioLE StudioLE changed the title ExportExcel write as string option DYN-1819 ExportExcel Write as String Option Nov 30, 2020
@mmisol mmisol self-requested a review November 30, 2020 20:00
@mmisol
Copy link
Collaborator

mmisol commented Nov 30, 2020

Hi @StudioLE . Could you please add a unit test for this?

Edit: For reference, here is the file where we have the unit tests related to Excel: https://github.com/DynamoDS/Dynamo/blob/master/test/Libraries/DynamoMSOfficeTests/ExcelTests.cs

@mjkkirschner
Copy link
Member

mjkkirschner commented Nov 30, 2020

I don't think these changes are allowed in terms of API compatability...
see
Adding a parameter with a default value.
https://stackoverflow.com/questions/1456785/a-definitive-guide-to-api-breaking-changes-in-net

see:
https://docs.microsoft.com/en-us/dotnet/core/compatibility/

❌ DISALLOWED: Adding, removing, or changing the order of parameters

while this might work pretty well for nodes - I don't think it will work for c# code that calls this code.

@mmisol
Copy link
Collaborator

mmisol commented Nov 30, 2020

@mjkkirschner Right, but this PR is doing what's described in the ticket. Could it be that we didn't consider this part of our API or disregarded the compatibility break? Copying @Amoursol

@Amoursol
Copy link
Contributor

@mjkkirschner Right, but this PR is doing what's described in the ticket. Could it be that we didn't consider this part of our API or disregarded the compatibility break? Copying @Amoursol

I had indeed not been aware of the compatibility break - assumed that adding a new node port (As we have done in other cases?) would be acceptable and a non-breaking change if default values adhered to existing graph conditions.

@mjkkirschner - What kind of issues will arise from this in a non-node basis, assuming my above assertions are correct?

@mjkkirschner
Copy link
Member

code which calls this node from c# will throw a MissingMethodException - so if a user has written another zero touch node or extension which references this will likely result in a failing node or crash from the extension.

What should likely be done is to:

  1. obsolete these nodes.
  2. Make sure they are hidden in the library (obsolete should do this AFAIK)
  3. Create a new node with the new input.
  4. Consider looking into using the [AlsoKnownAs] attribute - I can't remember the details of this attribute but it's made for migration/loading older graphs with new nodes.

@mjkkirschner
Copy link
Member

mjkkirschner commented Nov 30, 2020

it may make sense to use the migrations.xml file instead since theres already an existing one for dsoffice assembly:
https://github.com/DynamoDS/Dynamo/blob/master/src/Libraries/DSOffice/DSOffice.Migrations.xml

Either of these migration options will need manual and automated testing.

@mmisol
Copy link
Collaborator

mmisol commented Dec 8, 2020

@StudioLE Based on the comments made by @mjkkirschner , could we ask you to change the contribution to use a new node/function so that we can remain backwards compatible? Thank you

@SHKnudsen
Copy link
Contributor

Hi guys, im looking into getting this wrapped up, Sorry for the delay!

Im having some issues getting the migrations to work. I tried the following:

  • Create new node (ExportExcelWithStringParameter) <- name was just for testing btw..
  • Make a new migration:
  <priorNameHint>
    <oldName>DSOffice.Data.ExportExcel</oldName>
    <newName>DSOffice.Data.ExportExcelWithStringParameter</newName>
  </priorNameHint>
  • obsolete the old node so it dosent show in the library

Is there something im doing wrong here, it dosent really work at least. When i open a graph using the old ExportExcel node it dosent use the new ExportExcelWithStringParameter it just shows the old in a warning state as it is obsolete. For some reason copy and pasting the obsolete node will make a ExportExcelWithStringParameter node but renamed as ExportExcel.

@mmisol
Copy link
Collaborator

mmisol commented Dec 8, 2020

Hi @SHKnudsen . I'm not familiar with the migrations but maybe @mjkkirschner and @aparajit-pratap can chime in?

@aparajit-pratap
Copy link
Contributor

@SHKnudsen could you also try including the list of parameters with both node names in the migrations.xml file since the new node also has an additional parameter. Refer to this for an example:

<oldName>Autodesk.DesignScript.Geometry.Surface.ByLoft@Autodesk.DesignScript.Geometry.Curve[],Autodesk.DesignScript.Geometry.Curve</oldName>

@mjkkirschner
Copy link
Member

@SHKnudsen @StudioLE - for now can you try the following:

  1. Obsolete the existing node.
  2. Add a new node with the extra parameter - make sure this node has a new name - do not use the same name.
  3. Nevermind the migration for now.

@SHKnudsen
Copy link
Contributor

@mjkkirschner done.

Called the node ExportToExcel for now, hard to find a different name than the original. Let me know if there are other suggestions for the name.

Copy link
Contributor

@aparajit-pratap aparajit-pratap left a comment

Choose a reason for hiding this comment

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

@SHKnudsen thanks! You'll need to do one last thing - add an entry for the new node to the libraryItems.json file so that the remaining failing test passes. See: https://github.com/DynamoDS/Dynamo/wiki/Adding-or-Updating-Built-In-Library-Icons#step-5-update-testing-resources

iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAABl0RVh0U29m
dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAABMSURBVFhH7dCxCQAgDETRTCuO4Gwup5YpzkKuMfAf
pPmFcAYA4GbMvvK57Zl6xGl4dr6u5XNbPWqF0+pRK5xWj1rhtHrUCqcBwKciNnx+8yHggVbjAAAAAElF
TkSuQmCC
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did this icon change?

Copy link
Contributor

Choose a reason for hiding this comment

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

I had to rename the icon. Guess thats whats triggering the change?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It could be some randomness in the resx file introduced by Visual Studio, but it is strange because this is another icon, not the one that was renamed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right, hmm that is strange. Not even sure what this icon is used for, there is only a Small version of it

xeDuk3//vu9nyGkkgJc832/yXdf8GTP0iWb3zoUWlxPLyEMb9wetSfDa9u+J/tm0YxIMrYh2w0I6YPIw
J/mbonv8D7zpnw8R+16TMAsWlk+Gvzl7yLn8Oxp6xHyahHljgWsS5o0FrkmYNxa4JmHeWOCahHljgWsS
5o0FrkmYNxZ4nASdnH1uLPRmEhT+vPBJwEchhBBCCCGEEEIIIYQQQgghxBSsrHwC4O+ISk6Usf4AAAAA
SUVORK5CYII=
Copy link
Collaborator

Choose a reason for hiding this comment

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

The content for this one looks different too. Is that expected?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea not sure whats going on here, haven't touched this either

Copy link
Collaborator

Choose a reason for hiding this comment

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

I checked and in Dynamo the icons of the node look ok, so this is harmless.

/// <returns name="data">Data written to the spreadsheet.</returns>
/// <search>office,excel,spreadsheet</search>
[IsVisibleInDynamoLibrary(false)]
public static object[][] WriteToFile(string filePath, string sheetName, int startRow, int startCol, object[][] data, bool overWrite = false)
public static object[][] WriteToFile(string filePath, string sheetName, int startRow, int startCol, object[][] data, bool overWrite = false, bool writeAsString = false)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function is having a binary breaking change because optional parameters are a compile-time feature. Can we use an overload instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, hadnt realized this was public too, will fix that.

Copy link
Contributor

@aparajit-pratap aparajit-pratap Dec 10, 2020

Choose a reason for hiding this comment

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

This new method doesn't need to be public. This logic can actually be folded into the new ExportToExcel node and you can remove this method entirely. The only reason there existed an old WriteToFile method was that it was originally a node, which was later renamed to ExportExcel.

Copy link
Contributor

Choose a reason for hiding this comment

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

So one thing before i make this change. Would you prefer to have one private method that WriteToFile and ExportToExcel uses? other option would be to duplicate the logic from WriteToFile into ExportToExcel with the additional parameter.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think option 1 sounds good. I'd rather not duplicate the code if possible.

</data>
<data name="DSOffice.Data.ExportExcel.Small" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<data name="DSOffice.Data.ExportToExcel.Small" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we are not doing the migration yet, I think we should keep the icon for the old node too, rather than replace it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, but we still use the same icon for both right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, that should be fine.

Copy link
Collaborator

@mmisol mmisol left a comment

Choose a reason for hiding this comment

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

Looks good to me

xeDuk3//vu9nyGkkgJc832/yXdf8GTP0iWb3zoUWlxPLyEMb9wetSfDa9u+J/tm0YxIMrYh2w0I6YPIw
J/mbonv8D7zpnw8R+16TMAsWlk+Gvzl7yLn8Oxp6xHyahHljgWsS5o0FrkmYNxa4JmHeWOCahHljgWsS
5o0FrkmYNxZ4nASdnH1uLPRmEhT+vPBJwEchhBBCCCGEEEIIIYQQQgghxBSsrHwC4O+ISk6Usf4AAAAA
SUVORK5CYII=
Copy link
Collaborator

Choose a reason for hiding this comment

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

I checked and in Dynamo the icons of the node look ok, so this is harmless.

Copy link
Contributor

@aparajit-pratap aparajit-pratap left a comment

Choose a reason for hiding this comment

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

One last comment about the redundancy of the new WriteToFile method.

@mmisol
Copy link
Collaborator

mmisol commented Dec 11, 2020

@aparajit-pratap Could I ask you take one final look here? If you are ok with the last change I think we are good to merge.

@@ -864,7 +845,7 @@ public static object[][] ImportExcel(FileInfo file, string sheetName, bool readA

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a line white space here? Can we delete this?

@aparajit-pratap
Copy link
Contributor

@mmisol are we going to add any tests or have Sylvester add tests?

@mmisol
Copy link
Collaborator

mmisol commented Dec 11, 2020

Good point @aparajit-pratap . I didn't realize we didn't have them. Could you take care of adding one @SHKnudsen ?

@SHKnudsen
Copy link
Contributor

Yes sorry guys, actually thought there was tests on this one. Ill have a look at it now.

@SHKnudsen
Copy link
Contributor

Added a simple test that checks if the exported value is converted to string when the writeAsString is set to true.
image

@mmisol
Copy link
Collaborator

mmisol commented Dec 11, 2020

Thanks @SHKnudsen . I'll wait for self serve and merge.

@mmisol mmisol merged commit 5b9643f into DynamoDS:master Dec 11, 2020
"Nodes": [
{
"ConcreteType": "CoreNodeModels.Input.Filename, CoreNodeModels",
"HintPath": "C:\\Users\\SylvesterKnudsen\\Documents\\GitHub\\StudioLEDynamo\\test\\core\\excel\\WriteFile.xlsx",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we missed this during the PR review.. Not sure how self CI passed with this...

Copy link
Collaborator

Choose a reason for hiding this comment

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

@QilongTang Now that you mention it, I think @alfredo-pozo said ExcelTests are not run in self-serve CI. This is my bad, sorry for forgetting.

Copy link
Member

Choose a reason for hiding this comment

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

@QilongTang @mmisol - the weird part is why did we not get a master-15 job until today that contained this code?

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.

7 participants