コード例 #1
0
        private static ServiceElement CreateEnglishUtf8PrimaryLanguageServiceElement()
        {
            ServiceElement englishUtf8PrimaryLanguage = LanguageBaseItem.CreateElementSequenceFromList(
                new LanguageBaseItem[] { LanguageBaseItem.CreateEnglishUtf8PrimaryLanguageItem() });

            return(englishUtf8PrimaryLanguage);
        }
コード例 #2
0
        public string GetPrimaryMultiLanguageStringAttributeById(ushort id)
        {
            LanguageBaseItem lang = GetPrimaryLanguageBaseItem();

            if (lang == null)
            {
                lang = LanguageBaseItem.CreateEnglishUtf8PrimaryLanguageItem();
            }
            return(GetMultiLanguageStringAttributeById(id, lang));
        }
コード例 #3
0
        //--------------------------------------------------------------
        /// <summary>
        /// Determines whether a TextString service attribute with the specified ID
        /// and natural language
        /// is in the List.
        /// </summary>
        /// -
        /// <param name="id">The id of the service attribute to locate, as a
        /// <see cref="T:InTheHand.Net.Bluetooth.ServiceAttributeId"/>.</param>
        /// <param name="language">
        /// Which multi-language version of the string attribute to locate.
        /// </param>
        /// -
        /// <returns>true if item is found in the record; otherwise, false. </returns>
        public bool Contains(ushort id, LanguageBaseItem language)
        {
            if (language == null)
            {
                throw new ArgumentNullException("language");
            }
            ushort actualId = CreateLanguageBasedAttributeId(id, language.AttributeIdBase);
            bool   found    = TryGetAttributeById(actualId, out ServiceAttribute tmp);

            return(found && (tmp.Value.ElementType == ElementType.TextString));
        }
コード例 #4
0
        /// <summary>
        /// Returns the attribute with the given ID and natural language.
        /// </summary>
        /// -
        /// <param name="id">The id of the service attribute to locate, as a
        /// <see cref="T:InTheHand.Net.Bluetooth.ServiceAttributeId"/>.</param>
        /// <param name="language">
        /// Which multi-language version of the string attribute to locate.
        /// </param>
        /// -
        /// <returns>A <see cref="T:InTheHand.Net.Bluetooth.ServiceAttribute"/> holding
        /// the attribute with the specified ID and language.
        /// Is never <see langword="null"/>.
        /// </returns>
        /// -
        /// <exception cref="T:System.Collections.Generic.KeyNotFoundException">
        /// There is no attribute with the given Id with the given language base in the record.
        /// </exception>
        public ServiceAttribute GetAttributeById(ushort id, LanguageBaseItem language)
        {
            if (language == null)
            {
                throw new ArgumentNullException("language");
            }
            ushort           actualId = CreateLanguageBasedAttributeId(id, language.AttributeIdBase);
            ServiceAttribute attr     = GetAttributeById(actualId);

            System.Diagnostics.Debug.Assert(attr != null);
            return(attr);
        }
コード例 #5
0
        public string GetMultiLanguageStringAttributeById(ushort id, LanguageBaseItem language)
        {
            if (language == null)
            {
                throw new ArgumentNullException("language");
            }
            ushort           actualId = CreateLanguageBasedAttributeId(id, language.AttributeIdBase);
            ServiceAttribute attr     = GetAttributeById(actualId);
            ServiceElement   element  = attr.Value;
            // (No need to check that element is of type TextString, that's handled inside the following).
            string str = element.GetValueAsString(language);

            return(str);
        }
コード例 #6
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);
            }
#if V1
            IList elementList = elementSequence.GetValueAsElementList();
#else
            IList <ServiceElement> elementList = elementSequence.GetValueAsElementList();
#endif
            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   = elementList[i * ElementsPerItem];
                ServiceElement e2EncId  = elementList[i * ElementsPerItem + 1];
                ServiceElement e3BaseId = elementList[i * ElementsPerItem + 2];
                if (e1Lang.ElementType != ElementType.UInt16 || e2EncId.ElementType != ElementType.UInt16 || e3BaseId.ElementType != ElementType.UInt16)
                {
                    throw new System.Net.ProtocolViolationException(ErrorMsgLangBaseListParseNotU16);
                }
                if ((ushort)e3BaseId.Value == 0)
                {
                    throw new System.Net.ProtocolViolationException(ErrorMsgLangBaseListParseBaseInvalid);
                }
                LanguageBaseItem item = new LanguageBaseItem(
                    (ushort)e1Lang.Value, (ushort)e2EncId.Value, (ushort)e3BaseId.Value);
                items[i] = item;
            }
            return(items);
        }
コード例 #7
0
        //--------------------------------------------------------------

        /// <summary>
        /// Gets the list of LanguageBaseAttributeId items in the service record.
        /// </summary>
        /// -
        /// <remarks>
        /// See also <see cref="M:InTheHand.Net.Bluetooth.ServiceRecord.GetPrimaryLanguageBaseItem"/>.
        /// </remarks>
        /// -
        /// <returns>
        /// An array of <see cref="T:InTheHand.Net.Bluetooth.LanguageBaseItem"/>.
        /// An array of length zero is returned if the service record contains no such attribute.
        /// </returns>
        /// -
        /// <seealso cref="M:InTheHand.Net.Bluetooth.ServiceRecord.GetPrimaryLanguageBaseItem"/>
        public LanguageBaseItem[] GetLanguageBaseList()
        {
            if (!Contains(Bluetooth.AttributeIds.LanguageBaseAttributeIdList))
            {
                return(new LanguageBaseItem[0]);
            }
            ServiceAttribute attr = GetAttributeById(Bluetooth.AttributeIds.LanguageBaseAttributeIdList);

            if (attr.Value.ElementType != ElementType.ElementSequence)
            {
                return(new LanguageBaseItem[0]);
            }
            LanguageBaseItem[] langList;
            try
            {
                langList = LanguageBaseItem.ParseListFromElementSequence(attr.Value);
            }
            catch (System.Net.ProtocolViolationException)
            {
                return(new LanguageBaseItem[0]);
            }
            return(langList);
        }