예제 #1
0
        public void DeregisterPushToken(AppHandle app, string service, TaskCompletionSource <object> tcs)
        {
            var tcsHandle = GCHandle.Alloc(tcs);

            NativeMethods.push_deregister(this, app, service, (IntPtr)service.Length, GCHandle.ToIntPtr(tcsHandle), out var ex);
            ex.ThrowIfNecessary();
        }
예제 #2
0
        public void LinkCredentials(AppHandle app, Native.Credentials credentials, TaskCompletionSource <SyncUserHandle> tcs)
        {
            var tcsHandle = GCHandle.Alloc(tcs);

            NativeMethods.link_credentials(this, app, credentials, GCHandle.ToIntPtr(tcsHandle), out var ex);
            ex.ThrowIfNecessary(tcsHandle);
        }
예제 #3
0
        public void FetchAllApiKeys(AppHandle app, TaskCompletionSource <UserApiKey[]> tcs)
        {
            var tcsHandle = GCHandle.Alloc(tcs);

            NativeMethods.fetch_api_keys(this, app, GCHandle.ToIntPtr(tcsHandle), out var ex);
            ex.ThrowIfNecessary(tcsHandle);
        }
예제 #4
0
        public void CreateApiKey(AppHandle app, string name, TaskCompletionSource <UserApiKey[]> tcs)
        {
            var tcsHandle = GCHandle.Alloc(tcs);

            NativeMethods.create_api_key(this, app, name, (IntPtr)name.Length, GCHandle.ToIntPtr(tcsHandle), out var ex);
            ex.ThrowIfNecessary(tcsHandle);
        }
예제 #5
0
        public void CallFunction(AppHandle app, string name, string args, TaskCompletionSource <BsonPayload> tcs)
        {
            var tcsHandle = GCHandle.Alloc(tcs);

            NativeMethods.call_function(this, app, name, (IntPtr)name.Length, args, (IntPtr)args.Length, GCHandle.ToIntPtr(tcsHandle), out var ex);
            ex.ThrowIfNecessary();
        }
예제 #6
0
        public unsafe void EnableApiKey(AppHandle app, ObjectId id, TaskCompletionSource <object> tcs)
        {
            var tcsHandle   = GCHandle.Alloc(tcs);
            var primitiveId = PrimitiveValue.ObjectId(id);

            NativeMethods.enable_api_key(this, app, primitiveId, GCHandle.ToIntPtr(tcsHandle), out var ex);
            ex.ThrowIfNecessary(tcsHandle);
        }
예제 #7
0
        public bool TryGetApp(out AppHandle appHandle)
        {
            var result = NativeMethods.get_app(this, out var ex);

            ex.ThrowIfNecessary();

            if (result == IntPtr.Zero)
            {
                appHandle = null;
                return(false);
            }

            appHandle = new AppHandle(result);
            return(true);
        }
예제 #8
0
        public async Task <SyncUserHandle> LinkCredentialsAsync(AppHandle app, Native.Credentials credentials)
        {
            var tcs       = new TaskCompletionSource <SyncUserHandle>();
            var tcsHandle = GCHandle.Alloc(tcs);

            try
            {
                NativeMethods.link_credentials(this, app, credentials, GCHandle.ToIntPtr(tcsHandle), out var ex);
                ex.ThrowIfNecessary();

                return(await tcs.Task);
            }
            finally
            {
                tcsHandle.Free();
            }
        }
예제 #9
0
        public async Task <string> CallFunctionAsync(AppHandle app, string name, string args)
        {
            var tcs       = new TaskCompletionSource <string>();
            var tcsHandle = GCHandle.Alloc(tcs);

            try
            {
                NativeMethods.call_function(this, app, name, (IntPtr)name.Length, args, (IntPtr)args.Length, GCHandle.ToIntPtr(tcsHandle), out var ex);
                ex.ThrowIfNecessary();

                return(await tcs.Task);
            }
            finally
            {
                tcsHandle.Free();
            }
        }
예제 #10
0
        public async Task <UserApiKey[]> FetchAllApiKeysAsync(AppHandle app)
        {
            var tcs       = new TaskCompletionSource <UserApiKey[]>();
            var tcsHandle = GCHandle.Alloc(tcs);

            try
            {
                NativeMethods.fetch_api_keys(this, app, GCHandle.ToIntPtr(tcsHandle), out var ex);
                ex.ThrowIfNecessary();

                return(await tcs.Task);
            }
            finally
            {
                tcsHandle.Free();
            }
        }
