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

            DeviceAttachedMessage value = new DeviceAttachedMessage();

            value.DeviceID    = (int)data.Get(nameof(DeviceID)).ToObject();
            value.MessageType = Enum.Parse <MuxerMessageType>((string)data.Get(nameof(MessageType)).ToObject());
            value.Properties  = DeviceProperties.Read((NSDictionary)data.Get(nameof(Properties)));
            return(value);
        }
Exemple #2
0
        /// <summary>
        /// Reads a <see cref="DeviceListMessage"/> from a <see cref="NSDictionary"/>.
        /// </summary>
        /// <param name="data">
        /// The message data.
        /// </param>
        /// <returns>
        /// A <see cref="DeviceListMessage"/> object.
        /// </returns>
        public static DeviceListMessage Read(NSDictionary data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            var value      = new DeviceListMessage();
            var deviceList = (NSArray)data.Get(nameof(DeviceList));

            foreach (var entry in deviceList)
            {
                value.DeviceList.Add(DeviceAttachedMessage.Read((NSDictionary)entry));
            }

            return(value);
        }
Exemple #3
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));
            }
        }