private void codeActivity2_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            IXmlPageTemplate newPageTemplate = this.GetBinding <IXmlPageTemplate>("NewPageTemplate");

            string newPageTemplateMarkup = null;
            Guid   copyOfId = this.GetBinding <Guid>("CopyOfId");

            if (copyOfId == Guid.Empty)
            {
                newPageTemplateMarkup = _defaultTemplateMarkup.Replace("    ", "\t");
            }
            else
            {
                XDocument copyDocument = TemplateInfo.GetTemplateDocument(copyOfId);
                newPageTemplateMarkup = copyDocument.ToString();
            }

            IPageTemplateFile pageTemplateFile = DataFacade.BuildNew <IPageTemplateFile>();

            pageTemplateFile.FolderPath = "/";
            pageTemplateFile.FileName   = string.Format("{0}.xml", PathUtil.CleanFileName(newPageTemplate.Title, true) ?? newPageTemplate.Id.ToString());
            //if (FileNameAlreadyUsed(pageTemplateFile)) pageTemplateFile.FileName = newPageTemplate.Id.ToString() + pageTemplateFile.FileName;
            pageTemplateFile.SetNewContent(newPageTemplateMarkup);

            DataFacade.AddNew <IPageTemplateFile>(pageTemplateFile, "PageTemplateFileProvider");

            newPageTemplate.PageTemplateFilePath = "/" + pageTemplateFile.FileName;
            newPageTemplate = DataFacade.AddNew <IXmlPageTemplate>(newPageTemplate);

            PageTemplateProviderRegistry.FlushTemplates();

            addNewTreeRefresher.PostRefreshMesseges(newPageTemplate.GetDataEntityToken());

            this.ExecuteAction(newPageTemplate.GetDataEntityToken(), new WorkflowActionToken(typeof(EditXmlPageTemplateWorkflow)));
        }
Ejemplo n.º 2
0
 public override C1Console.Security.EntityToken GetEntityToken()
 {
     return(_xmlPageTemplate.GetDataEntityToken());
 }
        private void codeActivity1_ExecuteCode(object sender, EventArgs e)
        {
            IXmlPageTemplate pageTemplate       = this.GetBinding <IXmlPageTemplate>("PageTemplate");
            string           pageTemplateMarkup = this.GetBinding <string>("PageTemplateMarkup");

            bool   xhtmlParseable = true;
            string parseError     = null;

            try
            {
                XDocument parsedElement = XDocument.Parse(pageTemplateMarkup);

                ValidatePageTemplate(parsedElement);
            }
            catch (Exception ex)
            {
                xhtmlParseable = false;
                parseError     = ex.Message;
            }

            if (!xhtmlParseable)
            {
                FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);
                var consoleMessageService = serviceContainer.GetService <IManagementConsoleMessageService>();
                consoleMessageService.ShowMessage(
                    DialogType.Error,
                    GetString("EditXmlPageTemplateWorkflow.InvalidXmlTitle"),
                    GetString("EditXmlPageTemplateWorkflow.InvalidXmlMessage").FormatWith(parseError));
                return;
            }

            // Renaming related file if necessary
            string fileName = GetTemplateFileName(pageTemplate);

            if (Path.GetFileName(pageTemplate.PageTemplateFilePath) != fileName)
            {
                IPageTemplateFile file          = IFileServices.GetFile <IPageTemplateFile>(pageTemplate.PageTemplateFilePath);
                string            systemPath    = (file as FileSystemFileBase).SystemPath;
                string            newSystemPath = Path.Combine(Path.GetDirectoryName(systemPath), fileName);

                if (string.Compare(systemPath, newSystemPath, true) != 0 && C1File.Exists(newSystemPath))
                {
                    FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);
                    var consoleMessageService = serviceContainer.GetService <IManagementConsoleMessageService>();
                    consoleMessageService.ShowMessage(
                        DialogType.Error,
                        GetString("EditXmlPageTemplateWorkflow.InvalidXmlTitle"),
                        GetString("EditXmlPageTemplateWorkflow.CannotRenameFileExists").FormatWith(newSystemPath));
                    return;
                }

                C1File.Move(systemPath, newSystemPath);

                string newRelativePath = Path.Combine(Path.GetDirectoryName(pageTemplate.PageTemplateFilePath), fileName);
                pageTemplate.PageTemplateFilePath = newRelativePath;
            }

            IPageTemplateFile templateFile = IFileServices.GetFile <IPageTemplateFile>(pageTemplate.PageTemplateFilePath);

            templateFile.SetNewContent(pageTemplateMarkup);
            DataFacade.Update(templateFile);

            DataFacade.Update(pageTemplate);

            UpdateTreeRefresher updateTreeRefresher = this.CreateUpdateTreeRefresher(this.EntityToken);

            updateTreeRefresher.PostRefreshMesseges(pageTemplate.GetDataEntityToken());

            SetSaveStatus(true);
        }