namespace ServiceOutside.Models { public class PushNotificationsConfiguration { /// /// Type of apns system /// public enum APNS_TYPES { SANDBOX, PRODUCTION } /// /// Cert of apns server (APPLE) /// public string APNS_CERT { get; } /// /// BundleId for apns system /// public string APNS_BUNDLE_ID { get; } /// /// KeyId for apns system /// public string APNS_KEY_ID { get; } /// /// TeamId for apns system /// public string APNS_TEAM_ID { get; } /// /// Type of selected apns system /// public APNS_TYPES APNS_CERT_TYPE { get; } public string GOOGLE_CREDENTIAL_JSON { get; } /// /// Constructor of PushNotificationsConfiguration /// /// public PushNotificationsConfiguration(IConfigurationSection configurationSection) { IConfigurationSection APNS = configurationSection.GetSection("APNS"); if (APNS != null) { this.APNS_CERT = APNS.GetValue("Cert"); string apns_type = APNS.GetValue("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("BundleId"); this.APNS_TEAM_ID = APNS.GetValue("TeamId"); this.APNS_KEY_ID = APNS.GetValue("KeyId"); } IConfigurationSection GOOGLE = configurationSection.GetSection("GOOGLE"); if(GOOGLE != null) { this.GOOGLE_CREDENTIAL_JSON = GOOGLE.GetValue("CredentialJson"); } } /// /// Constructor of PushNotificationsConfiguration /// /// APNS Certificate file /// APNS BundleID /// APNS TeamID /// APNS KeyID /// Type of APNS(SANDBOX/PRODUCTION) 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; } /// /// Checks if all neccessary configurations for push service are defined /// public bool Valid { get { return (!string.IsNullOrEmpty(APNS_CERT) && !string.IsNullOrEmpty(APNS_BUNDLE_ID) && !string.IsNullOrEmpty(APNS_TEAM_ID) && !string.IsNullOrEmpty(APNS_KEY_ID)); } } } }