Skip to content

Commit

Permalink
Run plugin as trial run, readonly, keep cache (#1501)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn authored Jul 23, 2024
1 parent 30677cb commit 19566a8
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 33 deletions.
49 changes: 26 additions & 23 deletions OneMore/Commands/File/PluginDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions OneMore/Commands/File/PluginDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public PluginDialog()
"childBox",
"skipLockRadio",
"failLockRadio",
"trialBox",
"saveButton",
"okButton", // Run
"cancelButton=word_Cancel"
Expand All @@ -71,9 +72,6 @@ public PluginDialog()

targetBox.SelectedIndex = 0;

keepCache.Visible = new SettingsProvider()
.GetCollection("GeneralSheet").Get<bool>("experimental");

initializing = false;
}

Expand Down Expand Up @@ -114,8 +112,6 @@ public PluginDialog(Plugin plugin)
okButton.Enabled = false;
okButton.Visible = false;

keepCache.Visible = false;

initializing = false;
}

Expand All @@ -138,7 +134,7 @@ public PluginDialog(Plugin plugin)
};


public bool KeepCache => keepCache.Visible && keepCache.Checked;
public bool TrialRun => trialBox.Checked;


public string PageName { set; private get; }
Expand Down
27 changes: 23 additions & 4 deletions OneMore/Commands/File/RunPluginCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class RunPluginCommand : Command
private ProgressDialog progress = null;
private Page page;
private string workpath;
private bool keepCache;
private bool trialRun;


public RunPluginCommand()
Expand Down Expand Up @@ -121,7 +121,7 @@ private bool PromptForPlugin()
}

plugin = dialog.Plugin;
keepCache = dialog.KeepCache;
trialRun = dialog.TrialRun;
return true;
}

