Inheritance: Composite.C1Console.Security.ActionToken
Exemplo n.º 1
0
        private void saveCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            var updateTreeRefresher = CreateUpdateTreeRefresher(EntityToken);

            var selectedPage = GetBinding<IPage>("SelectedPage");
            var originalPage = DataFacade.GetData<IPage>(f => f.Id == selectedPage.Id && f.VersionId == selectedPage.VersionId).SingleOrDefault();

            var viewLabelUpdated = originalPage == null
                || selectedPage.MenuTitle != originalPage.MenuTitle
                || selectedPage.Title != originalPage.Title;

            var treeviewRequiresRefreshing = false;

            var dataToAdd = new Dictionary<string, IData>();
            var dataToUpdate = new Dictionary<string, IData>();

            var dataValidated = true;

            try
            {
                using (var transactionScope = TransactionsFacade.CreateNewScope())
                {
                    dataValidated = PrepareAddUpdateMetaData(selectedPage, dataToAdd, dataToUpdate);

                    if (dataValidated)
                    {
                        if (selectedPage.PageTypeId != originalPage.PageTypeId)
                        {
                            // Adding metadata fields
                            var oldPageMetaDataDefinitions = originalPage.GetAllowedMetaDataDefinitions().Except(selectedPage.GetAllowedMetaDataDefinitions(), new PageMetaDataDefinitionEqualityComparer());

                            foreach (var pageMetaDataDefinition in oldPageMetaDataDefinitions)
                            {
                                var oldMetaData = selectedPage.GetMetaData(pageMetaDataDefinition.Name, pageMetaDataDefinition.MetaDataTypeId);
                                if (oldMetaData != null)
                                {
                                    ProcessControllerFacade.FullDelete(oldMetaData);
                                }
                            }

                            bool newDataAdded = PageServices.AddPageTypePageFoldersAndApplications(selectedPage);

                            if (newDataAdded)
                            {
                                treeviewRequiresRefreshing = true;
                            }
                        }


                        foreach (var data in dataToAdd.Values)
                        {
                            DataFacade.AddNew(data);
                        }

                        foreach (var data in dataToUpdate.Values)
                        {
                            var publishControlled = data as IPublishControlled;
                            publishControlled.PublicationStatus = GenericPublishProcessController.Draft;

                            DataFacade.Update(data);
                        }

                        treeviewRequiresRefreshing |= (originalPage.Title != selectedPage.Title) ||
                                                   (originalPage.Description != selectedPage.Description) ||
                                                   (originalPage.PublicationStatus != selectedPage.PublicationStatus);

                        // NOTE: updating originalPage object, in order to make XML & SQL provider work in the same way
                        originalPage.TemplateId = selectedPage.TemplateId;
                        originalPage.PageTypeId = selectedPage.PageTypeId;
                        originalPage.Title = selectedPage.Title;
                        originalPage.MenuTitle = selectedPage.MenuTitle;
                        originalPage.UrlTitle = selectedPage.UrlTitle;
                        originalPage.FriendlyUrl = selectedPage.FriendlyUrl;
                        originalPage.Description = selectedPage.Description;
                        originalPage.PublicationStatus = selectedPage.PublicationStatus;
                        originalPage.SourceCultureName = selectedPage.SourceCultureName;
                        DataFacade.Update(originalPage);

                        var contentDictionary = GetBinding<Dictionary<string, string>>("NamedXhtmlFragments");
                        var existingContents = DataFacade.GetData<IPagePlaceholderContent>(f => f.PageId == selectedPage.Id && f.VersionId == selectedPage.VersionId).ToList();

                        foreach (var existingContent in existingContents)
                        {
                            if (contentDictionary.ContainsKey(existingContent.PlaceHolderId))
                            {
                                existingContent.Content = contentDictionary[existingContent.PlaceHolderId];
                                existingContent.PublicationStatus = GenericPublishProcessController.Draft;
                                DataFacade.Update(existingContent);
                            }
                            else
                            {
                                DataFacade.Delete(existingContent);
                            }
                        }

                        foreach (var contentDictionaryElement in contentDictionary.Where(f => existingContents.Any(existing => existing.PlaceHolderId == f.Key) == false))
                        {
                            var newContent = DataFacade.BuildNew<IPagePlaceholderContent>();
                            newContent.PageId = selectedPage.Id;
                            newContent.VersionId = selectedPage.VersionId;
                            newContent.PlaceHolderId = contentDictionaryElement.Key;
                            newContent.Content = contentDictionaryElement.Value;
                            newContent.SourceCultureName = UserSettings.ActiveLocaleCultureInfo.Name;
                            newContent.PublicationStatus = GenericPublishProcessController.Draft;

                            DataFacade.AddNew(newContent);
                        }
                    }

                    transactionScope.Complete();
                }

                if (_doPublish)
                {
                    var actionToken = new GenericPublishProcessController.PublishActionToken();

                    var serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);

                    ActionExecutorFacade.Execute(EntityToken, actionToken, serviceContainer);

                    treeviewRequiresRefreshing = false;
                }

                if (treeviewRequiresRefreshing)
                {
                    updateTreeRefresher.PostRefreshMesseges(selectedPage.GetDataEntityToken());
                }

                UpdateBinding("OldPublicationStatus", selectedPage.PublicationStatus);

                if (viewLabelUpdated)
                {
                    RerenderView();
                }
            }
            catch (Exception ex)
            {
                var mostSpecificException = ex;
                while (mostSpecificException.InnerException != null) mostSpecificException = mostSpecificException.InnerException;
                ShowMessage(DialogType.Error, "Save failed", $"Save failed: {mostSpecificException.Message}");
                Log.LogError("Page save", ex);
            }
            finally
            {
                SetSaveStatus(dataValidated);
            }
        }
