public IEnumerable <ActivityStreamChangeItem> GetChangesDescriptions(ActiviyStreamWriterContext context)
        {
            if (!this.CanApply(context))
            {
                yield break;
            }

            var attachToFolderPart = context.ContentItem.As <AttachToFolderPart>();

            FolderPartRecord newFolder = attachToFolderPart.Record.Folder;
            FolderPartRecord oldFolder = context.Snapshot != null ? context.Snapshot.Folder : null;

            if (oldFolder == null && newFolder == null)
            {
                yield break;
            }
            else if (oldFolder == null && newFolder != null)
            {
                newFolder = this.folderService.GetFolder(newFolder.Id).As <FolderPart>().Record;
                string change = T("{0} is added to the folder '{1}'", contentItemDescriptorManager.GetDescription(context.ContentItem), newFolder.Title).Text;
                yield return(new ActivityStreamChangeItem(change));
            }
            else if (oldFolder != null && newFolder == null)
            {
                oldFolder = this.folderService.GetFolder(oldFolder.Id).As <FolderPart>().Record;
                string change = T("{0} is detached from the folder '{1}'", contentItemDescriptorManager.GetDescription(context.ContentItem), oldFolder.Title).Text;
                yield return(new ActivityStreamChangeItem(change));
            }
            else if (oldFolder != null && newFolder != null && oldFolder.Id != newFolder.Id)
            {
                var oldFolderContentItem = this.folderService.GetFolder(oldFolder.Id);
                var newFolderContentItem = this.folderService.GetFolder(newFolder.Id);

                string change = T("{0} is detached from the folder '{1}'", contentItemDescriptorManager.GetDescription(context.ContentItem), oldFolderContentItem.Record.Title).Text;
                yield return(new ActivityStreamChangeItem(change, true, oldFolderContentItem.ContentItem.Id, oldFolderContentItem.ContentItem.VersionRecord.Id));

                change = T("{0} is added to the folder '{1}'", contentItemDescriptorManager.GetDescription(context.ContentItem), newFolderContentItem.Record.Title).Text;
                yield return(new ActivityStreamChangeItem(change, true, newFolderContentItem.ContentItem.Id, newFolderContentItem.ContentItem.VersionRecord.Id));
            }
        }
        public IEnumerable <ActivityStreamChangeItem> GetChangesDescriptions(ActiviyStreamWriterContext context)
        {
            if (!this.CanApply(context))
            {
                yield break;
            }

            var attachToProjectPart = context.ContentItem.As <AttachToProjectPart>();

            ProjectPartRecord newProject = attachToProjectPart.Record.Project;
            ProjectPartRecord oldProject = context.Snapshot != null ? context.Snapshot.Project : null;

            if (oldProject == null && newProject == null)
            {
                yield break;
            }
            else if (oldProject == null && newProject != null)
            {
                newProject = this.projectService.GetProject(newProject.Id).As <ProjectPart>().Record;
                string change = T("{0} is attached to project '{1}'", contentItemDescriptorManager.GetDescription(context.ContentItem), newProject.Title).Text;
                yield return(new ActivityStreamChangeItem(change));
            }
            else if (oldProject != null && newProject == null)
            {
                oldProject = this.projectService.GetProject(oldProject.Id).As <ProjectPart>().Record;
                string change = T("{0} is detached from the project '{1}'", contentItemDescriptorManager.GetDescription(context.ContentItem), oldProject.Title).Text;
                yield return(new ActivityStreamChangeItem(change));
            }
            else if (oldProject != null && newProject != null && oldProject.Id != newProject.Id)
            {
                var oldProjectContentItem = this.projectService.GetProject(oldProject.Id);
                var newProjectContentItem = this.projectService.GetProject(newProject.Id);

                string change = T("{0} is detached from the project '{1}'", contentItemDescriptorManager.GetDescription(context.ContentItem), oldProjectContentItem.Record.Title).Text;
                yield return(new ActivityStreamChangeItem(change, true, oldProjectContentItem.ContentItem.Id, oldProjectContentItem.ContentItem.VersionRecord.Id));

                change = T("{0} is attached to project '{1}'", contentItemDescriptorManager.GetDescription(context.ContentItem), newProjectContentItem.Record.Title).Text;
                yield return(new ActivityStreamChangeItem(change, true, newProjectContentItem.ContentItem.Id, newProjectContentItem.ContentItem.VersionRecord.Id));
            }
        }
Пример #3
0
        public ActivityStreamContentDescription GetContentDescription(ActiviyStreamWriterContext context)
        {
            if (!this.CanApply(context))
            {
                return(null);
            }

            var folderPart = context.ContentItem.As <FolderPart>();

            string folderDescription = contentItemDescriptorManager.GetDescription(context.ContentItem);

            RouteValueDictionary routeValueDictionary = new RouteValueDictionary();

            routeValueDictionary.Add("action", "Display");
            routeValueDictionary.Add("controller", "Folder");
            routeValueDictionary.Add("area", "Orchard.CRM.Project");
            routeValueDictionary.Add("id", context.ContentItem.Id);

            ActivityStreamContentDescription returnValue = new ActivityStreamContentDescription(StreamWriters.FolderStreamWriter)
            {
                Weight = 1, RouteValues = routeValueDictionary
            };

            var originalFolder = this.folderService.GetFolder(folderPart.Record.Id);

            // new folder
            if (originalFolder == null)
            {
                returnValue.Description = T("Creates new folder").Text;
            }
            else if (context.Snapshot == null)
            {
                returnValue.Description = T("Creates the '{0}'", folderDescription).Text;
            }
            else
            {
                returnValue.Description = string.Format("{0} {1}", this.T("on Folder").Text, folderDescription);
            }

            return(returnValue);
        }
        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));
                }
            }
        }