public static FinService GetFinService(FinContact contact, FinDialog dialog, StringDictionary arguments)
        {
            if (contact == null)
            {
                throw new ArgumentNullException("contact");
            }

            string acctBankCode = arguments[Arguments.AcctBankCode] ?? contact.BankCode;

            if (acctBankCode == null)
            {
                throw new ArgumentException("Bankleitzahl zu Konto fehlt!");
            }

            if (acctBankCode.Length != 8 || !FinUtil.IsDigits(acctBankCode))
            {
                throw new ArgumentException("Bankleitzahl zu Konto ist ungültig!");
            }

            string acctNo = arguments[Arguments.AcctNo];

            if (acctNo == null)
            {
                throw new ArgumentException("Kontonummer fehlt!");
            }

            if (acctNo == "" || acctNo.Length > 30)
            {
                throw new ArgumentException("Kontonummer ist ungültig!");
            }

            string acctCurrency = arguments["-acctcurrency"];

            if (acctCurrency == null)
            {
                acctCurrency = "EUR";
            }
            else if (acctCurrency.Length != 3 || !FinUtil.IsUpperAscii(acctCurrency))
            {
                throw new ArgumentException("Kontowährung ist ungültig!");
            }

            // Die Bankverbindung ist jetzt vollständig spezifiziert und wir können ein
            // FinService Objekt dafür anlegen.
            FinService aService = dialog != null ?
                                  new FinService(dialog, acctBankCode, acctNo, acctCurrency) :
                                  new FinService(contact, acctBankCode, acctNo, acctCurrency);

            return(aService);
        }
        public static FinService GetFinService(FinContact contact, FinDialog dialog, StringDictionary arguments)
        {
            if (contact == null)
            {
                throw new ArgumentNullException("contact");
            }

            string acctBankCode = arguments[Arguments.AcctBankCode] ?? contact.BankCode;
            if (acctBankCode == null)
            {
                throw new ArgumentException("Bankleitzahl zu Konto fehlt!");
            }

            if (acctBankCode.Length != 8 || !FinUtil.IsDigits(acctBankCode))
            {
                throw new ArgumentException("Bankleitzahl zu Konto ist ungültig!");
            }

            string acctNo = arguments[Arguments.AcctNo];
            if (acctNo == null)
            {
                throw new ArgumentException("Kontonummer fehlt!");
            }

            if (acctNo == "" || acctNo.Length > 30)
            {
                throw new ArgumentException("Kontonummer ist ungültig!");
            }

            string acctCurrency = arguments["-acctcurrency"];
            if (acctCurrency == null)
            {
                acctCurrency = "EUR";
            }
            else if (acctCurrency.Length != 3 || !FinUtil.IsUpperAscii(acctCurrency))
            {
                throw new ArgumentException("Kontowährung ist ungültig!");
            }

            // Die Bankverbindung ist jetzt vollständig spezifiziert und wir können ein
            // FinService Objekt dafür anlegen.
            FinService aService = dialog != null ?
                new FinService(dialog, acctBankCode, acctNo, acctCurrency) :
                new FinService(contact, acctBankCode, acctNo, acctCurrency);

            return aService;
        }
        public IActionResult DoAction(string action, StringDictionary arguments)
        {
            // In jedem Fall wird die PIN oder der Dialogkontext zur Fortführung benötigt.
            string pin = arguments[Arguments.Pin];
            string resume = arguments[Arguments.Resume];

            // Optional kann eine TAN oder eine TAN-Liste mitgegeben werden.
            // Wird beides nicht mitgegeben, so wird die TAN auf der Kommandozeile abgefragt.
            ITanSource tanSource = tanSourceFactory.GetTanSource(arguments);

            // Optional kann eine Datei für den HBCI-FinTsTrace angegeben werden.
            string traceFile = arguments[Arguments.Trace];

            // Wird der Schalter -suspend angegeben, so wird nach der Aktion keine
            // Dialogbeendigung durchgeführt, sondern einfach der Zustand in die angegebene Datei gespeichert.
            string suspend = arguments[Arguments.Suspend];

            // Die IAction Implementierung für die gewünschte Aktion erstellen.
            IAction cmd = actionFactory.GetAction(action);
            if (!cmd.Parse(action, arguments))
            {
                throw new ArgumentException("Wrong arguments for the given action!");
            }

            FinContact contact;
            FinDialog dialog = null;

            if (resume != null)
            {
                dialog = new FinDialog();
                dialog.Load(resume);
                contact = dialog.Contact;
            }
            else
            {
                contact = FinContactCreator.GetFinContact(arguments);
            }

            FinService service = FinServiceCreator.GetFinService(contact, dialog, arguments);
            IActionResult result = new ActionResult(Status.Unknown);

            try
            {
                service.ClearDocket();

                if (!service.Online)
                {
                    // Hinweis: eine erforderliche Synchronisierung wird von LogOn immer automatisch durchführt.
                    if (!service.LogOn(pin))
                    {
                        result = new ActionResult(Status.CouldNotLogOn);
                        goto _done;
                    }
                }

                if (service.Online) {

                    result = cmd.Execute(service, tanSource);

                    if (suspend != null)
                    {
                        service.Dialog.SaveAs(suspend);
                    }
                    else
                    {
                        service.LogOff();
                    }
                }

                _done:

                // Falls der Bankkontakt aus einer Datei geladen wurde, so muss diese nun noch
                // gespeichert werden, damit auch alle am Bankkontakt erfolgten Änderungen
                // erhalten bleiben.
                string sContactFile = arguments[Arguments.ContactFile];
                if (sContactFile != null)
                {
                    contact.SaveAs(sContactFile);
                }

                // Wurde eine Tracedatei angegeben, so wird der komplette HBCI FinTsTrace in diese
                // Datei geschrieben.
                if (traceFile != null)
                {
                    StreamWriter sw = File.CreateText(traceFile);
                    sw.Write(service.Trace);
                    sw.Close();
                }

                // Auftrag ausgeführt. Zuerst geben wir den gesammelten Laufzettel aus,
                // danach die Antwortdaten, sofern welche vorhanden sind.
                io.Write(service.Docket);

                if (result.Status != Status.CouldNotLogOn)
                {
                    ResponseData responseData = cmd.GetResponseData(service);
                    if (responseData.Formatted != null)
                    {
                        io.Write(responseData.Formatted);
                    }
                    result.Response = responseData;
                }
            }
            catch (Exception x)
            {
                throw new ActionException(x, service.Trace);
            }
            finally
            {
                service.Dispose();
            }

            return result;
        }
