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-5319 #13441

Merged
merged 15 commits into from
Nov 9, 2022
Merged

DYN-5319 #13441

Show file tree
Hide file tree
Changes from 12 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
4 changes: 2 additions & 2 deletions src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
// to distinguish one build from another. AssemblyFileVersion is specified
// in AssemblyVersionInfo.cs so that it can be easily incremented by the
// automated build process.
[assembly: AssemblyVersion("2.17.0.2986")]
[assembly: AssemblyVersion("2.17.0.3065")]
Copy link
Member

@mjkkirschner mjkkirschner Nov 7, 2022

Choose a reason for hiding this comment

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

please avoid committing this without a good reason, it causes conflicts etc as the file is autogenerated.



// By default, the "Product version" shown in the file properties window is
Expand All @@ -64,4 +64,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("2.17.0.2986")]
[assembly: AssemblyFileVersion("2.17.0.3065")]
95 changes: 95 additions & 0 deletions src/DynamoCore/Configuration/DynamoPlayerFolder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System.Collections.Generic;

namespace Dynamo.Configuration
{
/// <summary>
/// This class describes a folder (usually containing Dynamo graphs) added to the Dynamo Player or Generative Design
/// </summary>
public class DynamoPlayerFolder
{
/// <summary>
/// The full path if the folder
LongNguyenP marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public string Path;

/// <summary>
/// The display name of the folder
/// </summary>
public string DisplayName;

/// <summary>
/// The ID of the folder
/// </summary>
public string Id;

/// <summary>
/// Whether this folder is removable from the settings (Built-in folders are non-removable)
/// </summary>
public bool IsRemovable = true;

/// <summary>
/// The order of the folder
/// </summary>
public int Order = -1;

/// <summary>
/// Initialize a DynamoPlayerFolderItem
/// </summary>
/// <param name="path">The full path of the folder</param>
/// <param name="displayName">The display name of the folder</param>
/// <param name="id">The id of the folder</param>
/// <param name="isRemovable">The removalbe state of the folder</param>
/// <param name="order">The order of the folder in the UI</param>
public DynamoPlayerFolder(string path, string displayName, string id, bool isRemovable, int order)
{
Path = path;
DisplayName = displayName;
Id = id;
IsRemovable = isRemovable;
Order = order;
}

/// <summary>
/// Create an empty DynamoPlayerFolderItem
/// </summary>
public DynamoPlayerFolder()
LongNguyenP marked this conversation as resolved.
Show resolved Hide resolved
{

}
}

/// <summary>
/// This Class defines a group of folders assciated with a Dynamo Player or Generative Design entry point.
/// </summary>
public class DynamoPlayerFolderGroup
{
/// <summary>
/// The name of the Player entry point
/// </summary>
public string EntryPoint;

/// <summary>
/// The List of Folder Items for this group
/// </summary>
public List<DynamoPlayerFolder> Folders;

/// <summary>
/// Creates an empty DynamoPlayerFolderGroup
/// </summary>
public DynamoPlayerFolderGroup()
{
Folders = new List<DynamoPlayerFolder>();
}

/// <summary>
/// Initialize a DynamoPlayerFolderItem
/// </summary>
/// <param name="entryPoint">The name of the Player entry point</param>
/// <param name="folders">The list of Folder data</param>
public DynamoPlayerFolderGroup(string entryPoint, List<DynamoPlayerFolder> folders)
{
EntryPoint = entryPoint;
Folders = folders;
}
}
}
34 changes: 22 additions & 12 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Dynamo.Configuration
static class ExtensionMethods
{
/// <summary>
/// Copy Properties from a PreferenceSettings instance to another iterating the Properties of the destination instance and populate them from their source counterparts, excluding the properties that are obsolete and only read.
/// Copy Properties from a PreferenceSettings instance to another iterating the Properties of the destination instance and populate them from their source counterparts, excluding the properties that are obsolete and only read.
/// </summary>
/// <param name="source"></param>
/// <param name="destination"></param>
Expand Down Expand Up @@ -84,7 +84,7 @@ public class PreferenceSettings : NotificationObject, IPreferences, IRenderPreci
/// <summary>
/// Default time
/// </summary>
public static readonly System.DateTime DynamoDefaultTime = new System.DateTime(1977, 4, 12, 12, 12, 0, 0);
public static readonly System.DateTime DynamoDefaultTime = new System.DateTime(1977, 4, 12, 12, 12, 0, 0);

#endregion

Expand Down Expand Up @@ -162,7 +162,7 @@ public bool IsADPAnalyticsReportingApproved
public List<BackgroundPreviewActiveState> BackgroundPreviews { get; set; }

/// <summary>
/// Returns active state of specified background preview
/// Returns active state of specified background preview
/// </summary>
/// <param name="name">Background preview name</param>
/// <returns>The active state</returns>
Expand All @@ -174,7 +174,7 @@ public bool GetIsBackgroundPreviewActive(string name)
}

