Esempio n. 1
0
        public void TestTimeCalculations()
        {
            var totalDays    = 3;
            var periodicKeys =
                _periodicNotificationHolder.CalculateNotificationTimes(0, _periodicNotification, totalDays);

            foreach (var kvp in periodicKeys)
            {
                Debug.WriteLine($"Periodic ---> key - {kvp.Key} Time {kvp.Value:yy/MM/dd @ hh:mm tt}");
            }

            var regularKeys = _notificationHolder.CalculateNotificationTimes(300, _notification, totalDays);

            foreach (var kvp in regularKeys)
            {
                Debug.WriteLine($"Non Periodic ---> key - {kvp.Key} Time {kvp.Value:yy/MM/dd @ hh:mm tt}");
            }
        }
        public void AddOrUpdateNotification(NotificationModel model)
        {
            if (model.ID == 0)
            {
                // if theres nothing in the dictionary just set first key to 100
                int newKey = _notifications.Count > 0 ? _notifications.Keys.Max() + HolderGap : 100;

                model.ID = newKey;

                NotificationHolder holder = new NotificationHolder();
                var keys = holder.CalculateNotificationTimes(newKey, model, DaysToGenerate);
                _notifications.Add(newKey, holder);

                foreach (KeyValuePair <int, DateTime> timeSets in keys)
                {
                    //Todo: create your own implementation of this.
                    //CrossLocalNotifications.Current.Show($"Time to log your {model.LogType}!", model.Message,
                    //    timeSets.Key, timeSets.Value);
                }
            }
            else
            {
                NotificationHolder holder = _notifications[model.ID];

                foreach (int key in holder.SystemKeys.Keys)
                {
                    //Todo: create your own implementation of this.
                    //CrossLocalNotifications.Current.Cancel(key);
                }

                foreach (KeyValuePair <int, DateTime> timeSets in holder.SystemKeys)
                {
                    //Todo: create your own implementation of this.
                    //CrossLocalNotifications.Current.Show($"Time to log your {model.LogType}!",
                    //    model.Message, timeSets.Key, timeSets.Value);
                }
            }
            Save();
        }