Exemplo n.º 1
0
        protected virtual void DeleteChildrenCategories(IPage page)
        {
            var children = page.GetChildren().Where(p => p.PageTypeId == CategoryPages.CategoryPageTypeId || p.PageTypeId == CategoryPages.CategoryLandingPageTypeId).ToArray();

            foreach (var child in children)
            {
                DeleteChildrenCategories(child);
            }

            //if (!ExistInOtherLocale(GetCultures(), page))
            //	RemoveAllFolderAndMetaDataDefinitions(page);

            page.DeletePageStructure();
            ProcessControllerFacade.FullDelete(page);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deletes the versions of the given page in its current localization scope.
        /// </summary>
        public static void DeletePage(IPage page)
        {
            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                using (var conn = new DataConnection())
                {
                    conn.DisableServices();

                    var cultures = DataLocalizationFacade.ActiveLocalizationCultures.ToList();
                    cultures.Remove(page.DataSourceId.LocaleScope);

                    List <IPage> pagesToDelete = page.GetSubChildren().ToList();

                    foreach (IPage childPage in pagesToDelete)
                    {
                        if (!ExistInOtherLocale(cultures, childPage))
                        {
                            RemoveAllFolderAndMetaDataDefinitions(childPage);
                        }

                        childPage.DeletePageStructure(false);
                        ProcessControllerFacade.FullDelete(childPage);
                    }


                    if (!ExistInOtherLocale(cultures, page))
                    {
                        RemoveAllFolderAndMetaDataDefinitions(page);
                    }

                    page.DeletePageStructure();

                    Guid pageId       = page.Id;
                    var  pageVersions = DataFacade.GetData <IPage>(p => p.Id == pageId).ToList();

                    ProcessControllerFacade.FullDelete(pageVersions);
                }

                transactionScope.Complete();
            }
        }
Exemplo n.º 3
0
        private void finalizeCodeActivity_DeteleData_ExecuteCode(object sender, System.EventArgs e)
        {
            DeleteTreeRefresher deleteTreeRefresher = this.CreateDeleteTreeRefresher(this.EntityToken);

            IData data = ((DataEntityToken)this.EntityToken).Data;

            if (DataFacade.WillDeleteSucceed(data))
            {
                ProcessControllerFacade.FullDelete(data);

                deleteTreeRefresher.PostRefreshMesseges(true);
            }
            else
            {
                this.ShowMessage(
                    DialogType.Error,
                    StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "TreeGenericDelete.CascadeDeleteErrorTitle"),
                    StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "TreeGenericDelete.CascadeDeleteErrorMessage")
                    );
            }
        }
Exemplo n.º 4
0
            public void DeleteTemplate()
            {
                IFile file = IFileServices.GetFile <IPageTemplateFile>(_pageTemplate.PageTemplateFilePath);

                ProcessControllerFacade.FullDelete(_pageTemplate);

                if (file != null && file is FileSystemFileBase)
                {
                    FileSystemFileBase baseFile = file as FileSystemFileBase;
                    C1File.Delete(baseFile.SystemPath);

                    try
                    {
                        C1File.Delete(baseFile.SystemPath);
                    }
                    catch
                    {
                        LoggingService.LogWarning(LogTitle, "Failed to delete page template file: '{0}'".FormatWith(baseFile.SystemPath));
                    }
                }
            }
Exemplo n.º 5
0
        private void codeActivity2_ExecuteCode(object sender, EventArgs e)
        {
            bool hasSubPages = this.GetBinding <bool>("HasSubPages");

            DataEntityToken dataEntityToken = (DataEntityToken)this.EntityToken;
            IPage           selectedPage    = (IPage)dataEntityToken.Data;

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                if (DataFacade.WillDeleteSucceed <IPage>(selectedPage) == false)
                {
                    this.ShowMessage(
                        DialogType.Error,
                        StringResourceSystemFacade.GetString("Composite.Plugins.PageElementProvider", "DeletePageWorkflow.CascadeDeleteErrorTitle"),
                        StringResourceSystemFacade.GetString("Composite.Plugins.PageElementProvider", "DeletePageWorkflow.CascadeDeleteErrorMessage")
                        );

                    return;
                }

                List <CultureInfo> cultures = DataLocalizationFacade.ActiveLocalizationCultures.ToList();
                cultures.Remove(selectedPage.DataSourceId.LocaleScope);

                if (hasSubPages)
                {
                    List <IPage> pagesToDelete = selectedPage.GetSubChildren().ToList();

                    foreach (IPage page in pagesToDelete)
                    {
                        if (DataFacade.WillDeleteSucceed <IPage>(page) == false)
                        {
                            this.ShowMessage(
                                DialogType.Error,
                                StringResourceSystemFacade.GetString("Composite.Plugins.PageElementProvider", "DeletePageWorkflow.CascadeDeleteErrorTitle"),
                                StringResourceSystemFacade.GetString("Composite.Plugins.PageElementProvider", "DeletePageWorkflow.CascadeDeleteErrorMessage")
                                );

                            return;
                        }
                    }

                    foreach (IPage page in pagesToDelete)
                    {
                        if (ExistInOtherLocale(cultures, page) == false)
                        {
                            RemoveAllFolderAndMetaDataDefinitions(page);
                        }

                        page.DeletePageStructure();
                        ProcessControllerFacade.FullDelete(page);
                    }
                }

                if (ExistInOtherLocale(cultures, selectedPage) == false)
                {
                    RemoveAllFolderAndMetaDataDefinitions(selectedPage);
                }

                ParentTreeRefresher parentTreeRefresher = this.CreateParentTreeRefresher();
                parentTreeRefresher.PostRefreshMesseges(selectedPage.GetDataEntityToken(), 2);

                selectedPage.DeletePageStructure();
                ProcessControllerFacade.FullDelete(selectedPage);

                transactionScope.Complete();
            }
        }
Exemplo n.º 6
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.º 7
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);
            }
        }