/// <summary>
/// Sets active state of specified background preview
/// Sets active state of specified background preview
/// </summary>
/// <param name="name">Background preview name</param>
/// <param name="value">Active state</param>
Expand Down Expand Up @@ -373,7 +373,7 @@ private bool DeserializeDisableTrustWarnings(XmlNode preferenceSettingsElement)
try
{
return bool.Parse(preferenceSettingsElement.SelectSingleNode($@"//{nameof(DisableTrustWarnings)}").InnerText);

}
catch (Exception ex)
{
Expand Down Expand Up @@ -470,7 +470,7 @@ public string PythonTemplateFilePath
public int BackupFilesCount { get; set; }

/// <summary>
/// Indicates if the user has accepted the terms of
/// Indicates if the user has accepted the terms of
/// use for downloading packages from package manager.
/// </summary>
public bool PackageDownloadTouAccepted { get; set; }
Expand Down Expand Up @@ -644,7 +644,7 @@ public bool DisableCustomPackageLocations

/// <summary>
/// Limits the size of the tags used by the SearchDictionary
/// This static property is not serialized and is assigned NodeSearchTagSizeLimit's value
/// This static property is not serialized and is assigned NodeSearchTagSizeLimit's value
/// if found at deserialize time.
/// </summary>
internal static int nodeSearchTagSizeLimit = 300;
Expand All @@ -660,7 +660,7 @@ public int NodeSearchTagSizeLimit

/// <summary>
/// The Version of the IronPython package that Dynamo will download when it is found as missing in graphs.
/// This static property is not serialized and is assigned IronPythonResolveTargetVersion's value
/// This static property is not serialized and is assigned IronPythonResolveTargetVersion's value
/// if found at deserialize time.
/// </summary>
internal static Version ironPythonResolveTargetVersion = new Version(2, 4, 0);
Expand All @@ -680,6 +680,15 @@ public string IronPythonResolveTargetVersion
public List<string> ReadNotificationIds { get; set; }
#endregion

#region Dynamo Player and Generative Design settings

/// <summary>
/// Collections of folders used by individual Dynamo Player or Generative Design as entry points.
/// </summary>
public List<DynamoPlayerFolderGroup> DynamoPlayerFolderGroups { get; set; }

#endregion

/// <summary>
/// Initializes a new instance of the <see cref="PreferenceSettings"/> class.
/// </summary>
Expand Down Expand Up @@ -719,7 +728,7 @@ public PreferenceSettings()
BackupInterval = DefaultBackupInterval;
BackupFilesCount = 1;
BackupFiles = new List<string>();

CustomPackageFolders = new List<string>();

PythonTemplateFilePath = "";
Expand All @@ -732,6 +741,7 @@ public PreferenceSettings()
ViewExtensionSettings = new List<ViewExtensionSettings>();
GroupStyleItemsList = new List<GroupStyleItem>();
ReadNotificationIds = new List<string>();
DynamoPlayerFolderGroups = new List<DynamoPlayerFolderGroup>();
}

/// <summary>
Expand Down Expand Up @@ -761,11 +771,11 @@ public bool Save(string filePath)
}

/// <summary>
/// Saves PreferenceSettings in a default directory when no path is
/// Saves PreferenceSettings in a default directory when no path is
/// specified.
/// </summary>
/// <param name="preferenceFilePath">The file path to save preference
/// settings to. If this parameter is null or empty string, preference
/// settings to. If this parameter is null or empty string, preference
/// settings will be saved to the default path.</param>
/// <returns>True if file is saved successfully, false if an error occurred.</returns>
public bool SaveInternal(string preferenceFilePath)
Expand Down Expand Up @@ -1016,7 +1026,7 @@ public bool IsTrustedLocation(string location)
{
return false;
}

}

/// <summary>
Expand Down
50 changes: 40 additions & 10 deletions test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void TestLoad()

[Test]
[Category("UnitTests")]
public void TestGetPythonTemplateFilePath()
public void TestGetPythonTemplateFilePath ()
{
string settingDirectory = Path.Combine(TestDirectory, "settings");
string settingsFilePath = Path.Combine(settingDirectory, "DynamoSettings-PythonTemplate-initial.xml");
Expand Down Expand Up @@ -72,6 +72,7 @@ public void TestSettingsSerialization()
Assert.AreEqual(settings.UseHardwareAcceleration, true);
Assert.AreEqual(settings.ViewExtensionSettings.Count, 0);
Assert.AreEqual(settings.DefaultRunType, RunType.Automatic);
Assert.AreEqual(settings.DynamoPlayerFolderGroups.Count, 0);

// Save
settings.Save(tempPath);
Expand All @@ -90,6 +91,7 @@ public void TestSettingsSerialization()
Assert.AreEqual(settings.UseHardwareAcceleration, true);
Assert.AreEqual(settings.ViewExtensionSettings.Count, 0);
Assert.AreEqual(settings.DefaultRunType, RunType.Automatic);
Assert.AreEqual(settings.DynamoPlayerFolderGroups.Count, 0);

// Change setting values
settings.SetIsBackgroundPreviewActive("MyBackgroundPreview", false);
Expand Down Expand Up @@ -117,11 +119,20 @@ public void TestSettingsSerialization()
Status = WindowStatus.Maximized
}
});
settings.GroupStyleItemsList.Add(new GroupStyleItem
settings.GroupStyleItemsList.Add(new GroupStyleItem
{
Name = "TestGroup",
HexColorString = "000000"
Name = "TestGroup",
HexColorString = "000000"
});
settings.DynamoPlayerFolderGroups.Add(new DynamoPlayerFolderGroup()
{
EntryPoint = "GenerativeDesign",
Folders = new List<DynamoPlayerFolder>()
{
new DynamoPlayerFolder()
}
});


// Save
settings.Save(tempPath);
Expand Down Expand Up @@ -156,6 +167,8 @@ public void TestSettingsSerialization()
var styleItemsList = settings.GroupStyleItemsList[0];
Assert.AreEqual(styleItemsList.Name, "TestGroup");
Assert.AreEqual(styleItemsList.HexColorString, "000000");
Assert.AreEqual(settings.DynamoPlayerFolderGroups.Count, 1);
Assert.AreEqual(settings.DynamoPlayerFolderGroups[0].Folders.Count, 1);
}