Esempio n. 4
0
        public IActionResult DoAction(string action, StringDictionary arguments)
        {
            // In jedem Fall wird die PIN oder der Dialogkontext zur Fortführung benötigt.
            string pin    = arguments[Arguments.Pin];
            string resume = arguments[Arguments.Resume];

            // Optional kann eine TAN oder eine TAN-Liste mitgegeben werden.
            // Wird beides nicht mitgegeben, so wird die TAN auf der Kommandozeile abgefragt.
            ITanSource tanSource = tanSourceFactory.GetTanSource(arguments);

            // Optional kann eine Datei für den HBCI-FinTsTrace angegeben werden.
            string traceFile = arguments[Arguments.Trace];

            // Wird der Schalter -suspend angegeben, so wird nach der Aktion keine
            // Dialogbeendigung durchgeführt, sondern einfach der Zustand in die angegebene Datei gespeichert.
            string suspend = arguments[Arguments.Suspend];

            // Die IAction Implementierung für die gewünschte Aktion erstellen.
            IAction cmd = actionFactory.GetAction(action);

            if (!cmd.Parse(action, arguments))
            {
                throw new ArgumentException("Wrong arguments for the given action!");
            }

            FinContact contact;
            FinDialog  dialog = null;

            if (resume != null)
            {
                dialog = new FinDialog();
                dialog.Load(resume);
                contact = dialog.Contact;
            }
            else
            {
                contact = FinContactCreator.GetFinContact(arguments);
            }

            FinService    service = FinServiceCreator.GetFinService(contact, dialog, arguments);
            IActionResult result  = new ActionResult(Status.Unknown);

            try
            {
                service.ClearDocket();

                if (!service.Online)
                {
                    // Hinweis: eine erforderliche Synchronisierung wird von LogOn immer automatisch durchführt.
                    if (!service.LogOn(pin))
                    {
                        result = new ActionResult(Status.CouldNotLogOn);
                        goto _done;
                    }
                }

                if (service.Online)
                {
                    result = cmd.Execute(service, tanSource);

                    if (suspend != null)
                    {
                        service.Dialog.SaveAs(suspend);
                    }
                    else
                    {
                        service.LogOff();
                    }
                }

_done:

                // Falls der Bankkontakt aus einer Datei geladen wurde, so muss diese nun noch
                // gespeichert werden, damit auch alle am Bankkontakt erfolgten Änderungen
                // erhalten bleiben.
                string sContactFile = arguments[Arguments.ContactFile];
                if (sContactFile != null)
                {
                    contact.SaveAs(sContactFile);
                }

                // Wurde eine Tracedatei angegeben, so wird der komplette HBCI FinTsTrace in diese
                // Datei geschrieben.
                if (traceFile != null)
                {
                    StreamWriter sw = File.CreateText(traceFile);
                    sw.Write(service.Trace);
                    sw.Close();
                }

                // Auftrag ausgeführt. Zuerst geben wir den gesammelten Laufzettel aus,
                // danach die Antwortdaten, sofern welche vorhanden sind.
                io.Write(service.Docket);

                if (result.Status != Status.CouldNotLogOn)
                {
                    ResponseData responseData = cmd.GetResponseData(service);
                    if (responseData.Formatted != null)
                    {
                        io.Write(responseData.Formatted);
                    }
                    result.Response = responseData;
                }
            }
            catch (Exception x)
            {
                throw new ActionException(x, service.Trace);
            }
            finally
            {
                service.Dispose();
            }

            return(result);
        }