public void GetTitleWithCaseToken() { var c = new Case(); c.Subject = "title"; c.CaseId = 123; Assert.AreEqual("title (Case 123)", c.GetTitleWithCaseToken()); }
public void SyncTask(Case fogbugzCase, TaskItem outlookTask) { try { //Associate the case and task outlookTask.SetFogbugzCaseId(fogbugzCase.CaseId); Log.DebugFormat("Setting task metadata case id to {0}", fogbugzCase.CaseId); var subjectWithCaseId = fogbugzCase.GetTitleWithCaseToken(); var taskNewer = false; //Determine which is newer var taskLastModified = outlookTask.GetLastModifiedDate(); if (taskLastModified != null && taskLastModified > fogbugzCase.LastUpdated) taskNewer = true; Log.DebugFormat("Fogbugz case last update: {0}", fogbugzCase.LastUpdated); Log.DebugFormat("Outlook task last update: {0}", taskLastModified); if (taskNewer) { Log.Debug("Task is newer than the fogbugz case"); fogbugzCase.PercentComplete = outlookTask.PercentComplete; fogbugzCase.Subject = outlookTask.Subject; if (outlookTask.DueDate != OutlookConnector.EmptyDate) { if (fogbugzCase.Due != null && fogbugzCase.Due.Value.Date == outlookTask.DueDate.Date) { //Don't update fogbugz in this case, because we'll only be dropping the time component. //In other words, the fogbugz due date will be reset to midnight since Outlook doesn't store the time. } else { fogbugzCase.Due = outlookTask.DueDate; } } //Not sure how to translate priorities back to fogbugz } else { Log.Debug("Fogbugz case is newer than the task"); outlookTask.PercentComplete = fogbugzCase.PercentComplete; outlookTask.Subject = subjectWithCaseId; if (fogbugzCase.Due != null) { outlookTask.DueDate = fogbugzCase.Due.Value; //Only populate the start date if there is a due date, otherwise //the task will have a due date the same as the start (stupid) outlookTask.StartDate = fogbugzCase.Opened; } if (fogbugzCase.Priority == 1 || fogbugzCase.Priority == 2) outlookTask.Importance = OlImportance.olImportanceHigh; else if (fogbugzCase.Priority == 4 || fogbugzCase.Priority == 5 || fogbugzCase.Priority == 6) outlookTask.Importance = OlImportance.olImportanceLow; else outlookTask.Importance = OlImportance.olImportanceNormal; } var tokens = new List<KeyValuePair<string, string>> { //Note; tokens must be lower case new KeyValuePair<string, string>("caseid", fogbugzCase.CaseId.ToString()), new KeyValuePair<string, string>("emailsubject", Uri.EscapeUriString(subjectWithCaseId)) }; outlookTask.RTFBody = Encoding.ASCII.GetBytes(GenerateTaskBody(tokens)); } catch (Exception ex) { if(fogbugzCase != null) Log.Info(fogbugzCase.ToString()); if(outlookTask != null) Log.Info(outlookTask.ToString()); Log.Error("Error synchronizing tasks", ex); throw; } }