Exemple #1
0
        /// <summary>
        /// INI RDH
        /// </summary>
        public static bool Init_INI_RDH(int BLZ, string URL, int Port, int HBCIVersion, string UserID, string FilePath, string Password)
        {
            Log.Write("Starting Synchronisation");

            try
            {
                string segments;

                // Get public keys from bank
                if (HBCIVersion == 300)
                {
                    string segments_ = "HKIDN:" + SEGNUM.SETVal(2) + ":2+" + SEG_Country.Germany + ":" + BLZ + "+" + "9999999999" + "+0+0'" +
                                       "HKVVB:" + SEGNUM.SETVal(3) + ":3+11+0+1+" + Program.Buildname + "+" + Program.Version + "'";

                    segments = segments_;

                    if (DEBUG.Enabled)
                    {
                        DEBUG.Write("INI message: " + segments);
                    }

                    if (Helper.Parse_Segment_RDH_Key(RDHMessage.Send(URL, Port, RDHMessageAnonymous.Create(HBCIVersion,
                                                                                                           MSG.SETVal(1), DLG.SETVal(0), BLZ, segments)), BLZ, UserID))
                    {
                        // Sync OK
                        Log.Write("Synchronisation ok");

                        if (RDHKEY.OpenFromFile(FilePath, Password))
                        {
                            segments_ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+" + SEG_Country.Germany + ":" + BLZ + "+" + UserID + "+0+1'" +
                                        "HKSAK:" + SEGNUM.SETVal(4) + ":3+2+112+" + RDH_Profile.RDHPROFILE + "+" + SEG_Country.Germany +
                                        ":" + BLZ + ":" + UserID + ":" + Keytype.Enc + ":" + RDH_Profile.Version + ":1+5:2:10:@" + RDH_KEYSTORE.KEY_ENCRYPTION_PRIVATE.Length + "@" +
                                        RDH_KEYSTORE.KEY_ENCRYPTION_PRIVATE + ":12:@3@" + Converter.FromHexString("01 00 01") + ":13'" +
                                        "HKSAK:" + SEGNUM.SETVal(5) + ":3+2+112+" + RDH_Profile.RDHPROFILE + "+" + SEG_Country.Germany +
                                        ":" + BLZ + ":" + UserID + ":" + Keytype.Sig + ":" + RDH_Profile.Version + ":1+6:19:10:@" + RDH_KEYSTORE.KEY_SIGNING_PRIVATE.Length + "@" +
                                        RDH_KEYSTORE.KEY_SIGNING_PRIVATE + ":12:@3@" + Converter.FromHexString("01 00 01") + ":13'";

                            segments = segments_;

                            if (DEBUG.Enabled)
                            {
                                DEBUG.Write("Key exchange message: " + segments);
                            }

                            RDHMessage.Send(URL, Port, RDHMessage.Create(HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), BLZ, UserID, SYS.SETVal(0),
                                                                         segments, SEGNUM.SETInt(5)));

                            // INI OK
                            Log.Write("INI ok");

                            return(true);
                        }
                        else
                        {
                            Log.Write("INI failed");

                            return(false);
                        }
                    }
                    else
                    {
                        UserID = string.Empty;

                        Log.Write("Initialisation failed");

                        throw new Exception(HBCI_Exception.INI());
                    }
                }
                else
                {
                    Log.Write("HBCI version not supported");

                    throw new Exception(HBCI_Exception.HBCIVERSIONNOTSUPPORTED());
                }
            }
            catch (Exception ex)
            {
                UserID = string.Empty;

                Log.Write(ex.ToString());

                if (DEBUG.Enabled)
                {
                    DEBUG.Write("Software error: " + ex.ToString());
                }

                // Exception
                if (!DEBUG.Enabled)
                {
                    throw new Exception(HBCI_Exception.SOFTWARE() + ex.ToString());
                }
                else
                {
                    return(false);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// INI
        /// </summary>
        public static bool Init_INI(ConnectionDetails connectionDetails, bool anonymous)
        {
            if (!anonymous)
            {
                /// <summary>
                /// Sync
                /// </summary>
                try
                {
                    Log.Write("Starting Synchronisation");

                    string segments;

                    if (connectionDetails.HBCIVersion == 220)
                    {
                        string segments_ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + connectionDetails.Blz + "+" + connectionDetails.UserId + "+0+1'" +
                                           "HKVVB:" + SEGNUM.SETVal(4) + ":2+0+0+0+" + Program.Buildname + "+" + Program.Version + "'" +
                                           "HKSYN:" + SEGNUM.SETVal(5) + ":2+0'";

                        segments = segments_;
                    }
                    else if (connectionDetails.HBCIVersion == 300)
                    {
                        string segments_ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + connectionDetails.Blz + "+" + connectionDetails.UserId + "+0+1'" +
                                           "HKVVB:" + SEGNUM.SETVal(4) + ":3+0+0+0+" + Program.Buildname + "+" + Program.Version + "'" +
                                           "HKSYN:" + SEGNUM.SETVal(5) + ":3+0'";

                        segments = segments_;
                    }
                    else
                    {
                        //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                        //connectionDetails.UserId = string.Empty;
                        //connectionDetails.Pin = null;

                        Log.Write("HBCI version not supported");

                        throw new Exception("HBCI version not supported");
                    }

                    SEG.NUM = SEGNUM.SETInt(5);

                    if (Helper.Parse_Segment(connectionDetails.UserId, connectionDetails.Blz, connectionDetails.HBCIVersion,
                                             FinTSMessage.Send(connectionDetails.Url, FinTSMessage.Create(connectionDetails.HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), connectionDetails.Blz, connectionDetails.UserId,
                                                                                                          connectionDetails.Pin, SYS.SETVal(0), segments, null, SEG.NUM))))
                    {
                        // Sync OK
                        Log.Write("Synchronisation ok");

                        /// <summary>
                        /// INI
                        /// </summary>
                        if (connectionDetails.HBCIVersion == 220)
                        {
                            string segments_ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + connectionDetails.Blz + "+" + connectionDetails.UserId + "+" + Segment.HISYN + "+1'" +
                                               "HKVVB:" + SEGNUM.SETVal(4) + ":2+0+0+0+" + Program.Buildname + "+" + Program.Version + "'";

                            segments = segments_;
                        }
                        else if (connectionDetails.HBCIVersion == 300)
                        {
                            string segments_ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + connectionDetails.Blz + "+" + connectionDetails.UserId + "+" + Segment.HISYN + "+1'" +
                                               "HKVVB:" + SEGNUM.SETVal(4) + ":3+0+0+0+" + Program.Buildname + "+" + Program.Version + "'";

                            segments = segments_;
                        }
                        else
                        {
                            //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                            //connectionDetails.UserId = string.Empty;
                            //connectionDetails.Pin = null;

                            Log.Write("HBCI version not supported");

                            throw new Exception("HBCI version not supported");
                        }

                        SEG.NUM = SEGNUM.SETInt(4);

                        if (Helper.Parse_Segment(connectionDetails.UserId, connectionDetails.Blz, connectionDetails.HBCIVersion,
                                                 FinTSMessage.Send(connectionDetails.Url, FinTSMessage.Create(connectionDetails.HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), connectionDetails.Blz, connectionDetails.UserId, connectionDetails.Pin, Segment.HISYN,
                                                                                                              segments, Segment.HIRMS, SEG.NUM))))
                        {
                            return(true);
                        }
                        else
                        {
                            //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                            //connectionDetails.UserId = string.Empty;
                            //connectionDetails.Pin = null;

                            Log.Write("Initialisation failed");

                            throw new Exception("Initialisation failed");
                        }
                    }
                    else
                    {
                        //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                        //connectionDetails.UserId = string.Empty;
                        //connectionDetails.Pin = null;

                        Log.Write("Sync failed");

                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                    //connectionDetails.UserId = string.Empty;
                    //connectionDetails.Pin = null;

                    Log.Write(ex.ToString());

                    throw new Exception("Software error");
                }
            }
            else
            {
                /// <summary>
                /// Sync
                /// </summary>
                try
                {
                    Log.Write("Starting Synchronisation anonymous");

                    string segments;

                    if (connectionDetails.HBCIVersion == 300)
                    {
                        string segments_ = "HKIDN:" + SEGNUM.SETVal(2) + ":2+280:" + connectionDetails.Blz + "+" + "9999999999" + "+0+0'" +
                                           "HKVVB:" + SEGNUM.SETVal(3) + ":3+0+0+1+" + Program.Buildname + "+" + Program.Version + "'";

                        segments = segments_;
                    }
                    else
                    {
                        //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                        //connectionDetails.UserId = string.Empty;
                        //connectionDetails.Pin = null;

                        Log.Write("HBCI version not supported");

                        throw new Exception("HBCI version not supported");
                    }

                    SEG.NUM = SEGNUM.SETInt(4);

                    if (Helper.Parse_Segment(connectionDetails.UserId, connectionDetails.Blz, connectionDetails.HBCIVersion,
                                             FinTSMessage.Send(connectionDetails.Url, FinTSMessageAnonymous.Create(connectionDetails.HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), connectionDetails.Blz,
                                                                                                                   connectionDetails.UserId, connectionDetails.Pin, SYS.SETVal(0), segments, null, SEG.NUM))))
                    {
                        // Sync OK
                        Log.Write("Synchronisation anonymous ok");

                        /// <summary>
                        /// INI
                        /// </summary>
                        if (connectionDetails.HBCIVersion == 300)
                        {
                            string segments__ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + connectionDetails.Blz + "+" + connectionDetails.UserId + "+" + Segment.HISYN + "+1'" +
                                                "HKVVB:" + SEGNUM.SETVal(4) + ":3+0+0+0+" + Program.Buildname + "+" + Program.Version + "'" +
                                                "HKSYN:" + SEGNUM.SETVal(5) + ":3+0'";

                            segments = segments__;
                        }
                        else
                        {
                            //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                            //connectionDetails.UserId = string.Empty;
                            //connectionDetails.Pin = null;

                            Log.Write("HBCI version not supported");

                            throw new Exception("HBCI version not supported");
                        }

                        SEG.NUM = SEGNUM.SETInt(5);

                        if (Helper.Parse_Segment(connectionDetails.UserId, connectionDetails.Blz, connectionDetails.HBCIVersion,
                                                 FinTSMessage.Send(connectionDetails.Url, FinTSMessage.Create(connectionDetails.HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), connectionDetails.Blz, connectionDetails.UserId, connectionDetails.Pin,
                                                                                                              Segment.HISYN, segments, Segment.HIRMS, SEG.NUM))))
                        {
                            return(true);
                        }
                        else
                        {
                            //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                            //connectionDetails.UserId = string.Empty;
                            //connectionDetails.Pin = null;

                            Log.Write("Initialisation failed");

                            throw new Exception("Initialisation failed");
                        }
                    }
                    else
                    {
                        //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                        //connectionDetails.UserId = string.Empty;
                        //connectionDetails.Pin = null;

                        Log.Write("Sync failed");

                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                    //connectionDetails.UserId = string.Empty;
                    //connectionDetails.Pin = null;

                    Log.Write(ex.ToString());

                    DEBUG.Write("Software error: " + ex.ToString());

                    throw new Exception("Software error: " + ex.ToString());
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// INI
        /// </summary>
        public static HBCIDialogResult Init_INI(ConnectionDetails connectionDetails, bool anonymous)
        {
            if (!anonymous)
            {
                /// <summary>
                /// Sync
                /// </summary>
                try
                {
                    // If there is no customer system ID available, perform sync to get one
                    if (connectionDetails.CustomerSystemId == null)
                    {
                        var BankCode   = Transaction.HKSYN(connectionDetails);
                        var syncResult = new HBCIDialogResult(Helper.Parse_BankCode(BankCode));
                        if (!syncResult.IsSuccess)
                        {
                            Log.Write("Synchronisation failed.");
                            return(syncResult);
                        }
                    }
                    else
                    {
                        Segment.HISYN = connectionDetails.CustomerSystemId;
                    }

                    string segments;

                    /// <summary>
                    /// INI
                    /// </summary>
                    if (connectionDetails.HBCIVersion == 220)
                    {
                        string segments_ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + connectionDetails.BlzPrimary + "+" + connectionDetails.UserId + "+" + Segment.HISYN + "+1'" +
                                           "HKVVB:" + SEGNUM.SETVal(4) + ":2+0+0+0+" + Program.Buildname + "+" + Program.Version + "'";

                        segments = segments_;
                    }
                    else if (connectionDetails.HBCIVersion == 300)
                    {
                        string segments_ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + connectionDetails.BlzPrimary + "+" + connectionDetails.UserId + "+" + Segment.HISYN + "+1'" +
                                           "HKVVB:" + SEGNUM.SETVal(4) + ":3+0+0+0+" + Program.Buildname + "+" + Program.Version + "'";

                        segments = segments_;
                    }
                    else
                    {
                        //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                        //connectionDetails.UserId = string.Empty;
                        //connectionDetails.Pin = null;

                        Log.Write("HBCI version not supported");

                        throw new Exception("HBCI version not supported");
                    }

                    SEG.NUM = SEGNUM.SETInt(4);

                    var message  = FinTSMessage.Create(connectionDetails.HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), connectionDetails.BlzPrimary, connectionDetails.UserId, connectionDetails.Pin, Segment.HISYN, segments, Segment.HIRMS, SEG.NUM);
                    var response = FinTSMessage.Send(connectionDetails.Url, message);

                    var bankMessages = Helper.Parse_Segment(connectionDetails.UserId, connectionDetails.Blz, connectionDetails.HBCIVersion, response);
                    var result       = new HBCIDialogResult(bankMessages);
                    if (!result.IsSuccess)
                    {
                        Log.Write("Initialisation failed: " + result);
                    }

                    return(result);
                }
                catch (Exception ex)
                {
                    //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                    //connectionDetails.UserId = string.Empty;
                    //connectionDetails.Pin = null;

                    Log.Write(ex.ToString());

                    throw new Exception("Software error", ex);
                }
            }
            else
            {
                /// <summary>
                /// Sync
                /// </summary>
                try
                {
                    Log.Write("Starting Synchronisation anonymous");

                    string segments;

                    if (connectionDetails.HBCIVersion == 300)
                    {
                        string segments_ = "HKIDN:" + SEGNUM.SETVal(2) + ":2+280:" + connectionDetails.BlzPrimary + "+" + "9999999999" + "+0+0'" +
                                           "HKVVB:" + SEGNUM.SETVal(3) + ":3+0+0+1+" + Program.Buildname + "+" + Program.Version + "'";

                        segments = segments_;
                    }
                    else
                    {
                        //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                        //connectionDetails.UserId = string.Empty;
                        //connectionDetails.Pin = null;

                        Log.Write("HBCI version not supported");

                        throw new Exception("HBCI version not supported");
                    }

                    SEG.NUM = SEGNUM.SETInt(4);

                    string message  = FinTSMessageAnonymous.Create(connectionDetails.HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), connectionDetails.Blz, connectionDetails.UserId, connectionDetails.Pin, SYS.SETVal(0), segments, null, SEG.NUM);
                    string response = FinTSMessage.Send(connectionDetails.Url, message);

                    var messages = Helper.Parse_Segment(connectionDetails.UserId, connectionDetails.Blz, connectionDetails.HBCIVersion, response);
                    var result   = new HBCIDialogResult(messages);
                    if (!result.IsSuccess)
                    {
                        Log.Write("Synchronisation anonymous failed. " + result);
                        return(result);
                    }

                    // Sync OK
                    Log.Write("Synchronisation anonymous ok");

                    /// <summary>
                    /// INI
                    /// </summary>
                    if (connectionDetails.HBCIVersion == 300)
                    {
                        string segments__ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + connectionDetails.BlzPrimary + "+" + connectionDetails.UserId + "+" + Segment.HISYN + "+1'" +
                                            "HKVVB:" + SEGNUM.SETVal(4) + ":3+0+0+0+" + Program.Buildname + "+" + Program.Version + "'" +
                                            "HKSYN:" + SEGNUM.SETVal(5) + ":3+0'";

                        segments = segments__;
                    }
                    else
                    {
                        //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                        //connectionDetails.UserId = string.Empty;
                        //connectionDetails.Pin = null;

                        Log.Write("HBCI version not supported");

                        throw new Exception("HBCI version not supported");
                    }

                    SEG.NUM = SEGNUM.SETInt(5);

                    message  = FinTSMessage.Create(connectionDetails.HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), connectionDetails.BlzPrimary, connectionDetails.UserId, connectionDetails.Pin, Segment.HISYN, segments, Segment.HIRMS, SEG.NUM);
                    response = FinTSMessage.Send(connectionDetails.Url, message);

                    messages = Helper.Parse_Segment(connectionDetails.UserId, connectionDetails.Blz, connectionDetails.HBCIVersion, response);
                    result   = new HBCIDialogResult(messages);
                    if (!result.IsSuccess)
                    {
                        Log.Write("Initialisation failed.");
                    }

                    return(result);
                }
                catch (Exception ex)
                {
                    //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                    //connectionDetails.UserId = string.Empty;
                    //connectionDetails.Pin = null;

                    Log.Write(ex.ToString());

                    DEBUG.Write("Software error: " + ex.ToString());

                    throw new Exception("Software error: " + ex.ToString());
                }
            }
        }