예제 #11
0
        /// <summary>
        /// A factory method for creating an app with a particular <see cref="AppConfiguration"/>.
        /// </summary>
        /// <param name="config">The <see cref="AppConfiguration"/>, specifying key parameters for the app behavior.</param>
        /// <returns>An <see cref="App"/> instance can now be used to login users, call functions, or open synchronized Realms.</returns>
        public static App Create(AppConfiguration config)
        {
            Argument.NotNull(config, nameof(config));

            if (config.MetadataPersistenceMode.HasValue)
            {
                if (config.MetadataPersistenceMode == MetadataPersistenceMode.Encrypted && config.MetadataEncryptionKey == null)
                {
                    throw new ArgumentException($"{nameof(AppConfiguration.MetadataEncryptionKey)} must be set when {nameof(AppConfiguration.MetadataPersistenceMode)} is set to {nameof(MetadataPersistenceMode.Encrypted)}.");
                }

                if (config.MetadataPersistenceMode != MetadataPersistenceMode.Encrypted && config.MetadataEncryptionKey != null)
                {
                    throw new ArgumentException($"{nameof(AppConfiguration.MetadataPersistenceMode)} must be set to {nameof(MetadataPersistenceMode.Encrypted)} when {nameof(AppConfiguration.MetadataEncryptionKey)} is set.");
                }
            }

            var nativeConfig = new Native.AppConfiguration
            {
                AppId                      = config.AppId,
                BaseFilePath               = config.BaseFilePath ?? InteropConfig.DefaultStorageFolder,
                BaseUrl                    = config.BaseUri?.ToString().TrimEnd('/'),
                LocalAppName               = config.LocalAppName,
                LocalAppVersion            = config.LocalAppVersion,
                MetadataPersistence        = config.MetadataPersistenceMode,
                default_request_timeout_ms = (ulong?)config.DefaultRequestTimeout?.TotalMilliseconds ?? 0,
#pragma warning disable CS0618 // Type or member is obsolete - We still want to support people using it
                log_level = config.LogLevel != LogLevel.Info ? config.LogLevel : Logger.LogLevel,
            };

            if (config.CustomLogger != null)
            {
                var logger = Logger.Function((level, message) => config.CustomLogger(message, level));
                logger._logLevel            = nativeConfig.log_level;
                nativeConfig.managed_logger = GCHandle.ToIntPtr(logger.GCHandle);
            }
#pragma warning restore CS0618 // Type or member is obsolete
            else if (Logger.Default != null)
            {
                nativeConfig.managed_logger = GCHandle.ToIntPtr(Logger.Default.GCHandle);
            }

            var handle = AppHandle.CreateApp(nativeConfig, config.MetadataEncryptionKey);
            return(new App(handle));
        }
예제 #12
0
        public async Task EnableApiKeyAsync(AppHandle app, ObjectId id)
        {
            var tcs       = new TaskCompletionSource <object>();
            var tcsHandle = GCHandle.Alloc(tcs);

            try
            {
                var primitiveId = PrimitiveValue.ObjectId(id);
                NativeMethods.enable_api_key(this, app, primitiveId, GCHandle.ToIntPtr(tcsHandle), out var ex);
                ex.ThrowIfNecessary();

                await tcs.Task;
            }
            finally
            {
                tcsHandle.Free();
            }
        }
예제 #13
0
        public async Task <UserApiKey> CreateApiKeyAsync(AppHandle app, string name)
        {
            var tcs       = new TaskCompletionSource <UserApiKey[]>();
            var tcsHandle = GCHandle.Alloc(tcs);

            try
            {
                NativeMethods.create_api_key(this, app, name, (IntPtr)name.Length, GCHandle.ToIntPtr(tcsHandle), out var ex);
                ex.ThrowIfNecessary();

                var result = await tcs.Task;

                Debug.Assert(result.Length == 1, "The result of Create should be exactly 1 ApiKey.");

                return(result.Single());
            }
            finally
            {
                tcsHandle.Free();
            }
        }
예제 #14
0
        /// <summary>
        /// A factory method for creating an app with a particular <see cref="AppConfiguration"/>.
        /// </summary>
        /// <param name="config">The <see cref="AppConfiguration"/>, specifying key parameters for the app behavior.</param>
        /// <returns>An <see cref="App"/> instance can now be used to login users, call functions, or open synchronized Realms.</returns>
        public static App Create(AppConfiguration config)
        {
            Argument.NotNull(config, nameof(config));

            if (config.MetadataPersistenceMode.HasValue)
            {
                if (config.MetadataPersistenceMode == MetadataPersistenceMode.Encrypted && config.MetadataEncryptionKey == null)
                {
                    throw new ArgumentException($"{nameof(AppConfiguration.MetadataEncryptionKey)} must be set when {nameof(AppConfiguration.MetadataPersistenceMode)} is set to {nameof(MetadataPersistenceMode.Encrypted)}.");
                }

                if (config.MetadataPersistenceMode != MetadataPersistenceMode.Encrypted && config.MetadataEncryptionKey != null)
                {
                    throw new ArgumentException($"{nameof(AppConfiguration.MetadataPersistenceMode)} must be set to {nameof(MetadataPersistenceMode.Encrypted)} when {nameof(AppConfiguration.MetadataEncryptionKey)} is set.");
                }
            }

            var nativeConfig = new Native.AppConfiguration
            {
                AppId                      = config.AppId,
                BaseFilePath               = config.BaseFilePath ?? InteropConfig.DefaultStorageFolder,
                BaseUrl                    = config.BaseUri?.ToString().TrimEnd('/'),
                LocalAppName               = config.LocalAppName,
                LocalAppVersion            = config.LocalAppVersion,
                MetadataPersistence        = config.MetadataPersistenceMode,
                default_request_timeout_ms = (ulong?)config.DefaultRequestTimeout?.TotalMilliseconds ?? 0,
                log_level                  = config.LogLevel,
            };

            if (config.CustomLogger != null)
            {
                // TODO: should we free this eventually?
                var logHandle = GCHandle.Alloc(config.CustomLogger);
                nativeConfig.managed_log_callback = GCHandle.ToIntPtr(logHandle);
            }

            var handle = AppHandle.CreateApp(nativeConfig, config.MetadataEncryptionKey);

            return(new App(handle));
        }
