public SymConnectRequestMessage(int unitNumber, SymConnectMessageType type, string vendorName, string cardNumber, string accountNumber, RepgenInfo info)
     : this(unitNumber, type, vendorName, accountNumber, cardNumber)
 {
     if (type != SymConnectMessageType.RG)
     {
         throw new System.InvalidOperationException("Invalid parameters for symconnect message of type RG");
     }
     Repgen = info;
     ValidateSymConnectContent();
 }
 /// <summary>
 /// For TR requests
 /// </summary>
 /// <param name="type"></param>
 /// <param name="vendorName"></param>
 /// <param name="accountNumber"></param>
 /// <param name="cardNumber"></param>
 /// <param name="sourceLocator"></param>
 /// <param name="targetAccount"></param>
 /// <param name="targetLocator"></param>
 public SymConnectRequestMessage(int unitNumber, SymConnectMessageType type, string vendorName, string cardNumber, string accountNumber, IEnumerable <SymConnectRequestMessage.RecordDesignation> sourceLocator, string targetAccount, IEnumerable <SymConnectRequestMessage.RecordDesignation> targetLocator)
     : this(unitNumber, type, vendorName, accountNumber, cardNumber)
 {
     if (type != SymConnectMessageType.TR)
     {
         throw new System.InvalidOperationException("Invalid constructor for a symconnect message of type TR");
     }
     SourceLocators = sourceLocator;
     TargetAccount  = targetAccount;
     TargetLocators = targetLocator;
     ValidateSymConnectContent();
 }
        /// <summary>
        /// For IQ Messages
        /// </summary>
        /// <param name="type"></param>
        /// <param name="vendorName"></param>
        /// <param name="cardNumber"></param>
        /// <param name="accountNumber"></param>
        /// <param name="locator"></param>
        public SymConnectRequestMessage(int unitNumber, SymConnectMessageType type, string vendorName, string cardNumber, string accountNumber, IEnumerable <SymConnectRequestMessage.RecordDesignation> locator, IEnumerable <string> sourceFields)
            : this(unitNumber, type, vendorName, accountNumber, cardNumber)
        {
            if (type != SymConnectMessageType.IQ)
            {
                throw new System.InvalidOperationException("Invalid constructor for a symconnect message of type IQ");
            }
            SourceLocators = locator;
            SourceFields   = sourceFields;

            ValidateSymConnectContent();
        }
        /// <summary>
        /// For FM Messages
        /// </summary>
        /// <param name="unitNumber"></param>
        /// <param name="type"></param>
        /// <param name="vendorName"></param>
        /// <param name="cardNumber"></param>
        /// <param name="accountNumber"></param>
        /// <param name="locator"></param>
        /// <param name="targetFields"></param>
        /// <param name="fmType"></param>
        public SymConnectRequestMessage(int unitNumber, SymConnectMessageType type, string vendorName, string cardNumber,
                                        string accountNumber, IEnumerable <SymConnectRequestMessage.RecordDesignation> locator,
                                        Dictionary <string, string> targetFields, SymConnectFMType fmType)
            : this(unitNumber, type, vendorName, accountNumber, cardNumber)
        {
            if (type != SymConnectMessageType.FM)
            {
                throw new System.InvalidOperationException("Invalid constructor for a symconnect message of type FM");
            }
            SourceLocators = locator;
            //TargetLocators = locator;
            TargetFields = targetFields;
            FmType       = fmType;

            ValidateSymConnectContent();
        }
Beispiel #5
0
        public SymConnectResponseMessage(string responseString)
        {
            try
            {
                RawContent = responseString;
                //split on tildas
                List <string> raw = responseString.Split('~').ToList();

                //parse message type
                SymConnectMessageType messageType;
                if (!SymConnectMessageType.TryParse(raw[0].Substring(2), out messageType))
                {
                    throw new Exception($"{raw[0].Substring(2)} is an invalid Message Type");
                }
                _messageType = messageType;

                string responseCode      = raw.Single(slice => slice.StartsWith("K"));
                string responseCodeValue = responseCode.Substring(1).Split(':')[0];
                //parse out response code
                ResponseCode code;
                if (!ResponseCode.TryParse(responseCodeValue, out code))
                {
                    throw new Exception($"{responseCodeValue} is not contained in list of response codes");
                }
                _responseCode = code;

                //parse out Id
                //the ID is the first message element after the RS response component
                string preMessagePart      = raw.First(element => element.StartsWith("RS"));
                int    preMessagePartIndex = raw.ToList().IndexOf(preMessagePart);

                string idValue = raw[preMessagePartIndex + 1];
                _id = idValue;


                //now parse out J fields, or all response variables
                _fields = raw.Where(element => element.StartsWith("J"))
                          .Select(
                    fragment =>
                    //each J Value is split by an equal sign to denote a key value pair relationship.
                    new KeyValuePair <string, string>(fragment.Split('=').First(), fragment.Split('=').Last()));
            }
            catch (Exception ex)
            {
                throw new Exception($"{responseString} is an invalid SymConnectResponseMessage", ex);
            }
        }
        /// <summary>
        /// Base constructor
        /// </summary>
        /// <param name="type"></param>
        /// <param name="vendorName"></param>
        /// <param name="accountNumber"></param>
        /// <param name="cardNumber"></param>
        /// <param name="sourceLocators"></param>
        public SymConnectRequestMessage(int unitNumber, SymConnectMessageType type, string vendorName, string accountNumber, string cardNumber)
        {
            RequestId  = Guid.NewGuid();
            CardNumber = cardNumber;
            VendorName = vendorName;
            Type       = type;
            UnitNumber = unitNumber;

            //pad requests with less than 10
            if (accountNumber.Length < 10)
            {
                accountNumber = Enumerable.Repeat <char>('0', 10 - accountNumber.Length).Aggregate("", (x, y) => x + y) + accountNumber;
            }
            //if greater than 10, throw an exception

            if (accountNumber.Length > 10)
            {
                throw new InvalidOperationException("Cannot make a symconnect request with an account number with greater than 10 digits");
            }

            SourceAccount = accountNumber;
        }