public static void ConstructPartition(Tag tag)
        {
            try
            {
                if (tag.Status != TagStatus.FilterValueOK)
                {
                    throw new InvalidOperationException("ConstructPartition, wrong tag processing sequence");
                }
                if (!BitStringValidator.IsValidSGTIN96BitString(tag.BitStringValue))
                {
                    throw new ArgumentException("ConstructPartition, Invalid bitString");
                }

                tag.Partition = Convert.ToInt32(tag.BitStringValue.Substring(PARTITION_START_POSITION, PARTITION_LENGTH), 2);
                tag.Status    = TagStatus.PartitionValueOK;

                if (tag.Partition > PARTITION_MAX_VALUE)
                {
                    throw new ArgumentException("Parititon value out of range", "Partition");
                }
            }
            catch (Exception)
            {
                tag.Status = TagStatus.PartitionValueError;
                throw;
            }
        }
        public static void ConstructItemReference(Tag tag)
        {
            try
            {
                if (tag.Status != TagStatus.CompanyPrefixOK)
                {
                    throw new InvalidOperationException("ConstructItemReference, wrong tag processing sequence");
                }
                if (!BitStringValidator.IsValidSGTIN96BitString(tag.BitStringValue))
                {
                    throw new ArgumentException("ConstructItemReference, Invalid bitString");
                }

                var itemReferenceStartPosition = GetItemReferenceStartPosition(tag.Partition);
                var itemReferenceLength        = GetItemReferenceLength(tag.Partition);

                tag.ItemReference = Convert.ToInt32(tag.BitStringValue.Substring(itemReferenceStartPosition, itemReferenceLength), 2);
                tag.Status        = TagStatus.ItemReferenceOK;
            }
            catch (Exception)
            {
                tag.Status = TagStatus.ItemReferenceError;
                throw;
            }
        }
Exemplo n.º 3
0
        public static void ConstructHeader(Tag tag)
        {
            try
            {
                if (tag.Status != TagStatus.ConvertedToBitOK)
                {
                    throw new InvalidOperationException("ConstructHeader, wrong tag processing sequence");
                }
                if (!BitStringValidator.IsValidSGTIN96BitString(tag.BitStringValue))
                {
                    throw new ArgumentException("ConstructHeader, Invalid bitString");
                }

                tag.Header = Convert.ToInt32(tag.BitStringValue.Substring(HEADER_START_POSITION, HEADER_LENGTH), 2);
                tag.Status = TagStatus.HeaderValueOK;
                if (tag.Header != HEADER_VALID_VALUE)
                {
                    throw new ArgumentException("Header value not valid: " + tag.Header.ToString(), "tag.Header");
                }
            }
            catch (Exception)
            {
                tag.Status = TagStatus.HeaderValueError;
                throw;
            }
        }
Exemplo n.º 4
0
        public static void ConstructReference(Tag tag)
        {
            try
            {
                if (tag.Status != TagStatus.ItemReferenceOK)
                {
                    throw new InvalidOperationException("ConstructReference, wrong tag processing sequence");
                }
                if (!BitStringValidator.IsValidSGTIN96BitString(tag.BitStringValue))
                {
                    throw new ArgumentException("ConstructReference, Invalid bitString");
                }

                tag.SerialReference = Convert.ToInt64(tag.BitStringValue.Substring(SERIALREFERENCE_START_POSITION, SERIALREFERENCE_LENGTH), 2);
                tag.Status          = TagStatus.SerialReferenceOK;
            }
            catch (Exception)
            {
                tag.Status = TagStatus.SerialReferenceError;
                throw;
            }
        }
Exemplo n.º 5
0
        public static void ConstructCompanyPrefix(Tag tag)
        {
            try
            {
                if (tag.Status != TagStatus.PartitionValueOK)
                {
                    throw new InvalidOperationException("ConstructCompanyPrefix, wrong tag processing sequence");
                }
                if (!BitStringValidator.IsValidSGTIN96BitString(tag.BitStringValue))
                {
                    throw new ArgumentException("ConstructCompanyPrefix, Invalid bitString");
                }

                tag.CompanyPrefix = GetCompanyPrefixValue(tag.Partition, tag.BitStringValue);
                tag.Status        = TagStatus.CompanyPrefixOK;
            }
            catch (Exception)
            {
                tag.Status = TagStatus.CompanyPrefixError;
                throw;
            }
        }
Exemplo n.º 6
0
        public static void ConstructFilter(Tag tag)
        {
            try
            {
                if (tag.Status != TagStatus.HeaderValueOK)
                {
                    throw new InvalidOperationException("ConstructFilter, wrong tag processing sequence");
                }
                if (!BitStringValidator.IsValidSGTIN96BitString(tag.BitStringValue))
                {
                    throw new ArgumentException("ConstructFilter, Invalid bitString");
                }

                tag.Filter = Convert.ToInt32(tag.BitStringValue.Substring(FILTER_START_POSITION, FILTER_LENGTH), 2);
                tag.Status = TagStatus.FilterValueOK;
            }
            catch (Exception)
            {
                tag.Status = TagStatus.FilterValueError;
                throw;
            }
        }