44using System ;
55using System . Collections . Generic ;
66using System . IO ;
7- using System . Text ;
8- using System . Threading ;
7+ using System . Linq ;
98
109namespace Iot . Tools . DeviceListing
1110{
@@ -17,6 +16,7 @@ class DeviceInfo : IComparable<DeviceInfo>
1716 public HashSet < string > Categories { get ; private set ; } = new HashSet < string > ( ) ;
1817 public string CategoriesFilePath { get ; private set ; }
1918 public bool CategoriesFileExists { get ; private set ; }
19+ public string NuGetPackageId { get ; private set ; }
2020
2121 public DeviceInfo ( string readmePath , string categoriesFilePath )
2222 {
@@ -25,6 +25,7 @@ public DeviceInfo(string readmePath, string categoriesFilePath)
2525 Title = GetTitle ( readmePath ) ?? "Error" ;
2626 CategoriesFilePath = categoriesFilePath ;
2727 CategoriesFileExists = File . Exists ( categoriesFilePath ) ;
28+ NuGetPackageId = GetNugetPackageId ( readmePath ) ;
2829
2930 ImportCategories ( ) ;
3031 }
@@ -66,5 +67,34 @@ private void ImportCategories()
6667
6768 return null ;
6869 }
70+
71+ private string GetNugetPackageId ( string readmePath )
72+ {
73+ // find nuspec file
74+ var nuspecFiles = Directory . EnumerateFiles ( Path . GetDirectoryName ( readmePath ) ! , "*.nuspec" ) ;
75+
76+ // should have only one nuspec file
77+ if ( nuspecFiles is null || ! nuspecFiles . Any ( ) )
78+ {
79+ Console . WriteLine ( $ "Error: Can't find nuspec file for device { Name } ") ;
80+ return string . Empty ;
81+ }
82+
83+ // read nuspec file
84+ string [ ] nuspecLines = File . ReadAllLines ( nuspecFiles . First ( ) ) ;
85+
86+ // find package id
87+ foreach ( string line in nuspecLines )
88+ {
89+ if ( line . Contains ( "<id>" ) && line . Contains ( "</id>" ) )
90+ {
91+ return line . Split ( new [ ] { '<' , '>' } , StringSplitOptions . None ) [ 2 ] ;
92+ }
93+ }
94+
95+ // shouldn't reach here
96+ Console . WriteLine ( $ "Error: Can't find package id in nuspec file for device { Name } ") ;
97+ return string . Empty ;
98+ }
6999 }
70100}
0 commit comments