Beispiel #1
0
        /// <summary>
        /// Translates <paramref name="epcIdentifier"/> from one representation into another within the same coding scheme.
        /// [TDT 1.6 Version]
        /// </summary>
        /// <param name="epcIdentifier">The epcIdentifier to be converted.  This should be expressed as a string, in accordance with one of the grammars
        /// or patterns in the TDT markup files, i.e. a binary string consisting of characters '0' and '1', a URI (either tag-encoding or pure-identity formats),
        /// or a serialized identifier expressed as in Table 3</param>
        /// <param name="parameterList">This is a parameter string containing key value pairs, using the semicolon [';'] as delimiter between key=value pairs.
        /// <example>GTIN filter=3;companyprefixlength=7;tagLength=96</example>
        /// </param>
        /// <param name="outputFormat">The output format into which the epcIdentifier SHALL be converted.
        /// <value>BINARY</value>
        /// <value>LEGACY</value>
        /// <value>LEGACY_AI</value>
        /// <value>TAG_ENCODING</value>
        /// <value>PURE_IDENTITY</value>
        /// <value>ONS_HOSTNAME</value>
        /// </param>
        /// <returns>The converted value into one of the above formats as String.</returns>
        public String Translate(String epcIdentifier, String parameterList, String outputFormat)
        {
            // paramater normalization/validation
            epcIdentifier = epcIdentifier ?? String.Empty;
            epcIdentifier = epcIdentifier.Trim();
            parameterList = parameterList ?? String.Empty;
            parameterList = parameterList.Trim();
            outputFormat  = outputFormat ?? String.Empty;
            outputFormat  = outputFormat.Trim();
            LevelTypeList type = LevelTypeList.BINARY;

            if (String.IsNullOrEmpty(epcIdentifier))
            {
                throw new ArgumentNullException("epcIdentifier");
            }
            if (String.IsNullOrEmpty(outputFormat))
            {
                throw new ArgumentNullException("outputFormat");
            }
#if PocketPC
            if (!EnumHelper.TryParse <LevelTypeList>(outputFormat, ref type))
            {
                throw new ArgumentException("Invalid outputFormat", "outputFormat");
            }
#else
            if (!Enum.TryParse <LevelTypeList>(outputFormat, out type))
            {
                throw new ArgumentException("Invalid outputFormat", "outputFormat");
            }
#endif
            // convert the paramterList string to IEnumerable<Kvp<String, String>>
            List <KeyValuePair <String, String> > parameters = new List <KeyValuePair <string, string> >();
            String[] split = parameterList.Split(';');
            foreach (String s in split)
            {
                String[] split2 = s.Trim().Split('=');
                if (split2.Length == 2)
                {
                    parameters.Add(new KeyValuePair <string, string>(split2[0].Trim(), split2[1].Trim()));
                }
            }

            return(Translate(epcIdentifier, parameters, type));
        }
