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

            DeviceDetachedMessage value = new DeviceDetachedMessage();

            value.DeviceID    = (int)data.Get(nameof(DeviceID)).ToObject();
            value.MessageType = Enum.Parse <MuxerMessageType>((string)data.Get(nameof(MessageType)).ToObject());
            return(value);
        }
Ejemplo n.º 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));
            }
        }