Exemple #4
0
        public static string Init_HKSYN(ConnectionDetails connectionDetails)
        {
            Log.Write("Starting Synchronisation");

            string segments;

            if (connectionDetails.HBCIVersion == 220)
            {
                string segments_ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + connectionDetails.BlzPrimary + "+" + connectionDetails.UserId + "+0+1'" +
                                   "HKVVB:" + SEGNUM.SETVal(4) + ":2+0+0+0+" + Program.Buildname + "+" + Program.Version + "'" +
                                   "HKSYN:" + SEGNUM.SETVal(5) + ":2+0'";

                segments = segments_;
            }
            else if (connectionDetails.HBCIVersion == 300)
            {
                string segments_ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + connectionDetails.BlzPrimary + "+" + connectionDetails.UserId + "+0+1'" +
                                   "HKVVB:" + SEGNUM.SETVal(4) + ":3+0+0+0+" + Program.Buildname + "+" + Program.Version + "'" +
                                   "HKSYN:" + SEGNUM.SETVal(5) + ":3+0'";

                segments = segments_;
            }
            else
            {
                //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                //connectionDetails.UserId = string.Empty;
                //connectionDetails.Pin = null;

                Log.Write("HBCI version not supported");

                throw new Exception("HBCI version not supported");
            }

            SEG.NUM = SEGNUM.SETInt(5);

            string message  = FinTSMessage.Create(connectionDetails.HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), connectionDetails.BlzPrimary, connectionDetails.UserId, connectionDetails.Pin, SYS.SETVal(0), segments, null, SEG.NUM);
            string response = FinTSMessage.Send(connectionDetails.Url, message);

            Helper.Parse_Segment(connectionDetails.UserId, connectionDetails.Blz, connectionDetails.HBCIVersion, response);

            return(response);
        }