Beispiel #2
0
        /// <summary>
        /// Translates <paramref name="epcIdentifier"/> from one representation into another within the same coding scheme. 
        /// [.NET Version]
        /// </summary>
        /// <param name="epcIdentifier">The epcIdentifier to be converted.  This should be expressed as a string, in accordance with one of the grammars
        /// or patterns in the TDT markup files, i.e. a binary string consisting of characters '0' and '1', a URI (either tag-encoding or pure-identity formats),
        /// or a serialized identifier expressed as in Table 3</param>
        /// <param name="parameterList">IEnumerable list of key value pair parameters needed for doing some translations</param>
        /// <param name="outputFormat">The output format for the <paramref name="epcIdentifier"/> in the same scheme</param>
        /// <returns>The converted value into one of the above formats as String.</returns>
        public String Translate(String epcIdentifier, IEnumerable<KeyValuePair<String, String>> parameterList, LevelTypeList outputFormat)
        {
            // input normalization/validation
            epcIdentifier = epcIdentifier ?? String.Empty;
            epcIdentifier = epcIdentifier.Trim();
            epcIdentifier = Uri.UnescapeDataString(epcIdentifier);
            parameterList = parameterList ?? default(IEnumerable<KeyValuePair<String, String>>);
            if (String.IsNullOrEmpty(epcIdentifier)) throw new ArgumentNullException("input");

            // determine the input Option
            Tuple<Scheme, Level, Option> inputOption = GetInputOption(epcIdentifier, parameterList);

            // determine the output Option, seems to easy of a query
            Tuple<Scheme, Level, Option> outputOption = _options.Single((o) => o.Item1.name == inputOption.Item1.name & o.Item2.type == outputFormat & o.Item3.optionKey == inputOption.Item3.optionKey);

            // create the tokens associative array
            Dictionary<String, String> tokens = new Dictionary<string, string>();

            // add the input parameters to the tokens
            foreach (KeyValuePair<String, String> parameter in parameterList)
            {
                tokens.Add(parameter.Key, parameter.Value);
            }

            // extract the input tokens
            ExtractInputTokens(epcIdentifier, parameterList, inputOption, outputOption, tokens);

            // now derive some new tokens from basic fx & input tokens
            ProcessRules(inputOption, ModeList.EXTRACT, tokens);

            // now format the tokens for output
            ProcessRules(outputOption, ModeList.FORMAT, tokens);

            // Convert the tokens to binary if we have to
            ConvertTokensToBinary(outputOption, tokens);

            // use ABNF grammer to build the output string
            return BuildGrammer(outputOption, tokens);
        }
Beispiel #3
0
        /// <summary>
        /// Translates <paramref name="epcIdentifier"/> from one representation into another within the same coding scheme.
        /// [.NET Version]
        /// </summary>
        /// <param name="epcIdentifier">The epcIdentifier to be converted.  This should be expressed as a string, in accordance with one of the grammars
        /// or patterns in the TDT markup files, i.e. a binary string consisting of characters '0' and '1', a URI (either tag-encoding or pure-identity formats),
        /// or a serialized identifier expressed as in Table 3</param>
        /// <param name="parameterList">IEnumerable list of key value pair parameters needed for doing some translations</param>
        /// <param name="outputFormat">The output format for the <paramref name="epcIdentifier"/> in the same scheme</param>
        /// <returns>The converted value into one of the above formats as String.</returns>
        public String Translate(String epcIdentifier, IEnumerable <KeyValuePair <String, String> > parameterList, LevelTypeList outputFormat)
        {
            // input normalization/validation
            epcIdentifier = epcIdentifier ?? String.Empty;
            epcIdentifier = epcIdentifier.Trim();
            epcIdentifier = Uri.UnescapeDataString(epcIdentifier);
            parameterList = parameterList ?? default(IEnumerable <KeyValuePair <String, String> >);
            if (String.IsNullOrEmpty(epcIdentifier))
            {
                throw new ArgumentNullException("input");
            }

            // determine the input Option
            Tuple <Scheme, Level, Option> inputOption = GetInputOption(epcIdentifier, parameterList);

            // determine the output Option, seems to easy of a query
            Tuple <Scheme, Level, Option> outputOption = _options.Single((o) => o.Item1.name == inputOption.Item1.name & o.Item2.type == outputFormat & o.Item3.optionKey == inputOption.Item3.optionKey);

            // create the tokens associative array
            Dictionary <String, String> tokens = new Dictionary <string, string>();

            // add the input parameters to the tokens
            foreach (KeyValuePair <String, String> parameter in parameterList)
            {
                tokens.Add(parameter.Key, parameter.Value);
            }

            // extract the input tokens
            ExtractInputTokens(epcIdentifier, parameterList, inputOption, outputOption, tokens);

            // now derive some new tokens from basic fx & input tokens
            ProcessRules(inputOption, ModeList.EXTRACT, tokens);

            // now format the tokens for output
            ProcessRules(outputOption, ModeList.FORMAT, tokens);

            // Convert the tokens to binary if we have to
            ConvertTokensToBinary(outputOption, tokens);

            // use ABNF grammer to build the output string
            return(BuildGrammer(outputOption, tokens));
        }