tag:infinitekind.tenderapp.com,2009-01-14:/discussions/moneydance-development/5940-online-downloadInfinite Kind: Discussion 2021-06-16T18:22:29Ztag:infinitekind.tenderapp.com,2009-01-14:Comment/492212362021-05-29T05:21:49Z2021-05-29T05:21:49ZOnline Download<div><p>There is no documented API call.. But you can do it (thus, it's non-API and may not survive upgrades):</p>
<p>In Python you would call:</p>
<pre>
<code>moneydance.getBackgroundThread().scheduleNetSync()</code>
</pre>
<p>In Java, exactly the same but using your reference (or context()) for main..</p>
<p>NOTE: MD checks that it's the primary Sync dataset when opening a datafile, before triggering the downloads... I.E. you don't want all Sync copies doing this... You can check this using:</p>
<pre>
<code>if moneydance.getCurrentAccount().getBook().getLocalStorage().getBoolean("_is_master_node", True) then:</code>
</pre>
<p>To turn off Autodownload... Menu, Preferences, Network, untick Automatically Download in Background. This sets the config.dict key "net.auto_download" to false.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/492212362021-05-29T12:54:05Z2021-05-29T12:54:05ZOnline Download<div><p>Wow! The Amazing Stuart has the answer! Sean should really be paying you.<br>
I'll see if I can incorporate your suggestions in Java.</p>
<p>Thanks!</p></div>Dan Ptag:infinitekind.tenderapp.com,2009-01-14:Comment/492212362021-05-29T15:50:44Z2021-05-29T15:50:44ZOnline Download<div><p>Well, as I'm not a good programmer in python or java, this is going well.</p>
<p>I got the check on master node to work. However, I can't get to the<br>
background thread.</p>
<p><em>In Python you would call:</em></p>
<p>*moneydance.getBackgroundThread().scheduleNetSync() *</p>
<p><em>In Java, exactly the same but using your reference (or context()) for main.</em></p>
<p>I can't find any context that will do this. I may not have a required<br>
library imported.</p>
<p>I'll keep looking. Any 'nudge' would be appreciated.</p></div>Dan Ptag:infinitekind.tenderapp.com,2009-01-14:Comment/492212362021-05-29T16:12:10Z2021-05-29T16:12:10ZOnline Download<div><p>Ok. Well in your Java code you must already have a reference to main / context otherwise you couldn’t call the MD api functions. Do you have anything like xxxx.getUI(). The xxx is it.</p>
<p>Else post your Java code?</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/492212362021-05-29T16:16:49Z2021-05-29T16:16:49ZOnline Download<div><p>so... in your Main.java you will see something like this:</p>
<pre>
<code>public class Main
extends FeatureModule
{
private AccountListWindow accountListWindow = null;
public void init() {
// the first thing we will do is register this module to be invoked
// via the application toolbar
FeatureModuleContext context = getContext();
try {
context.registerFeature(this, "showconsole",
getIcon("accountlist"),
getName());
}
catch (Exception e) {
e.printStackTrace(System.err);
}
}</code>
</pre>
<p>context (above) or whatever you called it should be it....</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/492212362021-05-29T17:24:29Z2021-05-29T17:24:29ZOnline Download<div><p>I just reread you message. If you already got x.getCurrentAccount() to work, then x should be what you want....</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/492212362021-05-29T17:40:45Z2021-05-29T17:40:45ZOnline Download<div><p>Well, that's what I thought too. But it isn't working. I've made several attempts but here is the latest code:</p>
<pre>
<code>public void execAll() {
getPrefs();
if (!Prefs.doneToday) {
if (Prefs.doQUOTES) {getQuotes();}
if (Prefs.doFORUM) {doForum();}
if (Prefs.doAIG) {doAIG(); }
if (Prefs.doLPL) {doLPL();}
if (Prefs.doNW) {doNW();}
Prefs.savePrefs(prefFile);
System.err.println(String.format("%-8s %6s %-14s %-20s", "DAILY", "<INIT>", ft.format(new Date()),
"Daily Update Completed."));
} else {
System.err.println(String.format("%-8s %6s %-14s %-60s", "DAILY", "<INIT>", ft.format(new Date()),
"Daily Update Already Processed for Today."));
}
if (extension.getUnprotectedContext().getCurrentAccountBook().getLocalStorage().getBoolean("_is_master_node", true) ) {
System.err.println(String.format("%-8s %6s %-14s %-60s", "DAILY", "<INIT>", ft.format(new Date()),
"Yes, I am the Master Node."));
try {
FeatureModuleContext contxt = getContext();
System.err.println(String.format("%-8s %6s %-14s %-60s", "DAILY", "<INFO> ", ft.format(new Date()),
"Invoking NetSync."));
((BackgroundOpsThread) contxt).scheduleNetSync();
} catch (final Exception e) {
System.err.println(String.format("%-8s %6s %-14s %-60s", "DAILY", "<ERR> ", ft.format(new Date()),
e.getMessage()));
}
}
}</code>
</pre>
<p>The BackGroundOpsThread cast was suggested by Eclipse so I'm guessing the ScheduleNetSync is in there. It compiles but throws an exception.<br>
<em>class com.moneydance.apps.md.controller.Main cannot be cast to class com.moneydance.apps.md.controller.BackgroundOpsThread (com.moneydance.apps.md.controller.Main and com.moneydance.apps.md.controller.BackgroundOpsThread are in unnamed module of loader 'app')</em></p>
<p>I changed the contxt from getContext() to getUnprotectedContext - same result.</p>
<p>(I am NOT a java guy - as you can probably tell)</p></div>Dan Ptag:infinitekind.tenderapp.com,2009-01-14:Comment/492212362021-05-29T17:58:13Z2021-05-29T17:58:13ZOnline Download<div><p>FYI</p></div>Dan Ptag:infinitekind.tenderapp.com,2009-01-14:Comment/492212362021-05-29T20:43:46Z2021-05-29T22:14:03ZOnline Download<div><p>.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/492212362021-05-29T22:13:52Z2021-05-29T22:13:52ZOnline Download<div><p>I don't write Java myself (just read it), but I just tried adding this line, ran ant to build it, and it works for me.... Remember you're off-piste (off API here).. try:</p>
<pre>
<code>((com.moneydance.apps.md.controller.Main) getContext()).getBackgroundThread().scheduleNetSync();</code>
</pre></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/492212362021-05-29T23:13:41Z2021-05-29T23:13:41ZOnline Download<div><p>Success!</p>
<p>I've incorporated that into my extension and it works fine.<br>
Cautions noted.</p>
<p>Thanks for your help, Stuart. I would likely not have ever figured that cast out.</p>
<p>Dan</p></div>Dan P