示例#1
0
        /// <summary>
        /// Sendings to publish event handler.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="SendToPublishEventArgs{IContent}"/> instance containing the event data.</param>
        private void SendingToPublishEventHandler(IContentService sender, SendToPublishEventArgs <IContent> args)
        {
            if (args == null || args.Entity == null || args.Entity.Properties == null || args.Entity.Properties.Count == 0)
            {
                return;
            }

            // Get user making changes
            IUser user = UmbracoContext.Current.Security.CurrentUser;

            // Fetch original content
            IContent originalContent = UmbracoContext.Current.Application.Services.ContentService.GetById(args.Entity.Id);

            // Get the Umbraco db
            var db = UmbracoContext.Current.Application.DatabaseContext.Database;

            // Start a transaction
            using (var scope = db.GetTransaction())
            {
                DateTime now = DateTime.Now;

                // Find which properties were actually changed
                IList <Property> dirtyProps = args.Entity.Properties.ToList();
                foreach (Property dirtyProp in dirtyProps)
                {
                    Property originalProp = originalContent.Properties
                                            .Where(x => x.Id == dirtyProp.Id)
                                            .FirstOrDefault();

                    if (originalProp != null &&
                        originalProp.Value != null &&
                        string.Compare(originalProp.Value.ToString(), dirtyProp.Value.ToString(), false) != 0)
                    {
                        // Creates a new change history table item
                        ChangeHistory newChange = new ChangeHistory();

                        newChange.PropertyId        = dirtyProp.Id;
                        newChange.PropertyAlias     = dirtyProp.Alias;
                        newChange.NodeId            = args.Entity.Id;
                        newChange.UpdateDate        = now;
                        newChange.UpdatedBy         = user.Username;
                        newChange.PreviousValue     = originalProp.Value.ToString();
                        newChange.CurrentValue      = dirtyProp.Value.ToString();
                        newChange.PropertyTypeAlias = dirtyProp.PropertyType.PropertyEditorAlias;

                        db.Insert(newChange);
                    }
                }

                // Commit the transaction
                scope.Complete();
            }
        }
示例#2
0
        /// <summary>
        /// Executes handlers and events for the Send To Publication action.
        /// </summary>
        /// <param name="u">The User</param>
        public bool SendToPublication(User u)
        {
            SendToPublishEventArgs e = new SendToPublishEventArgs();
            FireBeforeSendToPublish(e);
            if (!e.Cancel)
            {
                BusinessLogic.Log.Add(BusinessLogic.LogTypes.SendToPublish, u, this.Id, "");

                BusinessLogic.Actions.Action.RunActionHandlers(this, ActionToPublish.Instance);

                FireAfterSendToPublish(e);
                return true;
            }

            return false;

        }
示例#3
0
 /// <summary>
 /// Raises the <see cref="E:AfterPublish"/> event.
 /// </summary>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected virtual void FireAfterSendToPublish(SendToPublishEventArgs e)
 {
     if (AfterSendToPublish != null)
         AfterSendToPublish(this, e);
 }
示例#4
0
 /// <summary>
 /// Raises the <see cref="E:BeforePublish"/> event.
 /// </summary>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected virtual void FireBeforeSendToPublish(SendToPublishEventArgs e)
 {
     if (BeforeSendToPublish != null)
         BeforeSendToPublish(this, e);
 }
 public virtual void SendingToPublish(IContentService contentService, SendToPublishEventArgs <IContent> args)
 {
 }
示例#6
0
        /// <summary>
        /// Executes handlers and events for the Send To Publication action.
        /// </summary>
        /// <param name="u">The User</param>
        public bool SendToPublication(User u)
        {
            var e = new SendToPublishEventArgs();
            FireBeforeSendToPublish(e);
            if (e.Cancel == false)
            {
                var sent = ApplicationContext.Current.Services.ContentService.SendToPublication(Content, u.Id);
                if (sent)
                {
                    FireAfterSendToPublish(e);
                    return true;    
                }
            }

            return false;

        }
示例#7
0
 void ContentService_SentToPublish(IContentService sender, SendToPublishEventArgs<IContent> e)
 {
     RefreshArticle(e.Entity);
 }