public IEnumerable <ActivityStreamChangeItem> GetChangesDescriptions(ActiviyStreamWriterContext context) { if (!this.CanApply(context)) { yield break; } var attachToMilestonePart = context.ContentItem.As <AttachToMilestonePart>(); int?newMilestoneId = attachToMilestonePart.Record.MilestoneId; int?oldMilestoneId = context.Snapshot != null ? context.Snapshot.MilestoneId: null; var newMilestone = newMilestoneId.HasValue? this.milestoneService.GetMilestone(newMilestoneId.Value).As <MilestonePart>() : null; if (oldMilestoneId == null && newMilestoneId == null) { yield break; } else if (oldMilestoneId == null && newMilestoneId != null) { string change = T( "{0} is added to the '{1}'", contentItemDescriptorManager.GetDescription(context.ContentItem), contentItemDescriptorManager.GetDescription(newMilestone)).Text; yield return(new ActivityStreamChangeItem(change)); } else if (oldMilestoneId != null && newMilestoneId == null) { var oldMilestone = this.milestoneService.GetMilestone(oldMilestoneId.Value).As <MilestonePart>(); string change = T( "{0} is detached from the '{1}'", contentItemDescriptorManager.GetDescription(context.ContentItem), contentItemDescriptorManager.GetDescription(oldMilestone)).Text; yield return(new ActivityStreamChangeItem(change)); } else if (oldMilestoneId != null && newMilestoneId != null && oldMilestoneId.Value != newMilestoneId.Value) { var oldContentItem = this.milestoneService.GetMilestone(oldMilestoneId.Value); string change = T( "{0} is detached from the '{1}'", contentItemDescriptorManager.GetDescription(context.ContentItem), contentItemDescriptorManager.GetDescription(oldContentItem)).Text; yield return(new ActivityStreamChangeItem(change)); change = T( "{0} is attached to the '{1}'", contentItemDescriptorManager.GetDescription(context.ContentItem), contentItemDescriptorManager.GetDescription(newMilestone)).Text; yield return(new ActivityStreamChangeItem(change)); } if (newMilestoneId.HasValue) { int oldOrder = context.Snapshot.OrderId; int?size = context.Snapshot.Size; if (oldOrder != attachToMilestonePart.Record.OrderId) { string change = T( "{0} is moved to the position '{1}' in '{2}'", contentItemDescriptorManager.GetDescription(context.ContentItem), attachToMilestonePart.Record.OrderId.ToString(CultureInfo.InvariantCulture), contentItemDescriptorManager.GetDescription(newMilestone)).Text; yield return(new ActivityStreamChangeItem(change, true, newMilestone.ContentItem.Id, newMilestone.ContentItem.VersionRecord.Id)); } if (size != attachToMilestonePart.Record.Size) { string change = T( "The Size of '{0}' in the milestone '{1}' is changed to'{2}'", contentItemDescriptorManager.GetDescription(context.ContentItem), contentItemDescriptorManager.GetDescription(newMilestone), attachToMilestonePart.Record.Size.ToString()).Text; yield return(new ActivityStreamChangeItem(change, true, newMilestone.ContentItem.Id, newMilestone.ContentItem.VersionRecord.Id)); } } }
public ActivityStreamContentDescription GetContentDescription(ActiviyStreamWriterContext context) { return(null); }
public void WriteChangesToStreamActivity(ContentItem contentItem, dynamic snapshot, bool createdBySystem, string mainStreamWriter) { var currentUser = this.services.WorkContext.CurrentUser; int?userId = !createdBySystem && currentUser != null ? (int?)currentUser.Id : null; List <ActivityStreamChangeItem> changes = new List <ActivityStreamChangeItem>(); List <ActivityStreamContentDescription> descriptions = new List <ActivityStreamContentDescription>(); IDictionary <string, object> oldDataDictionary = snapshot != null ? snapshot as IDictionary <string, object> : null; foreach (var writer in this.activityStreamWriters) { var writerSnapshot = oldDataDictionary != null ? oldDataDictionary[writer.Name] : null; ActiviyStreamWriterContext context = new ActiviyStreamWriterContext(contentItem, writerSnapshot, currentUser); if (writer.CanApply(context)) { var changeDescriptions = writer.GetChangesDescriptions(context); if (changeDescriptions != null) { changes.AddRange(changeDescriptions); } var activityContentDescription = writer.GetContentDescription(context); if (activityContentDescription != null) { descriptions.Add(activityContentDescription); } } } // description with highest weight ActivityStreamContentDescription contentDescription = null; if (!string.IsNullOrEmpty(mainStreamWriter)) { contentDescription = descriptions.FirstOrDefault(c => c.WriterName == mainStreamWriter); } if (contentDescription == null) { contentDescription = descriptions .OrderByDescending(c => c.Weight) .FirstOrDefault(); } // if it is an update, but noting is changed, then no activity record must be created if (snapshot != null && changes.Count == 0) { return; } string description = contentDescription.Description; if (changes.Count == 1) { description = string.Format(CultureInfo.InvariantCulture, "{1} - {0}", description, changes[0].Change).Trim(); changes.Clear(); } this.WriteChangesToStreamActivity(userId, contentItem.Id, contentItem.VersionRecord.Id, changes.ToArray(), description, contentDescription.RouteValues); }
public bool CanApply(ActiviyStreamWriterContext context) { return(context.ContentItem.As <FolderPart>() != null); }
public IEnumerable <ActivityStreamChangeItem> GetChangesDescriptions(ActiviyStreamWriterContext context) { if (!this.CanApply(context)) { return(null); } List <string> changes = new List <string>(); // TicketPartRecord old = context.Snapshot != null ? (context.Snapshot as TicketPartRecord) : null; // TicketPartRecord newValue = (context.ContentItem.As<TicketPart>()).Record; // WorkBookPart old = context.Snapshot != null ? (context.Snapshot as WorkBookPart) : null; // WorkBookPart newValue = context.ContentItem.As<WorkBookPart>(); // if (old == null) // { // string change = T["WorkBook is created"]; // return new[] { new ActivityStreamChangeItem(change) }; // } // change status // this.AddBasicDataRecordChange( // changes, // old.StatusRecord, // newValue.StatusRecord, // (id) => this.basicDataService.GetStatusRecords().FirstOrDefault(c => c.Id == id), // "changed the status to: '{0}'"); // this.AddBasicDataRecordChange( // changes, // old.ContentItem, // newValue.ContentItem, // (id) => _contentManager.GetAsync(id.ToString()).Result, // "changed the status to: '{0}'"); // change ticketType // this.AddBasicDataRecordChange( // changes, // old.TicketType, // newValue.TicketType, // (id) => this.basicDataService.GetTicketTypes().FirstOrDefault(c => c.Id == id), // "changed the Ticket Type to: '{0}'"); // change service // this.AddBasicDataRecordChange( // changes, // old.Service, // newValue.Service, // (id) => this.basicDataService.GetServices().Select(d => d.Record).FirstOrDefault(c => c.Id == id), // "changed the Service to: '{0}'"); // change priority // this.AddBasicDataRecordChange( // changes, // old.PriorityRecord, // newValue.PriorityRecord, // (id) => this.basicDataService.GetPriorities().FirstOrDefault(c => c.Id == id), // "changed the Priority to: '{0}'"); // change DueDate // if (old.DueDate != newValue.DueDate) // { // string newDueDateString = newValue.DueDate != null ? T(newValue.DueDate.Value.ToLongDateString() + " " + newValue.DueDate.Value.ToLongTimeString()).Text : this.T("null").Text; // newDueDateString = string.Format( // CultureInfo.CurrentUICulture, // T["changed the DueDate to: '{0}'"], // newDueDateString); // // changes.Add(newDueDateString); // } // change Title // if (old.ContentItem.DisplayText != newValue.ContentItem.DisplayText) // { // string newTitleString = !string.IsNullOrEmpty(newValue.ContentItem.DisplayText) ? newValue.ContentItem.DisplayText: this.T["Empty"]; // newTitleString = string.Format( // CultureInfo.CurrentUICulture, // T["changed the Title to: '{0}'"], // newTitleString); // // changes.Add(newTitleString); // } // change Description // if (old.Description != newValue.Description) // { // string newDescriptionString = !string.IsNullOrEmpty(newValue.Description) ? newValue.Description : this.T["Empty"]; // newDescriptionString = T("changed the Description").Text; // // changes.Add(newDescriptionString); // } return(changes.Select(c => new ActivityStreamChangeItem(c))); }
public bool CanApply(ActiviyStreamWriterContext context) { // return context.ContentItem.As<TicketPart>() != null; return(context.ContentItem.Has("WorkBookPart")); }