Пример #1
0
        /// <summary>
        /// Try to get the AI at the current position
        /// </summary>
        /// <param name="data">The row data from the scanner</param>
        /// <param name="index">The refrence of the current position</param>
        /// <param name="usePlaceHolder">Sets if the last character of the AI should replaced with a placehoder ("d")</param>
        /// <returns>The current AI or null if no match was found</returns>
        private GS1BarcodeItem GetAi(string data, ref int index, bool usePlaceHolder = false)
        {
            if (data.Length < _minLengthOfAi)
            {
                return(null);
            }

            IGS1Item result = null;

            // Step through the different lenghts of the AIs
            for (int i = _minLengthOfAi; i <= _maxLengthOfAi; i++)
            {
                // get the AI sub string
                string ai;
                try
                {
                    ai = data.Substring(index, i);
                }
                catch (Exception ex)
                {
                    var appException = new ApplicationException("AI substring failed, see inner exception", ex);
                    appException.Data.Add("data", data);
                    appException.Data.Add("index", index);
                    appException.Data.Add("i", i);

                    throw appException;
                }


                if (usePlaceHolder)
                {
                    try
                    {
                        ai = ai.Remove(ai.Length - 1) + "d";
                    }
                    catch (ArgumentOutOfRangeException argException)
                    {
                        //NOTE: if it fails maybe ignore and break out of the for loop since this GS1.AI doesn't exist?

                        throw new ArgumentOutOfRangeException($"AI Remove threw an exception with placeholder: {ai}{Environment.NewLine}Data: {data}", argException);
                    }
                }


                if (ApplicationItemDictionary.TryGetValue(ai, out result))
                {
                    index += i;
                    return((GS1BarcodeItem)result);
                }
                // if no AI found, try it with the next length
            }
            // if no AI found here, than try it with placeholders. Assumed that is the first sep where usePlaceHolder is false
            if (!usePlaceHolder)
            {
                result = GetAi(data, ref index, true);
            }
            return((GS1BarcodeItem)result);
        }
Пример #2
0
 public bool Contains(IGS1Item item)
 {
     return(Contains(item.Id));
 }
Пример #3
0
 internal void Add(IGS1Item segment)
 {
     Segments.Add(segment);
 }