1
+ namespace Skyline . DataMiner . Sdk . Helpers
2
+ {
3
+ using System ;
4
+ using System . Collections . Generic ;
5
+ using System . IO ;
6
+ using System . Linq ;
7
+ using System . Net . Http ;
8
+ using System . Xml ;
9
+ using System . Xml . Linq ;
10
+
11
+ using Skyline . DataMiner . CICD . FileSystem ;
12
+ using Skyline . DataMiner . CICD . Parsers . Common . VisualStudio . Projects ;
13
+
14
+ internal static class CatalogReferencesHelper
15
+ {
16
+ public static bool TryResolveCatalogReferences ( Project packageProject , out List < string > includedPackages , out string errorMessage )
17
+ {
18
+ includedPackages = null ;
19
+ errorMessage = null ;
20
+
21
+ string rootFolder = FileSystem . Instance . Directory . GetParentDirectory ( packageProject . ProjectDirectory ) ;
22
+ const string xmlFileName = "CatalogReferences.xml" ;
23
+ string xmlFilePath = FileSystem . Instance . Path . Combine ( packageProject . ProjectDirectory , "PackageContent" , xmlFileName ) ;
24
+
25
+ try
26
+ {
27
+ includedPackages = ResolveCatalogReferences ( xmlFilePath ) ;
28
+ return true ;
29
+ }
30
+ catch ( FileNotFoundException )
31
+ {
32
+ errorMessage = $ "{ xmlFileName } could not be found. Please make sure this file has been added with the default content.";
33
+ }
34
+ catch ( XmlException xe )
35
+ {
36
+ errorMessage = $ "XmlException: Please validate the { xmlFileName } file. ({ xe . Message } )";
37
+ }
38
+ catch ( Exception e )
39
+ {
40
+ errorMessage = $ "Unexpected exception occured: { e } ";
41
+ }
42
+
43
+ return false ;
44
+ }
45
+
46
+ private static List < string > ResolveCatalogReferences ( string xmlFilePath )
47
+ {
48
+ throw new NotSupportedException ( ) ;
49
+
50
+ // Load the XML file
51
+ var doc = XDocument . Load ( xmlFilePath ) ;
52
+ XNamespace ns = "http://www.skyline.be/catalogReferences" ;
53
+
54
+ var catalogItems = doc . Descendants ( ns + "CatalogReference" ) . ToList ( ) ;
55
+
56
+ using ( HttpClient client = new HttpClient ( ) )
57
+ {
58
+ //ICatalogService service = Downloader.FromCatalog(client);
59
+ foreach ( XElement catalogItem in catalogItems )
60
+ {
61
+ if ( ! Guid . TryParse ( catalogItem . Attribute ( "id" ) ? . Value , out Guid catalogItemGuid ) )
62
+ {
63
+ continue ;
64
+ }
65
+
66
+ XElement selection = catalogItem . Element ( ns + "Selection" ) ;
67
+ if ( selection == null || ! selection . HasElements )
68
+ {
69
+ continue ;
70
+ }
71
+
72
+ string specific = selection . Element ( ns + "Specific" ) ? . Value ;
73
+ if ( ! String . IsNullOrWhiteSpace ( specific ) )
74
+ {
75
+ //CatalogIdentifier identifier = CatalogIdentifier.WithVersion(catalogItemGuid, specific);
76
+
77
+ // Download specific version (if exists)
78
+ continue ;
79
+ }
80
+
81
+ XElement range = selection . Element ( ns + "Range" ) ;
82
+ if ( ! String . IsNullOrWhiteSpace ( range ? . Value ) )
83
+ {
84
+ Boolean . TryParse ( range . Attribute ( "allowPrerelease" ) ? . Value , out bool allowPrerelease ) ;
85
+ //CatalogIdentifier identifier = CatalogIdentifier.WithRange(catalogItemGuid, range.Value, allowPrerelease);
86
+ // Download latest version of range
87
+ }
88
+ }
89
+ }
90
+ }
91
+ }
92
+ }
0 commit comments