Expand Down Expand Up @@ -266,7 +266,8 @@ private async Task<bool> ExecuteWorker(ProgressDialog progress, CancellationToke
var absargs = Environment.ExpandEnvironmentVariables(plugin.Arguments);
var userargs = Environment.ExpandEnvironmentVariables(plugin.UserArguments);

logger.WriteLine($"running {abscmd} {absargs} \"{path}\" {userargs}");
var op = trialRun ? "trialing" : "running";
logger.WriteLine($"{op} {abscmd} {absargs} \"{path}\" {userargs}");

var info = new ProcessStartInfo
{
Expand Down Expand Up @@ -376,6 +377,18 @@ private XElement LoadUpdates(string content)

private async Task SavePage(XElement root)
{
if (!OneNote.ValidateSchema(root))
{
ShowError($"{Resx.Plugin_InvalidSchema}\n\nCache: {workpath}");
return;
}

if (trialRun)
{
ShowInfo(string.Format(Resx.Plugin_trialCompleted, workpath));
return;
}

try
{
await using var one = new OneNote();
Expand Down Expand Up @@ -466,6 +479,12 @@ private async Task CreatePage(OneNote one, XElement childRoot)

private async Task SaveHierarchy(XElement root)
{
if (trialRun)
{
ShowInfo(string.Format(Resx.Plugin_trialCompleted, workpath));
return;
}

try
{
await using var one = new OneNote();
Expand All @@ -481,7 +500,7 @@ private async Task SaveHierarchy(XElement root)

private void Cleanup(string workPath)
{
if (File.Exists(workPath) && !keepCache)
if (File.Exists(workPath) && !trialRun)
{
try
{
Expand Down
20 changes: 20 additions & 0 deletions OneMore/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions OneMore/Properties/Resources.ar-SA.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,12 @@
<value>توصيل في</value>
<comment>Open File Dialog title</comment>
</data>
<data name="Plugin_trialCompleted" xml:space="preserve">
<value>تم الانتهاء من التشغيل التجريبي

ذاكرة التخزين المؤقت: {0}</value>
<comment>message</comment>
</data>
<data name="Plugin_Unsuccessful" xml:space="preserve">
<value>لم يكتمل البرنامج المساعد بنجاح. </value>
<comment>error message</comment>
Expand Down Expand Up @@ -2189,6 +2195,10 @@
<value>تميوت</value>
<comment>label</comment>
</data>
<data name="PluginDialog_trialBox.Text" xml:space="preserve">
<value>التشغيل التجريبي - احتفظ بملف ذاكرة التخزين المؤقت ولا تقم بتحديث OneNote</value>
<comment>checkbox</comment>
</data>
<data name="PluginDialog_updateRadio.Text" xml:space="preserve">
<value>تحديث الصفحة الحالية</value>
<comment>radio button</comment>
Expand Down
10 changes: 10 additions & 0 deletions OneMore/Properties/Resources.de-DE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,12 @@ In diesem Abschnitt</value>
<value>Plugin</value>
<comment>Open File Dialog title</comment>
</data>
<data name="Plugin_trialCompleted" xml:space="preserve">
<value>Probelauf abgeschlossen

Cache: {0}</value>
<comment>message</comment>
</data>
<data name="Plugin_Unsuccessful" xml:space="preserve">
<value>Plugin wurde nicht erfolgreich abgeschlossen. </value>
<comment>error message</comment>
Expand Down Expand Up @@ -2187,6 +2193,10 @@ Alle Notizbücher und ihre Seiten</value>
<value>Tmeout</value>
<comment>label</comment>
</data>
<data name="PluginDialog_trialBox.Text" xml:space="preserve">
<value>Testlauf – Cache-Datei behalten und OneNote nicht aktualisieren</value>
<comment>checkbox</comment>
</data>
<data name="PluginDialog_updateRadio.Text" xml:space="preserve">
<value>Aktuelle Seite aktualisieren</value>
<comment>radio button</comment>
Expand Down
10 changes: 10 additions & 0 deletions OneMore/Properties/Resources.es-ES.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,12 @@ En esta sección</value>
<value>Enchufar</value>
<comment>Open File Dialog title</comment>
</data>
<data name="Plugin_trialCompleted" xml:space="preserve">
<value>Prueba completada

Caché: {0}</value>
<comment>message</comment>
</data>
<data name="Plugin_Unsuccessful" xml:space="preserve">
<value>El complemento no se completó correctamente. </value>
<comment>error message</comment>
Expand Down Expand Up @@ -2189,6 +2195,10 @@ Todos los cuadernos y sus páginas.</value>
<value>Tmeout</value>
<comment>label</comment>
</data>
<data name="PluginDialog_trialBox.Text" xml:space="preserve">
<value>Ejecución de prueba: mantenga el archivo de caché y no actualice OneNote</value>
<comment>checkbox</comment>
</data>
<data name="PluginDialog_updateRadio.Text" xml:space="preserve">
<value>Actualizar la página actual</value>
<comment>radio button</comment>
Expand Down
10 changes: 10 additions & 0 deletions OneMore/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,12 @@ Dans cette section</value>
<value>Brancher</value>
<comment>Open File Dialog title</comment>
</data>
<data name="Plugin_trialCompleted" xml:space="preserve">
<value>Essai terminé

Cache : {0}</value>
<comment>message</comment>
</data>
<data name="Plugin_Unsuccessful" xml:space="preserve">
<value>Le plug-in ne s'est pas terminé correctement. </value>
<comment>error message</comment>
Expand Down Expand Up @@ -2189,6 +2195,10 @@ Tous les cahiers et leurs pages</value>
<value>Temps d'attente</value>
<comment>label</comment>
</data>
<data name="PluginDialog_trialBox.Text" xml:space="preserve">
<value>Essai : conservez le fichier cache et ne mettez pas à jour OneNote</value>
<comment>checkbox</comment>
</data>
<data name="PluginDialog_updateRadio.Text" xml:space="preserve">
<value>Mettre à jour la page actuelle</value>
<comment>radio button</comment>
Expand Down
10 changes: 10 additions & 0 deletions OneMore/Properties/Resources.he-IL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,12 @@ Total Row Font
<value>חיבור</value>
<comment>Open File Dialog title</comment>
</data>
<data name="Plugin_trialCompleted" xml:space="preserve">
<value>ריצת הניסיון הושלמה

מטמון: {0}</value>
<comment>message</comment>
</data>
<data name="Plugin_Unsuccessful" xml:space="preserve">
<value>הפלאגין לא הושלם בהצלחה. ראה קובץ יומן.</value>
<comment>error message</comment>
Expand Down Expand Up @@ -2198,6 +2204,10 @@ Total Row Font
<value>Tmeout</value>
<comment>label</comment>
</data>
<data name="PluginDialog_trialBox.Text" xml:space="preserve">
<value>הפעלת ניסיון - שמור קובץ מטמון ואל תעדכן את OneNote</value>
<comment>checkbox</comment>
</data>
<data name="PluginDialog_updateRadio.Text" xml:space="preserve">
<value>עדכן את הדף הנוכחי</value>
<comment>radio button</comment>
Expand Down
10 changes: 10 additions & 0 deletions OneMore/Properties/Resources.nl-NL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,12 @@ In deze sectie</value>
<value>Inpluggen</value>
<comment>Open File Dialog title</comment>
</data>
<data name="Plugin_trialCompleted" xml:space="preserve">
<value>Proefdraaien voltooid

Cache: {0}</value>
<comment>message</comment>
</data>
<data name="Plugin_Unsuccessful" xml:space="preserve">
<value>De plug-in is niet succesvol voltooid. </value>
<comment>error message</comment>
Expand Down Expand Up @@ -2190,6 +2196,10 @@ Alle notitieboekjes en hun pagina's</value>
<value>Tmeout</value>
<comment>label</comment>
</data>
<data name="PluginDialog_trialBox.Text" xml:space="preserve">
<value>Proefdraaien: bewaar het cachebestand en werk OneNote niet bij</value>
<comment>checkbox</comment>
</data>
<data name="PluginDialog_updateRadio.Text" xml:space="preserve">
<value>Update huidige pagina</value>
<comment>radio button</comment>
Expand Down
Loading

0 comments on commit 19566a8

Please sign in to comment.