private void ContentServiceOnSaving(IContentService sender, ContentSavingEventArgs e)
        {
            var playlistEntities =
                e.SavedEntities.Where(ent => ent.ContentType.Alias.InvariantEquals(YoutubePlaylistConstants.ContentTypeAlias));

            foreach (var youtubePlaylist in playlistEntities)
            {
                var currentPlaylist = sender.GetById(youtubePlaylist.Id);

                if (currentPlaylist == null)
                {
                    continue;
                }

                var currentUrl = currentPlaylist.GetValue <string>(YoutubePlaylistConstants.YoutubePlaylistUrlNodeName);
                var newurl     = youtubePlaylist.GetValue <string>(YoutubePlaylistConstants.YoutubePlaylistUrlNodeName);

                if (!currentUrl.Equals(newurl, StringComparison.OrdinalIgnoreCase))
                {
                    youtubePlaylist.SetValue(YoutubePlaylistConstants.YoutubePlaylistUrlNodeName, currentUrl);

                    e.Messages.Add(new EventMessage("Playlist Url", "Once saved, playlist Url cannot be updated. Url was reverted to the original value.", EventMessageType.Warning));
                }
            }
        }
Exemplo n.º 2
0
        private void OnMediaSettingsClick(object sender, EventArgs e)
        {
            var savingArgs = new ContentSavingEventArgs {
                SavingReason = ContentSavingReason.ScheduleChanging
            };

            ContentEditManager <MediaScheduleChangeInfo> .ProcessContentEditChanges(
                Controller.Instance.ContentController.ActiveEditor,
                savingArgs);

            if (!savingArgs.Cancel)
            {
                using (var form = new FormMediaSettings())
                {
                    form.comboBoxEditMedia.Properties.Items.AddRange(FileStorageManager.Instance.SubStorages);
                    form.comboBoxEditMedia.EditValue = AppProfileManager.Instance.SubStorageName;
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        AppProfileManager.Instance.SubStorageName = form.comboBoxEditMedia.EditValue as string;
                        AppProfileManager.Instance.SaveProfile();

                        _processAppClosing = false;
                        AppManager.Instance.RestartApp();
                    }
                }
            }
        }
        private void ContentServiceOnSaving(IContentService sender, ContentSavingEventArgs e)
        {
            var playlistEntities =
                e.SavedEntities.Where(ent => ent.ContentType.Alias.InvariantEquals(YoutubePlaylistConstants.ContentTypeAlias));

            foreach (var youtubePlaylist in playlistEntities)
            {
                if (!string.IsNullOrEmpty(
                        youtubePlaylist.GetValue <string>(YoutubePlaylistConstants.YoutubePlaylistIdNodeName)))
                {
                    return;
                }

                var url = youtubePlaylist.GetValue <string>(YoutubePlaylistConstants.YoutubePlaylistUrlNodeName);

                Uri playlistUri;
                if (Uri.TryCreate(url, UriKind.Absolute, out playlistUri))
                {
                    var queryStringParameters = playlistUri.ParseQueryString();

                    if (queryStringParameters["list"] != null)
                    {
                        youtubePlaylist.SetValue(YoutubePlaylistConstants.YoutubePlaylistIdNodeName, queryStringParameters["list"]);
                    }
                }
            }
        }
        //private void ContentService_Copying(IContentService sender,CopyEventArgs<IContent> eventArgs) {
        //    ActionModel copy = null;
        //    int _currentUserId;

        //    using(var contextReference = _context.EnsureUmbracoContext()) {
        //        _currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id;
        //    }

        //    try {

        //        using(var scope = _scopeProvider.CreateScope(autoComplete: true)) {
        //            var sql = scope.SqlContext.Sql().Select("*").From<ActionModel>()
        //                            .Where<ActionModel>(x => x.id == 5);
        //            copy = scope.Database.Fetch<ActionModel>(sql).FirstOrDefault();
        //        }
        //    }
        //    catch(Exception ex) {
        //        _logger.Error<ActionModel>("Failed to get Content Protector setting for copy action: " + ex.Message);
        //    }

        //    if(copy != null) {
        //        if(copy.nodes.Contains(eventArgs.Copy.Id.ToString())) {
        //            if(!copy.userExceptions.Split(',').Contains(_currentUserId.ToString())) {
        //                eventArgs.Cancel = true;
        //                eventArgs.CanCancel = true;
        //                eventArgs.Messages.Add(new EventMessage("Action rejected. Contact website admin","You cannot copy " + eventArgs.Copy.Name,EventMessageType.Error));
        //            }
        //        }
        //    }

        //}

        //private void ContentService_Moving(IContentService sender,MoveEventArgs<IContent> eventArgs) {
        //    ActionModel move = null;
        //    int _currentUserId;

        //    using(var contextReference = _context.EnsureUmbracoContext()) {
        //        _currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id;
        //    }

        //    try {

        //        using(var scope = _scopeProvider.CreateScope(autoComplete: true)) {
        //            var sql = scope.SqlContext.Sql().Select("*").From<ActionModel>()
        //                            .Where<ActionModel>(x => x.id == 2);
        //            move = scope.Database.Fetch<ActionModel>(sql).FirstOrDefault();
        //        }
        //    }
        //    catch(Exception ex) {
        //        _logger.Error<ActionModel>("Failed to get Content Protector setting for move action: " + ex.Message);
        //    }

        //    foreach(var node in eventArgs.MoveInfoCollection) {
        //        if(move != null) {
        //            if(move.nodes.Contains(node.Entity.Id.ToString()) || move.disableAction) {
        //                if(!move.userExceptions.Split(',').Contains(_currentUserId.ToString())) {
        //                    eventArgs.CancelOperation(new EventMessage("Action rejected. Contact website admin","You cannot move " + node.Entity.Name,EventMessageType.Error));
        //                }
        //            }
        //        }
        //    }
        //}

        private void ContentService_Saving(IContentService sender, ContentSavingEventArgs eventArgs)
        {
            ActionModel save = null;
            int         _currentUserId;

            using (var contextReference = _context.EnsureUmbracoContext()) {
                _currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id;
            }

            try {
                using (var scope = _scopeProvider.CreateScope(autoComplete: true)) {
                    var sql = scope.SqlContext.Sql().Select("*").From <ActionModel>()
                              .Where <ActionModel>(x => x.id == 1);
                    save = scope.Database.Fetch <ActionModel>(sql).FirstOrDefault();
                }
            }
            catch (Exception ex) {
                _logger.Error <ActionModel>("Failed to get Content Protector setting for save action: " + ex.Message);
            }

            foreach (var node in eventArgs.SavedEntities)
            {
                if (save != null)
                {
                    if (save.nodes.Split(',').Contains(node.Id.ToString()) || save.disableAction)
                    {
                        if (!save.userExceptions.Split(',').Contains(_currentUserId.ToString()))
                        {
                            eventArgs.CancelOperation(new EventMessage("Action rejected. Contact website admin", "You cannot save " + node.Name, EventMessageType.Error));
                        }
                    }
                }
            }
        }
 public virtual void Saving(ContentSavingEventArgs savingArgs)
 {
     if (SettingsNotSaved)
     {
         ApplyChanges();
         ValidateChanges(savingArgs);
     }
 }
 /// <summary>
 /// <see cref="ContentService"/> Saving event handler
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ContentService_Saving(IContentService sender, ContentSavingEventArgs e)
 {
     foreach (var entity in e.SavedEntities)
     {
         var props = entity.GetPropertiesByEditor(_editorAlias);
         UpdatePropertyValues(props, true);
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// create the extension that adds extra logic when a content page is saved
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ContentService_Saving(IContentService sender, ContentSavingEventArgs e)
 {
     //Check if the content item type has a specific alias
     foreach (var content in e.SavedEntities.Where(c => c.ContentType.Alias.InvariantEquals("StandardPage")))
     {
         //Do something if the content is using the MyContentType doctype
     }
 }
        private static void OnSelectedRibbonTabChanged(object sender, EventArgs e)
        {
            if (_tabChangeInProgress)
            {
                return;
            }
            try
            {
                _tabChangeInProgress = true;

                _controller.ContentRibbon.Enabled = false;

                var nextControl = _controller.ContentControls
                                  .First(c => c.Identifier == (String)_controller.ContentRibbon.SelectedRibbonTabItem.Tag);

                if (_controller.ActiveControl is IContentEditControl <TChangeInfo> activeEditor)
                {
                    var savingArgs = new ContentSavingEventArgs {
                        SavingReason = ContentSavingReason.TabChanged, RequreScheduleInfoValidation = nextControl.RequreScheduleInfo
                    };
                    ContentEditManager <TChangeInfo> .ProcessContentEditChanges(activeEditor, savingArgs);

                    if (savingArgs.Cancel)
                    {
                        _controller.ContentRibbon.SelectedRibbonTabItem = _controller.ActiveControl.TabPage;
                        _controller.ContentRibbon.Enabled = true;
                        return;
                    }
                }
                _controller.MainPanelContainer.Visibility = LayoutVisibility.Never;
                _controller.EmptyPanel.Visibility         = LayoutVisibility.Always;
                foreach (var contentControl in _controller.ContentControls)
                {
                    contentControl.IsActive           = false;
                    ((Control)contentControl).Visible = false;
                }
                _controller.ActiveControl = nextControl;
                if (!_controller.MainPanel.Control.Controls.Contains((Control)_controller.ActiveControl))
                {
                    _controller.ActiveControl.InitBusinessObjects();
                    _controller.MainPanel.Control.Controls.Add((Control)_controller.ActiveControl);
                    _controller.ActiveControl.InitControl();
                }
                _controller.ActiveControl.ShowControl(e as ContentOpenEventArgs);
                ((Control)_controller.ActiveControl).Visible = true;
                ((Control)_controller.ActiveControl).BringToFront();
                _controller.EmptyPanel.Visibility         = LayoutVisibility.Never;
                _controller.MainPanelContainer.Visibility = LayoutVisibility.Always;

                _controller.ContentRibbon.Enabled = true;
            }
            finally
            {
                _tabChangeInProgress = false;
            }
        }
 public virtual void Save(ContentSavingEventArgs savingArgs)
 {
     if (SettingsNotSaved)
     {
         Application.DoEvents();
         FormProgress.ShowProgress("Saving Data...", SaveData);
         SettingsNotSaved = false;
         OnContentChanged(new ContentSavedEventArgs <TChangeInfo>(Identifier, ChangeInfo, savingArgs.SavingReason));
     }
 }
Exemplo n.º 10
0
 private void ContentService_Saving(IContentService sender, ContentSavingEventArgs e)
 {
     // One or more content nodes could be saved in a bulk publish
     foreach (var entity in e.SavedEntities)
     {
         // When a content node contains nested content property
         // Check if the copied node contains a nested content
         var nestedContentProps = entity.Properties.Where(x => x.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.Aliases.NestedContent);
         UpdateNestedContentProperties(nestedContentProps, true);
     }
 }
        public static void SaveScheduleAs()
        {
            if (_controller.ActiveEditor == null)
            {
                return;
            }
            var savingArgs = new ContentSavingEventArgs {
                SavingReason = ContentSavingReason.ScheduleSaved
            };

            _controller.ActiveEditor.Saving(savingArgs);
            if (savingArgs.Cancel)
            {
                if (savingArgs.ErrorMessages.Any() && savingArgs.SavingReason != ContentSavingReason.AppClosing)
                {
                    PopupMessageHelper.Instance.ShowWarning(String.Join(Environment.NewLine, savingArgs.ErrorMessages));
                }
                return;
            }
            using (var form = new FormScheduleName(true))
            {
                if (form.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                var scheduleSavingArgs = new ScheduleSavingEventArgs
                {
                    Name = form.ScheduleName,
                };
                ScheduleSavingAs?.Invoke(null, scheduleSavingArgs);
                _controller.ActiveEditor.Save(savingArgs);
                if (form.checkEditSaveAsTemplate.Checked)
                {
                    if (!FileStorageManager.Instance.UseLocalMode)
                    {
                        ScheduleSavingTemplate?.Invoke(null, scheduleSavingArgs);
                        PopupMessageHelper.Instance.ShowInformation("Data saved to the cloud");
                    }
                    else
                    {
                        PopupMessageHelper.Instance.ShowWarning("Cloud is not available");
                    }
                }
                else
                {
                    PopupMessageHelper.Instance.ShowInformation("Data Saved");
                }
            }
        }
Exemplo n.º 12
0
        private void OnOpenScheduleClick(object sender, EventArgs e)
        {
            var savingArgs = new ContentSavingEventArgs {
                SavingReason = ContentSavingReason.ScheduleChanging
            };

            ContentEditManager <MediaScheduleChangeInfo> .ProcessContentEditChanges(
                Controller.Instance.ContentController.ActiveEditor,
                savingArgs);

            if (!savingArgs.Cancel)
            {
                OpenSchedule();
            }
        }
        public static void SaveSchedule(bool silent = false)
        {
            if (_controller.ActiveEditor == null)
            {
                return;
            }
            var savingArgs = new ContentSavingEventArgs {
                SavingReason = ContentSavingReason.ScheduleSaved
            };

            ProcessContentEditChanges(_controller.ActiveEditor, savingArgs);
            if (!savingArgs.Cancel && !silent)
            {
                PopupMessageHelper.Instance.ShowInformation("Data Saved");
            }
        }
Exemplo n.º 14
0
 private void ForumPost_Saving(IContentService sender, ContentSavingEventArgs e)
 {
     //if it is a forumPost then check if it is from the back office or UI and cancel if back office.
     foreach (var content in e.SavedEntities.Where(c => c.ContentType.Alias.InvariantEquals("forumPost")))
     {
         var postinguser = System.Web.HttpContext.Current.User.Identity;
         if (postinguser is UmbracoBackOfficeIdentity)
         {
             if (content.IsPropertyDirty("postBody"))
             {
                 e.Messages.Add(new EventMessage("Forum", "Forum posts can not be edited in the back office", EventMessageType.Info));
                 e.Cancel = true;
             }
         }
     }
 }
Exemplo n.º 15
0
 private void OnCloseOnIdleTimerExpired(Object sender, EventArgs e)
 {
     if (!_processAppClosing)
     {
         return;
     }
     _processAppClosing = false;
     if (BusinessObjects.Instance.IdleManager.SaveOnClose)
     {
         var savingArgs = new ContentSavingEventArgs {
             SavingReason = ContentSavingReason.AppClosing
         };
         ContentEditManager <MediaScheduleChangeInfo> .ProcessContentEditChanges(
             Controller.Instance.ContentController.ActiveEditor,
             savingArgs);
     }
 }
Exemplo n.º 16
0
        public void ContentService_Saving(IContentService sender, ContentSavingEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("Saving & publishing");
            foreach (var content in e.SavedEntities.Where(c => c.ContentType.Alias.InvariantEquals("MyContentType")))
            {
                System.Diagnostics.Debug.WriteLine("Content found");
                var umbContentValue = content.GetValue("rTEtest");
                System.Diagnostics.Debug.WriteLine(umbContentValue);

                var database   = client.GetDatabase("BrianDatabaseTest");
                var collection = database.GetCollection <BsonDocument>("BrianCollectionTest");
                var document   = new BsonDocument {
                    { "theValue", umbContentValue.ToString() }
                };
                collection.InsertOne(document);
            }
        }
Exemplo n.º 17
0
        protected override void ValidateChanges(ContentSavingEventArgs savingArgs)
        {
            if (savingArgs.SavingReason == ContentSavingReason.AppClosing)
            {
                return;
            }
            if (!savingArgs.RequreScheduleInfoValidation)
            {
                return;
            }
            if (EditedSettings.EditMode != ScheduleEditMode.Regular)
            {
                return;
            }

            if (String.IsNullOrEmpty(EditedSettings.BusinessName))
            {
                savingArgs.Cancel = true;
                savingArgs.ErrorMessages.Add(
                    "Your schedule is missing important information!\nPlease make sure you have a Business Name before you proceed.");
                return;
            }
            if (String.IsNullOrEmpty(EditedSettings.DecisionMaker))
            {
                savingArgs.Cancel = true;
                savingArgs.ErrorMessages.Add(
                    "Your schedule is missing important information!\nPlease make sure you have a Owner/Decision-maker before you proceed.");
                return;
            }
            if (!EditedSettings.PresentationDate.HasValue)
            {
                savingArgs.Cancel = true;
                savingArgs.ErrorMessages.Add(
                    "Your schedule is missing important information!\nPlease make sure you have a Presentation Date before you proceed.");
                return;
            }
            if (!EditedSettings.UserFlightDateStart.HasValue || !EditedSettings.UserFlightDateEnd.HasValue)
            {
                savingArgs.Cancel = true;
                savingArgs.ErrorMessages.Add("Your schedule is missing important information!\nPlease make sure you have a Flight Dates before you proceed.");
                return;
            }
        }
        private void CheckForDuplicates(IContentService sender, ContentSavingEventArgs e)
        {
            var statusCodeAlias = "statusCode";

            foreach (var content in e.SavedEntities)
            {
                if (content.ContentType.Alias != "errorPage")
                {
                    // not an error page
                    continue;
                }

                var statusCode = content.GetValue <string>(statusCodeAlias);
                statusCode = Regex.Match(statusCode, @"\d+").Value;
                var errorPageService = new ErrorPageService(_contextFactory, _domainService, _logger);

                if (errorPageService.HasDuplicateErrorPage(statusCode, content.Id, content.ParentId))
                {
                    _logger.Info(GetType(), $"Saving of this item ({content.Name}) has been blocked.");
                    e.Cancel = true;
                    e.Messages.Add(new EventMessage("Saving of this item has been blocked", $"There is already an error page for status code {statusCode}.<br /> Please choose a different status code or edit the existing page instead.", EventMessageType.Warning));
                }
            }
        }
Exemplo n.º 19
0
        private void ContentService_Saving(IContentService sender, ContentSavingEventArgs e)
        {
            //Check if the content item type has a specific alias
            foreach (IContent content in e.SavedEntities.Where(c => c.ContentType.Alias.InvariantEquals("Tour")))
            {
                //Do something if the content is using the MyContentType doctype
                if (content.Id <= 0) //new record
                {
                    //e.Cancel = true;
                }
                else //existing record
                {
                    if (content.IsDirty())
                    {
                        //e.CancelOperation(new EventMessage("Foo permissions", "You cannot edit foo records", EventMessageType.Error));
                    }
                }

                if (content.ContentType.Alias == "aliasBar")
                {
                    // EmailService(content.Id);
                }
            }
        }
Exemplo n.º 20
0
        private void OnFormMainClosing(object sender, FormClosingEventArgs e)
        {
            if (!_processAppClosing)
            {
                return;
            }
            using (var form = new FormExitConfirmation())
            {
                form.Text = PopupMessageHelper.Instance.Title;
                if (form.ShowDialog(this) != DialogResult.OK)
                {
                    e.Cancel = true;
                    return;
                }
            }

            var savingArgs = new ContentSavingEventArgs {
                SavingReason = ContentSavingReason.AppClosing
            };

            ContentEditManager <MediaScheduleChangeInfo> .ProcessContentEditChanges(
                Controller.Instance.ContentController.ActiveEditor,
                savingArgs);
        }
 public static void ProcessContentEditChanges(IContentEditControl <TChangeInfo> contentEditor, ContentSavingEventArgs savingArgs)
 {
     if (contentEditor == null)
     {
         return;
     }
     contentEditor.Saving(savingArgs);
     if (savingArgs.Cancel)
     {
         if (savingArgs.ErrorMessages.Any() && savingArgs.SavingReason != ContentSavingReason.AppClosing)
         {
             PopupMessageHelper.Instance.ShowWarning(String.Join(Environment.NewLine, savingArgs.ErrorMessages));
         }
         return;
     }
     contentEditor.Save(savingArgs);
 }
        private void ContentService_Saving(IContentService sender, ContentSavingEventArgs e)
        {
            contentService = sender;
            using (var scope = scopeProvider.CreateScope())
            {
                foreach (var node in e.SavedEntities)
                {
                    var parentNodeId = node.ParentId;


                    // If the document type is a resourceItem
                    if (node.ContentType.Alias == BlogPage.ModelTypeAlias)
                    {
                        string parentModelTypeAlias  = String.Empty;
                        string modelTypeAlias        = String.Empty;
                        string datePropertyTypeAlias = String.Empty;

                        switch (node.ContentType.Alias)
                        {
                        case BlogPage.ModelTypeAlias:
                            modelTypeAlias        = BlogPage.ModelTypeAlias;
                            parentModelTypeAlias  = Section.ModelTypeAlias;
                            datePropertyTypeAlias = BlogPage.GetModelPropertyType(r => r.PublishedDate).Alias;
                            break;

                        default:
                            throw new Exception("Error setting Model/Prop alias");
                        }


                        IContent monthFolder;

                        if (parentNodeId <= 0 && e.CanCancel)
                        {
                            e.CancelOperation(new EventMessage("Error", "Something went wrong with publishing the resource", EventMessageType.Error));
                        }

                        var currentParent = GetCurrentParent(parentNodeId);
                        var date          = node.GetValue <DateTime>(datePropertyTypeAlias);

                        if (date == DateTime.MinValue)
                        {
                            date = DateTime.Today;
                            node.SetValue(datePropertyTypeAlias, date);
                        }
                        var dateYear  = date.ToString("yyyy");
                        var dateMonth = date.ToString("MMMM");

                        if (currentParent.ContentType.Alias == DateFolder.ModelTypeAlias)
                        {
                            bool moveNode = VerifyOrMoveToCorrectLocation(scope, currentParent, dateYear, dateMonth, out monthFolder);

                            if (moveNode)
                            {
                                node.SetParent(monthFolder);
                            }
                        }

                        else if (currentParent.ContentType.Alias == parentModelTypeAlias)
                        {
                            monthFolder = MoveToCorrectLocation(scope, currentParent, dateYear, dateMonth);

                            node.SetParent(monthFolder);
                        }
                    }
                }
                scope.Complete();
            }
        }
 protected virtual void ValidateChanges(ContentSavingEventArgs savingArgs)
 {
     savingArgs.Cancel = false;
 }