/// <inheritdoc /> public IList <IGameNotification> Deserialize(IGameNotificationsPlatform platform) { if (!File.Exists(filename)) { return(null); } using (var file = new FileStream(filename, FileMode.Open)) { using (var reader = new BinaryReader(file)) { // Version reader.ReadByte(); // Length int numElements = reader.ReadInt32(); var result = new List <IGameNotification>(numElements); for (var i = 0; i < numElements; ++i) { IGameNotification notification = platform.CreateNotification(); bool hasValue; // ID hasValue = reader.ReadBoolean(); if (hasValue) { notification.Id = reader.ReadInt32(); } // Title notification.Title = reader.ReadString(); // Body notification.Body = reader.ReadString(); // Body notification.Subtitle = reader.ReadString(); // Group notification.Group = reader.ReadString(); // Badge hasValue = reader.ReadBoolean(); if (hasValue) { notification.BadgeNumber = reader.ReadInt32(); } // Time notification.DeliveryTime = new DateTime(reader.ReadInt64(), DateTimeKind.Local); result.Add(notification); } return(result); } } }
/// <summary> /// Creates a new notification object for the current platform. /// </summary> /// <returns>The new notification, ready to be scheduled, or null if there's no valid platform.</returns> /// <exception cref="InvalidOperationException"><see cref="Initialize"/> has not been called.</exception> public IGameNotification CreateNotification() { if (!Initialized) { throw new InvalidOperationException("Must call Initialize() first."); } return(_platform?.CreateNotification()); }
public static IGameNotification AsGameNotification(this SerializableNotification serializableNotification, IGameNotificationsPlatform platform) { var notification = platform.CreateNotification(); notification.Id = serializableNotification.Id; notification.Title = serializableNotification.Title; notification.Body = serializableNotification.Body; notification.Subtitle = serializableNotification.Subtitle; notification.Channel = serializableNotification.Channel; notification.BadgeNumber = serializableNotification.BadgeNumber; notification.DeliveryTime = serializableNotification.DeliveryTime; return(notification); }