コード例 #1
0
ファイル: Authorization.cs プロジェクト: pietervp/workbooks-1
        internal unsafe void ToNative(ref NativeAuthorizationItemSet native)
        {
            var nativeItems = (NativeAuthorizationItem *)Marshal.AllocHGlobal(
                sizeof(NativeAuthorizationItem) * items.Count);

            native.count = items.Count;
            native.items = nativeItems;

            for (int i = 0; i < native.count; i++)
            {
                var item = items [i];

                nativeItems [i].flags = item.Flags;
                nativeItems [i].name  = Marshal.StringToHGlobalAuto(item.Name);

                if (item.Value == null)
                {
                    nativeItems [i].value    = IntPtr.Zero;
                    nativeItems [i].valueLen = IntPtr.Zero;
                }
                else
                {
                    nativeItems [i].value    = Marshal.StringToHGlobalAuto(item.Value);
                    nativeItems [i].valueLen = (IntPtr)item.Value.Length;
                }
            }
        }
コード例 #2
0
ファイル: Authorization.cs プロジェクト: pietervp/workbooks-1
        public static Authorization Create(
            AuthorizationRights rights,
            AuthorizationEnvironment environment,
            AuthorizationFlags flags)
        {
            NativeAuthorizationItemSet  rightsNative = new NativeAuthorizationItemSet();
            NativeAuthorizationItemSet *rightsPtr    = null;

            NativeAuthorizationItemSet  envNative = new NativeAuthorizationItemSet();
            NativeAuthorizationItemSet *envPtr    = null;

            int    code;
            IntPtr auth;

            try {
                if (rights != null && rights.Count > 0)
                {
                    rights.ToNative(ref rightsNative);
                    rightsPtr = &rightsNative;
                }

                if (environment != null)
                {
                    environment.ToAuthorizationItemSet().ToNative(ref envNative);
                    if (envNative.count > 0)
                    {
                        envPtr = &envNative;
                    }
                }

                code = AuthorizationCreate(rightsPtr, envPtr, flags, out auth);
                if (code != 0)
                {
                    return(null);
                }

                return(new Authorization(auth));
            } finally {
                AuthorizationItemSet.FreeNative(rightsPtr);
                AuthorizationItemSet.FreeNative(envPtr);
            }
        }