[Test]
Expand Down Expand Up @@ -212,7 +225,7 @@ public void TestSerializationTrustedLocations()
Assert.AreEqual(1, settingsLoaded.TrustedLocations.Count);

Assert.IsTrue(settingsLoaded.IsTrustedLocation(Path.GetTempPath()));
}
}

/// <summary>
/// Struct to support the comparison between two PreferenceSettings instances
Expand All @@ -221,7 +234,7 @@ struct PreferencesComparison
{
public List<string> Properties { get; set; }
public List<String> SamePropertyValues { get; set; }
public List<String> DifferentPropertyValues { get; set; }
public List<String> DifferentPropertyValues { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -264,6 +277,11 @@ PreferencesComparison comparePrefenceSettings(PreferenceSettings defaultSettings
{
var sourcePi = newGeneralSettings.GetType().GetProperty(destinationPi.Name);

if (sourcePi.Name == "DynamoPlayerFolderGroups")
{
string a = "";
}

if (!PropertyHasExcludedAttributes(destinationPi) && !PropertyHasStaticField(defaultSettings, destinationPi))
{
evaluatedProperties.Add(destinationPi.Name);
Expand Down Expand Up @@ -319,6 +337,18 @@ PreferencesComparison comparePrefenceSettings(PreferenceSettings defaultSettings
propertiesWithDifferentValue.Add(destinationPi.Name);
}
}
else if (destinationPi.PropertyType == typeof(List<DynamoPlayerFolderGroup>))
{
if (((List<DynamoPlayerFolderGroup>)sourcePi.GetValue(newGeneralSettings, null)).Count ==
((List<DynamoPlayerFolderGroup>)destinationPi.GetValue(defaultSettings, null)).Count)
{
propertiesWithSameValue.Add(destinationPi.Name);
}
else
{
propertiesWithDifferentValue.Add(destinationPi.Name);
}
}
else
{
if (newValue?.ToString() == oldValue?.ToString())
Expand All @@ -332,7 +362,7 @@ PreferencesComparison comparePrefenceSettings(PreferenceSettings defaultSettings
}
}
}

result.SamePropertyValues = propertiesWithSameValue;
result.DifferentPropertyValues = propertiesWithDifferentValue;
result.Properties = evaluatedProperties;
Expand Down Expand Up @@ -375,7 +405,7 @@ public void TestImportCopySettings()
defaultSettings.SetTrustedLocations(newSettings.TrustedLocations);

// checking if the default Setting instance has the same property values of the new one
var checkEquality = comparePrefenceSettings(defaultSettings, newSettings);
var checkEquality = comparePrefenceSettings(defaultSettings, newSettings);
Assert.IsTrue(checkEquality.SamePropertyValues.Count == checkEquality.Properties.Count);
}

Expand All @@ -399,7 +429,7 @@ public void TestAskForTrustedLocation()
bool isOpenedFile = true;
bool isHomeSpace = true;
bool isShowStartPage = false;
bool isFileInTrustedLocation = false;
bool isFileInTrustedLocation = false;
bool isDisableTrustWarnings = false;

// getting result
Expand All @@ -410,7 +440,7 @@ public void TestAskForTrustedLocation()
isShowStartPage,
isDisableTrustWarnings);

// checking the result
// checking the result
Assert.IsTrue(result == PreferenceSettings.AskForTrustedLocationResult.Ask, $"Conditions info: is opened file : {isOpenedFile} | is file in trusted location : {isFileInTrustedLocation} | is home space : {isHomeSpace} | is show Start page : {isShowStartPage} | is disable trust warnings : {isDisableTrustWarnings}");
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/settings/DynamoSettings-NewSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,7 @@
<ReadNotificationIds>
<string>1</string>
</ReadNotificationIds>
<DynamoPlayerFolderGroups>
<DynamoPlayerFolderGroup/>
</DynamoPlayerFolderGroups>
</PreferenceSettings>