Example #1
0
        override public void ValidateCustomer(string customerName)
        {
            if (string.IsNullOrEmpty(customerName))
            {
                throw new ArgumentNullException("customerName");
            }

            // save the name come what may
            _name = customerName;

            // send the name, PIN, 20
            bool  moreAccounts = true;
            short accountCount = 0;

            ACCT_INFO[] accountInfoArray;

            // set up a persistent connection
            _clientContextObj.ConnectionUsage = ConnectionTypes.PersistentOpen;

            // set up a security override connection
            _clientContextObj.User     = "******";
            _clientContextObj.Password = "******";

            // set up an empty array list
            ArrayList alNames = new ArrayList();

            try
            {
                while (moreAccounts)
                {
                    accountInfoArray = new ACCT_INFO[0];

                    moreAccounts = _Handler.GetAccounts(_name, 20, ref accountCount, ref accountInfoArray, ref _clientContextObj);

                    foreach (ACCT_INFO ai in accountInfoArray)
                    {
                        alNames.Add(ai.ACCT_NUMBER);
                    }
                }
                _Handler.ClosePersistentConnection(ref _clientContextObj);
                _isExistingCustomer = true;
            }
            catch (CustomTIException Ex)
            {
                bool isPersistent       = false;
                bool connectionIsViable = false;
                _Handler.UpdateContextInfo(ref _clientContextObj);
                isPersistent       = _clientContextObj.IsPersistent;
                connectionIsViable = _clientContextObj.IsConnectionViable;

                if (isPersistent && connectionIsViable)
                {
                    // close the persistent connection
                    _Handler.ClosePersistentConnection(ref _clientContextObj);
                }

                //parse out the Error code
                int    errorCode = Ex.UserErrorCode;
                string errorText = Ex.Message;
                string msgID     = Ex.TIExceptionMsgId;

                // say we can't handle this error
                bool errorHandlable = false;

                // if this is a Meta Data Error Block error, we got to the host, and then
                // it failed us, hopefully with customer not found
                if (msgID == META_DATA_ERROR)
                {
                    if (errorText.Contains("Customer name not found"))
                    {
                        errorHandlable = true;
                    }
                }

                // if its not handlable, leave
                if (!errorHandlable)
                {
                    throw;
                }

                // ok, at this point we have a non-existing customer
                _isExistingCustomer = false;
            }
            catch (Exception)
            {
                bool isPersistent       = false;
                bool connectionIsViable = false;
                _Handler.UpdateContextInfo(ref _clientContextObj);
                isPersistent       = _clientContextObj.IsPersistent;
                connectionIsViable = _clientContextObj.IsConnectionViable;

                if (isPersistent && connectionIsViable)
                {
                    // close the persistent connection
                    _Handler.ClosePersistentConnection(ref _clientContextObj);
                }

                // This is not a error that the App can handle.
                throw;
            }

            if (_isExistingCustomer)
            {
                // get the accounts available
                _accountNumbers = new string[alNames.Count];

                for (int index = 0; index < alNames.Count; index++)
                {
                    _accountNumbers[index] = (string)alNames[index];
                }

                // get the customers address data
                RetrieveCustomerInfo();
            }
        }