/// <summary> /// Creates a new push notification from a collection of key/value pairs or null if no notification Type is defined. /// </summary> /// <param name="knownTypes">A collection of known notifiation types.</param> /// <param name="notificationValues">A key/value pair of items for the notification.</param> /// <returns>The result of the conversion operation.</returns> public static PushNotificationParseResult FromDictionary(PushNotificationTypes knownTypes, IDictionary <string, string> notificationValues) { Throw.IfArgumentNull(notificationValues, "notificationValues"); Dictionary <string, string> values = new Dictionary <string, string>(notificationValues); if (values.Comparer != StringComparer.OrdinalIgnoreCase) { values = new Dictionary <string, string>(values, StringComparer.OrdinalIgnoreCase); } if (!values.ContainsKey(Constants.NotificationNameKey)) { return(new PushNotificationParseResult(PushNotificationParseResult.ResultCode.MissingName)); } string name = values[Constants.NotificationNameKey]; Type notificationType = knownTypes.TryGetType(name); if (notificationType != null) { PushNotification notification = (PushNotification)Activator.CreateInstance(notificationType); return (notification.Initialize(values) ? new PushNotificationParseResult(notification) : new PushNotificationParseResult(PushNotificationParseResult.ResultCode.FailedToInitialize)); } return(new PushNotificationParseResult(PushNotificationParseResult.ResultCode.UnknownName)); }
/// <summary> /// Scans the specified assembly for all classes with a PushNotificationAttribute. /// </summary> /// <param name="assembly">An assembly to scan.</param> /// <returns>A PushNotificationTypes instance.</returns> public static PushNotificationTypes FromAssembly(Assembly assembly) { return(new PushNotificationTypes(PushNotificationTypes.LoadNotificationTypes(assembly))); }