Example #1
0
        public void ApplyCredentialDictionary(CFHTTPAuthentication auth, NetworkCredential credential)
        {
            var keys   = new NSString [3];
            var values = new CFString [3];

            keys [0]   = _AuthenticationUsername;
            keys [1]   = _AuthenticationPassword;
            keys [2]   = _AuthenticationAccountDomain;
            values [0] = (CFString)credential.UserName;
            values [1] = (CFString)credential.Password;
            values [2] = credential.Domain != null ? (CFString)credential.Domain : null;

            var dict = CFDictionary.FromObjectsAndKeys(values, keys);

            try {
                CFStreamError error;
                var           ok = CFHTTPMessageApplyCredentialDictionary(
                    Handle, auth.Handle, dict.Handle, out error);
                if (ok)
                {
                    return;
                }
                throw GetException((ErrorHTTPAuthentication)error.code);
            } finally {
                dict.Dispose();
                values [0].Dispose();
                values [1].Dispose();
                if (values [2] != null)
                {
                    values [2].Dispose();
                }
            }
        }
Example #2
0
        public IDictionary <IOHIDElement, IOHIDValue> GetValues(IOHIDElement[] elements)
        {
            ThrowIfDisposed();
            if (elements == null)
            {
                throw new ArgumentNullException("elements");
            }
            var elementArray = CFArray.FromNativeObjects(elements);

            IOHIDElement[] keys        = new IOHIDElement[elements.Length];
            IOHIDValue[]   values      = new IOHIDValue[elements.Length];
            CFDictionary   multiple    = CFDictionary.FromObjectsAndKeys(values, keys);
            var            multipleRef = multiple.Handle;
            var            result      = IOHIDDeviceCopyValueMultiple(Handle, elementArray.Handle, ref multipleRef);

            IOObject.ThrowIfError(result);
            var dict = new Dictionary <IOHIDElement, IOHIDValue> (multiple.Count);

            IntPtr[] keyRefs, valueRefs;
            multiple.GetKeysAndValues(out keyRefs, out valueRefs);
            for (int i = 0; i < multiple.Count; i++)
            {
                dict.Add(new IOHIDElement(keyRefs [i], true), new IOHIDValue(valueRefs [i], true));
            }
            CFType.Release(multiple.Handle);
            return(dict);
        }
Example #3
0
        public void SetValueMultiple(IDictionary <IOHIDElement, IOHIDValue> dictonary)
        {
            ThrowIfDisposed();
            if (dictonary == null)
            {
                throw new ArgumentNullException("multiple");
            }
            var multiple = CFDictionary.FromObjectsAndKeys(dictonary.Values.ToArray(), dictonary.Keys.ToArray());
            var result   = IOHIDDeviceSetValueMultiple(Handle, multiple.Handle);

            CFType.Release(multiple.Handle);
            IOObject.ThrowIfError(result);
        }
Example #4
0
        public void ApplyCredentialDictionary(CFHTTPAuthentication auth, NetworkCredential credential)
        {
            if (auth is null)
            {
                throw new ArgumentNullException(nameof(auth));
            }
            if (credential is null)
            {
                throw new ArgumentNullException(nameof(credential));
            }

            var length = credential.Domain is null ? 2 : 3;

            var keys   = new NSString [length];
            var values = new CFString [length];

            keys [0]   = _AuthenticationUsername;
            keys [1]   = _AuthenticationPassword;
            values [0] = credential.UserName !;
            values [1] = credential.Password !;
            if (credential.Domain is not null)
            {
                keys [2]   = _AuthenticationAccountDomain;
                values [2] = credential.Domain;
            }

            var dict = CFDictionary.FromObjectsAndKeys(values, keys);

            try {
                CFStreamError error;
                var           ok = CFHTTPMessageApplyCredentialDictionary(
                    Handle, auth.Handle, dict.Handle, out error);
                if (ok)
                {
                    return;
                }
                throw GetException((CFStreamErrorHTTPAuthentication)error.code);
            } finally {
                dict.Dispose();
                values [0]?.Dispose();
                values [1]?.Dispose();
                values [2]?.Dispose();
            }
        }