Exemplo n.º 1
0
 public Placement(string valueToPlace, Regex pattern, bool isTopScorePlacement, VBA methodToCall)
 {
     _val = valueToPlace;
     _pat = pattern;
     _func = methodToCall;
     _isTopScore = isTopScorePlacement;
 }
Exemplo n.º 2
0
        private void SetConversionMethod()
        {
            string methodName = _conversionType.ToUpper();
            if (methodName.IndexOf('(') >= 0)
                methodName = methodName.Substring(0, methodName.IndexOf('('));

            switch (methodName)
            {
                case "INTTOBYTEARRAYHEX":
                    _conversionMethod = SetScore.ConvertData(
                        Convert.ToInt32(Data),
                        _convertedFieldLength,
                        HiConvert.IntToByteArrayHex,
                        _conversionWrapper);
                    break;
                case "INTTOBYTEARRAYHEXASHEX":
                    _conversionMethod = SetScore.ConvertData(
                        Convert.ToInt32(Data),
                        _convertedFieldLength,
                        HiConvert.IntToByteArrayHexAsHex,
                        _conversionWrapper);
                    break;
                case "INTTOBYTEARRAYSINGLEBCD":
                    _conversionMethod = SetScore.ConvertData(
                        Convert.ToInt32(Data),
                        _convertedFieldLength,
                        HiConvert.IntToByteArraySingleBCD,
                        _conversionWrapper);
                    break;
                case "TWOTOTHREEENCODING":
                    try
                    {
                        _conversionMethod = SetScore.TwoToThreeEncoding(
                            Convert.ToString(Data),
                            Convert.ToInt32(_conversionType.Substring(_conversionType.IndexOf('(') + 1,
                                _conversionType.IndexOf(')') - (_conversionType.IndexOf('(') + 1)).Trim()));
                    }
                    catch
                    {
                        throw new Exception("Conversion method format for TwoToThreeEncoding was incorrect. Correct format is: \"TwoToThreeEncoding(x)\"");
                    }
                    break;
                case "PADDATA":
                    try
                    {
                        _conversionMethod = SetScore.PadData(
                            Convert.ToString(Data),
                            _convertedFieldLength,
                            _conversionType.Substring(_conversionType.IndexOf('(') + 1,
                                _conversionType.IndexOf(',') - (_conversionType.IndexOf('(') + 1)).Trim(),
                            _conversionType.Substring(_conversionType.IndexOf(',') + 1,
                                _conversionType.IndexOf(')') - (_conversionType.IndexOf(',') + 1)).Trim());
                    }
                    catch
                    {
                        throw new Exception("Conversion method format for PadData was incorrect. Correct format is: \"PadData(x,y)\"");
                    }
                    break;
                case "PADDATAREVERSE":
                    try
                    {
                        _conversionMethod = SetScore.PadDataReverse(
                            Convert.ToString(Data),
                            _convertedFieldLength,
                            _conversionType.Substring(_conversionType.IndexOf('(') + 1,
                                _conversionType.IndexOf(',') - (_conversionType.IndexOf('(') + 1)).Trim(),
                            _conversionType.Substring(_conversionType.IndexOf(',') + 1,
                                _conversionType.IndexOf(')') - (_conversionType.IndexOf(',') + 1)).Trim());
                    }
                    catch
                    {
                        throw new Exception("Conversion method format for PadDataReverse was incorrect. Correct format is: \"PadDataReverse(x,y)\"");
                    }
                    break;
                default:
                    MethodInfo[] methodInfos = typeof(HTTF.ConvertValuesToBytes).GetMethods(
                        BindingFlags.Public | BindingFlags.Static);
                    for (int i = 0; i < methodInfos.Length; i++)
                    {
                        if (methodInfos[i].Name.ToUpper().Equals(_conversionType.ToUpper()))
                        {
                            _conversionMethod = (HTTF.ConvertValueToByteArray)Delegate.CreateDelegate(
                                typeof(HTTF.ConvertValueToByteArray), methodInfos[i]);
                            break;
                        }
                    }

                    if (_conversionMethod == null)
                    {
                        throw new Exception("Conversion method not found for \"" + _conversionType + "\"." +
                            Environment.NewLine + "If this is a custom conversion method please implement it " +
                            "in the Formatting.ConvertValuesToBytes. Otherwise, check your spelling and/or formatting.");
                    }

                    break;

                //case "CUSTOMNAME" is already taken care of in SetHiScore since it requires the tParams variable, and data.
                //case "NAME" is already taken care of in SetupMappings since it requires the tParams variable.
                //case "SWITCH" is also already taken care of in SetupMappings since it requires the switchMaps variable.
            }
        }