Ejemplo n.º 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 ResultMessage Read(NSDictionary data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            ResultMessage value = new ResultMessage();

            value.MessageType = Enum.Parse <MuxerMessageType>((string)data.Get(nameof(MessageType)).ToObject());
            value.Number      = (MuxerError)data.Get(nameof(Number)).ToObject();
            return(value);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public static void TestIssue38()
        {
            NSDictionary dict    = (NSDictionary)PropertyListParser.Parse(new FileInfo("test-files/issue33.pbxproj"));
            NSObject     fileRef = ((NSDictionary)((NSDictionary)dict.Get("objects")).Get("65541A9C16D13B8C00A968D5")).Get("fileRef");

            Assert.True(fileRef.Equals(new NSString("65541A9B16D13B8C00A968D5")));
        }
Ejemplo n.º 4
0
        public static void AddRequiredDeviceCapability(IIgorModule ModuleInst, string PlistPath, string NewRequiredDeviceCapability)
        {
            if (IgorAssert.EnsureTrue(ModuleInst, File.Exists(PlistPath), "Plist " + PlistPath + " doesn't exist!"))
            {
                FileInfo PlistFileInfo = new FileInfo(PlistPath);

                NSObject PlistRoot = PropertyListParser.Parse(PlistFileInfo);

                if (IgorAssert.EnsureTrue(ModuleInst, PlistRoot != null, "Plist " + PlistPath + " could not be parsed!"))
                {
                    if (IgorAssert.EnsureTrue(ModuleInst, typeof(NSDictionary).IsAssignableFrom(PlistRoot.GetType()), "Plist " + PlistPath + " root object is not a dictionary."))
                    {
                        NSDictionary RootDictionary = (NSDictionary)PlistRoot;

                        if (IgorAssert.EnsureTrue(ModuleInst, RootDictionary != null, "Plist root is not a dictionary."))
                        {
                            if (IgorAssert.EnsureTrue(ModuleInst, RootDictionary.ContainsKey("UIRequiredDeviceCapabilities"), "Can't find UIRequiredDeviceCapabilities in plist."))
                            {
                                NSObject DeviceCapabilities = RootDictionary.Get("UIRequiredDeviceCapabilities");

                                if (IgorAssert.EnsureTrue(ModuleInst, DeviceCapabilities != null, "Plist does not contain UIRequiredDeviceCapabilities."))
                                {
                                    if (IgorAssert.EnsureTrue(ModuleInst, typeof(NSArray).IsAssignableFrom(DeviceCapabilities.GetType()), "Plist UIRequiredDeviceCapabilities is not an array."))
                                    {
                                        NSArray CapabilitiesArray = (NSArray)DeviceCapabilities;

                                        if (IgorAssert.EnsureTrue(ModuleInst, CapabilitiesArray != null, "UIRequiredDeviceCapabilities is not an array."))
                                        {
                                            if (CapabilitiesArray.ContainsObject(new NSString(NewRequiredDeviceCapability)))
                                            {
                                                IgorDebug.Log(ModuleInst, "UIRequiredDeviceCapabilities already contains " + NewRequiredDeviceCapability);
                                            }
                                            else
                                            {
                                                NSSet NewCapabilitiesSet = new NSSet(CapabilitiesArray.GetArray());

                                                NewCapabilitiesSet.AddObject(new NSString(NewRequiredDeviceCapability));

                                                NSArray NewCapabilitiesArray = new NSArray(NewCapabilitiesSet.AllObjects());

                                                RootDictionary["UIRequiredDeviceCapabilities"] = NewCapabilitiesArray;

                                                IgorRuntimeUtils.DeleteFile(PlistPath);

                                                PropertyListParser.SaveAsXml(RootDictionary, PlistFileInfo);

                                                IgorDebug.Log(ModuleInst, NewRequiredDeviceCapability + " added to UIRequiredDeviceCapabilities.");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <inheritdoc/>
        public override void FromDictionary(NSDictionary data)
        {
            base.FromDictionary(data);

            this.Domain = data.GetString(nameof(this.Domain));
            this.Key    = data.GetString(nameof(this.Key));
            this.Type   = data.GetString(nameof(this.Type));

            if (data.ContainsKey(nameof(this.Value)))
            {
                this.Value = (T)data.Get(nameof(this.Value)).ToObject();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Reads a <see cref="DeviceProperties"/> from a <see cref="NSDictionary"/>.
        /// </summary>
        /// <param name="data">
        /// The message data.
        /// </param>
        /// <returns>
        /// A <see cref="DeviceProperties"/> object.
        /// </returns>
        public static DeviceProperties Read(NSDictionary data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            return(new DeviceProperties()
            {
                ConnectionSpeed = data.ContainsKey(nameof(ConnectionSpeed)) ? (int)data.Get(nameof(ConnectionSpeed)).ToObject() : 0,
                ConnectionType = Enum.Parse <MuxerConnectionType>((string)data.Get(nameof(ConnectionType)).ToObject()),
                DeviceID = (int)data.Get(nameof(DeviceID)).ToObject(),
                EscapedFullServiceName = data.ContainsKey(nameof(EscapedFullServiceName)) ? (string)data.Get(nameof(EscapedFullServiceName)).ToObject() : null,
                InterfaceIndex = data.ContainsKey(nameof(InterfaceIndex)) ? (int)data.Get(nameof(InterfaceIndex)).ToObject() : 0,
                LocationID = data.ContainsKey(nameof(LocationID)) ? (int)data.Get(nameof(LocationID)).ToObject() : 0,
                NetworkAddress = data.ContainsKey(nameof(NetworkAddress)) ? (byte[])data.Get(nameof(NetworkAddress)).ToObject() : null,
                ProductID = data.ContainsKey(nameof(ProductID)) ? (int)data.Get(nameof(ProductID)).ToObject() : 0,
                SerialNumber = (string)data.Get(nameof(SerialNumber)).ToObject(),
                UDID = data.ContainsKey(nameof(UDID)) ? (string)data.Get(nameof(UDID)).ToObject() : null,
                USBSerialNumber = data.ContainsKey(nameof(USBSerialNumber)) ? (string)data.Get(nameof(USBSerialNumber))?.ToObject() : null,
            });
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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));
            }
        }
Ejemplo n.º 9
0
        public static void AddBundleURLType(IIgorModule ModuleInst, string PlistPath, string NewURLScheme)
        {
            if (IgorAssert.EnsureTrue(ModuleInst, File.Exists(PlistPath), "Plist " + PlistPath + " doesn't exist!"))
            {
                FileInfo PlistFileInfo = new FileInfo(PlistPath);

                NSObject PlistRoot = PropertyListParser.Parse(PlistFileInfo);

                if (IgorAssert.EnsureTrue(ModuleInst, PlistRoot != null, "Plist " + PlistPath + " could not be parsed!"))
                {
                    if (IgorAssert.EnsureTrue(ModuleInst, typeof(NSDictionary).IsAssignableFrom(PlistRoot.GetType()), "Plist " + PlistPath + " root object is not a dictionary."))
                    {
                        NSDictionary RootDictionary = (NSDictionary)PlistRoot;

                        if (IgorAssert.EnsureTrue(ModuleInst, RootDictionary != null, "Plist root is not a dictionary."))
                        {
                            NSSet BundleURLTypes = null;

                            if (RootDictionary.ContainsKey("CFBundleURLTypes"))
                            {
                                NSObject BundleURLTypesObj = RootDictionary.Get("CFBundleURLTypes");

                                if (IgorAssert.EnsureTrue(ModuleInst, BundleURLTypesObj != null, "CFBundleURLTypes wasn't found in the root dictionary even though the key exists."))
                                {
                                    if (IgorAssert.EnsureTrue(ModuleInst, typeof(NSArray).IsAssignableFrom(BundleURLTypesObj.GetType()), "CFBundleURLTypes isn't an NSArray."))
                                    {
                                        BundleURLTypes = new NSSet(((NSArray)BundleURLTypesObj).GetArray());
                                    }
                                }
                            }

                            if (BundleURLTypes == null)
                            {
                                BundleURLTypes = new NSSet();
                            }

                            bool bAlreadyExists = false;

                            foreach (NSObject CurrentURLType in BundleURLTypes)
                            {
                                if (bAlreadyExists)
                                {
                                    break;
                                }

                                if (IgorAssert.EnsureTrue(ModuleInst, typeof(NSDictionary).IsAssignableFrom(CurrentURLType.GetType()), "One of the CFBundleURLTypes isn't an NSDictionary."))
                                {
                                    NSDictionary CurrentURLTypeDict = (NSDictionary)CurrentURLType;

                                    if (IgorAssert.EnsureTrue(ModuleInst, CurrentURLTypeDict != null, "One of the CFBundleURLTypes didn't cast to NSDictionary correctly."))
                                    {
                                        if (CurrentURLTypeDict.ContainsKey("CFBundleURLSchemes"))
                                        {
                                            NSObject CurrentURLSchemesArrayObj = CurrentURLTypeDict.Get("CFBundleURLSchemes");

                                            if (IgorAssert.EnsureTrue(ModuleInst, typeof(NSArray).IsAssignableFrom(CurrentURLSchemesArrayObj.GetType()), "A CFBundleURLSchemes key exists for a given CFBundleURLType, but it's not an NSArray type."))
                                            {
                                                NSArray CurrentURLSchemesArray = (NSArray)CurrentURLSchemesArrayObj;

                                                if (IgorAssert.EnsureTrue(ModuleInst, CurrentURLSchemesArray != null, "The CFBundleURLSchemes object didn't cast to NSDictionary correctly."))
                                                {
                                                    NSSet CurrentURLSchemesSet = new NSSet(CurrentURLSchemesArray.GetArray());

                                                    foreach (NSObject CurrentURLSchemeObj in CurrentURLSchemesSet)
                                                    {
                                                        if (IgorAssert.EnsureTrue(ModuleInst, typeof(NSString).IsAssignableFrom(CurrentURLSchemeObj.GetType()), "One of the CFBundleURLSchemes is not an NSString."))
                                                        {
                                                            NSString CurrentURLScheme = (NSString)CurrentURLSchemeObj;

                                                            if (IgorAssert.EnsureTrue(ModuleInst, CurrentURLScheme != null, "A CFBundleURLScheme entry didn't cast to NSString correctly."))
                                                            {
                                                                if (CurrentURLScheme.GetContent() == NewURLScheme)
                                                                {
                                                                    bAlreadyExists = true;

                                                                    IgorDebug.Log(ModuleInst, "URL scheme " + NewURLScheme + " is already in " + PlistPath);

                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            if (!bAlreadyExists)
                            {
                                NSString NewSchemeString = new NSString(NewURLScheme);

                                NSArray NewSchemeArray = new NSArray(1);

                                NewSchemeArray.SetValue(0, NewSchemeString);

                                NSDictionary NewTypeDictionary = new NSDictionary();

                                NewTypeDictionary.Add("CFBundleURLSchemes", NewSchemeArray);

                                BundleURLTypes.AddObject(NewTypeDictionary);

                                NSArray BundleURLTypesArray = new NSArray(BundleURLTypes.AllObjects());

                                if (RootDictionary.ContainsKey("CFBundleURLTypes"))
                                {
                                    RootDictionary["CFBundleURLTypes"] = BundleURLTypesArray;

                                    IgorDebug.Log(ModuleInst, "Updated CFBundleURLTypes to add " + NewURLScheme + ".");
                                }
                                else
                                {
                                    RootDictionary.Add("CFBundleURLTypes", BundleURLTypesArray);

                                    IgorDebug.Log(ModuleInst, "Added CFBundleURLTypes to add " + NewURLScheme + ".");
                                }

                                IgorRuntimeUtils.DeleteFile(PlistPath);

                                PropertyListParser.SaveAsXml(RootDictionary, PlistFileInfo);
                            }
                        }
                    }
                }
            }
        }