Exemple #5
0
        /// <summary>
        /// INI
        /// </summary>
        public static string Init_INI(ConnectionDetails connectionDetails, bool anonymous)
        {
            if (!anonymous)
            {
                /// <summary>
                /// Sync
                /// </summary>
                try
                {
                    string segments;

                    SEG.NUM = SEGNUM.SETInt(5);

                    /// <summary>
                    /// INI
                    /// </summary>
                    if (connectionDetails.HBCIVersion == 220)
                    {
                        string segments_ =
                            "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + connectionDetails.BlzPrimary + "+" + connectionDetails.UserId + "+" + Segment.HISYN + "+1'" +
                            "HKVVB:" + SEGNUM.SETVal(4) + ":2+0+0+0+" + Program.ProductId + "+" + Program.Version + "'";

                        segments = segments_;
                    }
                    else if (connectionDetails.HBCIVersion == 300)
                    {
                        string segments_ =
                            "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + connectionDetails.BlzPrimary + "+" + connectionDetails.UserId + "+" + Segment.HISYN + "+1'" +
                            "HKVVB:" + SEGNUM.SETVal(4) + ":3+0+0+0+" + Program.ProductId + "+" + Program.Version + "'";

                        if (Segment.HITANS != null && Segment.HITANS.Substring(0, 3).Equals("6+4"))
                        {
                            segments_ = HKTAN.Init_HKTAN(segments_);
                        }

                        segments = segments_;
                    }
                    else
                    {
                        //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                        //connectionDetails.UserId = string.Empty;
                        //connectionDetails.Pin = null;

                        Log.Write("HBCI version not supported");

                        throw new Exception("HBCI version not supported");
                    }

                    var message  = FinTSMessage.Create(connectionDetails.HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), connectionDetails.BlzPrimary, connectionDetails.UserId, connectionDetails.Pin, Segment.HISYN, segments, Segment.HIRMS, SEG.NUM);
                    var response = FinTSMessage.Send(connectionDetails.Url, message);

                    Helper.Parse_Segment(connectionDetails.UserId, connectionDetails.Blz, connectionDetails.HBCIVersion, response);

                    Segment.HITAN = Helper.Parse_String(Helper.Parse_String(response, "HITAN:", "'").Replace("?+", "??"), "++", "+").Replace("??", "?+");

                    return(response);
                }
                catch (Exception ex)
                {
                    //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                    //connectionDetails.UserId = string.Empty;
                    //connectionDetails.Pin = null;

                    Log.Write(ex.ToString());

                    throw new Exception("Software error", ex);
                }
            }
            else
            {
                /// <summary>
                /// Sync
                /// </summary>
                try
                {
                    Log.Write("Starting Synchronisation anonymous");

                    string segments;

                    if (connectionDetails.HBCIVersion == 300)
                    {
                        string segments_ =
                            "HKIDN:" + SEGNUM.SETVal(2) + ":2+280:" + connectionDetails.BlzPrimary + "+" + "9999999999" + "+0+0'" +
                            "HKVVB:" + SEGNUM.SETVal(3) + ":3+0+0+1+" + Program.ProductId + "+" + Program.Version + "'";

                        segments = segments_;
                    }
                    else
                    {
                        //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                        //connectionDetails.UserId = string.Empty;
                        //connectionDetails.Pin = null;

                        Log.Write("HBCI version not supported");

                        throw new Exception("HBCI version not supported");
                    }

                    SEG.NUM = SEGNUM.SETInt(4);

                    string message  = FinTSMessageAnonymous.Create(connectionDetails.HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), connectionDetails.Blz, connectionDetails.UserId, connectionDetails.Pin, SYS.SETVal(0), segments, null, SEG.NUM);
                    string response = FinTSMessage.Send(connectionDetails.Url, message);

                    var messages = Helper.Parse_Segment(connectionDetails.UserId, connectionDetails.Blz, connectionDetails.HBCIVersion, response);
                    var result   = new HBCIDialogResult(messages, response);
                    if (!result.IsSuccess)
                    {
                        Log.Write("Synchronisation anonymous failed. " + result);
                        return(response);
                    }

                    // Sync OK
                    Log.Write("Synchronisation anonymous ok");

                    /// <summary>
                    /// INI
                    /// </summary>
                    if (connectionDetails.HBCIVersion == 300)
                    {
                        string segments__ =
                            "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + connectionDetails.BlzPrimary + "+" + connectionDetails.UserId + "+" + Segment.HISYN + "+1'" +
                            "HKVVB:" + SEGNUM.SETVal(4) + ":3+0+0+0+" + Program.ProductId + "+" + Program.Version + "'" +
                            "HKSYN:" + SEGNUM.SETVal(5) + ":3+0'";

                        segments = segments__;
                    }
                    else
                    {
                        Log.Write("HBCI version not supported");

                        throw new Exception("HBCI version not supported");
                    }

                    SEG.NUM = SEGNUM.SETInt(5);

                    message  = FinTSMessage.Create(connectionDetails.HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), connectionDetails.BlzPrimary, connectionDetails.UserId, connectionDetails.Pin, Segment.HISYN, segments, Segment.HIRMS, SEG.NUM);
                    response = FinTSMessage.Send(connectionDetails.Url, message);

                    Helper.Parse_Segment(connectionDetails.UserId, connectionDetails.Blz, connectionDetails.HBCIVersion, response);

                    Segment.HITAN = Helper.Parse_String(Helper.Parse_String(response, "HITAN:", "'").Replace("?+", "??"), "++", "+").Replace("??", "?+");

                    return(response);
                }
                catch (Exception ex)
                {
                    //Since connectionDetails is a re-usable object, this shouldn't be cleared.
                    //connectionDetails.UserId = string.Empty;
                    //connectionDetails.Pin = null;

                    Log.Write(ex.ToString());

                    DEBUG.Write("Software error: " + ex.ToString());

                    throw new Exception("Software error: " + ex.ToString());
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// INI
        /// </summary>
        public static bool Init_INI(int BLZ, string URL, int HBCIVersion, string UserID, string PIN, bool Anonymous)
        {
            if (!Anonymous)
            {
                /// <summary>
                /// Sync
                /// </summary>
                try
                {
                    Log.Write("Starting Synchronisation");

                    string segments;

                    if (HBCIVersion == 220)
                    {
                        string segments_ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + BLZ + "+" + UserID + "+0+1'" +
                                           "HKVVB:" + SEGNUM.SETVal(4) + ":2+0+0+0+" + Program.Buildname + "+" + Program.Version + "'" +
                                           "HKSYN:" + SEGNUM.SETVal(5) + ":2+0'";

                        segments = segments_;
                    }
                    else if (HBCIVersion == 300)
                    {
                        string segments_ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + BLZ + "+" + UserID + "+0+1'" +
                                           "HKVVB:" + SEGNUM.SETVal(4) + ":3+0+0+0+" + Program.Buildname + "+" + Program.Version + "'" +
                                           "HKSYN:" + SEGNUM.SETVal(5) + ":3+0'";

                        segments = segments_;
                    }
                    else
                    {
                        UserID = string.Empty;
                        PIN    = null;

                        Log.Write("HBCI version not supported");

                        throw new Exception("HBCI version not supported");
                    }

                    SEG.NUM = SEGNUM.SETInt(5);

                    if (Helper.Parse_Segment(UserID, BLZ, HBCIVersion,
                                             FinTSMessage.Send(URL, FinTSMessage.Create(HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), BLZ, UserID,
                                                                                        PIN, SYS.SETVal(0), segments, null, SEG.NUM))))
                    {
                        // Sync OK
                        Log.Write("Synchronisation ok");

                        /// <summary>
                        /// INI
                        /// </summary>
                        if (HBCIVersion == 220)
                        {
                            string segments_ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + BLZ + "+" + UserID + "+" + Segment.HISYN + "+1'" +
                                               "HKVVB:" + SEGNUM.SETVal(4) + ":2+0+0+0+" + Program.Buildname + "+" + Program.Version + "'";

                            segments = segments_;
                        }
                        else if (HBCIVersion == 300)
                        {
                            string segments_ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + BLZ + "+" + UserID + "+" + Segment.HISYN + "+1'" +
                                               "HKVVB:" + SEGNUM.SETVal(4) + ":3+0+0+0+" + Program.Buildname + "+" + Program.Version + "'";

                            segments = segments_;
                        }
                        else
                        {
                            UserID = string.Empty;
                            PIN    = null;

                            Log.Write("HBCI version not supported");

                            throw new Exception("HBCI version not supported");
                        }

                        SEG.NUM = SEGNUM.SETInt(4);

                        if (Helper.Parse_Segment(UserID, BLZ, HBCIVersion,
                                                 FinTSMessage.Send(URL, FinTSMessage.Create(HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), BLZ, UserID, PIN, Segment.HISYN,
                                                                                            segments, Segment.HIRMS, SEG.NUM))))
                        {
                            return(true);
                        }
                        else
                        {
                            UserID = string.Empty;
                            PIN    = null;

                            Log.Write("Initialisation failed");

                            throw new Exception("Initialisation failed");
                        }
                    }
                    else
                    {
                        UserID = string.Empty;
                        PIN    = null;

                        Log.Write("Sync failed");

                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    UserID = string.Empty;
                    PIN    = null;

                    Log.Write(ex.ToString());

                    throw new Exception("Software error");
                }
            }
            else
            {
                /// <summary>
                /// Sync
                /// </summary>
                try
                {
                    Log.Write("Starting Synchronisation anonymous");

                    string segments;

                    if (HBCIVersion == 300)
                    {
                        string segments_ = "HKIDN:" + SEGNUM.SETVal(2) + ":2+280:" + BLZ + "+" + "9999999999" + "+0+0'" +
                                           "HKVVB:" + SEGNUM.SETVal(3) + ":3+0+0+1+" + Program.Buildname + "+" + Program.Version + "'";

                        segments = segments_;
                    }
                    else
                    {
                        UserID = string.Empty;
                        PIN    = null;

                        Log.Write("HBCI version not supported");

                        throw new Exception("HBCI version not supported");
                    }

                    SEG.NUM = SEGNUM.SETInt(4);

                    if (Helper.Parse_Segment(UserID, BLZ, HBCIVersion,
                                             FinTSMessage.Send(URL, FinTSMessageAnonymous.Create(HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), BLZ,
                                                                                                 UserID, PIN, SYS.SETVal(0), segments, null, SEG.NUM))))
                    {
                        // Sync OK
                        Log.Write("Synchronisation anonymous ok");

                        /// <summary>
                        /// INI
                        /// </summary>
                        if (HBCIVersion == 300)
                        {
                            string segments__ = "HKIDN:" + SEGNUM.SETVal(3) + ":2+280:" + BLZ + "+" + UserID + "+" + Segment.HISYN + "+1'" +
                                                "HKVVB:" + SEGNUM.SETVal(4) + ":3+0+0+0+" + Program.Buildname + "+" + Program.Version + "'" +
                                                "HKSYN:" + SEGNUM.SETVal(5) + ":3+0'";

                            segments = segments__;
                        }
                        else
                        {
                            UserID = string.Empty;
                            PIN    = null;

                            Log.Write("HBCI version not supported");

                            throw new Exception("HBCI version not supported");
                        }

                        SEG.NUM = SEGNUM.SETInt(5);

                        if (Helper.Parse_Segment(UserID, BLZ, HBCIVersion,
                                                 FinTSMessage.Send(URL, FinTSMessage.Create(HBCIVersion, MSG.SETVal(1), DLG.SETVal(0), BLZ, UserID, PIN,
                                                                                            Segment.HISYN, segments, Segment.HIRMS, SEG.NUM))))
                        {
                            return(true);
                        }
                        else
                        {
                            UserID = string.Empty;
                            PIN    = null;

                            Log.Write("Initialisation failed");

                            throw new Exception("Initialisation failed");
                        }
                    }
                    else
                    {
                        UserID = string.Empty;
                        PIN    = null;

                        Log.Write("Sync failed");

                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    UserID = string.Empty;
                    PIN    = null;

                    Log.Write(ex.ToString());

                    if (DEBUG.Enabled)
                    {
                        DEBUG.Write("Software error: " + ex.ToString());
                    }

                    throw new Exception("Software error: " + ex.ToString());
                }
            }
        }