Skip to content

Commit d0d371e

Browse files
committed
Now include also the compiled scripts if a required script references it
1 parent 5094db2 commit d0d371e

File tree

2 files changed

+75
-84
lines changed

2 files changed

+75
-84
lines changed

Low Code App Editor_1/Controllers/ExportController.cs

+70-84
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ private static string ExportPackage(IEngine engine, IEnumerable<App> apps, Expor
4040
{
4141
var now = DateTime.Now;
4242

43-
var scriptReferences = new Dictionary<string, List<string>>();
4443
var exportPath = Path.Combine(LowCodeAppEditorExportPath, $"{now.ToString("yyyy-MM-dd HH-mm-ss")}_App_Export.zip");
4544
if (apps.Count() == 1)
4645
{
@@ -98,79 +97,34 @@ private static string ExportPackage(IEngine engine, IEnumerable<App> apps, Expor
9897
else
9998
{
10099
engine.GenerateInformation($"Adding Scripts");
101-
102-
// Add the scripts used in the App
103-
var scripts = AddScriptsToArchive(zip, app);
104-
105-
engine.GenerateInformation($"Adding Script dependencies");
106-
107-
// Add script dependencies
108-
var appReferences = AddDependenciesToArchive(zip, app, scripts);
109-
foreach (var pair in appReferences)
110-
{
111-
if (!scriptReferences.ContainsKey(pair.Key))
112-
{
113-
scriptReferences.Add(pair.Key, pair.Value);
114-
}
115-
else
116-
{
117-
scriptReferences[pair.Key].AddRange(pair.Value);
118-
}
119-
}
100+
AddScriptsToArchive(zip, app);
120101
}
121102

122103
if (!options.ExcludeDom)
123104
{
124105
// Add Dom definitions
106+
engine.GenerateInformation($"Adding DOM modules, for app '{app.Name}'");
125107
domModuleIds.AddRangeUnique(app.LatestVersion.GetUsedDomModules());
108+
AddDomToArchive(engine, zip, domModuleIds, options);
126109
}
127110

128111
if (!options.ExcludeImages)
129112
{
130113
// Add Images to companion files
114+
engine.GenerateInformation($"Adding Images, for app '{app.Name}'");
131115
images.AddRangeUnique(app.LatestVersion.GetUsedImages());
116+
AddImagesToArchive(zip, images);
132117
}
133118

134119
if (!options.ExcludeThemes)
135120
{
136121
// Add Theme
122+
engine.GenerateInformation($"Adding Themes, for app '{app.Name}'");
137123
themes.AddRangeUnique(app.LatestVersion.GetUsedThemes());
124+
AddThemesToArchive(zip, themes);
138125
}
139126
}
140127

141-
// Add DOM modules
142-
if (options.ExcludeDom)
143-
{
144-
engine.GenerateInformation($"Skipping DOM modules");
145-
}
146-
else
147-
{
148-
engine.GenerateInformation($"Adding DOM modules");
149-
AddDomToArchive(engine, zip, domModuleIds, options);
150-
}
151-
152-
if (options.ExcludeImages)
153-
{
154-
engine.GenerateInformation($"Skipping Images");
155-
}
156-
else
157-
{
158-
// Add Images
159-
engine.GenerateInformation($"Adding Images");
160-
AddImagesToArchive(zip, images);
161-
}
162-
163-
if (options.ExcludeThemes)
164-
{
165-
engine.GenerateInformation($"Skipping Themes");
166-
}
167-
else
168-
{
169-
// Add Themes
170-
engine.GenerateInformation($"Adding Themes");
171-
AddThemesToArchive(zip, themes);
172-
}
173-
174128
engine.GenerateInformation($"Adding Installer code");
175129

176130
// Add custom Low Code App Installer Code
@@ -194,13 +148,9 @@ private static string ExportPackage(IEngine engine, IEnumerable<App> apps, Expor
194148
sb.AppendLine($"Script\\{Path.GetDirectoryName(file.FullName)}");
195149
}
196150

197-
// Add Assemblies
198-
foreach (var pair in scriptReferences)
151+
foreach(var dependency in zip.GetEntries("AppInstallContent\\Assemblies").Where(x => !x.FullName.EndsWith("\\")))
199152
{
200-
foreach (var reference in pair.Value)
201-
{
202-
sb.AppendLine($"Assembly\\{Path.GetDirectoryName(reference)} for automationscript:{pair.Key}");
203-
}
153+
sb.AppendLine(dependency.FullName);
204154
}
205155

206156
// Add CompanionFiles
@@ -243,50 +193,86 @@ private static void AddAppToArchive(ZipArchive zip, App app, ExportOptions optio
243193
}
244194
}
245195

246-
private static List<string> AddScriptsToArchive(ZipArchive zip, App app)
196+
private static void AddScriptsToArchive(ZipArchive zip, App app)
247197
{
248198
var scripts = app.LatestVersion.GetUsedScripts();
199+
var addedFiles = new List<string>();
249200
foreach (var script in scripts)
250201
{
251-
var scriptName = $"Script_{script}.xml";
252-
var scriptPath = Path.Combine(ScriptPath, scriptName);
253-
if (File.Exists(scriptPath))
202+
AddScriptToArchive(zip, app, script, addedFiles);
203+
}
204+
}
205+
206+
private static void AddScriptToArchive(ZipArchive zip, App app, string script, List<string> addedFiles)
207+
{
208+
var scriptName = $"Script_{script}.xml";
209+
var scriptPath = Path.Combine(ScriptPath, scriptName);
210+
if (File.Exists(scriptPath))
211+
{
212+
if(addedFiles.Exists(x => x == $"AppInstallContent\\Scripts\\{script}\\Script_{script}.xml"))
254213
{
255-
zip.CreateEntryFromFile(Path.Combine(ScriptPath, scriptName), Path.Combine("AppInstallContent", "Scripts", script, scriptName));
214+
return;
256215
}
216+
217+
zip.CreateEntryFromFile(Path.Combine(ScriptPath, scriptName), Path.Combine("AppInstallContent", "Scripts", script, scriptName));
218+
addedFiles.Add(Path.Combine("AppInstallContent", "Scripts", script, scriptName));
219+
AddDependenciesToArchive(zip, app, script, addedFiles);
220+
AddScriptReferencesToArchive(zip, app, script, addedFiles);
221+
}
222+
}
223+
224+
private static void AddScriptReferencesToArchive(ZipArchive zip, App app, string script, List<string> addedFiles)
225+
{
226+
var scriptName = $"Script_{script}.xml";
227+
var scriptPath = Path.Combine(ScriptPath, scriptName);
228+
if (!File.Exists(scriptPath))
229+
{
230+
return;
257231
}
258232

259-
return scripts;
233+
var scriptFile = File.ReadAllText(scriptPath);
234+
XDocument doc = XDocument.Parse(scriptFile);
235+
XNamespace ns = "http://www.skyline.be/automation";
236+
var refParams = doc.Descendants(ns + "Param").Where(param => (string)param.Attribute("type") == "scriptRef");
237+
foreach (var reference in refParams.Select(refParam => refParam.Value))
238+
{
239+
var split = reference.Split(':');
240+
var referenceScriptName = split[0];
241+
if (addedFiles.Exists(x => x == $"AppInstallContent\\Scripts\\{referenceScriptName}\\Script_{referenceScriptName}.xml"))
242+
{
243+
continue;
244+
}
245+
246+
AddScriptToArchive(zip, app, referenceScriptName, addedFiles);
247+
}
260248
}
261249

262-
private static Dictionary<string, List<string>> AddDependenciesToArchive(ZipArchive zip, App app, IEnumerable<string> scripts)
250+
private static void AddDependenciesToArchive(ZipArchive zip, App app, string script, List<string> addedFiles)
263251
{
264-
var scriptReferences = new Dictionary<string, List<string>>();
265-
foreach (var script in scripts)
252+
var scriptName = $"Script_{script}.xml";
253+
var scriptPath = Path.Combine(ScriptPath, scriptName);
254+
if (!File.Exists(scriptPath))
266255
{
267-
if (!scriptReferences.ContainsKey(script))
268-
scriptReferences.Add(script, new List<string>());
269-
var scriptName = $"Script_{script}.xml";
270-
var scriptPath = Path.Combine(ScriptPath, scriptName);
271-
if (!File.Exists(scriptPath))
256+
return;
257+
}
258+
259+
var scriptFile = File.ReadAllText(scriptPath);
260+
XDocument doc = XDocument.Parse(scriptFile);
261+
XNamespace ns = "http://www.skyline.be/automation";
262+
var refParams = doc.Descendants(ns + "Param").Where(param => (string)param.Attribute("type") == "ref");
263+
foreach (var reference in refParams.Select(refParam => refParam.Value))
264+
{
265+
if (addedFiles.Exists(x => x == reference.Replace(@"C:\Skyline DataMiner", "AppInstallContent\\Assemblies")))
272266
{
273267
continue;
274268
}
275269

276-
var scriptFile = System.IO.File.ReadAllText(scriptPath);
277-
XDocument doc = XDocument.Parse(scriptFile);
278-
XNamespace ns = "http://www.skyline.be/automation";
279-
var refParams = doc.Descendants(ns + "Param").Where(param => (string)param.Attribute("type") == "ref");
280-
foreach (var reference in refParams.Select(refParam => refParam.Value))
270+
if (reference.StartsWith(DllImportPath))
281271
{
282-
if (reference.StartsWith(DllImportPath))
283-
{
284-
scriptReferences[script].Add(reference);
285-
zip.CreateEntryFromFile(reference, reference.Replace(@"C:\Skyline DataMiner", "AppInstallContent\\Assemblies"));
286-
}
272+
zip.CreateEntryFromFile(reference, reference.Replace(@"C:\Skyline DataMiner", "AppInstallContent\\Assemblies"));
273+
addedFiles.Add(reference.Replace(@"C:\Skyline DataMiner", "AppInstallContent\\Assemblies"));
287274
}
288275
}
289-
return scriptReferences;
290276
}
291277

292278
private static void AddDomToArchive(IEngine engine, ZipArchive zip, IEnumerable<string> domModuleIds, ExportOptions options)

Low Code App Editor_1/Extensions.cs

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public static IEnumerable<ZipArchiveEntry> GetEntries(this ZipArchive archive, s
7272
return archive.Entries.Where(entry => entry.FullName.StartsWith(entryPath)).ToList();
7373
}
7474

75+
public static bool Exists(this ZipArchive archive, string entryPath)
76+
{
77+
return archive.Entries.Any(entry => entry.FullName == entryPath);
78+
}
79+
7580
public static List<JToken> FindPropertiesWithName(this JToken token, string propertyName)
7681
{
7782
var scriptProperties = new List<JToken>();

0 commit comments

Comments
 (0)