Skip to content

Commit 7c69e88

Browse files
committed
Preparation for CatalogReferences
1 parent 33ad80c commit 7c69e88

File tree

3 files changed

+98
-11
lines changed

3 files changed

+98
-11
lines changed
+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
}

Sdk/Helpers/ProjectReferenceHelper.cs Sdk/Helpers/ProjectReferencesHelper.cs

+1-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
using Skyline.DataMiner.CICD.FileSystem;
1313
using Skyline.DataMiner.CICD.Parsers.Common.VisualStudio.Projects;
1414

15-
internal static class ProjectReferenceHelper
15+
internal static class ProjectReferencesHelper
1616
{
1717
public static bool TryResolveProjectReferences(Project packageProject, out List<string> includedProjectPaths, out string errorMessage)
1818
{
@@ -130,13 +130,5 @@ private static bool MatchesPattern(string filePath, string pattern)
130130
string normalizedPattern = pattern.Replace("*", ".*").Replace(@"\", @"\\");
131131
return Regex.IsMatch(filePath, normalizedPattern, RegexOptions.IgnoreCase);
132132
}
133-
134-
private class SolutionFilter
135-
{
136-
public string Path { get; set; }
137-
138-
public string[] Projects { get; set; }
139-
}
140-
141133
}
142134
}

Sdk/Tasks/DmappCreation.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ public override bool Execute()
106106
baseLocation = FileSystem.Instance.Path.GetFullPath(FileSystem.Instance.Path.Combine(preparedData.Project.ProjectDirectory, BaseOutputPath));
107107
}
108108

109-
string destinationFilePath = Path.Combine(baseLocation, Configuration, $"{PackageId}.{PackageVersion}.dmapp");
109+
string destinationFilePath = FileSystem.Instance.Path.Combine(baseLocation, Configuration, $"{PackageId}.{PackageVersion}.dmapp");
110+
111+
// Create directories in case they don't exist yet
112+
FileSystem.Instance.Directory.CreateDirectory(FileSystem.Instance.Path.GetDirectoryName(destinationFilePath));
110113
IAppPackage package = appPackageBuilder.Build();
111114
string about = package.CreatePackage(destinationFilePath);
112115
Log.LogMessage(MessageImportance.Low, $"About created package:{Environment.NewLine}{about}");
@@ -160,7 +163,7 @@ private void AddProjectToPackage(PackageCreationData preparedData, AppPackage.Ap
160163

161164
private void PackageProjectReferences(PackageCreationData preparedData, AppPackage.AppPackageBuilder appPackageBuilder)
162165
{
163-
if (!ProjectReferenceHelper.TryResolveProjectReferences(preparedData.Project, out List<string> includedProjectPaths, out string errorMessage))
166+
if (!ProjectReferencesHelper.TryResolveProjectReferences(preparedData.Project, out List<string> includedProjectPaths, out string errorMessage))
164167
{
165168
Log.LogError(errorMessage);
166169
return;

0 commit comments

Comments
 (0)