Exemplo n.º 1
0
        public static IServiceCollection AddOneSignal(this IServiceCollection services,
                                                      Action <OneSignalOptions> configure = null)
        {
            var options = new OneSignalOptions();

            configure?.Invoke(options);
            services.AddTransient <IOneSignalClient, OneSignalClient>(oneSignalClient => new OneSignalClient(options));
            return(services);
        }
        public OneSignalClient(OneSignalOptions options)
        {
            _options = options;

            if (string.IsNullOrWhiteSpace(_options.AppId))
            {
                throw new OneSignalAppIdMissingException("AppId is missing");
            }

            if (string.IsNullOrWhiteSpace(_options.AuthorizationKey))
            {
                throw new OneSignalAuthorizationKeyMissingException("AuthorizationKey is missing");
            }

            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            };
        }