1
+ #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
2
+
3
+ namespace Skyline . DataMiner . Sdk . Tasks
4
+ {
5
+ using System ;
6
+ using System . Diagnostics ;
7
+ using System . IO . Compression ;
8
+
9
+ using Microsoft . Build . Framework ;
10
+
11
+ using Skyline . DataMiner . CICD . FileSystem ;
12
+
13
+ using Task = Microsoft . Build . Utilities . Task ;
14
+
15
+ public class CatalogInformation : Task , ICancelableTask
16
+ {
17
+ private bool cancel ;
18
+
19
+ #region Properties set from targets file
20
+
21
+ public string BaseOutputPath { get ; set ; }
22
+
23
+ public string Configuration { get ; set ; }
24
+
25
+ public string PackageId { get ; set ; }
26
+
27
+ public string PackageVersion { get ; set ; }
28
+
29
+ public string ProjectDirectory { get ; set ; }
30
+
31
+ #endregion Properties set from targets file
32
+
33
+ /// <summary>
34
+ /// Cancel the ongoing task
35
+ /// </summary>
36
+ public void Cancel ( )
37
+ {
38
+ cancel = true ;
39
+ }
40
+
41
+ public override bool Execute ( )
42
+ {
43
+ Stopwatch timer = Stopwatch . StartNew ( ) ;
44
+
45
+ try
46
+ {
47
+ if ( cancel )
48
+ {
49
+ // Early cancel if necessary
50
+ return true ;
51
+ }
52
+ // zip the CatalogInformation if it exists.
53
+ var fs = FileSystem . Instance ;
54
+ var catalogInformationFolder = fs . Path . Combine ( ProjectDirectory , "CatalogInformation" ) ;
55
+
56
+ if ( fs . Directory . Exists ( catalogInformationFolder ) )
57
+ {
58
+ // Store zip in bin\{Debug/Release} folder, similar like nupkg files.
59
+ string baseLocation = BaseOutputPath ;
60
+ if ( ! fs . Path . IsPathRooted ( BaseOutputPath ) )
61
+ {
62
+ // Relative path (starting from project directory
63
+ baseLocation = fs . Path . GetFullPath ( fs . Path . Combine ( ProjectDirectory , BaseOutputPath ) ) ;
64
+ }
65
+
66
+ string destinationFilePath = fs . Path . Combine ( baseLocation , Configuration , $ "{ PackageId } .{ PackageVersion } .CatalogInformation.zip") ;
67
+ fs . Directory . CreateDirectory ( fs . Path . GetDirectoryName ( destinationFilePath ) ) ;
68
+
69
+ ZipFile . CreateFromDirectory ( catalogInformationFolder , destinationFilePath , CompressionLevel . Optimal , includeBaseDirectory : false ) ;
70
+
71
+ Log . LogMessage ( MessageImportance . Low , $ "CatalogInformation zipped to { destinationFilePath } ") ;
72
+ }
73
+
74
+ if ( cancel )
75
+ {
76
+ return false ;
77
+ }
78
+
79
+ return ! Log . HasLoggedErrors ;
80
+ }
81
+ catch ( Exception e )
82
+ {
83
+ Log . LogError ( $ "Unexpected exception occurred during catalog information creation: { e } ") ;
84
+ return false ;
85
+ }
86
+ finally
87
+ {
88
+ timer . Stop ( ) ;
89
+ Log . LogMessage ( MessageImportance . High , $ "Catalog information creation took { timer . ElapsedMilliseconds } ms.") ;
90
+ }
91
+ }
92
+ }
93
+ }
0 commit comments