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

[Cherrypick] DYN-7154: missing thumbnail sample files (#15326) #15334

Merged
merged 4 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
82 changes: 64 additions & 18 deletions src/DynamoCoreWpf/Controls/StartPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public enum Action
ExternalUrl
}

internal StartPageListItem(string caption)
protected internal StartPageListItem(string caption)
{
this.Caption = caption;
}

internal StartPageListItem(string caption, string iconPath)
protected internal StartPageListItem(string caption, string iconPath)
{
this.Caption = caption;
this.icon = LoadBitmapImage(iconPath);
Expand Down Expand Up @@ -95,7 +95,7 @@ public Visibility IconVisibility

#region Private Class Helper Methods

private BitmapImage LoadBitmapImage(string iconPath)
protected BitmapImage LoadBitmapImage(string iconPath)
{
var format = @"pack://application:,,,/DynamoCoreWpf;component/UI/Images/StartPage/{0}";
iconPath = string.Format(format, iconPath);
Expand Down Expand Up @@ -127,8 +127,8 @@ internal StartPageViewModel(DynamoViewModel dynamoViewModel, bool isFirstRun)
this.isFirstRun = isFirstRun;

this.recentFiles = new ObservableCollection<StartPageListItem>();
sampleFiles = new ObservableCollection<SampleFileEntry>();
backupFiles = new ObservableCollection<StartPageListItem>();
this.sampleFiles = new ObservableCollection<SampleFileEntry>();
this.backupFiles = new ObservableCollection<StartPageListItem>();


#region File Operations
Expand Down Expand Up @@ -214,6 +214,7 @@ internal StartPageViewModel(DynamoViewModel dynamoViewModel, bool isFirstRun)
RefreshBackupFileList(dvm.Model.PreferenceSettings.BackupFiles);
dvm.RecentFiles.CollectionChanged += OnRecentFilesChanged;
}

internal void WalkDirectoryTree(System.IO.DirectoryInfo root, SampleFileEntry rootProperty)
{
try
Expand Down Expand Up @@ -248,14 +249,24 @@ internal void WalkDirectoryTree(System.IO.DirectoryInfo root, SampleFileEntry ro
{
sampleFolderPath = Path.GetDirectoryName(file.FullName);
}

// Add each file under the root directory property list.
rootProperty.AddChildSampleFile(new SampleFileEntry(file.Name, file.FullName));
var properties = GetFileProperties(file.FullName);

rootProperty.AddChildSampleFile(new SampleFileEntry(
file.Name,
file.FullName,
properties.thumbnail,
properties.author,
properties.description,
properties.date));
}
}
}
catch (Exception)
catch (Exception ex)
{
// Perhaps some permission problems?
DynamoViewModel.Model.Logger.Log("Error loading sample file: " + ex.StackTrace);
}
}

Expand Down Expand Up @@ -386,22 +397,17 @@ private void RefreshFileList(ObservableCollection<StartPageListItem> files,
var caption = Path.GetFileNameWithoutExtension(filePath);

// deserializes the file only once
var jsonObject = DeserializeJsonFile(filePath);
var description = jsonObject != null ? GetGraphDescription(jsonObject) : string.Empty;
var thumbnail = jsonObject != null ? GetGraphThumbnail(jsonObject) : string.Empty;
var author = jsonObject != null ? GetGraphAuthor(jsonObject) : Resources.DynamoXmlFileFormat;

var date = DynamoUtilities.PathHelper.GetDateModified(filePath);
var properties = GetFileProperties(filePath);

files.Add(new StartPageListItem(caption)
{
ContextData = filePath,
ToolTip = filePath,
SubScript = subScript,
Description = description,
Thumbnail = thumbnail,
Author = author,
DateModified = date,
Description = properties.description,
Thumbnail = properties.thumbnail,
Author = properties.author,
DateModified = properties.date,
ClickAction = StartPageListItem.Action.FilePath,

});
Expand Down Expand Up @@ -499,6 +505,33 @@ private void HandleExternalUrl(StartPageListItem item)
System.Diagnostics.Process.Start(new ProcessStartInfo(item.ContextData) { UseShellExecute = true });
}

/// <summary>
/// Attempts to deserialize a dynamo graph file and extract metadata from it
/// </summary>
/// <param name="filePath">The file path to the dynamo file</param>
/// <returns></returns>
internal (string description, string thumbnail, string author, string date) GetFileProperties(string filePath)
{
if (!filePath.ToLower().EndsWith(".dyn") && !filePath.ToLower().EndsWith(".dyf")) return (null, null, null, null);

try
{
var jsonObject = DeserializeJsonFile(filePath);
var description = jsonObject != null ? GetGraphDescription(jsonObject) : string.Empty;
var thumbnail = jsonObject != null ? GetGraphThumbnail(jsonObject) : string.Empty;
var author = jsonObject != null ? GetGraphAuthor(jsonObject) : Resources.DynamoXmlFileFormat;
var date = DynamoUtilities.PathHelper.GetDateModified(filePath);

return (description, thumbnail, author, date);
}
catch (Exception ex)
{
DynamoViewModel.Model.Logger.Log("Error deserializing dynamo graph file: " + ex.StackTrace);
return (null, null, null, null);
}

}

