diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..94ceffb --- /dev/null +++ b/.editorconfig @@ -0,0 +1,404 @@ +########################################## +# Common Settings +########################################## + +# This file is the top-most EditorConfig file +root = true + +# All Files +[*] +charset = utf-8 +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true + +########################################## +# File Extension Settings +########################################## + +# Visual Studio Solution Files +[*.sln] +indent_style = tab + +# Visual Studio XML Project Files +[*.{csproj,vbproj,vcxproj.filters,proj,projitems,shproj}] +indent_size = 2 + +# XML Configuration Files +[*.{xml,config,props,targets,nuspec,resx,ruleset,vsixmanifest,vsct}] +indent_size = 2 + +# JSON Files +[*.{json,json5,webmanifest}] +indent_size = 2 + +# YAML Files +[*.{yml,yaml}] +indent_size = 2 + +# Markdown Files +[*.md] +trim_trailing_whitespace = false + +# Web Files +[*.{htm,html,js,jsm,ts,tsx,css,sass,scss,less,svg,vue}] +indent_size = 2 + +# Batch Files +[*.{cmd,bat}] +end_of_line = crlf + +# Bash Files +[*.sh] +end_of_line = lf + +# Makefiles +[Makefile] +indent_style = tab + +########################################## +# Default .NET Code Style Severities +# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/configuration-options#scope +########################################## + +[*.{cs,csx,cake,vb,vbx}] +# Default Severity for all .NET Code Style rules below + +dotnet_analyzer_diagnostic.severity = warning +dotnet_diagnostic.CS1591.severity = none +dotnet_diagnostic.CS1573.severity = none +dotnet_diagnostic.CS8632.severity = none +dotnet_diagnostic.CS0168.severity = none +dotnet_diagnostic.CA1711.severity = none +dotnet_diagnostic.CA1000.severity = none +dotnet_diagnostic.CA1822.severity = none +dotnet_diagnostic.CA1010.severity = none +dotnet_diagnostic.CA1018.severity = none +dotnet_diagnostic.CA1716.severity = none +dotnet_diagnostic.CA1826.severity = none +dotnet_diagnostic.CA2208.severity = none +dotnet_diagnostic.CA1304.severity = none +dotnet_diagnostic.CA1305.severity = none +dotnet_diagnostic.CA1051.severity = none +dotnet_diagnostic.CA1310.severity = none +dotnet_diagnostic.IDE0050.severity = none +dotnet_diagnostic.IDE0052.severity = none +dotnet_diagnostic.IDE0058.severity = none +dotnet_diagnostic.IDE0060.severity = none +dotnet_diagnostic.IDE0063.severity = none +dotnet_diagnostic.IDE0058.severity = none +dotnet_diagnostic.IDE0130.severity = none + +########################################## +# File Header (Uncomment to support file headers) +# https://docs.microsoft.com/visualstudio/ide/reference/add-file-header +########################################## + +# [*.{cs,csx,cake,vb,vbx}] +# file_header_template = \n© PROJECT-AUTHOR\n + +# SA1636: File header copyright text should match +# Justification: .editorconfig supports file headers. If this is changed to a value other than "none", a stylecop.json file will need to added to the project. +# dotnet_diagnostic.SA1636.severity = none + +########################################## +# .NET Language Conventions +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions +########################################## + +# .NET Code Style Settings +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#net-code-style-settings +[*.{cs,csx,cake,vb,vbx}] +# "this." and "Me." qualifiers +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#this-and-me +dotnet_style_qualification_for_field = true:warning +dotnet_style_qualification_for_property = true:warning +dotnet_style_qualification_for_method = true:warning +dotnet_style_qualification_for_event = true:warning +# Language keywords instead of framework type names for type references +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#language-keywords +dotnet_style_predefined_type_for_locals_parameters_members = true:warning +dotnet_style_predefined_type_for_member_access = true:warning +# Modifier preferences +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#normalize-modifiers +dotnet_style_require_accessibility_modifiers = always:warning +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:warning +visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:warning +dotnet_style_readonly_field = true:warning +# Parentheses preferences +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#parentheses-preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_other_operators = always_for_clarity:suggestion +# Expression-level preferences +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#expression-level-preferences +dotnet_style_object_initializer = true:warning +dotnet_style_collection_initializer = true:warning +#dotnet_style_explicit_tuple_names = true:warning +dotnet_style_prefer_inferred_tuple_names = true:warning +dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning +dotnet_style_prefer_auto_properties = true:warning +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning +dotnet_style_prefer_conditional_expression_over_assignment = false:suggestion +dotnet_diagnostic.IDE0045.severity = suggestion +dotnet_style_prefer_conditional_expression_over_return = false:suggestion +dotnet_diagnostic.IDE0046.severity = suggestion +dotnet_style_prefer_compound_assignment = true:warning +# Null-checking preferences +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#null-checking-preferences +dotnet_style_coalesce_expression = true:warning +dotnet_style_null_propagation = true:warning +# Parameter preferences +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#parameter-preferences +dotnet_code_quality_unused_parameters = all:warning +# More style options (Undocumented) +# https://github.com/MicrosoftDocs/visualstudio-docs/issues/3641 +dotnet_style_operator_placement_when_wrapping = end_of_line +# https://github.com/dotnet/roslyn/pull/40070 +dotnet_style_prefer_simplified_interpolation = true:warning + +# C# Code Style Settings +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#c-code-style-settings +[*.{cs,csx,cake}] +# Implicit and explicit types +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#implicit-and-explicit-types +csharp_style_var_for_built_in_types = true:warning +csharp_style_var_when_type_is_apparent = true:warning +csharp_style_var_elsewhere = true:warning +# Expression-bodied members +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#expression-bodied-members +csharp_style_expression_bodied_methods = false +csharp_style_expression_bodied_constructors = false +csharp_style_expression_bodied_operators = true:warning +csharp_style_expression_bodied_properties = true:warning +csharp_style_expression_bodied_indexers = true:warning +csharp_style_expression_bodied_accessors = true:warning +csharp_style_expression_bodied_lambdas = false +csharp_style_expression_bodied_local_functions = true:warning +# Pattern matching +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#pattern-matching +csharp_style_pattern_matching_over_is_with_cast_check = true:warning +csharp_style_pattern_matching_over_as_with_null_check = true:warning +# Inlined variable declarations +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#inlined-variable-declarations +csharp_style_inlined_variable_declaration = true:warning +# Expression-level preferences +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#expression-level-preferences +csharp_prefer_simple_default_expression = false +# "Null" checking preferences +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#c-null-checking-preferences +csharp_style_throw_expression = true:warning +csharp_style_conditional_delegate_call = true:warning +# Code block preferences +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#code-block-preferences +csharp_prefer_braces = true:warning +# Unused value preferences +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#unused-value-preferences +csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion +dotnet_diagnostic.IDE0058.severity = suggestion +csharp_style_unused_value_assignment_preference = discard_variable:suggestion +dotnet_diagnostic.IDE0059.severity = suggestion +# Index and range preferences +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#index-and-range-preferences +csharp_style_prefer_index_operator = true:warning +csharp_style_prefer_range_operator = true:warning +# Miscellaneous preferences +# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#miscellaneous-preferences +csharp_style_deconstructed_variable_declaration = true:warning +csharp_style_pattern_local_over_anonymous_function = true:warning +csharp_prefer_static_local_function = true:warning +csharp_prefer_simple_using_statement = true:suggestion +dotnet_diagnostic.IDE0063.severity = suggestion + +########################################## +# .NET Formatting Conventions +# https://docs.microsoft.com/visualstudio/ide/editorconfig-code-style-settings-reference#formatting-conventions +########################################## + +# Organize usings +# https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#organize-using-directives +dotnet_sort_system_directives_first = true +# Newline options +# https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#new-line-options +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true +# Indentation options +# https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#indentation-options +csharp_indent_case_contents = true +csharp_indent_switch_labels = true +csharp_indent_labels = no_change +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents_when_block = false +# Spacing options +# https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#spacing-options +csharp_space_after_cast = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_between_parentheses = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_around_binary_operators = before_and_after +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_after_comma = true +csharp_space_before_comma = false +csharp_space_after_dot = false +csharp_space_before_dot = false +csharp_space_after_semicolon_in_for_statement = true +csharp_space_before_semicolon_in_for_statement = false +csharp_space_around_declaration_statements = false +csharp_space_before_open_square_brackets = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_square_brackets = false +# Wrapping options +# https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#wrap-options +csharp_preserve_single_line_statements = false +csharp_preserve_single_line_blocks = true + +########################################## +# .NET Naming Conventions +# https://docs.microsoft.com/visualstudio/ide/editorconfig-naming-conventions +########################################## + +[*.{cs,csx,cake,vb,vbx}] + +########################################## +# Styles +########################################## + +# camel_case_style - Define the camelCase style +dotnet_naming_style.camel_case_style.capitalization = camel_case +# pascal_case_style - Define the PascalCase style +dotnet_naming_style.pascal_case_style.capitalization = pascal_case +# first_upper_style - The first character must start with an upper-case character +dotnet_naming_style.first_upper_style.capitalization = first_word_upper +# prefix_interface_with_i_style - Interfaces must be PascalCase and the first character of an interface must be an 'I' +dotnet_naming_style.prefix_interface_with_i_style.capitalization = pascal_case +dotnet_naming_style.prefix_interface_with_i_style.required_prefix = I +# prefix_type_parameters_with_t_style - Generic Type Parameters must be PascalCase and the first character must be a 'T' +dotnet_naming_style.prefix_type_parameters_with_t_style.capitalization = pascal_case +dotnet_naming_style.prefix_type_parameters_with_t_style.required_prefix = T +# disallowed_style - Anything that has this style applied is marked as disallowed +dotnet_naming_style.disallowed_style.capitalization = pascal_case +# internal_error_style - This style should never occur... if it does, it indicates a bug in file or in the parser using the file +dotnet_naming_style.internal_error_style.capitalization = pascal_case + +########################################## +# .NET Design Guideline Field Naming Rules +# Naming rules for fields follow the .NET Framework design guidelines +# https://docs.microsoft.com/dotnet/standard/design-guidelines/index +########################################## + +# No other public/protected/protected_internal fields are allowed +# https://docs.microsoft.com/dotnet/standard/design-guidelines/field +dotnet_naming_symbols.other_public_protected_fields_group.applicable_accessibilities = public, protected, protected_internal +dotnet_naming_symbols.other_public_protected_fields_group.applicable_kinds = field +dotnet_naming_rule.other_public_protected_fields_disallowed_rule.symbols = other_public_protected_fields_group +dotnet_naming_rule.other_public_protected_fields_disallowed_rule.style = disallowed_style +dotnet_naming_rule.other_public_protected_fields_disallowed_rule.severity = error + +########################################## +# StyleCop Field Naming Rules +# Naming rules for fields follow the StyleCop analyzers +# This does not override any rules using disallowed_style above +# https://github.com/DotNetAnalyzers/StyleCopAnalyzers +########################################## + +# All constant fields must be PascalCase +# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1303.md +dotnet_naming_symbols.stylecop_constant_fields_group.applicable_accessibilities = public, internal, protected_internal, protected, private_protected, private +dotnet_naming_symbols.stylecop_constant_fields_group.required_modifiers = const +dotnet_naming_symbols.stylecop_constant_fields_group.applicable_kinds = field +dotnet_naming_rule.stylecop_constant_fields_must_be_pascal_case_rule.symbols = stylecop_constant_fields_group +dotnet_naming_rule.stylecop_constant_fields_must_be_pascal_case_rule.style = pascal_case_style +dotnet_naming_rule.stylecop_constant_fields_must_be_pascal_case_rule.severity = warning + +# Local variables must be camelCase +# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1312.md +dotnet_naming_symbols.stylecop_local_fields_group.applicable_accessibilities = local +dotnet_naming_symbols.stylecop_local_fields_group.applicable_kinds = local +dotnet_naming_rule.stylecop_local_fields_must_be_camel_case_rule.symbols = stylecop_local_fields_group +dotnet_naming_rule.stylecop_local_fields_must_be_camel_case_rule.style = camel_case_style +dotnet_naming_rule.stylecop_local_fields_must_be_camel_case_rule.severity = silent + +# This rule should never fire. However, it's included for at least two purposes: +# First, it helps to understand, reason about, and root-case certain types of issues, such as bugs in .editorconfig parsers. +# Second, it helps to raise immediate awareness if a new field type is added (as occurred recently in C#). +dotnet_naming_symbols.sanity_check_uncovered_field_case_group.applicable_accessibilities = * +dotnet_naming_symbols.sanity_check_uncovered_field_case_group.applicable_kinds = field +dotnet_naming_rule.sanity_check_uncovered_field_case_rule.symbols = sanity_check_uncovered_field_case_group +dotnet_naming_rule.sanity_check_uncovered_field_case_rule.style = internal_error_style +dotnet_naming_rule.sanity_check_uncovered_field_case_rule.severity = error + +dotnet_naming_rule.private_members_with_underscore.symbols = private_fields +dotnet_naming_rule.private_members_with_underscore.style = prefix_underscore +dotnet_naming_rule.private_members_with_underscore.severity = suggestion + +dotnet_naming_symbols.private_fields.applicable_kinds = field +dotnet_naming_symbols.private_fields.applicable_accessibilities = private + +dotnet_naming_style.prefix_underscore.capitalization = camel_case +dotnet_naming_style.prefix_underscore.required_prefix = _ + +########################################## +# Other Naming Rules +########################################## + +# All of the following must be PascalCase: +# - Namespaces +# https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-namespaces +# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1300.md +# - Classes and Enumerations +# https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces +# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1300.md +# - Delegates +# https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces#names-of-common-types +# - Constructors, Properties, Events, Methods +# https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-type-members +dotnet_naming_symbols.element_group.applicable_kinds = namespace, class, enum, struct, delegate, event, method, property +dotnet_naming_rule.element_rule.symbols = element_group +dotnet_naming_rule.element_rule.style = pascal_case_style +dotnet_naming_rule.element_rule.severity = warning + +# Interfaces use PascalCase and are prefixed with uppercase 'I' +# https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces +dotnet_naming_symbols.interface_group.applicable_kinds = interface +dotnet_naming_rule.interface_rule.symbols = interface_group +dotnet_naming_rule.interface_rule.style = prefix_interface_with_i_style +dotnet_naming_rule.interface_rule.severity = warning + +# Generics Type Parameters use PascalCase and are prefixed with uppercase 'T' +# https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces +dotnet_naming_symbols.type_parameter_group.applicable_kinds = type_parameter +dotnet_naming_rule.type_parameter_rule.symbols = type_parameter_group +dotnet_naming_rule.type_parameter_rule.style = prefix_type_parameters_with_t_style +dotnet_naming_rule.type_parameter_rule.severity = warning + +# Function parameters use camelCase +# https://docs.microsoft.com/dotnet/standard/design-guidelines/naming-parameters +dotnet_naming_symbols.parameters_group.applicable_kinds = parameter +dotnet_naming_rule.parameters_rule.symbols = parameters_group +dotnet_naming_rule.parameters_rule.style = camel_case_style +dotnet_naming_rule.parameters_rule.severity = warning + + +# Ignore paths +[**/Migrations/**] +dotnet_diagnostic.CA1707.severity = none +dotnet_diagnostic.IDE1006.severity = none +dotnet_diagnostic.IDE0050.severity = none + +[**/tests/**] +dotnet_diagnostic.CA1707.severity = none +dotnet_diagnostic.CA1310.severity = none diff --git a/README-NUGET.md b/README-NUGET.md new file mode 100644 index 0000000..2cc84e2 --- /dev/null +++ b/README-NUGET.md @@ -0,0 +1,264 @@ +![Logo](https://github.com/adessoTurkey-dotNET/AdsPush/blob/main/logo.png) + +### AdsPush + +**AdsPush** is the server-side push notification library supports fully APNS(Apple Push Notification Service) and FCM (Firebase Cloud Messaging) + +- [NuGet](https://www.nuget.org/packages/AdsPush) +- [Report Bug or Request Feature](https://github.com/adessoTurkey-dotNET/AdsPush/issues) +- [Contect Me Via Mail](mailto:mail@anildursunsenel.com?subject=AdsPush) +- [Contect Me Via Linkedin](https://www.linkedin.com/in/anıl-dursun-şenel) + +# Features +1. Abstraction sender works with APNS & FCM +2. Full support for all functionality platform specific parameters. +3. Support up-to-date recommended APIs. +4. Easy to use. +5. Advanced configuration options + + +# Get It Started +1. Install AdsPush by using the following command + + ` dotnet add package AdsPush ` from dotnet cli + + or ` Install-Package AdsPush ` from package console + +2. Decide using platform (APNS or/and FCM) and get the required configuration files from the portal. +3. Apply the following instructions to configure and send notifications. + +# Configuration +You have two easy options to be able configure AdsPush + +1. Using Microsoft Dependency Injection (recommended) + - Using default configuration provider (Microsoft Options Pattern) + - Using custom configuration provider. +2. Using direct sender instance. + +### Microsoft Dependency Injection + +Microsoft Dependency Injection is Microsoft's IOC library coming with .NET Core. AdsPush supports using MDI to be able to manage your push configuration and sending operations. + +If you're sing .NET 6 or newer version in `Program.cs` + +```csharp + +using AdsPush.Extensions; + +var builder = WebApplication.CreateBuilder(args); +//Option 1:From configuration +builder.Services.AddAdsPush(this.Congiguration); + +//Option 2:From Action +builder.Services.AddAdsPush(options => +{ + //Your configurations +}); + +//Option 3:From custom provider that is implementation of IAdsPushConfigurationProvider interface. +builder.Services.AddAdsPush(); +``` +If you're sing .NET 5 or any .NET Core version in `Startup.cs` + +```csharp +using AdsPush.Extensions; +... + + public override void ConfigureServices(IServiceCollection services) + { + //your code... + + //Option 1:From configuration + services.AddAdsPush(this.Congiguration); + + //Option 2:From Action + services.AddAdsPush(options => + { + //Your configurations + }); + + //Option 3:From custom provider that is implementation of IAdsPushConfigurationProvider interface. + services.AddAdsPush(); + +} +``` + +And put the following section in your in your `appsettings.[ENV].json` + +```json +{ + "Logging": { + ... + }, + "AdsPush": { + "MyApp": { + "TargetMappings": { + "Ios": "Apns", + "Android": "FirebaseCloudMessaging" + }, + "Apns": { + "P8PrivateKey": "", + "P8PrivateKeyId": "<10 digit p8 certificate id. Usually a part of a downloadable certificate filename>", + "TeamId": "", + "AppBundleIdentifier": "", + "EnvironmentType": "" + }, + "FirebaseCloudMessaging": { + "Type":"", + "ProjectId":"", + "PrivateKey": "", + "PrivateKeyId": "", + "ClientId": "", + "ClientEmail": "", + "AuthUri": "", + "AuthProviderX509CertUrl": "", + "TokenUri": "", + "ClientX509CertUrl": "" + } + } + } + ... +} +``` +If you wish to use host/pod environment or any secret provider you can set the following environment variables. + +```config +AdsPush__MyApp__Apns__AppBundleIdentifier= +AdsPush__MyApp__Apns__EnvironmentType= +AdsPush__MyApp__Apns__P8PrivateKey= +AdsPush__MyApp__Apns__P8PrivateKeyId=<10 digit p8 certificate id. Usually a part of a downloadable certificate filename> +AdsPush__MyApp__Apns__TeamId= +AdsPush__MyApp__FirebaseCloudMessaging__AuthProviderX509CertUrl= +AdsPush__MyApp__FirebaseCloudMessaging__AuthUri= +AdsPush__MyApp__FirebaseCloudMessaging__ClientEmail= +AdsPush__MyApp__FirebaseCloudMessaging__ClientId= +AdsPush__MyApp__FirebaseCloudMessaging__ClientX509CertUrl= +AdsPush__MyApp__FirebaseCloudMessaging__PrivateKey= +AdsPush__MyApp__FirebaseCloudMessaging__PrivateKeyId= +AdsPush__MyApp__FirebaseCloudMessaging__ProjectId= +AdsPush__MyApp__FirebaseCloudMessaging__TokenUri= +AdsPush__MyApp__FirebaseCloudMessaging__Type= +AdsPush__MyApp__TargetMappings__Android=FirebaseCloudMessaging +AdsPush__MyApp__TargetMappings__Ios=Apns + +``` + +Now, you can easily use wia DI as the. following. + +```csharp +private readonly IAdsPushSender _pushSender; +public MyService( + IAdsPushSenderFactory adsPushSenderFactory) +{ + this._pushSender = adsPushSenderFactory.GetSender("MyApp"); +} + +``` + +### Using Sender Instance + +The following lines of codes can be used without any DI configuration. + +```csharp + +using AdsPush; +using AdsPush.Abstraction; +using AdsPush.Abstraction.Settings; + +var builder = new AdsPushSenderBuilder(); +var apnsSettings = new AdsPushAPNSSettings() +{ + //put your configurations hare. +}; + +var firebaseSettings = new AdsPushFirebaseSettings() +{ + //put your configurations hare. +}; + +var sender = builder + .ConfigureApns(apnsSettings, null) + .ConfigureFirebase(firebaseSettings, AdsPushTarget.Android) + .BuildSender(); + +``` + +## Sending notifications + +When you obtain `IAdsPushSender` instance by using one the methods shown above, you're ready to send notification. The following sample code can be used trigger a basic notification request. + +```csharp + +await sender.BasicSendAsync( + AdsPushTarget.Ios, + "79eb1b9e623bbca0d2b218f44a18d7b8ef59dac4da5baa9949c3e99a48eb259a", + new () + { + Title = AdsPushText.CreateUsingString("test"), + Detail = AdsPushText.CreateUsingString("detail"), + Badge = 52, + Sound = "default", + Parameters = new Dictionary() + { + {"pushParam1","value1"}, + {"pushParam2","value2"}, + } + }); + +``` + +If you wish to access whole supported parameters of the related platform, the following methods can be helpful. + +```csharp + + +//sample for Apns +var apnsResult = await sender + .GetApnsSender() + .SendAsync( + new APNSRequest() + { + ApnsPayload = new() + { + Badge = 52, + Sound = "", + MutableContent = true, + FilterCriteria = "", + ThreadId = "", + TargetContentId = "", + Alert = new APNSAlert() + { + Title = "", + Body = "", + Subtitle = "" + } + //more... + }, + AdditionalParameters = new Dictionary() + { + {"pushParam1", "value1" }, + {"pushParam2", "value2"}, + {"pushParam3", 52}, + } + }, + "79eb1b9e623bbca0d2b218f44a18d7b8ef59dac4da5baa9949c3e99a48eb259a", + Guid.NewGuid()); + +//sample for FCM +var firebaseResult = await sender + .GetFirebaseSender() + .SendToSingleAsync(new Message() + { + Token = "", + Android = new AndroidConfig() + { + Priority = Priority.High, + }, + Notification = new() + { + Title = "", + Body = "", + ImageUrl = "" + } + }); +``` \ No newline at end of file diff --git a/src/AdsPush.APNS/AdsPush.APNS.csproj b/src/AdsPush.APNS/AdsPush.APNS.csproj index 768210e..ce5e131 100644 --- a/src/AdsPush.APNS/AdsPush.APNS.csproj +++ b/src/AdsPush.APNS/AdsPush.APNS.csproj @@ -4,7 +4,7 @@ netstandard2.0 AdsPush.APNS Anıl Dursun ŞENEL - push;APNS;service-side-push-library;Firebase;Apple;FCM + push;APNS;server-side-push-library;Firebase;Apple;FCM AdsPush is the server-side push notification library supports fully APNS(Apple Push Notification Service) and FCM (Firebase Cloud Messaging) @@ -13,7 +13,7 @@ https://github.com/adessoTurkey-dotNET/AdsPush https://github.com/adessoTurkey-dotNET/AdsPush/blob/main/LICENSE Copyright (c) 2023, Anıl Dursun ŞENEL - README.md + README-NUGET.md true @@ -25,7 +25,7 @@ - + diff --git a/src/AdsPush.Abstraction/APNS/APNSEnvironmentType.cs b/src/AdsPush.Abstraction/APNS/APNSEnvironmentType.cs index 8c0f0e4..df0be40 100644 --- a/src/AdsPush.Abstraction/APNS/APNSEnvironmentType.cs +++ b/src/AdsPush.Abstraction/APNS/APNSEnvironmentType.cs @@ -1,8 +1,17 @@ namespace AdsPush.Abstraction.APNS { + /// + /// APNS Supported environment type. + /// public enum APNSEnvironmentType { + /// + /// + /// Development, + /// + /// + /// Production } } diff --git a/src/AdsPush.Abstraction/APNS/APNSError.cs b/src/AdsPush.Abstraction/APNS/APNSError.cs index cb314ff..76c7e5a 100644 --- a/src/AdsPush.Abstraction/APNS/APNSError.cs +++ b/src/AdsPush.Abstraction/APNS/APNSError.cs @@ -7,8 +7,21 @@ namespace AdsPush.Abstraction.APNS /// public class APNSError { + /// + /// APNS Error reason. + /// + /// public APNSErrorReasonCode Reason {get; set;} + + /// + /// + /// public long? Timestamp {get; set; } + + /// + /// APNS Response. + /// + /// public HttpResponseMessage HttpResponse { get; set; } } } diff --git a/src/AdsPush.Abstraction/APNS/APNSErrorReasonCode.cs b/src/AdsPush.Abstraction/APNS/APNSErrorReasonCode.cs index b64e7bf..9095504 100644 --- a/src/AdsPush.Abstraction/APNS/APNSErrorReasonCode.cs +++ b/src/AdsPush.Abstraction/APNS/APNSErrorReasonCode.cs @@ -5,33 +5,117 @@ namespace AdsPush.Abstraction.APNS /// public enum APNSErrorReasonCode { + /// + /// + /// BadCollapseId, + /// + /// + /// BadDeviceToken, + /// + /// + /// BadExpirationDate, + /// + /// + /// BadMessageId, + /// + /// + /// BadPriority, + /// + /// + /// BadTopic, + /// + /// + /// DeviceTokenNotForTopic, + /// + /// + /// DuplicateHeaders, + /// + /// + /// IdleTimeout, + /// + /// + /// MissingDeviceToken, + /// + /// + /// MissingTopic, + /// + /// + /// PayloadEmpty, + /// + /// + /// TopicDisallowed, + /// + /// + /// BadCertificate, + /// + /// + /// BadCertificateEnvironment, + /// + /// + /// ExpiredProviderToken, + /// + /// + /// Forbidden, + /// + /// + /// InvalidProviderToken, + /// + /// + /// MissingProviderToken, + /// + /// + /// BadPath, + /// + /// + /// MethodNotAllowed, + /// + /// + /// Unregistered, + /// + /// + /// PayloadTooLarge, + /// + /// + /// TooManyProviderTokenUpdates, + /// + /// + /// TooManyRequests, + /// + /// + /// InternalServerError, + /// + /// + /// ServiceUnavailable, + /// + /// + /// Shutdown, } } diff --git a/src/AdsPush.Abstraction/APNS/APNSExpiration.cs b/src/AdsPush.Abstraction/APNS/APNSExpiration.cs index 21b3b8e..88b3fba 100644 --- a/src/AdsPush.Abstraction/APNS/APNSExpiration.cs +++ b/src/AdsPush.Abstraction/APNS/APNSExpiration.cs @@ -2,6 +2,9 @@ namespace AdsPush.Abstraction.APNS { + /// + /// + /// public class APNSExpiration { private APNSExpiration(long apnsExpiration) @@ -9,13 +12,30 @@ private APNSExpiration(long apnsExpiration) this.ApnsExpirationValue = apnsExpiration; } + /// + /// + /// public long ApnsExpirationValue { get; private set; } + /// + /// + /// + /// public static APNSExpiration SingeTry() => new APNSExpiration(0); + /// + /// + /// + /// + /// public static APNSExpiration FromTimeSpan(TimeSpan timeSpan) => new APNSExpiration( DateTimeOffset.UtcNow.ToUnixTimeSeconds() + (long)timeSpan.TotalSeconds); + /// + /// + /// + /// + /// public static APNSExpiration FromDate(DateTimeOffset expiryDate) => new APNSExpiration( expiryDate.ToUnixTimeSeconds()); diff --git a/src/AdsPush.Abstraction/APNS/APNSPayload.cs b/src/AdsPush.Abstraction/APNS/APNSPayload.cs index 0eb862c..1a921ae 100644 --- a/src/AdsPush.Abstraction/APNS/APNSPayload.cs +++ b/src/AdsPush.Abstraction/APNS/APNSPayload.cs @@ -8,6 +8,9 @@ namespace AdsPush.Abstraction.APNS /// public class APNSPayload { + /// + /// + /// [JsonProperty("apns-push-type")] public string PushType { get; set; } = "alert"; diff --git a/src/AdsPush.Abstraction/APNS/APNSRequest.cs b/src/AdsPush.Abstraction/APNS/APNSRequest.cs index b11b564..ec7e848 100644 --- a/src/AdsPush.Abstraction/APNS/APNSRequest.cs +++ b/src/AdsPush.Abstraction/APNS/APNSRequest.cs @@ -2,8 +2,14 @@ namespace AdsPush.Abstraction.APNS { + /// + /// Native APNS request model. + /// public class APNSRequest { + /// + /// + /// public APNSRequest() { this.AdditionalParameters = new Dictionary(); diff --git a/src/AdsPush.Abstraction/AdsPush.Abstraction.csproj b/src/AdsPush.Abstraction/AdsPush.Abstraction.csproj index 137abf7..699b723 100644 --- a/src/AdsPush.Abstraction/AdsPush.Abstraction.csproj +++ b/src/AdsPush.Abstraction/AdsPush.Abstraction.csproj @@ -4,7 +4,7 @@ netstandard2.0 AdsPush.Abstraction Anıl Dursun ŞENEL - push;APNS;service-side-push-library;Firebase;Apple;FCM + push;APNS;server-side-push-library;Firebase;Apple;FCM AdsPush is the server-side push notification library supports fully APNS(Apple Push Notification Service) and FCM (Firebase Cloud Messaging) @@ -13,12 +13,13 @@ https://github.com/adessoTurkey-dotNET/AdsPush https://github.com/adessoTurkey-dotNET/AdsPush/blob/main/LICENSE Copyright (c) 2023, Anıl Dursun ŞENEL - README.md + README-NUGET.md true + true - + diff --git a/src/AdsPush.Abstraction/AdsPushBasicSendPayload.cs b/src/AdsPush.Abstraction/AdsPushBasicSendPayload.cs index 8dcabe5..4cc1017 100644 --- a/src/AdsPush.Abstraction/AdsPushBasicSendPayload.cs +++ b/src/AdsPush.Abstraction/AdsPushBasicSendPayload.cs @@ -3,25 +3,62 @@ namespace AdsPush.Abstraction { + /// + /// AdsPush BasicSend payload + /// public class AdsPushBasicSendPayload { + /// + /// + /// public AdsPushBasicSendPayload() { this.Parameters = new Dictionary(); } + /// + /// Unique notification id. + /// public string Id { get; set; } = Guid.NewGuid().ToString(); + + /// + /// Basic notification tyoe. + /// + /// public AdsPushType PushType { get; set; } = AdsPushType.Alert; + /// + /// Notification Title + /// + /// public AdsPushText Title { get; set; } + /// + /// Notification detail text. + /// + /// public AdsPushText Detail { get; set; } + /// + /// Sound file name for notification. + /// public string Sound { get; set; } + + /// + /// Related group id to be able to group notification. + /// Ios thread id + /// public string GroupId { get; set; } + /// + /// Set budge for application. + /// public int? Badge { get; set; } + /// + /// Notification parameters/data. + /// + /// public Dictionary Parameters { get; set; } } diff --git a/src/AdsPush.Abstraction/AdsPushErrorType.cs b/src/AdsPush.Abstraction/AdsPushErrorType.cs index b3abc25..0652f3a 100644 --- a/src/AdsPush.Abstraction/AdsPushErrorType.cs +++ b/src/AdsPush.Abstraction/AdsPushErrorType.cs @@ -1,11 +1,29 @@ namespace AdsPush.Abstraction { + /// + /// AdsPush error categories. + /// public enum AdsPushErrorType { + /// + /// Unknown + /// Unknown, + /// + /// Push token is invalid + /// InvalidToken, + /// + /// could be be connect to the notification server. + /// ServiceUnavailable, + /// + /// The passing argument(s) is invalid format or any required argument is missing. + /// InvalidArgument, + /// + /// Service certificate/credential is missing/wrong. + /// InvalidAuthConfiguration } } diff --git a/src/AdsPush.Abstraction/AdsPushException.cs b/src/AdsPush.Abstraction/AdsPushException.cs index d60f125..b0391b0 100644 --- a/src/AdsPush.Abstraction/AdsPushException.cs +++ b/src/AdsPush.Abstraction/AdsPushException.cs @@ -3,8 +3,18 @@ namespace AdsPush.Abstraction { + /// + /// The basic AdsPush exception. + /// + /// public class AdsPushException : Exception { + /// + /// + /// + /// + /// + /// public AdsPushException( string message, AdsPushErrorType errorType, @@ -15,7 +25,16 @@ public AdsPushException( this.HttpResponse = httpResponse; } - public AdsPushErrorType ErrorType { get; set; } - public HttpResponseMessage HttpResponse { get; set; } + /// + /// Error group. + /// + /// + public AdsPushErrorType ErrorType { get; } + + /// + /// Related service http response. + /// + /// + public HttpResponseMessage HttpResponse { get; } } } diff --git a/src/AdsPush.Abstraction/AdsPushProvider.cs b/src/AdsPush.Abstraction/AdsPushProvider.cs index 726cdd3..5cf5378 100644 --- a/src/AdsPush.Abstraction/AdsPushProvider.cs +++ b/src/AdsPush.Abstraction/AdsPushProvider.cs @@ -1,8 +1,17 @@ namespace AdsPush.Abstraction { + /// + /// Supported notification server provider. + /// public enum AdsPushProvider { + /// + /// Apple push Notification Service + /// Apns, + /// + /// FCM - Firebase Cloud Messaging. + /// Firebase } } diff --git a/src/AdsPush.Abstraction/AdsPushTarget.cs b/src/AdsPush.Abstraction/AdsPushTarget.cs index 667472f..2da8354 100644 --- a/src/AdsPush.Abstraction/AdsPushTarget.cs +++ b/src/AdsPush.Abstraction/AdsPushTarget.cs @@ -1,8 +1,17 @@ namespace AdsPush.Abstraction { + /// + /// Notification target IOS + /// public enum AdsPushTarget { + /// + /// Apple IOS/iPadOS + /// Ios, + /// + /// Android + /// Android, } } diff --git a/src/AdsPush.Abstraction/AdsPushText.cs b/src/AdsPush.Abstraction/AdsPushText.cs index a23d489..902ac3e 100644 --- a/src/AdsPush.Abstraction/AdsPushText.cs +++ b/src/AdsPush.Abstraction/AdsPushText.cs @@ -2,8 +2,16 @@ namespace AdsPush.Abstraction { + /// + /// Use to create notification text. + /// public sealed class AdsPushText { + /// + /// Sets flat string to the notification. + /// + /// + /// public static AdsPushText CreateUsingString( string text) { @@ -12,6 +20,12 @@ public static AdsPushText CreateUsingString( null); } + /// + /// Sets localized text model supported by APNS and FXM + /// + /// + /// + /// public static AdsPushText CreateUsingLocalization( string localizationKey, IEnumerable localizationArgs) @@ -31,8 +45,19 @@ private AdsPushText( this.LocalizationArgs = localizationArgs; } + /// + /// Flat string. + /// public string Text { get; } + + /// + /// Localize string. + /// public string LocalizationKey { get; } + + /// + /// Localize string parameters. + /// public IEnumerable LocalizationArgs { get; } } } diff --git a/src/AdsPush.Abstraction/AdsPushType.cs b/src/AdsPush.Abstraction/AdsPushType.cs index 1cbb042..0a6ef75 100644 --- a/src/AdsPush.Abstraction/AdsPushType.cs +++ b/src/AdsPush.Abstraction/AdsPushType.cs @@ -2,9 +2,18 @@ namespace AdsPush.Abstraction { + /// + /// Basic notification types. + /// public enum AdsPushType { + /// + /// Shown notification. + /// Alert, + /// + /// Silent notification. + /// Background } } diff --git a/src/AdsPush.Abstraction/BoolToStringConverter.cs b/src/AdsPush.Abstraction/BoolToStringConverter.cs index dd73744..b76b086 100644 --- a/src/AdsPush.Abstraction/BoolToStringConverter.cs +++ b/src/AdsPush.Abstraction/BoolToStringConverter.cs @@ -3,8 +3,12 @@ namespace AdsPush.Abstraction { + /// + /// Applies conversion for notification system based format to bool types. + /// public class BoolToStringConverter : JsonConverter { + /// public override void WriteJson( JsonWriter writer, object value, @@ -13,6 +17,7 @@ public override void WriteJson( writer.WriteValue((bool)value ? 1 : 0); } + /// public override object ReadJson( JsonReader reader, Type objectType, @@ -22,6 +27,7 @@ public override object ReadJson( return reader.Value.ToString() == "1"; } + /// public override bool CanConvert( Type objectType) { diff --git a/src/AdsPush.Abstraction/Firebase/FirebaseNotificationBatchResult.cs b/src/AdsPush.Abstraction/Firebase/FirebaseNotificationBatchResult.cs index 1529f04..3a6c304 100644 --- a/src/AdsPush.Abstraction/Firebase/FirebaseNotificationBatchResult.cs +++ b/src/AdsPush.Abstraction/Firebase/FirebaseNotificationBatchResult.cs @@ -9,6 +9,11 @@ namespace AdsPush.Abstraction.Firebase /// public sealed class FirebaseNotificationBatchResult { + /// + /// + /// + /// + /// public FirebaseNotificationBatchResult( IList notificationResults) { diff --git a/src/AdsPush.Abstraction/Firebase/FirebaseNotificationResult.cs b/src/AdsPush.Abstraction/Firebase/FirebaseNotificationResult.cs index 4939d06..319a937 100644 --- a/src/AdsPush.Abstraction/Firebase/FirebaseNotificationResult.cs +++ b/src/AdsPush.Abstraction/Firebase/FirebaseNotificationResult.cs @@ -18,19 +18,46 @@ private FirebaseNotificationResult( this.MessagingException = messagingException; } + /// + /// + /// + /// + /// public static FirebaseNotificationResult CreateSuccessResult( string messageId) => new FirebaseNotificationResult(true, messageId, null); + /// + /// + /// + /// + /// public static FirebaseNotificationResult CreateFailedResult( FirebaseMessagingException firebaseMessagingException) => new FirebaseNotificationResult(false, string.Empty, firebaseMessagingException); + /// + /// + /// + /// + /// public static FirebaseNotificationResult CreateUsingFirebaseSendResponse( SendResponse sendResponse) => new FirebaseNotificationResult(sendResponse.IsSuccess, sendResponse.MessageId, sendResponse.Exception); + /// + /// The request is successful. + /// public bool IsSuccess { get; } + + /// + /// Unique message is. + /// public string MessageId { get; } + + /// + /// Firebase exception. + /// + /// public FirebaseMessagingException MessagingException { get; } } } diff --git a/src/AdsPush.Abstraction/IAdsPushConfigurationProvider.cs b/src/AdsPush.Abstraction/IAdsPushConfigurationProvider.cs index b96a280..e0f0621 100644 --- a/src/AdsPush.Abstraction/IAdsPushConfigurationProvider.cs +++ b/src/AdsPush.Abstraction/IAdsPushConfigurationProvider.cs @@ -4,8 +4,17 @@ namespace AdsPush.Abstraction { + /// + /// Providers a interface to be able customize configuration provider source. + /// public interface IAdsPushConfigurationProvider { + /// + /// Get settings for passing + /// + /// + /// + /// Task GetSettingsAsync( string appName, CancellationToken cancellationToken = default); diff --git a/src/AdsPush.Abstraction/Settings/AdsPushAppSettings.cs b/src/AdsPush.Abstraction/Settings/AdsPushAppSettings.cs index 3853582..d8f75b9 100644 --- a/src/AdsPush.Abstraction/Settings/AdsPushAppSettings.cs +++ b/src/AdsPush.Abstraction/Settings/AdsPushAppSettings.cs @@ -2,15 +2,32 @@ namespace AdsPush.Abstraction.Settings { + /// + /// AdsPush app settings. + /// public class AdsPushAppSettings { + /// + /// + /// public AdsPushAppSettings() { this.TargetMappings = new Dictionary(); } + /// + /// Mapping for platform and target service for that platform. + /// public Dictionary TargetMappings { get; set; } + + /// + /// Firebase configuration. + /// public AdsPushFirebaseSettings Firebase { get; set; } + + /// + /// APNS Configuration. + /// public AdsPushAPNSSettings Apns { get; set; } } } diff --git a/src/AdsPush.Abstraction/Settings/AdsPushSettings.cs b/src/AdsPush.Abstraction/Settings/AdsPushSettings.cs index 85a85ca..6c21870 100644 --- a/src/AdsPush.Abstraction/Settings/AdsPushSettings.cs +++ b/src/AdsPush.Abstraction/Settings/AdsPushSettings.cs @@ -2,6 +2,9 @@ namespace AdsPush.Abstraction.Settings { + /// + /// Main settings for AdsPush + /// public class AdsPushSettings : Dictionary { } diff --git a/src/AdsPush.Firebase/AdsPush.Firebase.csproj b/src/AdsPush.Firebase/AdsPush.Firebase.csproj index 3ef7c79..92c155f 100644 --- a/src/AdsPush.Firebase/AdsPush.Firebase.csproj +++ b/src/AdsPush.Firebase/AdsPush.Firebase.csproj @@ -13,12 +13,12 @@ https://github.com/adessoTurkey-dotNET/AdsPush https://github.com/adessoTurkey-dotNET/AdsPush/blob/main/LICENSE Copyright (c) 2023, Anıl Dursun ŞENEL - README.md + README-NUGET.md true - + diff --git a/src/AdsPush/AdsPush.csproj b/src/AdsPush/AdsPush.csproj index 1d76823..b83b8e9 100644 --- a/src/AdsPush/AdsPush.csproj +++ b/src/AdsPush/AdsPush.csproj @@ -4,7 +4,7 @@ netstandard2.0 AdsPush Anıl Dursun ŞENEL - push;APNS;service-side-push-library;Firebase;Apple;FCM + push;APNS;server-side-push-library;Firebase;Apple;FCM;ios-push;android-push;notofication;push-notification AdsPush is the server-side push notification library supports fully APNS(Apple Push Notification Service) and FCM (Firebase Cloud Messaging) @@ -14,12 +14,12 @@ https://github.com/adessoTurkey-dotNET/AdsPush https://github.com/adessoTurkey-dotNET/AdsPush/blob/main/LICENSE Copyright (c) 2023, Anıl Dursun ŞENEL - README.md + README-NUGET.md true - +