Exemplo n.º 1
0
        public void ParamsArray_None()
        {
            ServiceElement       element = new ServiceElement(ElementType.ElementSequence);
            IList_ServiceElement list    = element.GetValueAsElementList();

            Assert.AreEqual(0, list.Count);
        }
Exemplo n.º 2
0
        public void List_EmptyArray()
        {
            ServiceElement[]     array   = new ServiceElement[0];
            ServiceElement       element = new ServiceElement(ElementType.ElementSequence, array);
            IList_ServiceElement list    = element.GetValueAsElementList();

            Assert.AreEqual(0, list.Count);
        }
Exemplo n.º 3
0
        public void ParamsArray_Some()
        {
            ServiceElement e0      = new ServiceElement(ElementType.UInt8, (byte)5);
            ServiceElement e1      = new ServiceElement(ElementType.Uuid16, (UInt16)0x1105);
            ServiceElement e2      = new ServiceElement(ElementType.UInt16, (UInt16)0x5555);
            ServiceElement element = new ServiceElement(ElementType.ElementSequence,
                                                        e0, e1, e2);
            IList_ServiceElement list = element.GetValueAsElementList();

            Assert.AreEqual(3, list.Count);
            Assert.AreSame(e0, list[0]);
            Assert.AreSame(e1, list[1]);
            Assert.AreSame(e2, list[2]);
        }
Exemplo n.º 4
0
        //--------------------
        //

        /// <summary>
        /// Gets the list of <see cref="T:InTheHand.Net.Bluetooth.LanguageBaseItem"/>
        /// items in the service record.
        /// </summary>
        /// -
        /// <param name="elementSequence">
        /// A <see cref="T:InTheHand.Net.Bluetooth.ServiceElement"/> holding the
        /// data from the
        /// <see cref="F:InTheHand.Net.Bluetooth.AttributeIds.UniversalAttributeId.LanguageBaseAttributeIdList"/>
        /// attribute.
        /// </param>
        /// -
        /// <returns>
        /// An array of <see cref="T:InTheHand.Net.Bluetooth.LanguageBaseItem"/>.
        /// An array length zero is returned if the service record contains no such attribute.
        /// </returns>
        /// -
        /// <exception cref="T:System.ArgumentException">
        /// <paramref name="elementSequence"/> is not of type
        /// <see cref="F:InTheHand.Net.Bluetooth.ElementType.ElementSequence"/>.
        /// </exception>
        /// <exception cref="T:System.Net.ProtocolViolationException">
        /// The element sequence contains incorrectly formatted or invalid content,
        /// for example it contains the wrong element data types, or doesn't contain
        /// the elements in groups of three as required.
        /// </exception>
        public static LanguageBaseItem[] ParseListFromElementSequence(ServiceElement elementSequence)
        {
            if (elementSequence.ElementType != ElementType.ElementSequence)
            {
                throw new ArgumentException(ErrorMsgLangBaseListParseNotSequence);
            }

            IList <ServiceElement> elementList = elementSequence.GetValueAsElementList();

            int       numElements     = elementList.Count;
            const int ElementsPerItem = 3;

            if (numElements == 0 || (numElements % ElementsPerItem) != 0)
            {
                throw new System.Net.ProtocolViolationException(ErrorMsgLangBaseListParseNotInThrees);
            }
            int numItems = numElements / ElementsPerItem;

            LanguageBaseItem[] items = new LanguageBaseItem[numItems];
            for (int i = 0; i < numItems; ++i)
            {
                // Casts are for the non-Generic version.
                ServiceElement e1Lang   = (ServiceElement)elementList[i * ElementsPerItem];
                ServiceElement e2EncId  = (ServiceElement)elementList[i * ElementsPerItem + 1];
                ServiceElement e3BaseId = (ServiceElement)elementList[i * ElementsPerItem + 2];
                if (e1Lang.ElementType != ElementType.UInt16 || e2EncId.ElementType != ElementType.UInt16 || e3BaseId.ElementType != ElementType.UInt16)
                {
                    throw new System.Net.ProtocolViolationException(ErrorMsgLangBaseListParseNotU16);
                }
                if ((UInt16)e3BaseId.Value == 0)
                {
                    throw new System.Net.ProtocolViolationException(ErrorMsgLangBaseListParseBaseInvalid);
                }
                LanguageBaseItem item = new LanguageBaseItem(
                    (UInt16)e1Lang.Value, (UInt16)e2EncId.Value, (UInt16)e3BaseId.Value);
                items[i] = item;
            }
            return(items);
        }
        private static IList <Guid> ServiceRecordHelper_GetServiceClassIdList(ServiceAttribute attr)
        {
            ServiceElement e0 = attr.Value;

            if (e0.ElementType != ElementType.ElementSequence)
            {
                throw new ArgumentException("ServiceClassIdList needs ElementSequence at base.");
            }
            IList <ServiceElement> list   = e0.GetValueAsElementList();
            List <Guid>            result = new List <Guid>();

            foreach (ServiceElement eCur in list)
            {
                if (eCur.ElementTypeDescriptor != ElementTypeDescriptor.Uuid)
                {
                    throw new ArgumentException(
                              "ServiceClassIdList contains a " + eCur.ElementType + " element.");
                }
                result.Add(eCur.GetValueAsUuid());
            }
            return(result);
        }