Exemplo n.º 2
0
        public static bool PublishIfNeeded(IData data, bool doPublish, IDictionary<string, object> binding, Action<DialogType, string, string> messageAction)
        {
            if (!(data is IPublishControlled))
            {
                return false;
            }

            WorkflowInstance publishWorkflowInstance = null;
            WorkflowInstance unpublishWorkflowInstance = null;

            var publishDate = binding.ContainsKey("PublishDate") ? (DateTime?)binding["PublishDate"] : null;
            var unpublishDate = binding.ContainsKey("UnpublishDate") ? (DateTime?)binding["UnpublishDate"] : null;

            string cultureName = UserSettings.ActiveLocaleCultureInfo.Name;
            HandlePublishUnpublishWorkflows(data, cultureName, publishDate, unpublishDate, ref publishWorkflowInstance, ref unpublishWorkflowInstance);

            if (publishWorkflowInstance != null)
            {
                publishWorkflowInstance.Start();

                WorkflowFacade.RunWorkflow(publishWorkflowInstance);
            }

            if (unpublishWorkflowInstance != null)
            {
                unpublishWorkflowInstance.Start();

                WorkflowFacade.RunWorkflow(unpublishWorkflowInstance);
            }

            if (!doPublish)
            {
                return false;
            }

            if (publishWorkflowInstance == null || publishDate < DateTime.Now)
            {
                var actionToken = new GenericPublishProcessController.PublishActionToken();
                var serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);

                ActionExecutorFacade.Execute(data.GetDataEntityToken(), actionToken, serviceContainer);

                return true;
            }

            var title = Texts.Website_Forms_Administrative_EditPage_PublishDatePreventPublishTitle;
            var message = Texts.Website_Forms_Administrative_EditPage_PublishDatePreventPublish;

            messageAction(DialogType.Warning, title, message);

            return false;
        }