#endregion

}
Expand Down Expand Up @@ -623,15 +656,28 @@ private void StartPage_OnDrop(object sender, DragEventArgs e)
#endregion
}

public class SampleFileEntry
public class SampleFileEntry : StartPageListItem
{
List<SampleFileEntry> childSampleFiles = null;

public SampleFileEntry(string name, string path)
: base(name)
{
this.FileName = name;
this.FilePath = path;
}

public SampleFileEntry(string name, string path, string thumbnail, string author, string description, string dateModified)
: base(name)
{
this.FileName = name;
this.FilePath = path;
this.Thumbnail = thumbnail;
this.Author = author;
this.Description = description;
this.DateModified = dateModified;
}

public void AddChildSampleFile(SampleFileEntry childSampleFile)
{
if (null == childSampleFiles)
Expand Down
9 changes: 9 additions & 0 deletions src/DynamoCoreWpf/DynamoCoreWpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,19 @@


<Target Name="NpmRunBuildHomePage" BeforeTargets="BeforeBuild">
<PropertyGroup>
Copy link
Contributor Author

@reddyashish reddyashish Jun 20, 2024

Choose a reason for hiding this comment

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

@aaron @zeusongit this change is coming #15316 regarding the skip install step but it is only added for this npm target. Is this ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it.

<PackageVersion>1.0.15</PackageVersion>
<PackageName>DynamoHome</PackageName>
</PropertyGroup>
<Exec Command="$(PowerShellCommand) -ExecutionPolicy ByPass -Command echo ($(SolutionDir)\pkgexist.ps1 $(PackageName) $(PackageVersion))" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="ShouldInstall" />
</Exec>
<Message Text="Skipping Install for $(PackageName) $(PackageVersion), package up to date." Condition="!$(ShouldInstall)" Importance="high"></Message>
<!--This command updates the npm registry configuration if necessary-->
<Exec Command="$(PowerShellCommand) -ExecutionPolicy ByPass -Command $(SolutionDir)\setnpmreg.ps1" />
<!--Download a specific build of the Dynamo Home package from npm-->
<Exec Command="npm pack @dynamods/dynamo-home@1.0.14" />
<Exec Command="npm pack @dynamods/dynamo-home@1.0.15" Condition="$(ShouldInstall)"/>
</Target>

<Target Name="ExtractTGZFileDynamoHome" DependsOnTargets="NpmRunBuildHomePage" BeforeTargets="BeforeBuild">
Expand Down
4 changes: 4 additions & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,7 @@ Dynamo.UI.Controls.SampleFileEntry.Children.get -> System.Collections.Generic.IE
Dynamo.UI.Controls.SampleFileEntry.FileName.get -> string
Dynamo.UI.Controls.SampleFileEntry.FilePath.get -> string
Dynamo.UI.Controls.SampleFileEntry.SampleFileEntry(string name, string path) -> void
Dynamo.UI.Controls.SampleFileEntry.SampleFileEntry(string name, string path, string thumbnail, string author, string description, string dateModified) -> void
Dynamo.UI.Controls.ShortcutBarItem
Dynamo.UI.Controls.ShortcutBarItem.ImgDisabledSource.get -> string
Dynamo.UI.Controls.ShortcutBarItem.ImgDisabledSource.set -> void
Expand Down Expand Up @@ -1465,6 +1466,9 @@ Dynamo.UI.Controls.StartPageListItem.DateModified.set -> void
Dynamo.UI.Controls.StartPageListItem.Description.get -> string
Dynamo.UI.Controls.StartPageListItem.Icon.get -> System.Windows.Media.ImageSource
Dynamo.UI.Controls.StartPageListItem.IconVisibility.get -> System.Windows.Visibility
Dynamo.UI.Controls.StartPageListItem.LoadBitmapImage(string iconPath) -> System.Windows.Media.Imaging.BitmapImage
Dynamo.UI.Controls.StartPageListItem.StartPageListItem(string caption) -> void
Dynamo.UI.Controls.StartPageListItem.StartPageListItem(string caption, string iconPath) -> void
Dynamo.UI.Controls.StartPageListItem.SubScript.get -> string
Dynamo.UI.Controls.StartPageListItem.SubScript.set -> void
Dynamo.UI.Controls.StartPageListItem.Thumbnail.get -> string
Expand Down
17 changes: 17 additions & 0 deletions test/DynamoCoreWpfTests/HomePageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,23 @@ public void CanOpenGraphOnDragAndDrop()
}
#endregion

[Test]
public void TestDeserializeDynamoGraphProperties()
{
// Arrange
var filePath = Path.Combine(GetTestDirectory(ExecutingDirectory), @"core\Home.dyn");
var vm = View.DataContext as DynamoViewModel;
var startPage = new StartPageViewModel(vm, true);

// Act
var properties = startPage.GetFileProperties(filePath);

// Assert
Assert.AreEqual(properties.description, "Test description");
Assert.AreEqual(properties.author, "John Doe");
Assert.IsFalse(string.IsNullOrEmpty(properties.thumbnail));
}

#region helpers

/// <summary>
Expand Down
Loading
Loading