*/
protected void sync() throws Exception
{
////////////////////////////////////////////////////////////////////
// lokale Variablen
ProgressMonitor monitor = HBCISynchronizeBackend.this.worker.getMonitor();
Application.getMessagingFactory().getMessagingQueue(HBCI_TRACE).sendMessage(new HBCITraceMessage(HBCITraceMessage.Type.ID,this.getKonto().getID()));
Application.getMessagingFactory().getMessagingQueue(HBCI_TRACE).sendMessage(new HBCITraceMessage(HBCITraceMessage.Type.INFO,"\n\n" + i18n.tr("{0} Synchronisiere Konto: {1}",HBCI.LONGDATEFORMAT.format(new Date()),this.getKonto().getLongName())));
// Wir ermitteln anhand der Gesamt-Anzahl von Jobs, wieviel Fortschritt
// pro Job gemacht wird, addieren das fuer unsere Gruppe, ziehen noch
// einen Teil fuer Passport-Initialisierung ab (3%) sowie 3% fuer die Job-Auswertung
// und geben den Rest den Jobs in unserer Gruppe. Wir rechnen am Anfang erstmal mit Double,
// um die Rundungsdifferenzen etwas kleiner zu halten
double chunk = 100d / ((double) HBCISynchronizeBackend.this.worker.getSynchronization().size()) * ((double)this.jobs.size());
int step = (int) ((chunk - 6) / this.jobs.size());
////////////////////////////////////////////////////////////////////
boolean haveError = false;
boolean inCatch = false;
try
{
this.checkInterrupted();
monitor.log(" ");
monitor.log(i18n.tr("Synchronisiere Konto: {0}",this.getKonto().getLongName()));
Passport passport = new TaskPassportInit().execute();
this.handle = new TaskHandleInit(passport).execute();
this.handler = new TaskHandleOpen(handle).execute();
new TaskSepaInfo(handler).execute();
Logger.info("processing jobs");
for (SynchronizeJob job:this.jobs)
{
this.checkInterrupted();
AbstractHBCIJob[] list = ((HBCISynchronizeJob)job).createHBCIJobs();
for (AbstractHBCIJob hbciJob:list)
{
this.checkInterrupted();
monitor.setStatusText(i18n.tr("Aktiviere HBCI-Job: \"{0}\"",job.getName()));
Logger.info("adding job " + hbciJob.getIdentifier() + " to queue");
HBCIJob j = handler.newJob(hbciJob.getIdentifier());
this.dumpJob(j);
hbciJob.setJob(j);
j.addToQueue();
this.hbciJobs.add(hbciJob);
if (hbciJob.isExclusive())
{
Logger.info("job will be executed in seperate hbci message");
handler.newMsg();
}
}
monitor.addPercentComplete(step);
}
////////////////////////////////////////////////////////////////////////
// Jobs ausfuehren
Logger.info("executing jobs");
monitor.setStatusText(i18n.tr("F�hre HBCI-Jobs aus"));
this.handler.execute();
monitor.setStatusText(i18n.tr("HBCI-Jobs ausgef�hrt"));
//
////////////////////////////////////////////////////////////////////////
}
catch (Exception e)
{
haveError = true;
inCatch = true;
throw e;
}
finally
{
try
{
String name = null;
// Waehrend der Ergebnis-Auswertung findet KEIN "checkInterrupted" Check statt,
// da sonst Job-Ergebnisse verloren gehen wuerden.
// //////////////////////////////////////////////////////////////////////
// Job-Ergebnisse auswerten.
// checkInterrupted wird hier nicht aufgerufen, um sicherzustellen, dass
// dieser Vorgang nicht abgebrochen wird.
for (AbstractHBCIJob hbciJob:this.hbciJobs)
{
try
{
name = hbciJob.getName();
monitor.setStatusText(i18n.tr("Werte Ergebnis von HBCI-Job \"{0}\" aus",name));
Logger.info("executing check for job " + hbciJob.getIdentifier());
hbciJob.handleResult();
}
catch (Throwable t)
{
haveError = true;
// Nur loggen, wenn wir nicht abgebrochen wurden. Waeren sonst nur Folgefehler
if (!HBCISynchronizeBackend.this.worker.isInterrupted())
{
if (t instanceof ApplicationException)
{
monitor.setStatusText(t.getMessage());
}
else
{
monitor.setStatusText(i18n.tr("Fehler beim Auswerten des HBCI-Auftrages {0}", name));
Logger.error("error while processing job result",t);
monitor.log(t.getMessage());
}
}
}
}
monitor.addPercentComplete(3);
if (haveError || HBCISynchronizeBackend.this.worker.isInterrupted())
{
Logger.warn("found errors or synchronization cancelled, clear PIN cache");
DialogFactory.clearPINCache(this.handler != null ? this.handler.getPassport() : null);