public static void CreateAppointment(ExchangeService service, string fechaInicio, string fechaFin, string lugar, string nombre, string dias) { Appointment app = new Appointment(service); app.Subject = nombre; app.Location = lugar; DateTime dateInicio = Convert.ToDateTime(fechaInicio); DateTime dateFin = Convert.ToDateTime(fechaFin); TimeSpan timeSpan = dateFin.Subtract(dateInicio); string timeFor = timeSpan.ToString(@"hh\:mm\:ss"); var time = TimeSpan.Parse(timeFor); app.Start = dateInicio; app.End = dateInicio.Add(time); //----- if (dias != "") { DayOfTheWeek[] days = stringToDays(dias); app.Recurrence = new Recurrence.WeeklyPattern(app.Start.Date, 1, days); app.Recurrence.StartDate = app.Start.Date; app.Recurrence.EndDate = dateFin; } app.IsReminderSet = true; app.ReminderMinutesBeforeStart = 15; app.Save(SendInvitationsMode.SendToAllAndSaveCopy); }
static void Main(string[] args) { var url = "http://*****:*****@word1"; var domain = (string)null; //"CONTOSO"; ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true; // ignore certificate errors for HTTPS var exchange = new ExchangeService(ExchangeVersion.Exchange2007_SP1) { Url = new Uri(url), Credentials = new WebCredentials(username, password, domain), }; // req#1: this succeeds Test("GetUserAvailability (FreeBusy only)", () => exchange.GetUserAvailability(new[]{new AttendeeInfo{SmtpAddress = username}}, new TimeWindow(DateTime.Today, DateTime.Today.AddDays(1)), AvailabilityData.FreeBusy)); // req#2: this fails with an empty response Test("GetUserAvailability (FreeBusyAndSuggestions)", () => exchange.GetUserAvailability(new[]{new AttendeeInfo{SmtpAddress = username}}, new TimeWindow(DateTime.Today, DateTime.Today.AddDays(1)), AvailabilityData.FreeBusyAndSuggestions)); // req#3: this fails because the ResponseMessages xml element is empty Test("CreateItem", () => { var appointment = new Appointment(exchange); appointment.Start = DateTime.Today.AddHours(10); appointment.End = DateTime.Today.AddHours(12); appointment.Subject = "Test appointment"; appointment.Save(); }); }
public ReserveRoomResponse Execute(ReserveRoomRequest request) { var response = new ReserveRoomResponse(); try { // Get mailbox info var requestMailboxInfo = new GetMailboxInfo.GetMailboxInfoRequest( email: request.MailboxEmail); var responseMailboxInfo = new GetMailboxInfo().Execute(requestMailboxInfo); if (!responseMailboxInfo.Success) { response.ErrorMessage = responseMailboxInfo.ErrorMessage; return response; } // Connect to Exchange var service = ExchangeServiceConnector.GetService(request.MailboxEmail); var mbx = new Mailbox(request.MailboxEmail); FolderId fid = new FolderId(WellKnownFolderName.Calendar, mbx); //CalendarFolder calendar = CalendarFolder.Bind(service, fid, new PropertySet(FolderSchema.ManagedFolderInformation, FolderSchema.ParentFolderId, FolderSchema.ExtendedProperties)); // Create appointment var appointment = new Appointment(service); appointment.Subject = "Impromptu Meeting"; appointment.Body = "Booked via Conference Room app."; appointment.Start = DateTime.Now; appointment.End = DateTime.Now.AddMinutes(request.BookMinutes); appointment.Location = responseMailboxInfo.DisplayName; appointment.Save(fid, SendInvitationsMode.SendToNone); // Verify saved Item item = Item.Bind(service, appointment.Id, new PropertySet(ItemSchema.Subject)); if (item == null) { response.ErrorMessage = "Error saving appointment to calendar."; return response; } else { response.AppointmentId = appointment.Id; response.Success = true; } } catch (Exception e) { response.ErrorMessage = e.ToString(); return response; } return response; }
public void CreateAndSaveMeeting(Meeting m) { try { Appointment a = new Appointment(service); a.Subject = m.Title; a.Body = m.Description; a.Start = DataHelper.StringToDate(m.Start, DataHelper.DateStringLong); a.End = DataHelper.StringToDate(m.End, DataHelper.DateStringLong); a.Location = m.Location; foreach (string email in m.Invited) { a.RequiredAttendees.Add(email); } a.Save(SendInvitationsMode.SendToAllAndSaveCopy); } catch (Exception e) { throw new ServiceException("Cannot create meeting", e); } }
/** * Function: CreateNewAppointment * Creates a new appointment. * Returns the AppID (appointment id) for future changes **/ static string CreateNewAppointment(ExchangeService service, string subject, string body, DateTime date, int duration, string status) { Console.WriteLine("Creating a New Item: " + subject); // Create an appointmet and identify the Exchange service. Appointment appointment = new Appointment(service); // Set details appointment.Subject = subject; appointment.Body = body; appointment.Start = date; appointment.End = appointment.Start.AddHours(duration); StringList categories = new Microsoft.Exchange.WebServices.Data.StringList(); categories.Add(status); appointment.Categories = categories; appointment.IsReminderSet = false; // Save and Send appointment.Save(SendInvitationsMode.SendToNone); // Get ItemId for future updates return ""+appointment.Id+""; }
public WhartonEWSResponse CreateCalendarItem( String apiKey, String emlUserAddress, String lstReqAttendeeEmail, String lstOptAttendeeEmail, String dtCalItemStart, String dtCalItemEnd, String strCalItemSubject, String strCalItemLocation, String strCalItemBody, Boolean blnAllDayFlag, String strCalItemCategories ) { WhartonEWSResponse rsp = new WhartonEWSResponse(); Boolean success = true; String miscData = ""; try { // Initialize EWS service. ExchangeService service = getService(emlUserAddress, apiKey); //parse input date/time values into native DateTime types DateTime rangeStart = DateTime.Parse(dtCalItemStart); DateTime rangeEnd = DateTime.Parse(dtCalItemEnd); //create the appointment object Appointment newAppointment = new Appointment(service); //fill in the details newAppointment.Subject = strCalItemSubject; newAppointment.Body = strCalItemBody; newAppointment.Body.BodyType = BodyType.Text; newAppointment.Start = rangeStart; newAppointment.End = rangeEnd; newAppointment.Location = strCalItemLocation; newAppointment.IsAllDayEvent = blnAllDayFlag; if (lstReqAttendeeEmail.Length > 0) { lstReqAttendeeEmail.Replace(';', ','); String[] reqAttendees = lstReqAttendeeEmail.Split(','); foreach (String a in reqAttendees) { newAppointment.RequiredAttendees.Add(a.Trim()); } } if (lstOptAttendeeEmail.Length > 0) { lstOptAttendeeEmail.Replace(';', ','); String[] optAttendees = lstOptAttendeeEmail.Split(','); foreach (String a in optAttendees) { newAppointment.OptionalAttendees.Add(a.Trim()); } } if (strCalItemCategories.Length > 0) { String[] cats = strCalItemCategories.Split(','); foreach (String cat in cats) { newAppointment.Categories.Add(cat); } } //save it! newAppointment.Save(SendInvitationsMode.SendToAllAndSaveCopy); rsp.SimpleData = true; } catch (Exception e) { if (!(int.TryParse(e.Message, out rsp.StatusCode))) { //if the parsing fails, then set a default value of 500 rsp.StatusCode = 500; } rsp.Msg = e.Message; success = false; miscData = "{ \"ErrMsg\":\"" + rsp.Msg + "\" }"; rsp.StackTrace = e.StackTrace; if (e.InnerException != null) { rsp.InnerException = e.InnerException.ToString(); } } //audit addAuditLog(apiKey, emlUserAddress, "CreateCalendarItem", success, miscData); return rsp; }
public Task<bool> ReserveRoom(RoomInfo room, TimeSpan duration) { Appointment appointment = new Appointment(_service); // Set the properties on the appointment object to create the appointment. appointment.Subject = "Room reservation"; appointment.Body = $"Automatically created by FindMeRoomOSS on {DateTime.Now}"; appointment.Start = DateTime.Now; appointment.End = appointment.Start + duration; appointment.Location = room.RoomId; appointment.RequiredAttendees.Add(room.RoomId); // Save the appointment to your calendar. appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy); PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties); // Verify that the appointment was created by using the appointment's item ID. appointment = Item.Bind(_service, appointment.Id, psPropSet) as Appointment; if (appointment == null) { return Task.FromResult(false); } return Task.Run(async () => { var finishTime = DateTime.Now + CreationTimeout; Attendee roomAttendee; // wait till the room accepts do { Debug.WriteLine("Waiting for response..."); await Task.Delay(1000); // refresh appointment data appointment = Item.Bind(_service, appointment.Id, psPropSet) as Appointment; if (appointment == null) { Debug.WriteLine("Appointment has been deleted"); return false; } roomAttendee = appointment.RequiredAttendees.FirstOrDefault(att => att.Address == room.RoomId); if (roomAttendee == null) { Debug.WriteLine("Someone is messing with our appointment"); return false; } } while (DateTime.Now < finishTime && ( !roomAttendee.ResponseType.HasValue || roomAttendee.ResponseType == MeetingResponseType.Unknown || roomAttendee.ResponseType == MeetingResponseType.NoResponseReceived )); Debug.WriteLine($"Response is {roomAttendee.ResponseType}..."); return roomAttendee.ResponseType.HasValue && roomAttendee.ResponseType.Value == MeetingResponseType.Accept; }); }
public IHttpActionResult Create(CreateAppointmentRequest request) { var service = ExchangeServer.Open(); var appointment = new Appointment(service); // Set the properties on the appointment object to create the appointment. appointment.Subject = request.Subject; appointment.Body = request.Body; appointment.Start = DateTime.Parse(request.Start); //appointment.StartTimeZone = TimeZoneInfo.Local; appointment.End = DateTime.Parse(request.End); //appointment.EndTimeZone = TimeZoneInfo.Local; appointment.Location = request.Location; //appointment.ReminderDueBy = DateTime.Now; foreach(var email in request.Recipients) { appointment.RequiredAttendees.Add(email); } // Save the appointment to your calendar. appointment.Save(SendInvitationsMode.SendOnlyToAll); // Verify that the appointment was created by using the appointment's item ID. Item item = Item.Bind(service, appointment.Id, new PropertySet(ItemSchema.Subject)); var response = new CreateAppointmentResponse { Message = "Appointment created: " + item.Subject, AppointId = appointment.Id.ToString() }; return Ok(response); }
private Appointment CreateExchangeCalendarEvent(string subject, string body, DateTime start, DateTime end) { var userCredential = GetExchangeUserCredential(); var exchangeService = _microsoftExchangeServiceProvider.GetMicrosoftExchangeService(userCredential); var isDefaultCalendarExist = false; var defaultCalendar = DependencyResolver.Resolve<IExchangeCalendarEventSyncDataService>().GetDefaultCalendarFolder(userCredential, out isDefaultCalendarExist); Appointment appointment = new Appointment(exchangeService); appointment.Subject = subject; appointment.Body = new MessageBody(BodyType.Text, body); appointment.Start = start; appointment.End = end; appointment.Save(defaultCalendar.Id); appointment = GetExchangeCalendarEvent(appointment.Id.UniqueId); return appointment; }
public string CreateNewAppointmentE(string subject_, string StartDate_,string finisDate_,string body_,string location_, List<string> attendees_) { string errorAppointment = ""; try { ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010); service.UseDefaultCredentials = true; service.Credentials = new WebCredentials("XXXXXXXXX", "XXXXX", "XXXX");//@uanl.mx service.AutodiscoverUrl("*****@*****.**"); Appointment appointment = new Appointment(service); appointment.Subject = subject_; appointment.Body = body_; appointment.Start = Convert.ToDateTime(StartDate_); appointment.End = Convert.ToDateTime(finisDate_); appointment.Location = location_; foreach (string attendee in attendees_) appointment.RequiredAttendees.Add(attendee); appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy); return errorAppointment; } catch { return errorAppointment = "an error trying to send the appoitment happend" ; } }
public void StartNewMeeting(string roomAddress, string securityKey, string title, int minutes) { if (_securityRepository.GetSecurityRights(roomAddress, securityKey) != SecurityStatus.Granted) { throw new UnauthorizedAccessException(); } var status = GetStatus(roomAddress); if (status.Status != RoomStatus.Free) { throw new Exception("Room is not free"); } using (_concurrencyLimiter.StartOperation()) { var calId = new FolderId(WellKnownFolderName.Calendar, new Mailbox(roomAddress)); var now = _dateTimeService.Now.TruncateToTheMinute(); minutes = Math.Max(0, Math.Min(minutes, Math.Min(120, status.NextMeeting.ChainIfNotNull(m => (int?)m.Start.Subtract(now).TotalMinutes) ?? 120))); var appt = new Appointment(_exchangeService); appt.Start = now; appt.End = now.AddMinutes(minutes); appt.Subject = title; appt.Body = "Scheduled via conference room management system"; appt.Save(calId, SendInvitationsMode.SendToNone); log.DebugFormat("Created {0} for {1}", appt.Id.UniqueId, roomAddress); _meetingRepository.StartMeeting(appt.Id.UniqueId); BroadcastUpdate(roomAddress); } }
public static void CreateReservation(string roomAddress, int duration) { Appointment newApt = new Appointment(_exchangeService); newApt.Subject = "Walk up"; newApt.Start = DateTime.Now; newApt.StartTimeZone = TimeZoneInfo.Local; newApt.End = DateTime.Now.AddMinutes(duration); newApt.EndTimeZone = TimeZoneInfo.Local; newApt.Resources.Add(roomAddress); newApt.Save(SendInvitationsMode.SendOnlyToAll); //set 'pending' item so that quick GetRoomAvailability calls //won't miss this appointment just because the meeting room //hasn't accepted yet. Since this only applies to Walk Up //reservations (and you can only have one of those at a time) //we can store this in a single cached value _memoryCache.Add(GetRoomPendingEventKey(roomAddress), new CalendarEvent() { Subject = newApt.Subject, StartTime = newApt.Start, EndTime = newApt.End, Status = "Busy" }, DateTime.Now.AddMinutes(2)); _memoryCache.Remove(GetRoomEventsKey(roomAddress)); }