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(); }
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); }
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); }
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); }
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(); }
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); }
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); }
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(); } }
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(); } }
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(); } }
/// <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)); }
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(); } }
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(); } }
/// <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)); }
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(); } }
public static extern IntPtr switch_user(AppHandle app, SyncUserHandle user, out NativeException ex);
public static extern IntPtr get_logged_in_users(AppHandle app, [Out] IntPtr[] users, IntPtr bufsize, out NativeException ex);
public static extern IntPtr get_current_user(AppHandle app, out NativeException ex);
public static extern void reconnect(AppHandle app);
public static extern bool immediately_run_file_actions(AppHandle app, [MarshalAs(UnmanagedType.LPWStr)] string path, IntPtr path_len, out NativeException ex);
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);
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);
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);
public static extern void send_reset_password_email(AppHandle app, [MarshalAs(UnmanagedType.LPWStr)] string email, IntPtr email_len, IntPtr tcs_ptr, out NativeException ex);
public static extern void reset_for_testing(AppHandle app);
public static extern void login_user(AppHandle app, Native.Credentials credentials, IntPtr tcs_ptr, out NativeException ex);
public static extern void remove_user(AppHandle app, SyncUserHandle user, IntPtr tcs_ptr, out NativeException ex);
public static extern IntPtr get_session(AppHandle app, SharedRealmHandle realm, out NativeException ex);
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);
public static extern void resent_confirmation_email(AppHandle app, [MarshalAs(UnmanagedType.LPWStr)] string email, IntPtr email_len, IntPtr tcs_ptr, out NativeException ex);