Пример #1
0
        public static AppHandle CreateApp(Native.AppConfiguration config, byte[] encryptionKey)
        {
            var handle = NativeMethods.create_app(config, encryptionKey, out var ex);

            ex.ThrowIfNecessary();
            return(new AppHandle(handle));
        }
Пример #2
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));
        }
Пример #3
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));
        }
Пример #4
0
 public static extern IntPtr create_app(Native.AppConfiguration app_config, byte[] encryptionKey, out NativeException ex);