private void TopicTapToAddMethod(Topic topic)
        {
            if (topic == null)
            {
                return;
            }
            if (Topics == null)
            {
                Topics = new ObservableCollection <Topic>();
            }

            if (Topics.Contains(topic) == false)
            {
                Topics.Add(topic);
            }

            RaisePropertyChanged(() => Topics);

            if (_navigate == null)
            {
                return;
            }

            _navigate.GoBack();
        }
Пример #2
0
        private void OnTopicSubscribed(object sender, TopicSubscribedEventArgs e)
        {
            if (Topics.Contains(e.Topic))
            {
                return;
            }

            Topics.Add(e.Topic);

            if (Topics.Count == 1)
            {
                Topic = e.Topic;
            }
        }
Пример #3
0
        public void Subscribe()
        {
            if (!Topics.Contains(Topic))
            {
                Topics.Add(Topic);
            }
            if (!subscribedToEvent)
            {
                subscribedToEvent = true;
                MqttHandler.Instance.ClientMessageArrived += HandleMqttHandlerInstanceClientMessageArrived;
            }

            MqttHandler.Instance.Subscribe(Topic, Qos);
            MessageHistory += Environment.NewLine + "Subscribed to: " + Topic;
        }
Пример #4
0
        private void StartConsume()
        {
            Task.Factory.StartNew(async() =>
            {
                while (await MessageChannel.Reader.WaitToReadAsync())
                {
                    if (!MessageChannel.Reader.TryRead(out var message))
                    {
                        continue;
                    }
                    var context = new MessageHandleContext(message.Topic, message.Message);
                    if (!Topics.Contains(message.Topic))
                    {
                        continue;
                    }

                    await HandleMessageAsync(() => context);
                }
            });
        }
Пример #5
0
        /// <summary>
        /// Process a single small group. Determine if the small group leader has taken
        /// attendance for their last small group and if not send the leader (and
        /// optionally assistant-leaders) an e-mail to remind them.
        /// </summary>
        /// <param name="group">The small group to check attendance for.</param>
        /// <returns>True/false status indicating if a fatal error occurred.</returns>
        Boolean ProcessGroup(Group group)
        {
            GroupOccurrence occurrence = null;
            DayOfWeek       dow;
            DateTime        meetingDate;


            //
            // If this small group is not active, ignore it.
            //
            if (group.Active == false)
            {
                return(true);
            }

            //
            // If they have limited the cluster types and this cluster type is not in
            // the list of valid cluster types, then skip it.
            //
            if (Topics.Length > 0 && Topics.Contains(group.Topic.LookupID) == false)
            {
                return(true);
            }

            //
            // Determine the meeting day of the week.
            //
            if (group.MeetingDay == null)
            {
                return(true);
            }
            if (group.MeetingDay.Value.Equals("Sunday", StringComparison.CurrentCultureIgnoreCase))
            {
                dow = DayOfWeek.Sunday;
            }
            else if (group.MeetingDay.Value.Equals("Monday", StringComparison.CurrentCultureIgnoreCase))
            {
                dow = DayOfWeek.Monday;
            }
            else if (group.MeetingDay.Value.Equals("Tuesday", StringComparison.CurrentCultureIgnoreCase))
            {
                dow = DayOfWeek.Tuesday;
            }
            else if (group.MeetingDay.Value.Equals("Wednesday", StringComparison.CurrentCultureIgnoreCase))
            {
                dow = DayOfWeek.Wednesday;
            }
            else if (group.MeetingDay.Value.Equals("Thursday", StringComparison.CurrentCultureIgnoreCase))
            {
                dow = DayOfWeek.Thursday;
            }
            else if (group.MeetingDay.Value.Equals("Friday", StringComparison.CurrentCultureIgnoreCase))
            {
                dow = DayOfWeek.Friday;
            }
            else if (group.MeetingDay.Value.Equals("Saturday", StringComparison.CurrentCultureIgnoreCase))
            {
                dow = DayOfWeek.Saturday;
            }
            else
            {
                if (Debug)
                {
                    _message.AppendFormat("Could not determine meeting day of week for small group {0}, value was '{1}'<br />", group.Name, group.MeetingDay.Value);
                }

                return(true);
            }

            //
            // Walk backwards from today. We don't consider "today" a valid day
            // so start on the previous day.
            //
            for (DateTime dt = DateTime.Now.AddDays(-1); ; dt = dt.AddDays(-1))
            {
                if (dt.DayOfWeek == dow)
                {
                    meetingDate = dt;
                    break;
                }
            }

            //
            // Find the existing occurrence for this group.
            //
            foreach (GroupOccurrence occ in group.Occurrences)
            {
                //
                // The occurrence must match the date portion of the expected meeting date.
                //
                if (occ.StartTime.Year == meetingDate.Year && occ.StartTime.Month == meetingDate.Month &&
                    occ.StartTime.Day == meetingDate.Day)
                {
                    occurrence = occ;
                    break;
                }
            }

            //
            // If the occurrence already has attendance taken, then they are all good.
            //
            if (occurrence != null && occurrence.Attendance > 0)
            {
                if (Debug)
                {
                    _message.AppendFormat("Small group '{0}' has already taken attendance on '{1}'.<br />", group.Name, occurrence.StartTime.ToShortDateString());
                }

                return(true);
            }

            //
            // Make sure the grace period has passed.
            //
            DateTime a, b;

            a           = DateTime.Now.AddDays(-(GracePeriod + 1));
            b           = DateTime.Now.AddDays(-GracePeriod);
            meetingDate = new DateTime(meetingDate.Year, meetingDate.Month, meetingDate.Day, 23, 59, 59);
            if (meetingDate.CompareTo(a) > 0 &&
                meetingDate.CompareTo(b) < 0)
            {
                List <Person> leaders = new List <Person>();

                //
                // Add the primary group leader to the list.
                //
                leaders.Add(group.Leader);

                //
                // Make a list of all the assistant leaders.
                //
                if (AssistantLeaderRoles.Length > 0)
                {
                    foreach (GroupMember gm in group.Members)
                    {
                        if (gm.Active && AssistantLeaderRoles.Contains(gm.Role.LookupID))
                        {
                            leaders.Add(gm);
                        }
                    }
                }

                //
                // Send an e-mail to each person in the list.
                //
                foreach (Person leader in leaders)
                {
                    AttendanceReminder          reminder = new AttendanceReminder();
                    Dictionary <string, string> fields   = new Dictionary <string, string>();

                    _message.AppendFormat("Sending e-mail to leader '{1}' of Small Group '{0}' which meets on {2}<br />", new object[] { group.Name, leader.FullName, group.MeetingDay.Value });

                    reminder.LoadFields(fields, leader, group);

                    //
                    // Send an e-mail to the first active e-mail address the leader has.
                    //
                    foreach (PersonEmail email in leader.Emails)
                    {
                        if (email.Active)
                        {
                            //
                            // Send the e-mail and then stop looking for a valid e-mail address.
                            //
                            reminder.Send(email.Email, fields);

                            break;
                        }
                    }
                }
            }

            return(true);
        }