Google 캘린더를 WPF용 C1Scheduler와 함께 사용하기
페이지 정보
작성자 GrapeCity 작성일 2021-04-12 14:09 조회 4,691회 댓글 0건본문
첨부파일
관련링크
는 즉시 사용할 수 있는 일정 솔루션으로서, 반복되는 약속, 알림, 레이블, 데이터 바인딩, 그룹화 등 매우 풍부한 기능과 함께 제공됩니다. 이 솔루션을 통해 사용자는 아무런 사전 지식이 없어도 힘들이지 않고 새로운 일정 응용 프로그램을 만들 수 있습니다.
이 문서에서는 WPF용 C1Scheduler를 사용하는 방법과 약속을 가장 인기 있는 웹 기반 캘린더 에서 데스크톱 응용 프로그램으로 동기화하는 방법에 대해 알아보겠습니다.
먼저 Google 캘린더 API를 통해 Google 캘린더에서 이벤트를 가져오는 데 필요한 NuGet 패키지를 추가하겠습니다.
Google 캘린더 라이브러리는 특정 기간 동안 이벤트와 상호 작용할 수 있도록 를 제공합니다. CalendarService를 래핑하고 Google 캘린더 이벤트를 C1Scheduler 으로 제공할 어댑터를 만들어 보겠습니다. 다음은 이 어댑터가 구현할 인터페이스를 나타낸 것입니다.
public interface IAppointmentAdapter { event EventHandler<SyncEventArgs> SyncStarting; event EventHandler SyncFinished; event EventHandler SyncFailed; AppointmentsResponse GetAppointments(RequestParameters requestParameters); void AddAppointment(Appointment appointment); void DeleteAppointment(Appointment appointment); void UpdateAppointment(Appointment appointment); Task Sync(); }
아래 다이어그램에서는 어댑터가 처리하는 완전한 프로세스를 보여줍니다.
이어서 이러한 단계들을 하나씩 자세히 살펴보겠습니다.
Google 캘린더에서 이벤트 가져오기
Google 캘린더 API와의 모든 통신은 다음과 같이 IAppointmentAdapter를 구현하는 어댑터를 통해 이루어집니다.
public class GoogleEventAppointmentAdapter : IAppointmentAdapter { }
이벤트를 가져오라는 요청은 다음과 같이 구성됩니다.
public AppointmentsResponse GetAppointments(RequestParameters requestParameters) { EventsResource.ListRequest request = _service.Events.List(_calendarId); request.TimeMin = requestParameters.MinDate; request.TimeMax = requestParameters.MaxDate; request.SingleEvents = requestParameters.SingleEvents; request.ShowDeleted = requestParameters.ShowDeleted; request.MaxResults = requestParameters.MaxResults; request.PageToken = requestParameters.PageToken; if (request.SingleEvents.Value) { request.OrderBy = requestParameters.OrderBy == OrderBy.StartTime ? EventsResource.ListRequest.OrderByEnum.StartTime : EventsResource.ListRequest.OrderByEnum.Updated; } var response = request.Execute(); _fetchedEvents = response.Items; // Map fetched Events to Appointments }
캘린더에서 이벤트를 가져온 후에는 스케줄러의 약속에 매핑해야 합니다. 다음 섹션에서는 이러한 매핑에 대해 자세히 설명합니다.
이벤트를 약속에 매핑하기
Google API는 당사의 약속을 표시하는 클래스를 제공합니다.
데스크톱 응용 프로그램에서 이 이벤트를 가져오기 위해 이벤트 개체는 아래와 같이 C1Scheduler의 약속 개체에 매핑됩니다.
다음과 같이 C# 식을 통해 구현됩니다.
public static readonly Expression<Func<Event, Appointment>> AsAppointment = source => new Appointment() { Subject = source.Summary, Body = source.Description, Location = source.Location, Label = new Label() { Color = GoogleCalendarColors.FirstOrDefault(x => x.Id == source.ColorId).Color }, Start = source.Start.DateTime == null ? DateTime.Parse(source.Start.Date) : source.Start.DateTime.Value, End = source.End.DateTime == null ? DateTime.Parse(source.End.Date) : source.End.DateTime.Value }; var appointments = _fetchedEvents.AsQueryable().Select(Mapper.AsAppointment).ToList();
C1Scheduler의 AppointmentStorage 채우기
약속은 Google 캘린더 이벤트에 상응하는 것으로, C1Scheduler의 에서 유지 관리됩니다. 이벤트를 약속에 매핑한 후에는 다음과 같이 스토리지에 채울 수 있습니다.
_appointmentsResponse = _syncManager.Adapter.GetAppointments(requestParameters); _scheduler.BeginUpdate(); foreach (var appointment in _appointmentsResponse.Appointments) { _scheduler.DataStorage.AppointmentStorage.Appointments.Add(appointment); appointment.Label = _scheduler.DataStorage.LabelStorage.Labels.FirstOrDefault(x => x.Color == appointment.Label.Color); } _scheduler.EndUpdate();
약속 추가, 업데이트 및 삭제
약속과의 사용자 상호 작용을 위해 C1Scheduler는 , , 와 같은 다양한 이벤트를 발생시킵니다. 이러한 이벤트는 어댑터가 변경 사항을 Google 캘린더로 다시 동기화하기에 가장 적합한 장소입니다.
private void SchedulerAppointmentAdded(object sender, AppointmentActionEventArgs e) { _syncManager.Adapter.AddAppointment(e.Appointment); } private void SchedulerBeforeAppointmentSave(object sender, AppointmentActionEventArgs e) { _syncManager.Adapter.UpdateAppointment(e.Appointment); } private void SchedulerAppointmentDeleted(object sender, AppointmentActionEventArgs e) { _syncManager.Adapter.DeleteAppointment(e.Appointment); }
CalendarService를 통해 추가, 삭제 및 업데이트할 구현은 다음과 같습니다.
// Add a new appointment to google calendar. _service.Events.Insert(Mapper.ConvertToEvent(appointment), _calendarId).Execute(); // Delete an existing appointment from google calendar. _service.Events.Delete(_calendarId, GetMappedEventId(appointment)).Execute(); // Update an edited appointment to google calendar. var editedEvent = Mapper.ConvertToEvent(appointment); _service.Events.Update(editedEvent, _calendarId, GetMappedEventId(appointment)).Execute();
이렇게 하면 어댑터가 완료됩니다. 이 어댑터를 사용해 Google 캘린더의 이벤트를 C1Scheduler 인스턴스에 추가하십시오. 다음은 이 어댑터를 사용하는 샘플 응용 프로그램의 이미지입니다.
전체 샘플은 첨부파일을 통해 다운받으실 수 있습니다.
결론
C1Scheduler는 iCal과 같은 인기 있는 파일 형식을 대상으로 한 가져오기 및 내보내기를 기본적으로 지원합니다.
웹 기반 캘린더와의 연결을 기본적으로 지원하지는 않지만 인기 있는 웹 기반 캘린더 API는 단순하고 확장 가능한 모델을 제공합니다. 여기서 보시다시피 이 단순하고 확장 가능한 모델을 이용해 웹 기반 캘린더에서 이벤트/약속/회의를 가져오고 내보낼 수 있습니다.
이 포스팅에서 만든 어댑터는 클래스 라이브러리로 추가되었고 데스크톱 스케줄러를 Google 캘린더와 연결하는 데 바로 사용할 수 있습니다. 또한 이와 유사한 방식으로 Outlook과 같은 다른 웹 기반 캘린더에 사용할 자체 어댑터를 만들 수 있습니다.
댓글목록
등록된 댓글이 없습니다.