Exemplo n.º 3
0
        private void saveCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            var updateTreeRefresher = CreateUpdateTreeRefresher(EntityToken);

            var selectedPage = GetBinding<IPage>("SelectedPage");
            var originalPage = DataFacade.GetData<IPage>(f => f.Id == selectedPage.Id).SingleOrDefault();

            var viewLabelUpdated = originalPage == null
                || selectedPage.MenuTitle != originalPage.MenuTitle
                || selectedPage.Title != originalPage.Title;

            var treeviewRequiresRefreshing = false;

            var dataToAdd = new Dictionary<string, IData>();
            var dataToUpdate = new Dictionary<string, IData>();

            var dataValidated = true;

            WorkflowInstance publishWorkflowInstance = null;
            WorkflowInstance unpublishWorkflowInstance = null;

            try
            {
                using (var transactionScope = TransactionsFacade.CreateNewScope())
                {
                    dataValidated = PrepareAddUpdateMetaData(selectedPage, dataToAdd, dataToUpdate);

                    if (dataValidated)
                    {
                        PublishControlledHelper.HandlePublishUnpublishWorkflows(selectedPage, UserSettings.ActiveLocaleCultureInfo.Name, PublishDate, UnpublishDate, ref publishWorkflowInstance, ref unpublishWorkflowInstance);

                        if (selectedPage.PageTypeId != originalPage.PageTypeId)
                        {
                            // Adding metadata fields
                            var oldPageMetaDataDefinitions = originalPage.GetAllowedMetaDataDefinitions().Except(selectedPage.GetAllowedMetaDataDefinitions(), new PageMetaDataDefinitionEqualityComparer());

                            foreach (var pageMetaDataDefinition in oldPageMetaDataDefinitions)
                            {
                                var oldMetaData = selectedPage.GetMetaData(pageMetaDataDefinition.Name, pageMetaDataDefinition.MetaDataTypeId);
                                if (oldMetaData != null)
                                {
                                    ProcessControllerFacade.FullDelete(oldMetaData);
                                }
                            }


                            // Adding page folders
                            var pageTypeDataFolderTypeLinks =
                                DataFacade.GetData<IPageTypeDataFolderTypeLink>().
                                Where(f => f.PageTypeId == selectedPage.PageTypeId).
                                Evaluate().
                                RemoveDeadLinks();

                            foreach (var pageTypeDataFolderTypeLink in pageTypeDataFolderTypeLinks)
                            {
                                if (selectedPage.GetFolderDefinitionId(pageTypeDataFolderTypeLink.DataTypeId) != Guid.Empty) continue;

                                selectedPage.AddFolderDefinition(pageTypeDataFolderTypeLink.DataTypeId);
                                treeviewRequiresRefreshing = true;
                            }



                            // Adding applications
                            var pageTypeTreeLinks =
                                DataFacade.GetData<IPageTypeTreeLink>().
                                Where(f => f.PageTypeId == selectedPage.PageTypeId).
                                Evaluate().
                                RemoveDeadLinks();

                            foreach (var pageTypeTreeLink in pageTypeTreeLinks)
                            {
                                var tree = TreeFacade.GetTree(pageTypeTreeLink.TreeId);
                                if (tree.HasAttachmentPoints(selectedPage.GetDataEntityToken())) continue;

                                TreeFacade.AddPersistedAttachmentPoint(pageTypeTreeLink.TreeId, typeof(IPage), selectedPage.Id);
                                treeviewRequiresRefreshing = true;
                            }
                        }


                        foreach (var data in dataToAdd.Values)
                        {
                            DataFacade.AddNew(data);
                        }

                        foreach (var data in dataToUpdate.Values)
                        {
                            var publishControlled = data as IPublishControlled;
                            publishControlled.PublicationStatus = GenericPublishProcessController.Draft;

                            DataFacade.Update(data);
                        }

                        treeviewRequiresRefreshing |= (originalPage.Title != selectedPage.Title) ||
                                                   (originalPage.Description != selectedPage.Description) ||
                                                   (originalPage.PublicationStatus != selectedPage.PublicationStatus);

                        // NOTE: updating originalPage object, in order to make XML & SQL provider work in the same way
                        originalPage.TemplateId = selectedPage.TemplateId;
                        originalPage.PageTypeId = selectedPage.PageTypeId;
                        originalPage.Title = selectedPage.Title;
                        originalPage.MenuTitle = selectedPage.MenuTitle;
                        originalPage.UrlTitle = selectedPage.UrlTitle;
                        originalPage.FriendlyUrl = selectedPage.FriendlyUrl;
                        originalPage.Description = selectedPage.Description;
                        originalPage.PublicationStatus = selectedPage.PublicationStatus;
                        originalPage.SourceCultureName = selectedPage.SourceCultureName;
                        DataFacade.Update(originalPage);

                        var contentDictionary = GetBinding<Dictionary<string, string>>("NamedXhtmlFragments");
                        var existingContents = DataFacade.GetData<IPagePlaceholderContent>(f => f.PageId == selectedPage.Id).ToList();

                        foreach (var existingContent in existingContents)
                        {
                            if (contentDictionary.ContainsKey(existingContent.PlaceHolderId))
                            {
                                existingContent.Content = contentDictionary[existingContent.PlaceHolderId];
                                existingContent.PublicationStatus = GenericPublishProcessController.Draft;
                                DataFacade.Update(existingContent);
                            }
                            else
                            {
                                DataFacade.Delete(existingContent);
                            }
                        }

                        foreach (var contentDictionaryElement in contentDictionary.Where(f => existingContents.Any(existing => existing.PlaceHolderId == f.Key) == false))
                        {
                            var newContent = DataFacade.BuildNew<IPagePlaceholderContent>();
                            newContent.PageId = selectedPage.Id;
                            newContent.PlaceHolderId = contentDictionaryElement.Key;
                            newContent.Content = contentDictionaryElement.Value;
                            newContent.SourceCultureName = UserSettings.ActiveLocaleCultureInfo.Name;
                            newContent.PublicationStatus = GenericPublishProcessController.Draft;

                            DataFacade.AddNew(newContent);
                        }
                    }

                    transactionScope.Complete();
                }

                if (publishWorkflowInstance != null)
                {
                    publishWorkflowInstance.Start();
                    WorkflowFacade.RunWorkflow(publishWorkflowInstance);
                }

                if (unpublishWorkflowInstance != null)
                {
                    unpublishWorkflowInstance.Start();
                    WorkflowFacade.RunWorkflow(unpublishWorkflowInstance);
                }

                if (_doPublish)
                {
                    if (publishWorkflowInstance == null || PublishDate < DateTime.Now)
                    {
                        var actionToken = new GenericPublishProcessController.PublishActionToken();

                        var serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);

                        ActionExecutorFacade.Execute(EntityToken, actionToken, serviceContainer);

                        treeviewRequiresRefreshing = false;
                    }
                    else
                    {
                        var title = StringResourceSystemFacade.GetString("Composite.Management", "Website.Forms.Administrative.EditPage.PublishDatePreventPublishTitle");
                        var message = StringResourceSystemFacade.GetString("Composite.Management", "Website.Forms.Administrative.EditPage.PublishDatePreventPublish");
                        ShowMessage(DialogType.Warning, title, message);
                    }
                }

                if (treeviewRequiresRefreshing)
                {
                    updateTreeRefresher.PostRefreshMesseges(selectedPage.GetDataEntityToken());
                }

                UpdateBinding("OldPublicationStatus", selectedPage.PublicationStatus);

                if (viewLabelUpdated)
                {
                    RerenderView();
                }
            }
            catch (Exception ex)
            {
                var mostSpecificException = ex;
                while (mostSpecificException.InnerException != null) mostSpecificException = mostSpecificException.InnerException;
                ShowMessage(DialogType.Error, "Save failed", string.Format("Save failed: {0}", mostSpecificException.Message));
                Log.LogError("Page save", ex);
            }
            finally
            {
                SetSaveStatus(dataValidated);
            }
        }