public void Show(AppointmentGroup appointments)
        {
            Trace.WriteLine("Show " + appointments);

            if (appointments == null || !appointments.Next.Any())
            {
                return;
            }

            var distinctTimes = 1;
            var prev = appointments.Next.First();
            var first = prev;
            var prevWindow = this;
            Show(prev);

            foreach (var appointment in appointments.Next.Skip(1))
            {
                if (appointment.Start > prev.Start)
                {
                    if (distinctTimes++ > 2 && appointment.Start.Subtract(first.Start).TotalMinutes > 15)
                    {
                        break;
                    }
                }

                var child = new NotificationWindow(this);
                children.Add(child);
                child.Top = prevWindow.Top + prevWindow.Height + 5;
                child.Left = Left;
                child.Show(appointment);
                prevWindow = child;
            }

            EnsureChildrenOnScreen();
        }
        public AppointmentGroup GetNextAppointments()
        {
            try
            {
                var newAppointments = new AppointmentGroup();

                var service = new ExchangeService();
                service.UseDefaultCredentials = true;
                service.AutodiscoverUrl(UserPrincipal.Current.EmailAddress);

                DateTime from = DateTime.Now.AddMinutes(-5);
                DateTime to = DateTime.Today.AddDays(1);

                IEnumerable<Appointment> appointments =
                    service.FindAppointments(WellKnownFolderName.Calendar, new CalendarView(from, to))
                        .Select(MakeAppointment);

                newAppointments.Next =
                    appointments.Where(o => o != null && o.Start >= DateTime.Now)
                        .OrderBy(o => o.Start).ToList();

                nextAppointments = newAppointments;
                return newAppointments;
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
                return nextAppointments;
            }
        }
