Beispiel #1
0
        /// <summary>
        /// Reads a <see cref="DevicePairedMessage"/> from a <see cref="NSDictionary"/>.
        /// </summary>
        /// <param name="data">
        /// The message data.
        /// </param>
        /// <returns>
        /// A <see cref="DeviceDetachedMessage"/> object.
        /// </returns>
        public static DevicePairedMessage Read(NSDictionary data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            DevicePairedMessage value = new DevicePairedMessage();

            value.DeviceID    = (int)data.Get(nameof(DeviceID)).ToObject();
            value.MessageType = Enum.Parse <MuxerMessageType>((string)data.Get(nameof(MessageType)).ToObject());
            return(value);
        }
Beispiel #2
0
        /// <summary>
        /// Reads a <see cref="MuxerMessage"/> object from a <see cref="NSDictionary"/> value.
        /// </summary>
        /// <param name="data">
        /// The data to read.
        /// </param>
        /// <returns>
        /// The <see cref="MuxerMessage"/> representation of the <paramref name="data"/>.
        /// </returns>
        public static MuxerMessage ReadAny(NSDictionary data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (data.ContainsKey(nameof(MessageType)))
            {
                var messageType = Enum.Parse <MuxerMessageType>((string)data.Get(nameof(MessageType)).ToObject());

                switch (messageType)
                {
                case MuxerMessageType.Attached:
                    return(DeviceAttachedMessage.Read(data));

                case MuxerMessageType.Detached:
                    return(DeviceDetachedMessage.Read(data));

                case MuxerMessageType.Paired:
                    return(DevicePairedMessage.Read(data));

                case MuxerMessageType.Result:
                    return(ResultMessage.Read(data));

                default:
                    throw new ArgumentOutOfRangeException(nameof(data));
                }
            }
            else if (data.ContainsKey("DeviceList"))
            {
                return(DeviceListMessage.Read(data));
            }
            else if (data.ContainsKey("BUID"))
            {
                return(BuidMessage.Read(data));
            }
            else if (data.ContainsKey("PairRecordData"))
            {
                return(PairingRecordDataMessage.Read(data));
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(data));
            }
        }