@@ -202,154 +202,7 @@ public async Task CommandBinding_GeneralDispatchAnyUiDialogs(
202
202
203
203
if ( cmd == "saveas" )
204
204
{
205
- // start
206
- ticket . StartExec ( ) ;
207
-
208
- // open?
209
- if ( ! PackageCentral . MainAvailable || PackageCentral . MainItem . Container == null )
210
- {
211
- LogErrorToTicket ( ticket , "No open AASX file to be saved." ) ;
212
- return ;
213
- }
214
-
215
- // shall be a local/ user file?!
216
- var isLocalFile = PackageCentral . MainItem . Container is PackageContainerLocalFile ;
217
- var isUserFile = PackageCentral . MainItem . Container is PackageContainerUserFile ;
218
- if ( ! isLocalFile && ! isUserFile )
219
- if ( ! ticket . ScriptMode
220
- && AnyUiMessageBoxResult . Yes != await DisplayContext . MessageBoxFlyoutShowAsync (
221
- "Current AASX file is not a local or user file. Proceed and convert to such file?" ,
222
- "Save" , AnyUiMessageBoxButton . YesNo , AnyUiMessageBoxImage . Hand ) )
223
- return ;
224
-
225
- // filename
226
- var ucsf = await DisplayContextPlus . MenuSelectSaveFilenameAsync (
227
- ticket , "File" ,
228
- "Save AASX package" ,
229
- PackageCentral . MainItem . Filename ,
230
- "AASX package files (*.aasx)|*.aasx|AASX package files w/ JSON (*.aasx)|*.aasx|" +
231
- ( ! isLocalFile ? "" : "AAS XML file (*.xml)|*.xml|AAS JSON file (*.json)|*.json|" ) +
232
- "All files (*.*)|*.*" ,
233
- "Save AASX: No valid filename." ,
234
- reworkSpecialFn : true ) ;
235
- if ( ucsf ? . Result != true )
236
- return ;
237
-
238
- // do
239
- try
240
- {
241
- // dead-csharp off
242
- //// establish target filename
243
- //if (ucsf.Location == AnyUiDialogueDataSaveFile.LocationKind.User)
244
- //{
245
- // targetFn = PackageContainerUserFile.BuildUserFilePath(ucsf.TargetFileName);
246
- // targetFnForLRU = null;
247
- //}
248
-
249
- //if (ucsf.Location == AnyUiDialogueDataSaveFile.LocationKind.Download)
250
- //{
251
- // // produce a .tmp file
252
- // targetFn = System.IO.Path.GetTempFileName();
253
- // targetFnForLRU = null;
254
-
255
- // // rename better
256
- // var _filterItems = AnyUiDialogueDataOpenFile.DecomposeFilter(ucsf.Filter);
257
- // targetFn = AnyUiDialogueDataOpenFile.ApplyFilterItem(
258
- // fi: _filterItems[ucsf.FilterIndex],
259
- // fn: targetFn,
260
- // userFn: ucsf.TargetFileName,
261
- // final: 3);
262
- //}
263
-
264
- //// if not local, do a bit of voodoo ..
265
- //if (!isLocalFile && !isUserFile && PackageCentral.MainItem.Container != null)
266
- //{
267
- // // establish local
268
- // if (!await PackageCentral.MainItem.Container.SaveLocalCopyAsync(
269
- // targetFn,
270
- // runtimeOptions: PackageCentral.CentralRuntimeOptions))
271
- // {
272
- // // Abort
273
- // LogErrorToTicket(ticket,
274
- // "Not able to copy current AASX file to local file. Aborting!");
275
- // return;
276
- // }
277
-
278
- // // re-load
279
- // MainWindow.UiLoadPackageWithNew(
280
- // PackageCentral.MainItem, null, targetFn, onlyAuxiliary: false,
281
- // storeFnToLRU: targetFnForLRU);
282
- // return;
283
- //}
284
-
285
- //
286
- // ELSE .. already local
287
- //
288
- // dead-csharp on
289
-
290
- // preferred format
291
- var prefFmt = AdminShellPackageEnv . SerializationFormat . None ;
292
- if ( ucsf . FilterIndex == 1 )
293
- prefFmt = AdminShellPackageEnv . SerializationFormat . Xml ;
294
- if ( ucsf . FilterIndex == 2 )
295
- prefFmt = AdminShellPackageEnv . SerializationFormat . Json ;
296
-
297
- // save
298
- DisplayContextPlus . RememberForInitialDirectory ( ucsf . TargetFileName ) ;
299
- await PackageCentral . MainItem . SaveAsAsync ( ucsf . TargetFileName , prefFmt : prefFmt ,
300
- doNotRememberLocation : ucsf . Location != AnyUiDialogueDataSaveFile . LocationKind . Local ) ;
301
-
302
- // backup (only for AASX)
303
- if ( ucsf . FilterIndex == 0 )
304
- if ( Options . Curr . BackupDir != null )
305
- PackageCentral . MainItem . Container . BackupInDir (
306
- System . IO . Path . GetFullPath ( Options . Curr . BackupDir ) ,
307
- Options . Curr . BackupFiles ,
308
- PackageContainerBase . BackupType . FullCopy ) ;
309
-
310
- // as saving changes the structure of pending supplementary files, re-display
311
- MainWindow . RedrawAllAasxElements ( ) ;
312
-
313
- // LRU?
314
- // record in LRU?
315
- try
316
- {
317
- var lru = PackageCentral ? . Repositories ? . FindLRU ( ) ;
318
- if ( lru != null && ucsf . Location == AnyUiDialogueDataSaveFile . LocationKind . Local )
319
- lru . Push ( PackageCentral ? . MainItem ? . Container as PackageContainerRepoItem ,
320
- ucsf . TargetFileName ) ;
321
- }
322
- catch ( Exception ex )
323
- {
324
- Log . Singleton . Error (
325
- ex , $ "When managing LRU files") ;
326
- return ;
327
- }
328
-
329
- // if it is a download, provide link
330
- if ( ucsf . Location == AnyUiDialogueDataSaveFile . LocationKind . Download
331
- && DisplayContextPlus . WebBrowserServicesAllowed ( ) )
332
- {
333
- try
334
- {
335
- await DisplayContextPlus . WebBrowserDisplayOrDownloadFile (
336
- ucsf . TargetFileName , "application/octet-stream" ) ;
337
- Log . Singleton . Info ( "Download initiated." ) ;
338
- }
339
- catch ( Exception ex )
340
- {
341
- Log . Singleton . Error (
342
- ex , $ "When downloading saved file") ;
343
- return ;
344
- }
345
- }
346
- }
347
- catch ( Exception ex )
348
- {
349
- LogErrorToTicket ( ticket , ex , "when saving AASX" ) ;
350
- return ;
351
- }
352
- Log . Singleton . Info ( "AASX saved successfully as: {0}" , ucsf . TargetFileName ) ;
205
+ await PerformSaveAsAsync ( ticket ) ;
353
206
}
354
207
355
208
if ( cmd == "close" && PackageCentral ? . Main != null )
@@ -1674,55 +1527,120 @@ private async Task CommandBinding_FixAndFinalizeAsync(AasxMenuActionTicket ticke
1674
1527
Log . Singleton . Info ( "Fixed issues of AASX: {0}" , PackageCentral . MainItem . Filename ) ;
1675
1528
}
1676
1529
1677
- //Save
1678
- // start
1679
- ticket . StartExec ( ) ;
1530
+ //SaveAS
1531
+ await PerformSaveAsAsync ( ticket ) ;
1532
+
1680
1533
1681
- // open?
1682
- if ( ! PackageCentral . MainStorable )
1683
- {
1684
- LogErrorToTicket ( ticket , "No open AASX file to be saved." ) ;
1534
+ }
1535
+ catch ( Exception ex )
1536
+ {
1537
+ Log . Singleton . Error ( ex . Message ) ;
1538
+ Log . Singleton . Error ( ex . StackTrace ) ;
1539
+ }
1540
+
1541
+ }
1542
+
1543
+ private async Task PerformSaveAsAsync ( AasxMenuActionTicket ticket )
1544
+ {
1545
+ // start
1546
+ ticket . StartExec ( ) ;
1547
+
1548
+ // open?
1549
+ if ( ! PackageCentral . MainAvailable || PackageCentral . MainItem . Container == null )
1550
+ {
1551
+ LogErrorToTicket ( ticket , "No open AASX file to be saved." ) ;
1552
+ return ;
1553
+ }
1554
+
1555
+ // shall be a local/ user file?!
1556
+ var isLocalFile = PackageCentral . MainItem . Container is PackageContainerLocalFile ;
1557
+ var isUserFile = PackageCentral . MainItem . Container is PackageContainerUserFile ;
1558
+ if ( ! isLocalFile && ! isUserFile )
1559
+ if ( ! ticket . ScriptMode
1560
+ && AnyUiMessageBoxResult . Yes != await DisplayContext . MessageBoxFlyoutShowAsync (
1561
+ "Current AASX file is not a local or user file. Proceed and convert to such file?" ,
1562
+ "Save" , AnyUiMessageBoxButton . YesNo , AnyUiMessageBoxImage . Hand ) )
1685
1563
return ;
1686
- }
1687
1564
1688
- // do
1689
- try
1690
- {
1691
- // save
1692
- await PackageCentral . MainItem . SaveAsAsync ( runtimeOptions : PackageCentral . CentralRuntimeOptions ) ;
1565
+ // filename
1566
+ var ucsf = await DisplayContextPlus . MenuSelectSaveFilenameAsync (
1567
+ ticket , "File" ,
1568
+ "Save AASX package" ,
1569
+ PackageCentral . MainItem . Filename ,
1570
+ "AASX package files (*.aasx)|*.aasx|AASX package files w/ JSON (*.aasx)|*.aasx|" +
1571
+ ( ! isLocalFile ? "" : "AAS XML file (*.xml)|*.xml|AAS JSON file (*.json)|*.json|" ) +
1572
+ "All files (*.*)|*.*" ,
1573
+ "Save AASX: No valid filename." ,
1574
+ reworkSpecialFn : true ) ;
1575
+ if ( ucsf ? . Result != true )
1576
+ return ;
1693
1577
1694
- // backup
1578
+ // do
1579
+ try
1580
+ {
1581
+ // preferred format
1582
+ var prefFmt = AdminShellPackageEnv . SerializationFormat . None ;
1583
+ if ( ucsf . FilterIndex == 1 )
1584
+ prefFmt = AdminShellPackageEnv . SerializationFormat . Xml ;
1585
+ if ( ucsf . FilterIndex == 2 )
1586
+ prefFmt = AdminShellPackageEnv . SerializationFormat . Json ;
1587
+
1588
+ // save
1589
+ DisplayContextPlus . RememberForInitialDirectory ( ucsf . TargetFileName ) ;
1590
+ await PackageCentral . MainItem . SaveAsAsync ( ucsf . TargetFileName , prefFmt : prefFmt ,
1591
+ doNotRememberLocation : ucsf . Location != AnyUiDialogueDataSaveFile . LocationKind . Local ) ;
1592
+
1593
+ // backup (only for AASX)
1594
+ if ( ucsf . FilterIndex == 0 )
1695
1595
if ( Options . Curr . BackupDir != null )
1696
1596
PackageCentral . MainItem . Container . BackupInDir (
1697
1597
System . IO . Path . GetFullPath ( Options . Curr . BackupDir ) ,
1698
1598
Options . Curr . BackupFiles ,
1699
1599
PackageContainerBase . BackupType . FullCopy ) ;
1700
1600
1701
- // may be was saved to index
1702
- if ( PackageCentral ? . MainItem ? . Container ? . Env ? . AasEnv != null )
1703
- PackageCentral . MainItem . Container . SignificantElements
1704
- = new IndexOfSignificantAasElements ( PackageCentral . MainItem . Container . Env . AasEnv ) ;
1705
-
1706
- // may be was saved to flush events
1707
- MainWindow . CheckIfToFlushEvents ( ) ;
1601
+ // as saving changes the structure of pending supplementary files, re-display
1602
+ MainWindow . RedrawAllAasxElements ( ) ;
1708
1603
1709
- // as saving changes the structure of pending supplementary files, re-display
1710
- MainWindow . RedrawAllAasxElements ( keepFocus : true ) ;
1604
+ // LRU?
1605
+ // record in LRU?
1606
+ try
1607
+ {
1608
+ var lru = PackageCentral ? . Repositories ? . FindLRU ( ) ;
1609
+ if ( lru != null && ucsf . Location == AnyUiDialogueDataSaveFile . LocationKind . Local )
1610
+ lru . Push ( PackageCentral ? . MainItem ? . Container as PackageContainerRepoItem ,
1611
+ ucsf . TargetFileName ) ;
1711
1612
}
1712
1613
catch ( Exception ex )
1713
1614
{
1714
- LogErrorToTicket ( ticket , ex , "when saving AASX" ) ;
1615
+ Log . Singleton . Error (
1616
+ ex , $ "When managing LRU files") ;
1715
1617
return ;
1716
1618
}
1717
1619
1718
- Log . Singleton . Info ( "Fixed the issues and successfully saved AASX: {0}" , PackageCentral . MainItem . Filename ) ;
1620
+ // if it is a download, provide link
1621
+ if ( ucsf . Location == AnyUiDialogueDataSaveFile . LocationKind . Download
1622
+ && DisplayContextPlus . WebBrowserServicesAllowed ( ) )
1623
+ {
1624
+ try
1625
+ {
1626
+ await DisplayContextPlus . WebBrowserDisplayOrDownloadFile (
1627
+ ucsf . TargetFileName , "application/octet-stream" ) ;
1628
+ Log . Singleton . Info ( "Download initiated." ) ;
1629
+ }
1630
+ catch ( Exception ex )
1631
+ {
1632
+ Log . Singleton . Error (
1633
+ ex , $ "When downloading saved file") ;
1634
+ return ;
1635
+ }
1636
+ }
1719
1637
}
1720
1638
catch ( Exception ex )
1721
1639
{
1722
- Log . Singleton . Error ( ex . Message ) ;
1723
- Log . Singleton . Error ( ex . StackTrace ) ;
1640
+ LogErrorToTicket ( ticket , ex , "when saving AASX" ) ;
1641
+ return ;
1724
1642
}
1725
-
1643
+ Log . Singleton . Info ( "AASX saved successfully as: {0}" , ucsf . TargetFileName ) ;
1726
1644
}
1727
1645
1728
1646
//
0 commit comments