private bool IsValidOutlookLogin(Page _Page, string sEmailID, string sEmailPass) { bool bRet = false; try { ExchangeService service = GetServiceEx(sEmailID, sEmailPass); List <AttendeeInfo> attendees = new List <AttendeeInfo>(); attendees.Add(new AttendeeInfo(sEmailID)); GetUserAvailabilityResults results = service.GetUserAvailability(attendees, new TimeWindow(DateTime.Now, DateTime.Now.AddHours(24)), AvailabilityData.FreeBusy); AttendeeAvailability myAvailablity = results.AttendeesAvailability.FirstOrDefault(); if (myAvailablity != null) { Console.WriteLine(String.Format("FREE", myAvailablity.CalendarEvents.Count)); } return(true); } catch (Exception ex) { var w32ex = ex as Win32Exception; uh.ShowHTMLMessage(_Page, ErrorNumber.SetType("00", errorType.LoginError), ex.Message); bRet = false; } return(bRet); }
private void DisplayAttendeeResults(AttendeeDataContainer attendeeData) { // Clear existing availability information this.AttendeeAvailabilityList.Items.Clear(); this.CalEventsList.Items.Clear(); // Display the given AttendeeAvailability in the ListView AttendeeAvailability availability = attendeeData.Availability; if (availability != null && availability.Result == ServiceResult.Success) { // Change the label text to indicate the selected attendee //this.AttendeeAvailabilityGroup.Text = string.Format(SelectedAttendeeLabelText, attendeeData.Info.SmtpAddress); ListViewItem availRow = this.AttendeeAvailabilityList.Items.Add(PropertyInterpretation.GetPropertyValue(availability.ViewType)); availRow.SubItems.Add(PropertyInterpretation.GetPropertyValue(availability.WorkingHours)); if (availability.MergedFreeBusyStatus.Count > 0) { availRow.SubItems.Add(PropertyInterpretation.GetPropertyValue(availability.MergedFreeBusyStatus)); } foreach (CalendarEvent calEvent in availability.CalendarEvents) { ListViewItem calRow = this.CalEventsList.Items.Add(PropertyInterpretation.GetPropertyValue(calEvent.FreeBusyStatus)); calRow.SubItems.Add(PropertyInterpretation.GetPropertyValue(calEvent.StartTime)); calRow.SubItems.Add(PropertyInterpretation.GetPropertyValue(calEvent.EndTime)); if (calEvent.Details != null) { calRow.SubItems.Add(calEvent.Details.Subject); calRow.SubItems.Add(calEvent.Details.Location); calRow.SubItems.Add(calEvent.Details.IsException.ToString()); calRow.SubItems.Add(calEvent.Details.IsMeeting.ToString()); calRow.SubItems.Add(calEvent.Details.IsPrivate.ToString()); calRow.SubItems.Add(calEvent.Details.IsRecurring.ToString()); calRow.SubItems.Add(calEvent.Details.IsReminderSet.ToString()); calRow.SubItems.Add(calEvent.Details.StoreId); } } } else if (availability != null && availability.Result == ServiceResult.Error) { ErrorDialog.ShowServiceResponseMsgBox( availability, String.Format("Availability request returned an error for attendee, {0}.", attendeeData.Info.SmtpAddress), string.Empty, MessageBoxIcon.Warning); } else if (availability != null) { throw new NotImplementedException( string.Format( "Unexpected ServiceResult, {0}, for AttendeeAvailability", availability.Result.ToString())); } }
object ParseResponse(EwsServiceXmlReader reader) { GetUserAvailabilityResults serviceResponse = new GetUserAvailabilityResults(); if (this.IsFreeBusyViewRequested) { serviceResponse.AttendeesAvailability = new ServiceResponseCollection <AttendeeAvailability>(); reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.FreeBusyResponseArray); do { reader.Read(); if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.FreeBusyResponse)) { AttendeeAvailability freeBusyResponse = new AttendeeAvailability(); freeBusyResponse.LoadFromXml(reader, XmlElementNames.ResponseMessage); if (freeBusyResponse.ErrorCode == ServiceError.NoError) { freeBusyResponse.LoadFreeBusyViewFromXml(reader, this.Options.RequestedFreeBusyView); } serviceResponse.AttendeesAvailability.Add(freeBusyResponse); } }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.FreeBusyResponseArray)); } if (this.IsSuggestionsViewRequested) { serviceResponse.SuggestionsResponse = new SuggestionsResponse(); reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.SuggestionsResponse); serviceResponse.SuggestionsResponse.LoadFromXml(reader, XmlElementNames.ResponseMessage); if (serviceResponse.SuggestionsResponse.ErrorCode == ServiceError.NoError) { serviceResponse.SuggestionsResponse.LoadSuggestedDaysFromXml(reader); } reader.ReadEndElement(XmlNamespace.Messages, XmlElementNames.SuggestionsResponse); } return(serviceResponse); }
private void AddResultsToAttendee(AttendeeInfo attendee, AttendeeAvailability availability) { // Find the given attendee in the AttendeeList and add the // passed AttendeeAvailability and Suggestion so they can be // displayed when the attendee is selected. foreach (ListViewItem item in this.AttendeeList.Items) { AttendeeDataContainer?attendeeData = item.Tag as AttendeeDataContainer?; if (attendeeData.HasValue) { // Match the attendees by SMTP address AttendeeDataContainer data = attendeeData.Value; if (String.Equals(attendee.SmtpAddress, data.Info.SmtpAddress, StringComparison.CurrentCultureIgnoreCase)) { // If we found the attendee then set the values and break out data.Availability = availability; item.Tag = data; return; } } } DebugLog.WriteVerbose(string.Format("Leave: Attendee, {0}, not found in AttendeeList", attendee.SmtpAddress)); }
internal AttendeeDataContainer(AttendeeInfo info) { this.Info = info; this.Availability = null; }
private void GetAvailabilityButton_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; // Get AttendeeInfo from AttendeeList List <AttendeeInfo> attendees = null; if (!this.TryGetAttendeesFromList(out attendees)) { ErrorDialog.ShowWarning("There must be at least one attendee listed to retrieve availability for."); return; } // Get TimeWindow from input TimeWindow window = new TimeWindow( this.StartWindowDate.Value.ToUniversalTime(), this.EndWindowDate.Value.ToUniversalTime()); // Get RequestedData from input AvailabilityData requestedData = AvailabilityData.FreeBusy; if (this.availDataCombo.SelectedItem.HasValue) { requestedData = this.availDataCombo.SelectedItem.Value; } // Collect AvailabilityOptions from form input AvailabilityOptions options = new AvailabilityOptions(); if (this.CurrentMeetingCheck.Checked) { options.CurrentMeetingTime = this.CurrentMeetingDate.Value; } else { options.CurrentMeetingTime = null; } options.MeetingDuration = Convert.ToInt32(this.MeetingDurationText.Text); options.DetailedSuggestionsWindow = new TimeWindow( this.StartDetailDate.Value, this.EndDetailDate.Value); options.GlobalObjectId = this.GlobalObjectIdText.Text; options.GoodSuggestionThreshold = Convert.ToInt32(this.GoodSuggestThresholdText.Text); options.MaximumNonWorkHoursSuggestionsPerDay = Convert.ToInt32(this.MaxNonWorkSuggestText.Text); options.MaximumSuggestionsPerDay = Convert.ToInt32(this.MaxSuggestPerDayText.Text); options.MergedFreeBusyInterval = Convert.ToInt32(this.MergeFBIntervalText.Text); if (this.minSuggestQualCombo.SelectedItem.HasValue) { options.MinimumSuggestionQuality = this.minSuggestQualCombo.SelectedItem.Value; } if (this.requestFBViewCombo.SelectedItem.HasValue) { options.RequestedFreeBusyView = this.requestFBViewCombo.SelectedItem.Value; } // Remember which attendee was selected in the AttendeeList int selectedIndex = -1; if (this.AttendeeList.SelectedItems != null && this.AttendeeList.SelectedItems.Count == 1) { selectedIndex = this.AttendeeList.SelectedItems[0].Index; this.AttendeeList.Items[selectedIndex].Selected = false; } // Make the EWS request GetUserAvailabilityResults results = this.CurrentService.GetUserAvailability( attendees, window, requestedData, options); // Enable result lists this.AttendeeAvailabilityList.Enabled = true; this.CalEventsList.Enabled = true; this.SuggestionsList.Enabled = true; // Attach AttendeeAvailability to the associated attendee in the ListView. // It can be assumed that the order of the AttendeesAvailability and Suggestions // results arrays correspond to the order of the attendees. for (int i = 0; i < attendees.Count; i++) { AttendeeAvailability availResult = null; if (results.AttendeesAvailability != null && results.AttendeesAvailability[i] != null) { availResult = results.AttendeesAvailability[i]; } this.AddResultsToAttendee(attendees[i], availResult); } if (results.Suggestions != null) { // Display the Suggestion in the ListView foreach (Suggestion suggest in results.Suggestions) { foreach (TimeSuggestion time in suggest.TimeSuggestions) { ListViewItem timeItem = this.SuggestionsList.Items.Add(suggest.Date.ToShortDateString()); timeItem.SubItems.Add(suggest.Quality.ToString()); timeItem.SubItems.Add(time.MeetingTime.ToShortTimeString()); timeItem.SubItems.Add(time.Quality.ToString()); timeItem.SubItems.Add(time.Conflicts.Count.ToString()); timeItem.SubItems.Add(time.IsWorkTime.ToString()); } } } // Reset the selected Attendee and display the results or show a message // to inform the user how to display results. if (selectedIndex > -1) { this.AttendeeList.Items[selectedIndex].Selected = true; } else { //this.AttendeeAvailabilityGroup.Text = "Select an attendee in the list to display availability results."; } } finally { this.Cursor = Cursors.Default; } }