private void AssertTaskAndGoogleCalendarEventAreEqual(CooperTask cooperTask, Event calendarEvent) { MicrosoftAssert.AreEqual(cooperTask.Subject, calendarEvent.Summary); MicrosoftAssert.AreEqual(cooperTask.Body, calendarEvent.Description); MicrosoftAssert.AreEqual(cooperTask.DueTime.Value.Date, Rfc3339DateTime.Parse(calendarEvent.End.DateTime).ToLocalTime().Date); MicrosoftAssert.AreEqual(FormatTime(cooperTask.LastUpdateTime), FormatTime(Rfc3339DateTime.Parse(calendarEvent.Updated).ToLocalTime())); }
/// <summary> /// 创建Google Calendar Event /// </summary> private void CreateGoogleCalendarEvent(GoogleCalendarEventSyncData calendarEventData, CalendarService googleCalendarService, Calendar defaultCalendar) { global::Google.Apis.Calendar.v3.Data.Event calendarEvent = null; bool success = false; try { //创建Google Calendar Event calendarEvent = googleCalendarService.Events.Insert(calendarEventData.GoogleCalendarEvent, defaultCalendar.Id).Fetch(); _logger.InfoFormat("新增Google日历事件#{0}|{1}|{2}", calendarEvent.Id, calendarEvent.Summary, _account.ID); success = true; } catch (Exception ex) { _logger.Error("CreateGoogleCalendarEvent has exception.", ex); } if (success) { //更新任务最后更新时间,确保与Google Calendar Event的最后更新时间一致 UpdateTaskLastUpdateTime(long.Parse(calendarEventData.SyncId), Rfc3339DateTime.Parse(calendarEvent.Updated).ToLocalTime()); //创建同步信息 if (defaultCalendar.Summary == GoogleSyncSettings.DefaultCalendarName) { SyncInfo syncInfo = new SyncInfo(); syncInfo.AccountId = _account.ID; syncInfo.LocalDataId = calendarEventData.SyncId; syncInfo.SyncDataId = calendarEvent.Id; syncInfo.SyncDataType = calendarEventData.SyncType; InsertSyncInfo(syncInfo); } } }
private Event CreateGoogleCalendarEvent(string subject, string body, DateTime startTime, DateTime endTime) { var calendarEvent = new Event(); calendarEvent.Summary = subject; calendarEvent.Description = body; var startTimeUtc = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, startTime.Minute, startTime.Second, DateTimeKind.Utc); var endTimeUtc = new DateTime(endTime.Year, endTime.Month, endTime.Day, endTime.Hour, endTime.Minute, endTime.Second, DateTimeKind.Utc); string start = Rfc3339DateTime.ToString(startTimeUtc); string end = Rfc3339DateTime.ToString(endTimeUtc); calendarEvent.Start = new EventDateTime() { DateTime = start }; calendarEvent.End = new EventDateTime() { DateTime = end }; var token = GetGoogleUserToken(); var googleCalendarService = _externalServiceProvider.GetGoogleCalendarService(token); bool isDefaultCalendarExist = false; var defaultCalendar = DependencyResolver.Resolve <IGoogleCalendarEventSyncDataService>().GetDefaultCalendar(token, out isDefaultCalendarExist); calendarEvent = googleCalendarService.Events.Insert(calendarEvent, defaultCalendar.Id).Fetch(); calendarEvent = GetGoogleCalendarEvent(calendarEvent.Id); return(calendarEvent); }
private GoogleTask UpdateGoogleTask(string id, string subject, string body, DateTime dueTime, bool isCompleted) { var token = GetGoogleUserToken(); var googleTaskService = _externalServiceProvider.GetGoogleTaskService(token); var isDefaultTaskListExist = false; var taskList = DependencyResolver.Resolve <IGoogleTaskSyncDataService>().GetDefaultTaskList(token, out isDefaultTaskListExist); var task = GetGoogleTask(id); task.Title = subject; task.Notes = body; var dueTimeUtcFormat = new DateTime(dueTime.Year, dueTime.Month, dueTime.Day, 0, 0, 0, DateTimeKind.Utc); task.Due = Rfc3339DateTime.ToString(dueTimeUtcFormat); if (isCompleted) { task.Status = "completed"; } else { task.Status = "needsAction"; } googleTaskService.Tasks.Update(task, taskList.Id, task.Id).Fetch(); task = GetGoogleTask(id); return(task); }
/// <summary> /// 创建Google Task /// </summary> private void CreateGoogleTask(GoogleTaskSyncData taskData, TasksService googleTaskService, TaskList defaultTaskList) { global::Google.Apis.Tasks.v1.Data.Task googleTask = null; bool success = false; try { //创建Google Task googleTask = googleTaskService.Tasks.Insert(taskData.GoogleTask, defaultTaskList.Id).Fetch(); _logger.InfoFormat("新增Google任务#{0}|{1}|{2}", googleTask.Id, googleTask.Title, _account.ID); success = true; } catch (Exception ex) { _logger.Error("CreateGoogleTask has exception.", ex); } if (success) { //更新任务最后更新时间,确保与Google Task的最后更新时间一致 UpdateTaskLastUpdateTime(long.Parse(taskData.SyncId), Rfc3339DateTime.Parse(googleTask.Updated).ToLocalTime()); //创建同步信息 if (defaultTaskList.Title == GoogleSyncSettings.DefaultTaskListName) { SyncInfo syncInfo = new SyncInfo(); syncInfo.AccountId = _account.ID; syncInfo.LocalDataId = taskData.SyncId; syncInfo.SyncDataId = googleTask.Id; syncInfo.SyncDataType = taskData.SyncType; InsertSyncInfo(syncInfo); } } }
public void Sync_Update_GoogleCalendarEvent_AccordingWith_Task_Test() { _logger.Info("--------------开始执行测试:Sync_Update_GoogleCalendarEvent_AccordingWith_Task_Test"); InitializeAccountAndConnection(_googleConnectionId); var googleCalendarEvent = CreateGoogleCalendarEvent("cooper calendar event", "description of event", DateTime.Now, DateTime.Now.AddHours(2)); MicrosoftAssert.IsNotNull(googleCalendarEvent); _syncProcessor.SyncTasksAndContacts( _googleConnectionId, new List <ISyncService <TaskSyncData, ISyncData, TaskSyncResult> > { DependencyResolver.Resolve <IGoogleCalendarEventSyncService>() }, null); var syncInfo = GetSyncInfoBySyncDataId(_account.ID, googleCalendarEvent.Id, SyncDataType.GoogleCalendarEvent); MicrosoftAssert.IsNotNull(syncInfo); var cooperTask = GetCooperTask(long.Parse(syncInfo.LocalDataId)); MicrosoftAssert.IsNotNull(cooperTask); AssertTaskAndGoogleCalendarEventAreEqual(cooperTask, googleCalendarEvent); //更新Task cooperTask = UpdateCooperTask(cooperTask.ID, cooperTask.Subject + "_updated", cooperTask.Body + "_updated", cooperTask.DueTime.Value.Date.AddDays(1), true); var lastUpdateTime = Rfc3339DateTime.Parse(googleCalendarEvent.Updated).ToLocalTime(); UpdateTaskLastUpdateTime(cooperTask, lastUpdateTime.AddSeconds(1)); //同步 _syncProcessor.SyncTasksAndContacts( _googleConnectionId, new List <ISyncService <TaskSyncData, ISyncData, TaskSyncResult> > { DependencyResolver.Resolve <IGoogleCalendarEventSyncService>() }, null); //重新获取 cooperTask = GetCooperTask(cooperTask.ID); googleCalendarEvent = GetGoogleCalendarEvent(syncInfo.SyncDataId); //对比结果 MicrosoftAssert.IsNotNull(googleCalendarEvent); MicrosoftAssert.AreEqual(cooperTask.Subject, googleCalendarEvent.Summary); MicrosoftAssert.AreEqual(cooperTask.Body, googleCalendarEvent.Description); MicrosoftAssert.AreEqual(FormatTime(cooperTask.LastUpdateTime), FormatTime(Rfc3339DateTime.Parse(googleCalendarEvent.Updated).ToLocalTime())); }
/// <summary> /// 更新Google Calendar Event /// </summary> private void UpdateGoogleCalendarEvent(GoogleCalendarEventSyncData calendarEventData, CalendarService googleCalendarService, Calendar defaultCalendar) { try { googleCalendarService.Events.Update(calendarEventData.GoogleCalendarEvent, defaultCalendar.Id, calendarEventData.Id).Fetch(); _logger.InfoFormat("更新Google日历事件#{0}|{1}|{2}", calendarEventData.Id, calendarEventData.Subject, _account.ID); var updatedGoogleCalendarEvent = googleCalendarService.Events.Get(defaultCalendar.Id, calendarEventData.Id).Fetch(); UpdateTaskLastUpdateTime(long.Parse(calendarEventData.SyncId), Rfc3339DateTime.Parse(updatedGoogleCalendarEvent.Updated).ToLocalTime()); } catch (Exception ex) { _logger.Error("UpdateGoogleCalendarEvent has exception.", ex); } }
/// <summary> /// 更新Google Task /// </summary> private void UpdateGoogleTask(GoogleTaskSyncData taskData, TasksService googleTaskService, TaskList defaultTaskList) { try { googleTaskService.Tasks.Update(taskData.GoogleTask, defaultTaskList.Id, taskData.Id).Fetch(); _logger.InfoFormat("更新Google任务#{0}|{1}|{2}", taskData.Id, taskData.Subject, _account.ID); var updatedGoogleTask = googleTaskService.Tasks.Get(defaultTaskList.Id, taskData.Id).Fetch(); UpdateTaskLastUpdateTime(long.Parse(taskData.SyncId), Rfc3339DateTime.Parse(updatedGoogleTask.Updated).ToLocalTime()); } catch (Exception ex) { _logger.Error("UpdateGoogleTask has exception.", ex); } }
public void Sync_Update_GoogleTask_AccordingWith_Task_Test() { _logger.Info("--------------开始执行测试:Sync_Update_GoogleTask_AccordingWith_Task_Test"); InitializeAccountAndConnection(_googleConnectionId); //首先创建 var cooperTask = CreateCooperTask("cooper task or update test 0001", "description of task", DateTime.Now.Date.AddDays(2), false); MicrosoftAssert.IsNotNull(cooperTask); //同步 _syncProcessor.SyncTasksAndContacts( _googleConnectionId, new List <ISyncService <TaskSyncData, ISyncData, TaskSyncResult> > { DependencyResolver.Resolve <IGoogleTaskSyncService>() }, null); //重新获取 var syncInfo = GetSyncInfoByLocalDataId(_account.ID, cooperTask.ID.ToString(), SyncDataType.GoogleTask); MicrosoftAssert.IsNotNull(syncInfo); var googleTask = GetGoogleTask(syncInfo.SyncDataId); MicrosoftAssert.IsNotNull(googleTask); AssertTaskAndGoogleTaskAreEqual(cooperTask, googleTask); //更新Task cooperTask = UpdateCooperTask(cooperTask.ID, cooperTask.Subject + "_updated", cooperTask.Body + "_updated", cooperTask.DueTime.Value.Date.AddDays(1), true); UpdateTaskLastUpdateTime(cooperTask, Rfc3339DateTime.Parse(googleTask.Updated).ToLocalTime().AddSeconds(1)); //同步 _syncProcessor.SyncTasksAndContacts( _googleConnectionId, new List <ISyncService <TaskSyncData, ISyncData, TaskSyncResult> > { DependencyResolver.Resolve <IGoogleTaskSyncService>() }, null); //重新获取 googleTask = GetGoogleTask(syncInfo.SyncDataId); //对比结果 MicrosoftAssert.IsNotNull(googleTask); AssertTaskAndGoogleTaskAreEqual(cooperTask, googleTask); }
private void AssertTaskAndGoogleTaskAreEqual(CooperTask cooperTask, GoogleTask googleTask) { MicrosoftAssert.AreEqual(cooperTask.Subject, googleTask.Title); MicrosoftAssert.AreEqual(cooperTask.Body, googleTask.Notes); var dueDate = Rfc3339DateTime.Parse(googleTask.Due); MicrosoftAssert.AreEqual(cooperTask.DueTime, new DateTime(dueDate.Year, dueDate.Month, dueDate.Day)); if (cooperTask.IsCompleted) { MicrosoftAssert.AreEqual("completed", googleTask.Status); } else { MicrosoftAssert.AreEqual("needsAction", googleTask.Status); } var lastUpdateTime = Rfc3339DateTime.Parse(googleTask.Updated).ToLocalTime(); MicrosoftAssert.AreEqual(FormatTime(cooperTask.LastUpdateTime), FormatTime(lastUpdateTime)); }
private void ParsePidf(byte[] pidfContent) { presence presence; using (MemoryStream stream = new MemoryStream(pidfContent)) { XmlSerializer serializer = new XmlSerializer(typeof(presence)); presence = serializer.Deserialize(stream) as presence; } PresenceStatus status = PresenceStatus.Offline; if (presence != null) { person[] persons = presence.Persons; person person = null; if (persons != null) { if (persons.Length > 0) { person = persons[0]; } DateTime lastTimeStamp = DateTime.MinValue; foreach (person p in persons) { String timeStamp = p.GetTimeStamp(); if (!String.IsNullOrEmpty(timeStamp)) { DateTime timestamp = Rfc3339DateTime.Parse(timeStamp); if (timestamp.CompareTo(lastTimeStamp) > 0) { lastTimeStamp = timestamp; person = p; } } } } String statusicon = (person != null && person.statusicon != null) ? person.statusicon.Value : null; Contact contact = this.contactService.ContactFind(presence.entity); if (contact != null) { if (person != null) { // // Basic // if (person.overridingWillingness != null) { status = (person.overridingWillingness.basic == basicType.closed) ? PresenceStatus.Offline : PresenceStatus.Online; if (!String.IsNullOrEmpty(person.overridingWillingness.Until)) { contact.HyperAvaiability = Rfc3339DateTime.Parse(person.overridingWillingness.Until).ToLocalTime(); } } // // Activities // if (person.activities != null && person.activities.ItemsElementName != null) { if (person.activities.ItemsElementName.Length > 0) { switch (person.activities.ItemsElementName[0]) { case BogheCore.Generated.rpid.ItemsChoiceType.away: case BogheCore.Generated.rpid.ItemsChoiceType.shopping: case BogheCore.Generated.rpid.ItemsChoiceType.sleeping: case BogheCore.Generated.rpid.ItemsChoiceType.working: case BogheCore.Generated.rpid.ItemsChoiceType.appointment: status = PresenceStatus.Away; break; case BogheCore.Generated.rpid.ItemsChoiceType.busy: status = PresenceStatus.Busy; break; case BogheCore.Generated.rpid.ItemsChoiceType.vacation: status = PresenceStatus.BeRightBack; break; case BogheCore.Generated.rpid.ItemsChoiceType.onthephone: case BogheCore.Generated.rpid.ItemsChoiceType.playing: status = PresenceStatus.OnThePhone; break; case BogheCore.Generated.rpid.ItemsChoiceType.dinner: case BogheCore.Generated.rpid.ItemsChoiceType.breakfast: case BogheCore.Generated.rpid.ItemsChoiceType.meal: status = PresenceStatus.OutToLunch; break; } } } // Assign status contact.PresenceStatus = status; // Free Text String note = person.GetNote(); if (!String.IsNullOrEmpty(note)) { contact.FreeText = note; } // Avatar /*if (!String.IsNullOrEmpty(statusicon)) * { * contact.Avatar = this.GetContactStatusIcon(statusicon); * }*/ // Home Page String hp = person.homepage; if (!String.IsNullOrEmpty(hp)) { contact.HomePage = hp; } // Service willingness (open/closed) // IMPORTANT: ignore availability[service.status] /*if (presence.tuple != null && presence.tuple.Length > 0) * { * foreach (tuple service in presence.tuple) * { * if (service != null && service.willingness != null && service.serviceDescription != null) * { * if (service.willingness.basic == basicType.closed) * { * contact.AddClosedServices(service.serviceDescription.serviceid); * } * else if (contact.ClosedServices.Contains(service.serviceDescription.serviceid)) * { * contact.RemoveClosedServices(service.serviceDescription.serviceid); * } * } * } * }*/ } else { // Get the first tuple tuple tuple = (presence.tuple != null && presence.tuple.Length > 0) ? presence.tuple[0] : null; contact.PresenceStatus = (tuple != null && tuple.status != null && tuple.status.basic == basic.open) ? PresenceStatus.Online : PresenceStatus.Offline; } } } }
private presence BuildFullPresence() { presence pres = this.PartialPublication ? new pidffull() : new presence(); pres.entity = this.FromUri; if (this.personId == null) { this.personId = String.Format("{0}{1:D7}", "p", ++MyPublicationSession.personIdCounter); } basic status = basic.closed; String note = "Offline"; BogheCore.Generated.rpid.ItemsChoiceType activity = BogheCore.Generated.rpid.ItemsChoiceType.unknown; switch (this.PresenceStatus) { case PresenceStatus.Busy: note = "Busy"; status = basic.open; activity = BogheCore.Generated.rpid.ItemsChoiceType.busy; break; case PresenceStatus.Away: note = "Away"; status = basic.open; activity = BogheCore.Generated.rpid.ItemsChoiceType.away; break; case PresenceStatus.Online: note = "Online"; status = basic.open; break; case PresenceStatus.HyperAvailable: note = "Hyper-Available"; status = basic.open; break; case PresenceStatus.BeRightBack: note = "Be Right Back"; status = basic.open; activity = BogheCore.Generated.rpid.ItemsChoiceType.vacation; break; case PresenceStatus.OnThePhone: note = "On The Phone"; status = basic.open; activity = BogheCore.Generated.rpid.ItemsChoiceType.onthephone; break; case PresenceStatus.OutToLunch: note = "Out To Lunch"; status = basic.open; activity = BogheCore.Generated.rpid.ItemsChoiceType.meal; break; } /*== Person ==*/ pres.Persons = new person[1] { new person() }; pres.Persons[0].id = this.personId; pres.Persons[0].timestamp = Rfc3339DateTime.ToString(DateTime.UtcNow); pres.Persons[0].overridingWillingness = new overridingwillingness(); pres.Persons[0].overridingWillingness.basicSpecified = true; pres.Persons[0].overridingWillingness.basic = (status == basic.closed) ? basicType.closed : basicType.open; if (this.PresenceStatus == PresenceStatus.HyperAvailable) { /* The RCS HyperAvailability information is carried by the OMA Overriding Willingness combined with an "until" value as specified in * [Presence2.0_DDS], with element basic->open. */ pres.Persons[0].overridingWillingness.Until = Rfc3339DateTime.ToString(DateTime.UtcNow.AddMinutes(this.HyperAvailabilityTimeout)); } pres.Persons[0].note = new BogheCore.Generated.data_model.Note_t[1] { new BogheCore.Generated.data_model.Note_t() }; pres.Persons[0].note[0].Value = String.IsNullOrEmpty(this.FreeText) ? note : this.FreeText; pres.Persons[0].activities = new activities(); pres.Persons[0].activities.ItemsElementName = new BogheCore.Generated.rpid.ItemsChoiceType[1]; pres.Persons[0].activities.ItemsElementName[0] = activity; pres.Persons[0].activities.Items = new BogheCore.Generated.rpid.empty[1]; pres.Persons[0].activities.Items[0] = new BogheCore.Generated.rpid.empty(); /*pres.Persons[0].mood = new mood(); * pres.Persons[0].mood.ItemsElementName = new ItemsChoiceType1[1]; * pres.Persons[0].mood.ItemsElementName[0] = this.Mood; * pres.Persons[0].mood.Items = new BogheCore.Generated.rpid.empty[1]; * pres.Persons[0].mood.Items[0] = new BogheCore.Generated.rpid.empty();*/ if (!String.IsNullOrEmpty(this.StatusIconUrl)) { pres.Persons[0].statusicon = new statusicon(); pres.Persons[0].statusicon.Value = this.StatusIconUrl; } if (!String.IsNullOrEmpty(this.HomePage)) { pres.Persons[0].homepage = this.HomePage; } /*== device ==*/ pres.Device = new device(); pres.Device.id = String.Format("{0}{1}", "d", "0001"); pres.Device.deviceID = RCSService.DEVICE_ID; pres.Device.Status = new status(); pres.Device.Status.basicSpecified = true; pres.Device.Status.basic = status; pres.Device.DeviceCapabilities = new BogheCore.Generated.pidf_caps.devcaps(); pres.Device.DeviceCapabilities.mobility = new BogheCore.Generated.pidf_caps.mobilitytype(); pres.Device.DeviceCapabilities.mobility.supported = new BogheCore.Generated.pidf_caps.mobilitytypes(); pres.Device.DeviceCapabilities.mobility.supported.@fixed = String.Empty; pres.Device.NetworkAvaibility = new networkavailability(); pres.Device.NetworkAvaibility.network = new networkavailabilityNetwork[1]; pres.Device.NetworkAvaibility.network[0] = new networkavailabilityNetwork(); pres.Device.NetworkAvaibility.network[0].id = "IMS"; pres.Device.NetworkAvaibility.network[0].active = new emptyType(); return(pres); }
public void Rfc3339DateTimeTest() { Rfc3339DateTime rfc3339DateTime = new Rfc3339DateTime(); Console.WriteLine(rfc3339DateTime.ToRfc3339String()); }