/**
* Appointment:创建单一约会(全天和非全天)
*/
private void createSingleAppointment(String userName, String password, String domain, String subject, String location, String startsTime, String endsTime, String body, boolean isAllDay) {
ExchangeService service = new EWS().connectEWS(userName, password, domain);
try {
Appointment appointment = new Appointment(service);
// 中国标准时间
TimeZoneDefinition tz = getTimeZoneDefinition(service, TIME_ZONE_CTT);
appointment.setSubject(subject); // 约会标题
appointment.setLocation(location); // 约会地点
appointment.setBody(MessageBody.getMessageBodyFromText(body)); // 约会正文
HashMap times = getStartsAndEndsTime(startsTime, endsTime);
appointment.setStart((Date) times.get("startsTime"));
appointment.setStartTimeZone(tz);
appointment.setEnd((Date) times.get("endsTime"));
appointment.setEndTimeZone(tz);
appointment.setIsAllDayEvent(isAllDay); // 是否全天事件
appointment.save(WellKnownFolderName.Calendar, SendInvitationsMode.SendToNone);
} catch (Exception e) {
System.out.println("Error: Fail to create single appointment!");
e.printStackTrace();
}
}
private TimeZoneDefinition getTimeZoneDefinition(ExchangeService service, String timeZoneID) {
TimeZoneDefinition timeZoneDefinition = null;
try {
for (TimeZoneDefinition tzd : service.getServerTimeZones()) {
if(tzd.getId().equalsIgnoreCase(timeZoneID)) {
timeZoneDefinition = tzd;
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return timeZoneDefinition;
}
网友评论