Beispiel #1
0
        /// <summary>
        /// Get exchange status
        /// </summary>
        void GetExchangeStatus()
        {
            try
            {
                if (ReadSetting("username") != null || ReadSetting("username") == "" && ReadSetting("exchangeHost") != null || ReadSetting("exchangeHost") == "")
                {
                    exchangeService = new ExchangeService(ExchangeVersion.Exchange2013);
                    AvailabilityOptions myOptions = new AvailabilityOptions();
                    myOptions.MeetingDuration       = 2;
                    myOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;

                    List <AttendeeInfo> attendees = new List <AttendeeInfo>();

                    attendees.Add(new AttendeeInfo()
                    {
                        SmtpAddress  = ReadSetting("epost"),
                        AttendeeType = MeetingAttendeeType.Required
                    });

                    // TODO: get url for webservice
                    exchangeService.Url         = new Uri(ReadSetting("exchangeHost"));
                    exchangeService.Credentials = new WebCredentials(ReadSetting("username"), StringCipher.Decrypt(ReadSetting("password")));
                    var userStatus = exchangeService.GetUserAvailability(attendees, new TimeWindow(DateTime.Now, DateTime.Now.AddDays(1)),
                                                                         AvailabilityData.FreeBusy,
                                                                         myOptions);

                    var userDetailedStatus = userStatus.AttendeesAvailability.First();

                    // initial green
                    PushGreen();

                    foreach (var calendarItem in userDetailedStatus.CalendarEvents)
                    {
                        Console.WriteLine("User status for: " + ReadSetting("username"));
                        Console.WriteLine("  Free/busy status: " + calendarItem.FreeBusyStatus);
                        Console.WriteLine("  Start time: " + calendarItem.StartTime);
                        Console.WriteLine("  End time: " + calendarItem.EndTime);

                        if (calendarItem.StartTime <= DateTime.Now && DateTime.Now <= calendarItem.EndTime &&
                            calendarItem.FreeBusyStatus == LegacyFreeBusyStatus.Busy)
                        {
                            PushRed();
                        }
                        else if (calendarItem.StartTime <= DateTime.Now && DateTime.Now <= calendarItem.EndTime &&
                                 calendarItem.FreeBusyStatus == LegacyFreeBusyStatus.Free)
                        {
                            PushGreen();
                        }
                        else if (calendarItem.StartTime <= DateTime.Now && DateTime.Now <= calendarItem.EndTime &&
                                 calendarItem.FreeBusyStatus == LegacyFreeBusyStatus.OOF || calendarItem.FreeBusyStatus == LegacyFreeBusyStatus.Tentative || calendarItem.FreeBusyStatus == LegacyFreeBusyStatus.WorkingElsewhere)
                        {
                            PushYellow();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //statusbar.Text = "Error: Problemer med exchange tilkobling...";

                setStatusText("Error: Problems with Exchange connection...");
            }
        }