예제 #15
0
        public async Task <UserApiKey?> FetchApiKeyAsync(AppHandle app, ObjectId id)
        {
            var tcs       = new TaskCompletionSource <UserApiKey[]>();
            var tcsHandle = GCHandle.Alloc(tcs);

            try
            {
                var primitiveId = PrimitiveValue.ObjectId(id);
                NativeMethods.fetch_api_key(this, app, primitiveId, GCHandle.ToIntPtr(tcsHandle), out var ex);
                ex.ThrowIfNecessary();

                var result = await tcs.Task;

                Debug.Assert(result == null || result.Length <= 1, "The result of the fetch operation should be either null, or an array of 0 or 1 elements.");

                return(result == null || result.Length == 0 ? (UserApiKey?)null : result.Single());
            }
            finally
            {
                tcsHandle.Free();
            }
        }
예제 #16
0
 public static extern IntPtr switch_user(AppHandle app, SyncUserHandle user, out NativeException ex);
예제 #17
0
 public static extern IntPtr get_logged_in_users(AppHandle app, [Out] IntPtr[] users, IntPtr bufsize, out NativeException ex);
예제 #18
0
 public static extern IntPtr get_current_user(AppHandle app, out NativeException ex);
예제 #19
0
 public static extern void reconnect(AppHandle app);
예제 #20
0
 public static extern bool immediately_run_file_actions(AppHandle app, [MarshalAs(UnmanagedType.LPWStr)] string path, IntPtr path_len, out NativeException ex);
예제 #21
0
 public static extern IntPtr get_path_for_realm(AppHandle app, SyncUserHandle user, [MarshalAs(UnmanagedType.LPWStr)] string partition, IntPtr partition_len, IntPtr buffer, IntPtr bufsize, out NativeException ex);
예제 #22
0
 public static extern void call_reset_password_function(AppHandle app,
                                                        [MarshalAs(UnmanagedType.LPWStr)] string username, IntPtr username_len,
                                                        [MarshalAs(UnmanagedType.LPWStr)] string password, IntPtr password_len,
                                                        IntPtr tcs_ptr, out NativeException ex);
예제 #23
0
 public static extern void reset_password(AppHandle app,
                                          [MarshalAs(UnmanagedType.LPWStr)] string password, IntPtr password_len,
                                          [MarshalAs(UnmanagedType.LPWStr)] string token, IntPtr token_len,
                                          [MarshalAs(UnmanagedType.LPWStr)] string token_id, IntPtr token_id_len,
                                          IntPtr tcs_ptr, out NativeException ex);
예제 #24
0
 public static extern void send_reset_password_email(AppHandle app,
                                                     [MarshalAs(UnmanagedType.LPWStr)] string email, IntPtr email_len,
                                                     IntPtr tcs_ptr, out NativeException ex);
예제 #25
0
 public static extern void reset_for_testing(AppHandle app);
예제 #26
0
 public static extern void login_user(AppHandle app, Native.Credentials credentials, IntPtr tcs_ptr, out NativeException ex);
예제 #27
0
 public static extern void remove_user(AppHandle app, SyncUserHandle user, IntPtr tcs_ptr, out NativeException ex);
예제 #28
0
 public static extern IntPtr get_session(AppHandle app, SharedRealmHandle realm, out NativeException ex);
예제 #29
0
 public static extern IntPtr get_user_for_testing(
     AppHandle app,
     [MarshalAs(UnmanagedType.LPWStr)] string id_buf, IntPtr id_len,
     [MarshalAs(UnmanagedType.LPWStr)] string refresh_token_buf, IntPtr refresh_token_len,
     [MarshalAs(UnmanagedType.LPWStr)] string access_token_buf, IntPtr access_token_len,
     out NativeException ex);
예제 #30
0
 public static extern void resent_confirmation_email(AppHandle app,
                                                     [MarshalAs(UnmanagedType.LPWStr)] string email, IntPtr email_len,
                                                     IntPtr tcs_ptr, out NativeException ex);