Skip to content

Commit 5200dad

Browse files
committed
* first version working
1 parent 0c6ca2e commit 5200dad

File tree

5 files changed

+112
-13
lines changed

5 files changed

+112
-13
lines changed

src/AasxCsharpLibrary/AdminShellUtil.cs

+39-2
Original file line numberDiff line numberDiff line change
@@ -1090,11 +1090,12 @@ public static string GetTemporaryDirectory()
10901090

10911091
// see: https://stackoverflow.com/questions/6386113/using-system-io-packaging-to-generate-a-zip-file
10921092
public static void AddFileToZip(
1093-
string zipFilename, string fileToAdd,
1093+
string zipFilename,
1094+
string fileToAdd,
10941095
CompressionOption compression = CompressionOption.Normal,
10951096
FileMode fileMode = FileMode.OpenOrCreate)
10961097
{
1097-
using (Package zip = System.IO.Packaging.Package.Open(zipFilename, FileMode.OpenOrCreate))
1098+
using (Package zip = System.IO.Packaging.Package.Open(zipFilename, fileMode))
10981099
{
10991100
string destFilename = ".\\" + Path.GetFileName(fileToAdd);
11001101
Uri uri = PackUriHelper.CreatePartUri(new Uri(destFilename, UriKind.Relative));
@@ -1113,6 +1114,42 @@ public static void AddFileToZip(
11131114
}
11141115
}
11151116

1117+
public static void RecursiveAddDirToZip(
1118+
Package zip,
1119+
string localPath,
1120+
string zipPath = "",
1121+
CompressionOption compression = CompressionOption.Normal)
1122+
{
1123+
// enumerate only on this level
1124+
foreach (var infn in Directory.EnumerateDirectories(localPath, "*"))
1125+
{
1126+
// recurse
1127+
RecursiveAddDirToZip(
1128+
zip,
1129+
localPath: infn,
1130+
zipPath: Path.Combine(zipPath, Path.GetFileName(infn)),
1131+
compression: compression);
1132+
}
1133+
1134+
foreach (var infn in Directory.EnumerateFiles(localPath, "*"))
1135+
{
1136+
string destFilename = ".\\" + Path.Combine(zipPath, Path.GetFileName(infn));
1137+
Uri uri = PackUriHelper.CreatePartUri(new Uri(destFilename, UriKind.Relative));
1138+
if (zip.PartExists(uri))
1139+
{
1140+
zip.DeletePart(uri);
1141+
}
1142+
PackagePart part = zip.CreatePart(uri, "", compression);
1143+
using (FileStream fileStream = new FileStream(infn, FileMode.Open, FileAccess.Read))
1144+
{
1145+
using (Stream dest = part.GetStream())
1146+
{
1147+
fileStream.CopyTo(dest);
1148+
}
1149+
}
1150+
}
1151+
}
1152+
11161153
//
11171154
// some URL enabled path handling
11181155
//

src/AasxPackageExplorer/debug.MIHO.script

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// Tool("sammaspectimport", "File", "C:\\HOMI\\Develop\\Aasx\\repo\\samm-test\\Batch-MM-2_0_0.ttl");
1111
Tool("editkey");
1212
Select("Submodel", "First");
13+
Select("Submodel", "Next");
14+
Tool("exportsmtasciidoc", "File", "C:\\Users\\homi0002\\Desktop\\tmp\\new.zip", "AntoraStyle", "true");
1315
// Tool("sammaspectimport", "File", "C:\\HOMI\\Develop\\Aasx\\repo\\samm-test\\Aspect_Example_SML_MLP.ttl");
1416
// Tool("exportpredefineconcepts", "File", "C:\HOMI\Develop\Aasx\repo\aid\new.txt");
1517
// Tool("submodelinstancefromsmtconcepts");

src/AasxPluginExportTable/Smt/AnyUiDialogueSmtExport.cs

+19-6
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static async Task ExportSmtDialogBased(
8080
var panel = new AnyUiStackPanel();
8181
var helper = new AnyUiSmallWidgetToolkit();
8282

83-
var g = helper.AddSmallGrid(5, 2, new[] { "220:", "*" },
83+
var g = helper.AddSmallGrid(6, 2, new[] { "220:", "*" },
8484
padding: new AnyUiThickness(0, 5, 0, 5));
8585
panel.Add(g);
8686

@@ -140,26 +140,39 @@ public static async Task ExportSmtDialogBased(
140140
colSpan: 2),
141141
(b) => { record.IncludeTables = b; });
142142

143-
// Row 3 : Export HTML
144-
helper.AddSmallLabelTo(g, 3, 0, content: "Export HTML:",
143+
// Row 3 : Include Tables
144+
helper.AddSmallLabelTo(g, 3, 0, content: "Antora style:",
145145
verticalAlignment: AnyUiVerticalAlignment.Center,
146146
verticalContentAlignment: AnyUiVerticalAlignment.Center);
147147
AnyUiUIElement.SetBoolFromControl(
148148
helper.Set(
149149
helper.AddSmallCheckBoxTo(g, 3, 1,
150+
content: "(dedicated sub-folders for images and diagrams)",
151+
isChecked: record.AntoraStyle,
152+
verticalContentAlignment: AnyUiVerticalAlignment.Center),
153+
colSpan: 2),
154+
(b) => { record.AntoraStyle = b; });
155+
156+
// Row 4 : Export HTML
157+
helper.AddSmallLabelTo(g, 4, 0, content: "Export HTML:",
158+
verticalAlignment: AnyUiVerticalAlignment.Center,
159+
verticalContentAlignment: AnyUiVerticalAlignment.Center);
160+
AnyUiUIElement.SetBoolFromControl(
161+
helper.Set(
162+
helper.AddSmallCheckBoxTo(g, 4, 1,
150163
content: "(export command given by options will be executed)",
151164
isChecked: record.ExportHtml,
152165
verticalContentAlignment: AnyUiVerticalAlignment.Center),
153166
colSpan: 2),
154167
(b) => { record.ExportHtml = b; });
155168

156-
// Row 4 : Export PDF
157-
helper.AddSmallLabelTo(g, 4, 0, content: "Export PDF:",
169+
// Row 5 : Export PDF
170+
helper.AddSmallLabelTo(g, 5, 0, content: "Export PDF:",
158171
verticalAlignment: AnyUiVerticalAlignment.Center,
159172
verticalContentAlignment: AnyUiVerticalAlignment.Center);
160173
AnyUiUIElement.SetBoolFromControl(
161174
helper.Set(
162-
helper.AddSmallCheckBoxTo(g, 4, 1,
175+
helper.AddSmallCheckBoxTo(g, 5, 1,
163176
content: "(export command given by options will be executed)",
164177
isChecked: record.ExportPdf,
165178
verticalContentAlignment: AnyUiVerticalAlignment.Center),

src/AasxPluginExportTable/Smt/ExportSmt.cs

+49-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ This source code may use other Open Source software components (see LICENSE.txt)
3131
using AasxPluginExportTable.Table;
3232
using System.Runtime.Intrinsics.X86;
3333
using AnyUi;
34+
using System.Drawing.Drawing2D;
35+
using System.IO.Packaging;
3436

3537
namespace AasxPluginExportTable.Smt
3638
{
@@ -50,6 +52,10 @@ public class ExportSmt
5052
protected StringBuilder _adoc = new StringBuilder();
5153
protected bool _singleFile = true;
5254

55+
protected string _locationPages = "";
56+
protected string _locationImages = "";
57+
protected string _locationDiagrams = "";
58+
5359
protected void ProcessTextBlob(string header, Aas.IBlob blob)
5460
{
5561
// any content
@@ -171,7 +177,7 @@ protected void ProcessImageLink(Aas.ISubmodelElement sme)
171177
fn = args.fileName;
172178

173179
// save absolute
174-
var absFn = Path.Combine(_tempDir, fn);
180+
var absFn = Path.Combine(_locationImages, fn);
175181
File.WriteAllBytes(absFn, data);
176182
_log?.Info("Image data with {0} bytes writen to {1}.", data.Length, absFn);
177183

@@ -213,7 +219,7 @@ protected void ProcessUml(Aas.IReferenceElement refel)
213219
if (refel.IdShort.HasContent())
214220
pumlName = AdminShellUtil.FilterFriendlyName(refel.IdShort);
215221
var pumlFn = pumlName + ".puml";
216-
var absPumlFn = Path.Combine(_tempDir, pumlFn);
222+
var absPumlFn = Path.Combine(_locationDiagrams, pumlFn);
217223

218224
// make options
219225
var umlOptions = new ExportUmlRecord();
@@ -349,6 +355,32 @@ public void ExportSmtToFile(
349355
_tempDir = AdminShellUtil.GetTemporaryDirectory();
350356
log?.Info("ExportSmt: using temp directory {0} ..", _tempDir);
351357

358+
_locationPages = _tempDir;
359+
_locationImages = _tempDir;
360+
_locationDiagrams = _tempDir;
361+
362+
// sub-folders?
363+
if (optionsSmt.AntoraStyle)
364+
{
365+
try
366+
{
367+
_locationPages = Path.Combine(_tempDir, "pages");
368+
_locationImages = Path.Combine(_tempDir, "images");
369+
_locationDiagrams = Path.Combine(Path.Combine(_tempDir, "partials"), "diagrams");
370+
371+
Directory.CreateDirectory(_locationPages);
372+
Directory.CreateDirectory(_locationImages);
373+
Directory.CreateDirectory(Path.Combine(_tempDir, "partials"));
374+
Directory.CreateDirectory(_locationDiagrams);
375+
376+
_log?.Info(StoredPrint.Color.Black,
377+
"Created dedicated sub-folders for pages, images, partials/diagrams.");
378+
} catch (Exception ex)
379+
{
380+
_log?.Error(ex, "Creating sub-folders within " + _tempDir);
381+
}
382+
}
383+
352384
// predefined semantic ids
353385
var defs = AasxPredefinedConcepts.AsciiDoc.Static;
354386
var mm = MatchMode.Relaxed;
@@ -402,7 +434,7 @@ public void ExportSmtToFile(
402434
? AdminShellUtil.FilterFriendlyName(_srcSm.IdShort)
403435
: "output";
404436
var adocFn = title + ".adoc";
405-
var absAdocFn = Path.Combine(_tempDir, adocFn);
437+
var absAdocFn = Path.Combine(_locationPages, adocFn);
406438

407439
// write it
408440
File.WriteAllText(absAdocFn, adocText);
@@ -439,15 +471,27 @@ public void ExportSmtToFile(
439471
else
440472
{
441473
// create zip package
474+
#if __old_
442475
var first = true;
443476
foreach (var infn in Directory.EnumerateFiles(_tempDir, "*"))
477+
// foreach (var infn in Directory.GetFiles(_tempDir, "*", SearchOption.AllDirectories))
444478
{
445479
AdminShellUtil.AddFileToZip(
446-
fn, infn,
480+
fn,
481+
infn,
447482
fileMode: first ? FileMode.Create : FileMode.OpenOrCreate);
448483
first = false;
449484
}
450-
log?.Info("ExportSmt: packed all files to {0}", fn);
485+
#else
486+
using (Package zip = System.IO.Packaging.Package.Open(fn, FileMode.Create))
487+
{
488+
AdminShellUtil.RecursiveAddDirToZip(
489+
zip,
490+
_tempDir);
491+
}
492+
#endif
493+
494+
log?.Info("ExportSmt: packed all files to {0}", fn);
451495
}
452496

453497
// remove temp directory

src/AasxPluginExportTable/Smt/ExportSmtRecord.cs

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public class ExportSmtRecord
3434
[AasxMenuArgument(help: "If true, will include table data in main AsciiDoc file.")]
3535
public bool IncludeTables = true;
3636

37+
[AasxMenuArgument(help: "If true, will do dedicated sub-folders for images and diagrams.")]
38+
public bool AntoraStyle = false;
39+
3740
[AasxMenuArgument(help: "If true, will execute external program to produce HTML from AsciiDic.")]
3841
public bool ExportHtml = false;
3942

0 commit comments

Comments
 (0)