private void ParseExistingTemplateForCopying(Guid templateId, out string codeTemplate, out string folderPath)
        {
            var razorTemplate = PageTemplateFacade.GetPageTemplate(templateId) as RazorPageTemplateDescriptor;

            Verify.IsNotNull(razorTemplate, "Failed to get razor template descriptor by id '{0}'", templateId);

            var provider = PageTemplateProviderRegistry.GetProviderByTemplateId(templateId) as RazorPageTemplateProvider;

            Verify.IsNotNull(provider, "Failed to get razor template provider by template id '{0}'", templateId);

            string fullPath = PathUtil.Resolve(razorTemplate.VirtualPath);
            string text     = C1File.ReadAllText(fullPath);



            const string quote = @"""";

            Verify.That(text.IndexOf(templateId.ToString(), StringComparison.OrdinalIgnoreCase) > 0,
                        "Failed to replace existing templateId '{0}'", templateId);

            text = text.Replace(templateId.ToString(), Marker_TemplateId, StringComparison.OrdinalIgnoreCase);

            // Replacing title
            text = text.Replace("@" + quote + razorTemplate.Title.Replace(quote, quote + quote) + quote,
                                quote + Marker_TemplateTitle + quote)
                   .Replace(quote + CSharpEncodeString(razorTemplate.Title) + quote,
                            quote + Marker_TemplateTitle + quote);

            codeTemplate = text;
            folderPath   = Path.GetDirectoryName(fullPath);
        }
Example #2
0
        private void codeActivity2_ExecuteCode(object sender, EventArgs e)
        {
            var entityToken = this.EntityToken;
            ITemplateDeleter templateDeleter = GetPageTemplateDeleter(entityToken);

            string errorMessage = null;

            if (!templateDeleter.CanBeDeleted() || TemplateIsReferenced(templateDeleter.TemplateId, ref errorMessage))
            {
                string message = GetStr("DeletePageTemplateWorkflow.CascadeDeleteErrorMessage");
                if (errorMessage != null)
                {
                    message += " " + errorMessage;
                }

                this.ShowMessage(DialogType.Error,
                                 GetStr("DeletePageTemplateWorkflow.CascadeDeleteErrorTitle"),
                                 message);

                return;
            }

            var parentTreeRefresher = this.CreateParentTreeRefresher();

            parentTreeRefresher.PostRefreshMesseges(EntityToken);

            templateDeleter.DeleteTemplate();
            PageTemplateProviderRegistry.FlushTemplates();
        }
Example #3
0
        /// <summary>
        /// Builds the page renderer.
        /// </summary>
        /// <param name="pageTemplateId">The page template id.</param>
        /// <returns></returns>
        public static IPageRenderer BuildPageRenderer(Guid pageTemplateId)
        {
            var provider = PageTemplateProviderRegistry.GetProviderByTemplateId(pageTemplateId);

            Verify.IsNotNull(provider, "Failed to get page template with id '{0}'. The template may contain errors preventing it to compile. Check the Orckestra CMS log for possible compilation errors.", pageTemplateId);

            return(provider.BuildPageRenderer(pageTemplateId));
        }
        private void saveCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            string[] files = GetFiles();

            var fileContent = new List <string>();

            for (int i = 0; i < files.Length; i++)
            {
                string bindingPrefix = GetBindingPrefix(i);

                fileContent.Add(this.GetBinding <string>(bindingPrefix + "Content"));
            }

            // Fixing html specific escape sequences in .master file
            string fixedMaster       = PageTemplateHelper.FixHtmlEscapeSequences(fileContent[0]);
            bool   viewNeedsUpdating = fileContent[0] != fixedMaster;

            fileContent[0] = fixedMaster;


            EntityToken newEntityToken;

            if (!CompileAndValidate(files, fileContent, out newEntityToken))
            {
                SetSaveStatus(false);
                return;
            }

            for (int i = 0; i < files.Length; i++)
            {
                var websiteFile = new WebsiteFile(files[i]);

                websiteFile.WriteAllText(fileContent[i]);
            }

            PageTemplateProviderRegistry.FlushTemplates();

            if (newEntityToken != null)
            {
                SetSaveStatus(true, newEntityToken);

                SerializedEntityToken = EntityTokenSerializer.Serialize(newEntityToken);
            }
            else
            {
                SetSaveStatus(true);
            }

            if (viewNeedsUpdating)
            {
                UpdateBinding(GetBindingPrefix(0) + "Content", fixedMaster);
                RerenderView();
            }

            this.CreateParentTreeRefresher().PostRefreshMesseges(this.EntityToken);
        }
Example #5
0
        /// <summary>
        /// Gets the page template.
        /// </summary>
        /// <param name="pageTemplateId">The page template id.</param>
        /// <returns></returns>
        public static PageTemplateDescriptor GetPageTemplate(Guid pageTemplateId)
        {
            var provider = PageTemplateProviderRegistry.GetProviderByTemplateId(pageTemplateId);

            if (provider == null)
            {
                return(null);
            }

            return(provider.GetPageTemplates().FirstOrDefault(t => t.Id == pageTemplateId));
        }
        private void Watcher_OnChanged(object sender, FileSystemEventArgs e)
        {
            // Ignoring system and temporary files
            if (e.Name.StartsWith(TempFilePrefix))
            {
                return;
            }

            PageTemplateProviderRegistry.FlushTemplates();
            PageTemplatePreview.ClearCache();
        }
Example #7
0
        private void Watcher_OnChanged(object sender, FileSystemEventArgs e)
        {
            // Ignoring changes to files, not related to master pages, and temporary files
            if (e.Name.StartsWith(TempFilePrefix) ||
                !Regex.IsMatch(e.Name, FileWatcher_Regex, RegexOptions.IgnoreCase))
            {
                return;
            }

            PageTemplateProviderRegistry.FlushTemplates();
            PageTemplatePreview.ClearCache();
        }
Example #8
0
        private void codeActivity2_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            Guid   newTemplateId = Guid.NewGuid();
            string newTitle      = this.GetBinding <string>(Binding_Title);

            string newPageTemplate_Markup, newPageTemplate_Codebehind, templateFolder;

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

            if (copyOfId == Guid.Empty)
            {
                newPageTemplate_Markup     = NewMasterPage_Markup;
                newPageTemplate_Codebehind = NewMasterPage_Codebehind;

                templateFolder = GetMasterPagesRootFolder();
            }
            else
            {
                ParseTemplateForCopying(copyOfId, out newPageTemplate_Markup, out newPageTemplate_Codebehind, out templateFolder);
            }

            string masterFilePath, codeFilePath;

            GenerateFileNames(templateFolder, newTitle, newTemplateId, out masterFilePath, out codeFilePath);

            newPageTemplate_Markup     = newPageTemplate_Markup.Replace(Marker_Codebehind, Path.GetFileName(codeFilePath));
            newPageTemplate_Codebehind = newPageTemplate_Codebehind
                                         .Replace(Marker_TemplateId, newTemplateId.ToString())
                                         .Replace(Marker_TemplateTitle, CSharpEncodeString(newTitle));

            C1File.WriteAllText(codeFilePath, newPageTemplate_Codebehind);
            C1File.WriteAllText(masterFilePath, newPageTemplate_Markup);

            var entityToken = new PageTemplateEntityToken(newTemplateId);

            PageTemplateProviderRegistry.FlushTemplates();

            addNewTreeRefresher.PostRefreshMesseges(entityToken);

            this.ExecuteAction(entityToken, new WorkflowActionToken(typeof(EditMasterPageWorkflow)));
        }
Example #9
0
        private void ParseTemplateForCopying(
            Guid templateId,
            out string markupTemplate,
            out string codebehindTemplate,
            out string templateFolder)
        {
            var masterTemplate = PageTemplateFacade.GetPageTemplate(templateId) as MasterPagePageTemplateDescriptor;

            Verify.IsNotNull(masterTemplate, "Failed to get MasterPagePageTemplateDescriptor by template id '{0}'", templateId);

            var provider = PageTemplateProviderRegistry.GetProviderByTemplateId(templateId) as MasterPagePageTemplateProvider;

            Verify.IsNotNull(provider, "Failed to get MasterPagePageTemplateProvider by template id '{0}'", templateId);

            string markup     = C1File.ReadAllText(masterTemplate.FilePath);
            string codebehind = C1File.ReadAllText(masterTemplate.CodeBehindFilePath);

            string codebehindFileName = Path.GetFileName(masterTemplate.CodeBehindFilePath);

            // Parsing markup
            markup = markup.Replace(codebehindFileName, Marker_Codebehind);

            // Parsing codebehind
            const string quote = @"""";

            Verify.That(codebehind.IndexOf(templateId.ToString(), StringComparison.OrdinalIgnoreCase) > 0,
                        "Failed to replace existing templateId '{0}'", templateId);

            codebehind = codebehind.Replace(templateId.ToString(), Marker_TemplateId, StringComparison.OrdinalIgnoreCase);

            // Replacing title, considering 2 types of encoding
            codebehind = codebehind.Replace("@" + quote + masterTemplate.Title.Replace(quote, quote + quote) + quote,
                                            quote + Marker_TemplateTitle + quote);
            codebehind = codebehind.Replace(quote + CSharpEncodeString(masterTemplate.Title) + quote,
                                            quote + Marker_TemplateTitle + quote);


            markupTemplate     = markup;
            codebehindTemplate = codebehind;
            templateFolder     = Path.GetDirectoryName(masterTemplate.CodeBehindFilePath);
        }
        private void saveCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            string virtualPath = GetFileVirtualPath();
            string filePath    = PathUtil.Resolve(virtualPath);

            WebsiteFile websiteFile = new WebsiteFile(filePath);

            string content     = this.GetBinding <string>("FileContent");
            string fixedSource = PageTemplateHelper.FixHtmlEscapeSequences(content);

            EntityToken newEntityToken;
            bool        isValid = ValidateMarkup(virtualPath, fixedSource, out newEntityToken);

            if (isValid)
            {
                websiteFile.WriteAllText(fixedSource);

                PageTemplateProviderRegistry.FlushTemplates();

                this.CreateParentTreeRefresher().PostRefreshMesseges(this.EntityToken);
            }

            if (isValid && newEntityToken != null)
            {
                SetSaveStatus(true, newEntityToken);

                SerializedEntityToken = EntityTokenSerializer.Serialize(newEntityToken);
            }
            else
            {
                SetSaveStatus(isValid);
            }

            if (isValid && fixedSource != content)
            {
                UpdateBinding("FileContent", fixedSource);
                RerenderView();
            }
        }
        private void codeActivity2_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            Guid   newTemplateId = Guid.NewGuid();
            string newTitle      = this.GetBinding <string>(Binding_Title);

            string newPageTemplateMarkup, folderPath;

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

            if (copyOfId == Guid.Empty)
            {
                newPageTemplateMarkup = DefaultRazorTemplateMarkup;
                folderPath            = GetRazorTemplatesRootFolder();
            }
            else
            {
                ParseExistingTemplateForCopying(copyOfId, out newPageTemplateMarkup, out folderPath);
            }

            newPageTemplateMarkup = newPageTemplateMarkup
                                    .Replace(Marker_TemplateId, newTemplateId.ToString())
                                    .Replace(Marker_TemplateTitle, CSharpEncodeString(newTitle));


            string filePath = GeneratedCshtmlFileName(folderPath, newTitle, newTemplateId);

            C1File.WriteAllText(filePath, newPageTemplateMarkup);

            var entityToken = new PageTemplateEntityToken(newTemplateId);

            PageTemplateProviderRegistry.FlushTemplates();

            addNewTreeRefresher.PostRefreshMesseges(entityToken);

            this.ExecuteAction(entityToken, new WorkflowActionToken(typeof(EditRazorPageTemplateWorkflow)));
        }
        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)));
        }