103 lines
3.4 KiB
C#
103 lines
3.4 KiB
C#
|
namespace ServiceOutside.Models
|
|||
|
{
|
|||
|
public class PushNotificationsConfiguration
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Type of apns system
|
|||
|
/// </summary>
|
|||
|
public enum APNS_TYPES { SANDBOX, PRODUCTION }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Cert of apns server (APPLE)
|
|||
|
/// </summary>
|
|||
|
public string APNS_CERT { get; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// BundleId for apns system
|
|||
|
/// </summary>
|
|||
|
public string APNS_BUNDLE_ID { get; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// KeyId for apns system
|
|||
|
/// </summary>
|
|||
|
public string APNS_KEY_ID { get; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// TeamId for apns system
|
|||
|
/// </summary>
|
|||
|
public string APNS_TEAM_ID { get; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Type of selected apns system
|
|||
|
/// </summary>
|
|||
|
public APNS_TYPES APNS_CERT_TYPE { get; }
|
|||
|
|
|||
|
public string GOOGLE_CREDENTIAL_JSON { get; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Constructor of PushNotificationsConfiguration
|
|||
|
/// </summary>
|
|||
|
/// <param name="configurationSection"></param>
|
|||
|
public PushNotificationsConfiguration(IConfigurationSection configurationSection)
|
|||
|
{
|
|||
|
IConfigurationSection APNS = configurationSection.GetSection("APNS");
|
|||
|
|
|||
|
if (APNS != null)
|
|||
|
{
|
|||
|
this.APNS_CERT = APNS.GetValue<string>("Cert");
|
|||
|
string apns_type = APNS.GetValue<string>("Type");
|
|||
|
|
|||
|
if(!string.IsNullOrEmpty(apns_type))
|
|||
|
{
|
|||
|
APNS_TYPES outAPNSType = APNS_TYPES.SANDBOX;
|
|||
|
|
|||
|
if(Enum.TryParse(apns_type, out outAPNSType))
|
|||
|
{
|
|||
|
APNS_CERT_TYPE = outAPNSType;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
this.APNS_BUNDLE_ID = APNS.GetValue<string>("BundleId");
|
|||
|
this.APNS_TEAM_ID = APNS.GetValue<string>("TeamId");
|
|||
|
this.APNS_KEY_ID = APNS.GetValue<string>("KeyId");
|
|||
|
}
|
|||
|
|
|||
|
IConfigurationSection GOOGLE = configurationSection.GetSection("GOOGLE");
|
|||
|
|
|||
|
if(GOOGLE != null)
|
|||
|
{
|
|||
|
this.GOOGLE_CREDENTIAL_JSON = GOOGLE.GetValue<string>("CredentialJson");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Constructor of PushNotificationsConfiguration
|
|||
|
/// </summary>
|
|||
|
/// <param name="apns_cert">APNS Certificate file</param>
|
|||
|
/// <param name="bundle_id">APNS BundleID</param>
|
|||
|
/// <param name="team_id">APNS TeamID</param>
|
|||
|
/// <param name="key_id">APNS KeyID</param>
|
|||
|
/// <param name="apns_cert">Type of APNS(SANDBOX/PRODUCTION)</param>
|
|||
|
public PushNotificationsConfiguration(string apns_cert, string bundle_id, string team_id, string key_id, APNS_TYPES apns_type, string google_json)
|
|||
|
{
|
|||
|
this.APNS_CERT = apns_cert;
|
|||
|
this.APNS_CERT_TYPE = apns_type;
|
|||
|
this.APNS_BUNDLE_ID = bundle_id;
|
|||
|
this.APNS_TEAM_ID = team_id;
|
|||
|
this.APNS_KEY_ID = key_id;
|
|||
|
this.GOOGLE_CREDENTIAL_JSON = google_json;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Checks if all neccessary configurations for push service are defined
|
|||
|
/// </summary>
|
|||
|
public bool Valid
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return (!string.IsNullOrEmpty(APNS_CERT) && !string.IsNullOrEmpty(APNS_BUNDLE_ID) && !string.IsNullOrEmpty(APNS_TEAM_ID) && !string.IsNullOrEmpty(APNS_KEY_ID));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|