@@ -57,12 +57,12 @@ public enum Action
57
57
ExternalUrl
58
58
}
59
59
60
- internal StartPageListItem ( string caption )
60
+ protected internal StartPageListItem ( string caption )
61
61
{
62
62
this . Caption = caption ;
63
63
}
64
64
65
- internal StartPageListItem ( string caption , string iconPath )
65
+ protected internal StartPageListItem ( string caption , string iconPath )
66
66
{
67
67
this . Caption = caption ;
68
68
this . icon = LoadBitmapImage ( iconPath ) ;
@@ -95,7 +95,7 @@ public Visibility IconVisibility
95
95
96
96
#region Private Class Helper Methods
97
97
98
- private BitmapImage LoadBitmapImage ( string iconPath )
98
+ protected BitmapImage LoadBitmapImage ( string iconPath )
99
99
{
100
100
var format = @"pack://application:,,,/DynamoCoreWpf;component/UI/Images/StartPage/{0}" ;
101
101
iconPath = string . Format ( format , iconPath ) ;
@@ -127,8 +127,8 @@ internal StartPageViewModel(DynamoViewModel dynamoViewModel, bool isFirstRun)
127
127
this . isFirstRun = isFirstRun ;
128
128
129
129
this . recentFiles = new ObservableCollection < StartPageListItem > ( ) ;
130
- sampleFiles = new ObservableCollection < SampleFileEntry > ( ) ;
131
- backupFiles = new ObservableCollection < StartPageListItem > ( ) ;
130
+ this . sampleFiles = new ObservableCollection < SampleFileEntry > ( ) ;
131
+ this . backupFiles = new ObservableCollection < StartPageListItem > ( ) ;
132
132
133
133
134
134
#region File Operations
@@ -214,6 +214,7 @@ internal StartPageViewModel(DynamoViewModel dynamoViewModel, bool isFirstRun)
214
214
RefreshBackupFileList ( dvm . Model . PreferenceSettings . BackupFiles ) ;
215
215
dvm . RecentFiles . CollectionChanged += OnRecentFilesChanged ;
216
216
}
217
+
217
218
internal void WalkDirectoryTree ( System . IO . DirectoryInfo root , SampleFileEntry rootProperty )
218
219
{
219
220
try
@@ -248,14 +249,24 @@ internal void WalkDirectoryTree(System.IO.DirectoryInfo root, SampleFileEntry ro
248
249
{
249
250
sampleFolderPath = Path . GetDirectoryName ( file . FullName ) ;
250
251
}
252
+
251
253
// Add each file under the root directory property list.
252
- rootProperty . AddChildSampleFile ( new SampleFileEntry ( file . Name , file . FullName ) ) ;
254
+ var properties = GetFileProperties ( file . FullName ) ;
255
+
256
+ rootProperty . AddChildSampleFile ( new SampleFileEntry (
257
+ file . Name ,
258
+ file . FullName ,
259
+ properties . thumbnail ,
260
+ properties . author ,
261
+ properties . description ,
262
+ properties . date ) ) ;
253
263
}
254
264
}
255
265
}
256
- catch ( Exception )
266
+ catch ( Exception ex )
257
267
{
258
268
// Perhaps some permission problems?
269
+ DynamoViewModel . Model . Logger . Log ( "Error loading sample file: " + ex . StackTrace ) ;
259
270
}
260
271
}
261
272
@@ -386,22 +397,17 @@ private void RefreshFileList(ObservableCollection<StartPageListItem> files,
386
397
var caption = Path . GetFileNameWithoutExtension ( filePath ) ;
387
398
388
399
// deserializes the file only once
389
- var jsonObject = DeserializeJsonFile ( filePath ) ;
390
- var description = jsonObject != null ? GetGraphDescription ( jsonObject ) : string . Empty ;
391
- var thumbnail = jsonObject != null ? GetGraphThumbnail ( jsonObject ) : string . Empty ;
392
- var author = jsonObject != null ? GetGraphAuthor ( jsonObject ) : Resources . DynamoXmlFileFormat ;
393
-
394
- var date = DynamoUtilities . PathHelper . GetDateModified ( filePath ) ;
400
+ var properties = GetFileProperties ( filePath ) ;
395
401
396
402
files . Add ( new StartPageListItem ( caption )
397
403
{
398
404
ContextData = filePath ,
399
405
ToolTip = filePath ,
400
406
SubScript = subScript ,
401
- Description = description ,
402
- Thumbnail = thumbnail ,
403
- Author = author ,
404
- DateModified = date ,
407
+ Description = properties . description ,
408
+ Thumbnail = properties . thumbnail ,
409
+ Author = properties . author ,
410
+ DateModified = properties . date ,
405
411
ClickAction = StartPageListItem . Action . FilePath ,
406
412
407
413
} ) ;
@@ -499,6 +505,33 @@ private void HandleExternalUrl(StartPageListItem item)
499
505
System . Diagnostics . Process . Start ( new ProcessStartInfo ( item . ContextData ) { UseShellExecute = true } ) ;
500
506
}
501
507
508
+ /// <summary>
509
+ /// Attempts to deserialize a dynamo graph file and extract metadata from it
510
+ /// </summary>
511
+ /// <param name="filePath">The file path to the dynamo file</param>
512
+ /// <returns></returns>
513
+ internal ( string description , string thumbnail , string author , string date ) GetFileProperties ( string filePath )
514
+ {
515
+ if ( ! filePath . ToLower ( ) . EndsWith ( ".dyn" ) && ! filePath . ToLower ( ) . EndsWith ( ".dyf" ) ) return ( null , null , null , null ) ;
516
+
517
+ try
518
+ {
519
+ var jsonObject = DeserializeJsonFile ( filePath ) ;
520
+ var description = jsonObject != null ? GetGraphDescription ( jsonObject ) : string . Empty ;
521
+ var thumbnail = jsonObject != null ? GetGraphThumbnail ( jsonObject ) : string . Empty ;
522
+ var author = jsonObject != null ? GetGraphAuthor ( jsonObject ) : Resources . DynamoXmlFileFormat ;
523
+ var date = DynamoUtilities . PathHelper . GetDateModified ( filePath ) ;
524
+
525
+ return ( description , thumbnail , author , date ) ;
526
+ }
527
+ catch ( Exception ex )
528
+ {
529
+ DynamoViewModel . Model . Logger . Log ( "Error deserializing dynamo graph file: " + ex . StackTrace ) ;
530
+ return ( null , null , null , null ) ;
531
+ }
532
+
533
+ }
534
+
502
535
#endregion
503
536
504
537
}
@@ -623,15 +656,28 @@ private void StartPage_OnDrop(object sender, DragEventArgs e)
623
656
#endregion
624
657
}
625
658
626
- public class SampleFileEntry
659
+ public class SampleFileEntry : StartPageListItem
627
660
{
628
661
List < SampleFileEntry > childSampleFiles = null ;
629
662
630
663
public SampleFileEntry ( string name , string path )
664
+ : base ( name )
631
665
{
632
666
this . FileName = name ;
633
667
this . FilePath = path ;
634
668
}
669
+
670
+ public SampleFileEntry ( string name , string path , string thumbnail , string author , string description , string dateModified )
671
+ : base ( name )
672
+ {
673
+ this . FileName = name ;
674
+ this . FilePath = path ;
675
+ this . Thumbnail = thumbnail ;
676
+ this . Author = author ;
677
+ this . Description = description ;
678
+ this . DateModified = dateModified ;
679
+ }
680
+
635
681
public void AddChildSampleFile ( SampleFileEntry childSampleFile )
636
682
{
637
683
if ( null == childSampleFiles )
0 commit comments