示例#3
0
        public AppointmentGroup GetNextAppointments()
        {
            try
            {
                var newAppointments = new AppointmentGroup();

                var service = new ExchangeService();
                service.UseDefaultCredentials = true;
                service.AutodiscoverUrl(UserPrincipal.Current.EmailAddress);


                DateTime from = DateTime.Now.AddMinutes(-5);
                DateTime to   = DateTime.Today.AddDays(1);


                IEnumerable <Appointment> appointments =
                    service.FindAppointments(WellKnownFolderName.Calendar, new CalendarView(from, to))
                    .Select(MakeAppointment);

                newAppointments.Next =
                    appointments.Where(o => o != null && o.Start >= DateTime.Now)
                    .OrderBy(o => o.Start).ToList();

                nextAppointments = newAppointments;
                return(newAppointments);
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
                return(nextAppointments);
            }
        }
        private void PollerOnNextAppointmentChanged(object sender,
                                                    AppointmentChangePoller.NextAppointmentChangedEventHandlerArgs args)
        {
            AppointmentGroup appts = args.NextAppointments;

            timer.updateNextAppointment(appts);
            UpdateTooltip(appts);

            if (first)
            {
                notificationWindow.Show(appts);
                first = false;
            }
        }
 private void CheckOutlook()
 {
     AppointmentGroup newAppointments = outlookService.GetNextAppointments();
     if (newAppointments != nextAppointments || firstCheck)
     {
         firstCheck = false;
         nextAppointments = newAppointments;
         if (NextAppointmentChanged != null)
         {
             Trace.WriteLine("AppointmentChange.fire " + newAppointments);
             NextAppointmentChanged(this,
                 new NextAppointmentChangedEventHandlerArgs {NextAppointments = nextAppointments});
         }
     }
 }
        private void CheckOutlook()
        {
            AppointmentGroup newAppointments = outlookService.GetNextAppointments();

            if (newAppointments != nextAppointments || firstCheck)
            {
                firstCheck       = false;
                nextAppointments = newAppointments;
                if (NextAppointmentChanged != null)
                {
                    Trace.WriteLine("AppointmentChange.fire " + newAppointments);
                    NextAppointmentChanged(this,
                                           new NextAppointmentChangedEventHandlerArgs {
                        NextAppointments = nextAppointments
                    });
                }
            }
        }
        private void UpdateTooltip(AppointmentGroup appointments)
        {
            if (appointments != null)
            {
                notifyIcon.IconSource = connectedIcon;

                Appointment next = appointments.Next.FirstOrDefault(a => a.Start > DateTime.Now);
                if (next != null)
                {
                    notifyIcon.ToolTipText = string.Format("Next: {0} - {1}",
                        next.Start.ToShortTimeString(),
                        next.Subject);
                }
                else
                {
                    notifyIcon.ToolTipText = "No further appointments today";
                }
            }
            else
            {
                notifyIcon.ToolTipText = "Unable to contact exchange server";
                notifyIcon.IconSource = disconnectedIcon;
            }
        }
        private void UpdateTooltip(AppointmentGroup appointments)
        {
            if (appointments != null)
            {
                notifyIcon.IconSource = connectedIcon;

                Appointment next = appointments.Next.FirstOrDefault(a => a.Start > DateTime.Now);
                if (next != null)
                {
                    notifyIcon.ToolTipText = string.Format("Next: {0} - {1}",
                                                           next.Start.ToShortTimeString(),
                                                           next.Subject);
                }
                else
                {
                    notifyIcon.ToolTipText = "No further appointments today";
                }
            }
            else
            {
                notifyIcon.ToolTipText = "Unable to contact exchange server";
                notifyIcon.IconSource  = disconnectedIcon;
            }
        }
        public void updateNextAppointment(AppointmentGroup appointments)
        {
            warningTimer.Stop();
            notifyTimer.Stop();

            nextAppointments = appointments;

            if (appointments != null && appointments.Next.Any())
            {
                var interval = (appointments.Next.First().Start - DateTime.Now);

                if (interval.TotalSeconds > 1)
                {
                    notifyTimer.Interval = interval;
                    notifyTimer.Start();

                    if (notifyTimer.Interval > TimeSpan.FromMinutes(5))
                    {
                        warningTimer.Interval = notifyTimer.Interval.Subtract(TimeSpan.FromMinutes(5));
                        warningTimer.Start();
                    }
                }
            }
        }
        public void updateNextAppointment(AppointmentGroup appointments)
        {
            warningTimer.Stop();
            notifyTimer.Stop();

            nextAppointments = appointments;

            if (appointments != null && appointments.Next.Any())
            {
                var interval = (appointments.Next.First().Start - DateTime.Now);

                if (interval.TotalSeconds > 1)
                {
                    notifyTimer.Interval = interval;
                    notifyTimer.Start();

                    if (notifyTimer.Interval > TimeSpan.FromMinutes(5))
                    {
                        warningTimer.Interval = notifyTimer.Interval.Subtract(TimeSpan.FromMinutes(5));
                        warningTimer.Start();
                    }
                }
            }
        }
        public void Show(AppointmentGroup appointments)
        {
            Trace.WriteLine("Show " + appointments);

            if (appointments == null || !appointments.Next.Any())
            {
                return;
            }

            var distinctTimes = 1;
            var prev          = appointments.Next.First();
            var first         = prev;
            var prevWindow    = this;

            Show(prev);

            foreach (var appointment in appointments.Next.Skip(1))
            {
                if (appointment.Start > prev.Start)
                {
                    if (distinctTimes++ > 2 && appointment.Start.Subtract(first.Start).TotalMinutes > 15)
                    {
                        break;
                    }
                }

                var child = new NotificationWindow(this);
                children.Add(child);
                child.Top  = prevWindow.Top + prevWindow.Height + 5;
                child.Left = Left;
                child.Show(appointment);
                prevWindow = child;
            }

            EnsureChildrenOnScreen();
        }
 protected bool Equals(AppointmentGroup other)
 {
     return(Equals(Next, other.Next));
 }
 protected bool Equals(AppointmentGroup other)
 {
     return Equals(Next, other.Next);
 }