private void AddAttendeeToList(AttendeeInfo attendee) { if (attendee == null) { DebugLog.WriteVerbose("Leave: attendee is null"); return; } if (String.IsNullOrEmpty(attendee.SmtpAddress)) { DebugLog.WriteVerbose("Leave: Attendee's SMTP address is null or empty"); return; } // Reset the availability results for all attendees and require // a new availability request since we have new attendee list this.ClearAvailabilityResults(); // Load the visual elements of the row with attendee data ListViewItem row = this.AttendeeList.Items.Add(attendee.SmtpAddress); row.SubItems.Add(attendee.AttendeeType.ToString()); row.SubItems.Add(attendee.ExcludeConflicts.ToString()); // Store the original object in the tag for use later row.Tag = new AttendeeDataContainer(attendee); }
public List <Room> LoadRooms(int preferredFloor) { List <Room> rooms = new List <Room>(); // For each room in the Seattle conference address... foreach (var room in service.GetRooms("*****@*****.**")) { // Skip any room that doesn't have the parsable data. if (!room.Name.Contains('[')) { continue; } RoomInfo roomInfo = RoomInfo.ParseRoomInfo(room.Name); // .. Create an attendee and a time window, which has to be at least 1 day. AttendeeInfo attendee = GetAttendeeFromRoom(room); rooms.Add(new Room { AttendeeInfo = attendee, RoomInfo = roomInfo }); } // Sort by max people first, then floor. rooms = (from n in rooms orderby Math.Abs(n.RoomInfo.Floor - preferredFloor) ascending, n.RoomInfo.MaxPeople ascending select n).ToList(); return(rooms); }
private void AddAttendeeButton_Click(object sender, EventArgs e) { AttendeeInfo info = null; if (AttendeeInfoDialog.ShowDialog(this.CurrentService, out info) == DialogResult.OK) { this.AddAttendeeToList(info); } }
private static AttendeeInfo GetAttendeeFromRoom(EmailAddress room) { var attendee = new AttendeeInfo(room.Address); attendee.ExcludeConflicts = false; attendee.AttendeeType = MeetingAttendeeType.Organizer; return(attendee); }
/// <summary> /// Get the availability details of the accounts /// </summary> static void GetAvailabilityDetails(ExchangeService service, String startDate, String endDate, params String[] emailAddresses) { // If the date is invaild, we will set today as the start date. DateTime startMeetingDate; startMeetingDate = DateTime.TryParse(startDate, out startMeetingDate) ? startMeetingDate : DateTime.Now; // If the date is invaild, we will set two days after the start date as the end date. DateTime endMeetingDate; endMeetingDate = DateTime.TryParse(endDate, out endMeetingDate) && endMeetingDate >= startMeetingDate ? endMeetingDate : startMeetingDate.AddDays(2); List <AttendeeInfo> attendees = new List <AttendeeInfo>(); foreach (String emailAddress in emailAddresses) { AttendeeInfo attendee = new AttendeeInfo(emailAddress); attendees.Add(attendee); } TimeWindow timeWindow = new TimeWindow(startMeetingDate, endMeetingDate); AvailabilityOptions availabilityOptions = new AvailabilityOptions(); availabilityOptions.MeetingDuration = 60; GetUserAvailabilityResults userAvailabilityResults = service.GetUserAvailability(attendees, timeWindow, AvailabilityData.FreeBusyAndSuggestions, availabilityOptions); Console.WriteLine("{0,-15}{1,-21}{2,-11}{3,-14}{4,-10}{5,-9}", "FreeBusyStatus", "StartTime", "EndTime", "Subject", "Location", "IsMeeting"); foreach (AttendeeAvailability userAvailabilityResult in userAvailabilityResults.AttendeesAvailability) { if (userAvailabilityResult.ErrorCode.CompareTo(ServiceError.NoError) == 0) { foreach (CalendarEvent calendarEvent in userAvailabilityResult.CalendarEvents) { Console.WriteLine("{0,-15}{1,-21}{2,-11}{3,-14}{4,-10}{5,-9}", calendarEvent.FreeBusyStatus, calendarEvent.StartTime.ToShortDateString() + " " + calendarEvent.StartTime.ToShortTimeString(), calendarEvent.EndTime.ToShortTimeString(), calendarEvent.Details.Subject, calendarEvent.Details.Location, calendarEvent.Details.IsMeeting); } } } }
private List <AttendeeInfo> getSalasDeReuniaoPorWebConfig() { List <AttendeeInfo> listaParticipantes = new List <AttendeeInfo>(); string EmailsWebConfig = new ConfiguracaoBS().obterConfiguracao().SalasEstaticas; var arrayEmails = EmailsWebConfig.Split(';').ToArray(); foreach (var sala in arrayEmails) { AttendeeInfo participante = new AttendeeInfo(sala, MeetingAttendeeType.Room, false); listaParticipantes.Add(participante); } return(listaParticipantes); }
/// <summary> /// Show a dialog to allow the user to input settings to /// create an AttendeeInfo object. /// </summary> /// <param name="attendee"> /// Out parameter representing the AttendeeInfo created /// from the dialog settings. /// </param> /// <returns> /// Returns DialogResult.OK if the user clicked OK and the /// AttendeeInfo was created successfully. /// </returns> public static DialogResult ShowDialog(ExchangeService service, out AttendeeInfo attendee) { AttendeeInfo newAttendee = null; DialogResult result = AttendeeInfoDialog.ShowDialog(service, null, null, out newAttendee); if (result == DialogResult.OK && newAttendee != null) { attendee = newAttendee; } else { attendee = null; } return(result); }
private List <AttendeeInfo> getSalasDeReuniao(ExchangeService service) { List <AttendeeInfo> listaParticipantes = new List <AttendeeInfo>(); EmailAddressCollection rooms = service.GetRoomLists(); foreach (var item in rooms) { var salas = service.GetRooms(item.Address); foreach (var sala in salas) { AttendeeInfo participante = new AttendeeInfo(sala.Address, MeetingAttendeeType.Room, false); listaParticipantes.Add(participante); } } return(listaParticipantes); }
public static List <CalendarEvent> GetRoomAvailability(string roomAddress) { //short cache just to prevent crazy accesses //it is recommended to keep this cache shorter than the page refresh //otherwise the frequent refresh doesn't do any good string RoomEventsKey = GetRoomEventsKey(roomAddress); var returnValue = (List <CalendarEvent>)_memoryCache.Get(RoomEventsKey); if (returnValue == null) { var attendee = new AttendeeInfo(roomAddress, MeetingAttendeeType.Room, false); var results = _exchangeService.GetUserAvailability(new List <AttendeeInfo>() { attendee }, new TimeWindow(DateTime.Today, DateTime.Today.AddDays(1)), AvailabilityData.FreeBusy); returnValue = results.AttendeesAvailability.SelectMany(a => a.CalendarEvents).Select(e => new CalendarEvent() { Subject = e.Details.Subject, StartTime = e.StartTime, EndTime = e.EndTime, Status = e.FreeBusyStatus.ToString() }).OrderBy(e => e.StartTime).ToList(); //add the pending item if necessary var pendingItem = (CalendarEvent)_memoryCache.Get(GetRoomPendingEventKey(roomAddress)); //match on StartTime/EndTime because we know its unique for a given room if (pendingItem != null && !returnValue.Any(c => c.EndTime.Equals(pendingItem.EndTime) && c.StartTime.Equals(pendingItem.StartTime))) { returnValue.Add(pendingItem); } _memoryCache.Add(RoomEventsKey, returnValue, DateTime.Now.AddSeconds(45)); } return(returnValue); //if we need attendee details in the future - use this // var appointments = exchangeService.FindAppointments(new FolderId(WellKnownFolderName.Calendar,new Mailbox(roomAddress)), // new CalendarView(DateTime.Today, DateTime.Today.AddDays(4))); }
/// <summary> /// Show a dialog to allow the user to input settings to /// create an AttendeeInfo object from the given information. /// </summary> /// <param name="address">Default address to preload in the form</param> /// <param name="attendeeType">Default MeetingAttendeeType to preload in the form</param> /// <param name="attendee">Output parameter representing the AttendeeInfo created /// from the dialog settings.</param> /// <returns> /// Returns DialogResult.OK if the user clicked OK and the /// AttendeeInfo was created successfully. /// </returns> public static DialogResult ShowDialog( ExchangeService service, EmailAddress address, MeetingAttendeeType attendeeType, out AttendeeInfo attendee) { AttendeeInfo newAttendee = null; DialogResult result = AttendeeInfoDialog.ShowDialog(service, address, attendeeType, out newAttendee); if (result == DialogResult.OK && newAttendee != null) { attendee = newAttendee; } else { attendee = null; } return(result); }
private static DialogResult ShowDialog( ExchangeService service, EmailAddress address, MeetingAttendeeType?attendeeType, out AttendeeInfo attendee) { if (service == null) { throw new ArgumentNullException("service", ExceptionHelper.ExchangeServiceRequiredMessage); } AttendeeInfoDialog dialog = new AttendeeInfoDialog(); dialog.CurrentService = service; if (attendeeType.HasValue) { dialog.defaultAttendeeType = attendeeType.Value; } if (address != null) { dialog.defaultAddress = address; } DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK && dialog.currentAttendee != null) { attendee = dialog.currentAttendee; } else { attendee = null; } return(result); }
private void OkButton_Click(object sender, EventArgs e) { AttendeeInfo attendee = new AttendeeInfo(); if (String.IsNullOrEmpty(this.SmtpAddressText.Text)) { ErrorDialog.ShowWarning("An SMTP address is required in order to create an AttendeeInfo object."); return; } else { attendee.SmtpAddress = this.SmtpAddressText.Text; } if (this.attendeeTypeCombo.SelectedItem.HasValue) { attendee.AttendeeType = this.attendeeTypeCombo.SelectedItem.Value; } attendee.ExcludeConflicts = this.ExcludeConflictsCheck.Checked; this.currentAttendee = attendee; }
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)); }
/// <summary> /// Obtem a disponibilidade de um usuário smtp /// </summary> /// <param name="smtp"></param> /// <returns></returns> public Status obterDisponibilidadeExchange(string smtp, string zoneId = "E. South America Standard Time") { // SE O SMTP NÃO ENVIAR O ENDEREÇO DO HOST "@XPTO.COM.BR", PREENCHE AUTOMATICAMENTE COM O DOMINIO DA CONTA CONFIGURADA if (!smtp.Contains("@")) { var config = new ConfiguracaoBS().obterConfiguracao(); if (config != null) { string host = config.EmailAddress.Split('@')[1]; smtp = smtp + '@' + host; } } // Instancia o objeto de retorno de status Status retorno = new Status(); try { // Atribui a janela de tempo da Pesquisa // Precisamos de salas de reunião que já tenham iniciado seu cronômetro em 15 minutos // O prazo de 6 horas é necessário para cumprir especificação técnica do método. DateTime startTime = DateTime.Now.ToUniversalTime(); var diferencaParaOutroDia = 24 - DateTime.Now.ToUniversalTime().Hour; var janelaDeTempo = new TimeWindow(startTime, startTime.AddHours(diferencaParaOutroDia)); var janelaDeSugestao = new TimeWindow(startTime, startTime.AddHours(diferencaParaOutroDia)); // Atribui os parametros de busca var options = new AvailabilityOptions { MeetingDuration = 30 , RequestedFreeBusyView = FreeBusyViewType.Detailed , MergedFreeBusyInterval = 5 , MaximumSuggestionsPerDay = 1 , GoodSuggestionThreshold = 25 , CurrentMeetingTime = startTime //DateTime.Now , DetailedSuggestionsWindow = janelaDeSugestao , MinimumSuggestionQuality = SuggestionQuality.Poor }; // Para a consulta, é obrigatorio enviar uma lista de participantes da reuniao // Como a única informação que precisamos é a da Sala, enviamos apenas um elemento List <AttendeeInfo> listaUnicoElemento = new List <AttendeeInfo>(); AttendeeInfo UnicoElemento = new AttendeeInfo(); // instancia o elemento unico para a lista obrigatória UnicoElemento.SmtpAddress = smtp; // preenche com o smtp da checagem listaUnicoElemento.Add(UnicoElemento); // INICIO - Efetua a busca no exchange com os parâmetros selecionados GetUserAvailabilityResults resultadoDisponibilidade = this.service.GetUserAvailability(listaUnicoElemento, janelaDeTempo, AvailabilityData.FreeBusyAndSuggestions, options); // FIM - busca Exchange // PRIMEIRA TENTATIVA DE OBTENCAO DA DISPONIBILIDADE - ATRAVÉS DO RESULTADO DA DISPONIBILIDADE foreach (AttendeeAvailability avail in resultadoDisponibilidade.AttendeesAvailability) { string erro = string.Empty; if (avail.Result == ServiceResult.Error) { erro = (avail.Result != null ? "RESULT = " + avail.Result.ToString() + " | " : "") + (avail.ErrorCode != null ? "ErrorCode = " + avail.ErrorCode.ToString() + " | " : "") + (avail.ErrorDetails != null ? "ErrorDetais = " + avail.ErrorDetails.ToString() + " | " : "") + (avail.ErrorMessage != null ? "ErrorMessage = " + avail.ErrorMessage.ToString() + " | " : "") + (avail.ErrorProperties.Count() > 0 ? "ErrorProperties = " + avail.ErrorProperties.ToString() : ""); } var calendarios = avail.CalendarEvents.Where(x => x.StartTime <DateTime.Now.ToUniversalTime() && x.EndTime> DateTime.Now.ToUniversalTime()).ToList(); if (calendarios.Count() > 0) { foreach (CalendarEvent calItem in calendarios) { if (calItem.FreeBusyStatus == LegacyFreeBusyStatus.Busy || calItem.FreeBusyStatus == LegacyFreeBusyStatus.OOF || calItem.FreeBusyStatus == LegacyFreeBusyStatus.Tentative || calItem.FreeBusyStatus == LegacyFreeBusyStatus.WorkingElsewhere) { // Se a data de fim da reuniao já tiver passado, então a sala está livre if (calItem.EndTime < DateTime.Now.ToUniversalTime()) { retorno.StatusDisponibilidade = StatusDisponibilidade.Livre; retorno.Mensagem = ""; } // Se já passou 30 minutos de iniciada uma reunião e não terminou else if ((DateTime.Now.ToUniversalTime() >= calItem.StartTime.ToUniversalTime().AddMinutes(30)) && (DateTime.Now.ToUniversalTime() <= calItem.EndTime.ToUniversalTime())) { retorno.StatusDisponibilidade = StatusDisponibilidade.EmReuniao30; TimeZoneInfo zonaFuso = TimeZoneInfo.FindSystemTimeZoneById(zoneId); var dataFimZonaFuso = TimeZoneInfo.ConvertTimeFromUtc(calItem.EndTime, zonaFuso); retorno.Mensagem = "Reunião já inicada há mais de 30 minutos com término às " + dataFimZonaFuso.ToString(); // calItem.EndTime.ToLocalTime().ToString(); // inclui na lista de eventos de calendários do retorno retorno.ListaEventos.Add(converterCalendarEventParaCalendarioEvento(calItem)); } // Se já passou 15 minutos de iniciada uma reunião e não terminou else if ((DateTime.Now.ToUniversalTime() >= calItem.StartTime.ToUniversalTime().AddMinutes(15)) && (DateTime.Now.ToUniversalTime() <= calItem.EndTime.ToUniversalTime())) { TimeZoneInfo zonaFuso = TimeZoneInfo.FindSystemTimeZoneById(zoneId); var dataFimZonaFuso = TimeZoneInfo.ConvertTimeFromUtc(calItem.EndTime, zonaFuso); retorno.StatusDisponibilidade = StatusDisponibilidade.EmReuniao; retorno.Mensagem = "Reunião já inicada há mais de 15 minutos com término às " + dataFimZonaFuso.ToString(); // calItem.EndTime.ToLocalTime().ToString(); // inclui na lista de eventos de calendários do retorno retorno.ListaEventos.Add(converterCalendarEventParaCalendarioEvento(calItem)); } else { TimeZoneInfo zonaFuso = TimeZoneInfo.FindSystemTimeZoneById(zoneId); var dataInicioZonaFuso = TimeZoneInfo.ConvertTimeFromUtc(calItem.StartTime, zonaFuso); var dataFimZonaFuso = TimeZoneInfo.ConvertTimeFromUtc(calItem.EndTime, zonaFuso); retorno.StatusDisponibilidade = StatusDisponibilidade.Ocupado; retorno.Mensagem = " Ocupado de " + dataInicioZonaFuso.ToString() + " até " + dataFimZonaFuso.ToString(); //retorno.Mensagem = " Ocupado de " + calItem.StartTime.ToLocalTime().ToString() + " até " + calItem.EndTime.ToLocalTime().ToString(); // inclui na lista de eventos de calendários do retorno retorno.ListaEventos.Add(converterCalendarEventParaCalendarioEvento(calItem)); } break; } else { TimeZoneInfo zonaFuso = TimeZoneInfo.FindSystemTimeZoneById(zoneId); var dataInicioZonaFuso = TimeZoneInfo.ConvertTimeFromUtc(calItem.StartTime, zonaFuso); retorno.StatusDisponibilidade = StatusDisponibilidade.Livre; retorno.Mensagem = "Livre a partir de " + dataInicioZonaFuso.ToString(); //calItem.StartTime.ToString(); } } } else { // O Status ainda é desconhecido // Se for usar a opção de lógica por sugestão, manter desconhecido retorno.StatusDisponibilidade = StatusDisponibilidade.Livre; // StatusDisponibilidade.Desconhecido; // Mensagem ao usuário retorno.Mensagem = "Não encontramos eventos de calendário para esta sala."; if (!erro.Equals(string.Empty)) { retorno.StatusDisponibilidade = StatusDisponibilidade.Desconhecido; // Mensagem ao usuário retorno.Mensagem = "[ERROR] " + erro; } } } // SUGESTÃO DE DATA MAIS PRÓXIMA DA DATA ATUAL if (resultadoDisponibilidade.Suggestions.Count > 0) { // PEGAR A SUGESTAO MAIS CEDO var sugestaoMaisCedo = resultadoDisponibilidade.Suggestions.OrderBy(x => x.Date).FirstOrDefault(); // SE POR VENTURA HOUVE SUGESTOES DE HORA, ELA TEM PRIORIDADE NO RETORNO if (sugestaoMaisCedo.TimeSuggestions.Count > 0) { var horaDoEncontro = sugestaoMaisCedo.TimeSuggestions.OrderBy(x => x.MeetingTime).FirstOrDefault().MeetingTime; TimeZoneInfo zonaFuso = TimeZoneInfo.FindSystemTimeZoneById(zoneId); horaDoEncontro = TimeZoneInfo.ConvertTimeFromUtc(horaDoEncontro, zonaFuso); retorno.SugestaoProximaReuniao = horaDoEncontro.ToLocalTime(); } else { TimeZoneInfo zonaFuso = TimeZoneInfo.FindSystemTimeZoneById(zoneId); var sugestao = TimeZoneInfo.ConvertTimeFromUtc(sugestaoMaisCedo.Date, zonaFuso); retorno.SugestaoProximaReuniao = sugestaoMaisCedo.Date; } } } catch (Exception ex) { string msgDisponibilidade = "[EXCEPTION] " + (ex.Message != null ? "MESSAGE = " + ex.Message.ToString() + " | " : "") + (ex.InnerException != null ? "INNER = " + ex.InnerException.ToString() + " | " : "") + (ex.StackTrace != null ? "STACKTRACE = " + ex.StackTrace.ToString() + " | " : "") + (ex.Source != null ? "SOURCE = " + ex.Source.ToString() : ""); retorno.Mensagem = msgDisponibilidade; retorno.StatusDisponibilidade = StatusDisponibilidade.Desconhecido; } return(retorno); }
internal AttendeeDataContainer(AttendeeInfo info) { this.Info = info; this.Availability = null; }