/// <summary> /// The method to get the value indicating whether the appointment is imported. /// </summary> /// <param name="item"> /// The item. /// </param> /// <returns> /// The <see cref="bool"/> indicating whether the appointment is imported. /// </returns> public static bool IsImported(this AppointmentItem item) { if (item == null) { return(false); } var isImportedValue = item.GetAppointmentCustomId(Constants.FieldImportedFromRedmine); return(isImportedValue.GetValueOrDefault(0) == 1); }
/// <summary> /// Gets the issue id /// </summary> /// <param name="item">the appointment item</param> /// <returns>the id if set</returns> public static int?GetIssueId(this AppointmentItem item) { if (item != null) { int?issueID; var itemEntryID = item.EntryID; if (itemEntryID == null || !issueIdCache.TryGetValue(itemEntryID, out issueID)) { issueID = item.GetAppointmentCustomId(Constants.FieldRedmineIssueId); if (itemEntryID != null) { issueIdCache[item.EntryID] = issueID; } } return(issueID); } return(null); }
/// <summary> /// Method that checks the previous state of an appointment and tries to reset that state. /// </summary> /// <param name="item">The appointment for which to set the previous state.</param> public static void ResetPreviousState(this AppointmentItem item) { var previousState = item.GetAppointmentCustomId(Constants.FieldAppointmentPreviousState); if (!previousState.HasValue) { return; } var state = AppointmentState.AllStates.FirstOrDefault(s => s.Value == previousState.Value); if (state == null) { return; } if (state == AppointmentState.Synchronized) { Log.Warn(string.Format("Appointment state set to synchronized. #{0} Previus state: {1}", item.GetIssueId(), item.Categories)); } item.SetAppointmentState(state); item.Save(); }
/// <summary> /// Sets the appointment category to give the appointment the correct color /// </summary> /// <param name="item">The item to set</param> /// <param name="state">The appointment state to set to the appointment</param> public static void SetAppointmentState(this AppointmentItem item, AppointmentState state) { var newCategories = new List <string>(); // get the previous categories and remove our categories if (!string.IsNullOrEmpty(item.Categories)) { foreach (var itm in item.Categories.Split(';')) { // Preserve other categories. if (!AppointmentState.IsValidAppointmentStateName(itm)) { newCategories.Add(itm); } } } // set our new categories newCategories.Insert(0, state.Name); if (state == AppointmentState.Modified) { item.SetAppointmentModificationDate(DateTime.Now); } item.Categories = string.Join(";", newCategories); // Update the previous sate of the appointment, if the current state is not syncerror. var previousState = item.GetAppointmentCustomId(Constants.FieldAppointmentState); if (previousState.HasValue && previousState.Value != AppointmentState.SyncError.Value) { item.SetAppointmentCustomId(Constants.FieldAppointmentPreviousState, previousState); } item.SetAppointmentCustomId(Constants.FieldAppointmentState, state.Value); }
/// <summary> /// Gets the time entry id /// </summary> /// <param name="item">the appointment item</param> /// <returns>the id if set</returns> public static int?GetTimeEntryId(this AppointmentItem item) { return(item != null?item.GetAppointmentCustomId(Constants.FieldRedmineTimeEntryId) : null); }