private void ProcessTransformations(int classId, string className) { // Get the transformations DataSet transformationsDS = TransformationInfoProvider.GetTransformations(classId); if (!DataHelper.DataSourceIsEmpty(transformationsDS)) { foreach (DataRow transformationRow in transformationsDS.Tables[0].Rows) { // Get the type string type = ValidationHelper.GetString(transformationRow["TransformationType"], "ascx"); TransformationTypeEnum transformationType = TransformationInfoProvider.GetTransformationTypeEnum(type); // Only export ASCX transformations if (transformationType == TransformationTypeEnum.Ascx) { string transformationName = ValidationHelper.GetString(transformationRow["TransformationName"], ""); string transformationCode = ValidationHelper.GetString(transformationRow["TransformationCode"], ""); int checkedOutByUserId = ValidationHelper.GetInteger(transformationRow["TransformationCheckedOutByUserID"], 0); string checkedOutMachineName = ValidationHelper.GetString(transformationRow["TransformationCheckedOutMachineName"], ""); if ((checkedOutByUserId == 0) || (checkedOutMachineName.ToLower() != HTTPHelper.MachineName.ToLower())) { string filename = TransformationInfoProvider.GetTransformationUrl(className + "." + transformationName, null, TransformationTypeEnum.Ascx); // Prepare the code string code = transformationCode; code = TransformationInfoProvider.AddTransformationDirectives(code, true); SiteManagerFunctions.SaveCodeFile(filename, code); } } } } }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); bool editingEnabled = true; bool isAscx = (drpType.SelectedValue.ToLower() == "ascx"); // Disable items when virtual path provider is disabled if (!SettingsKeyProvider.UsingVirtualPathProvider && (ti != null)) { if (isAscx) { lblVirtualInfo.Text = string.Format(GetString("Transformation.VirtualPathProviderNotRunning"), TransformationInfoProvider.GetTransformationUrl(ti.TransformationFullName, null, TransformationTypeEnum.Ascx)); plcVirtualInfo.Visible = true; editingEnabled = false; txtCSS.Enabled = false; } tbWysiwyg.Enabled = !isAscx; pnlCheckOutInfo.Visible = false; } string info = null; // Setup the information and code type if (isAscx) { txtCode.Editor.Language = LanguageEnum.ASPNET; txtCode.UseAutoComplete = false; // Check the edit code permission if (!user.IsAuthorizedPerResource("CMS.Design", "EditCode")) { editingEnabled = false; info = ResHelper.GetString("EditCode.NotAllowed"); ltlDirectives.Visible = false; } } else { txtCode.Editor.Language = LanguageEnum.HTMLMixed; txtCode.UseAutoComplete = true; } if (!String.IsNullOrEmpty(info)) { lblTransformationInfo.Text = info; } lblTransformationInfo.Visible = !String.IsNullOrEmpty(lblTransformationInfo.Text); this.plcInfo.Visible = isAscx; this.txtCode.ReadOnly = !editingEnabled; }
protected void drpTransformationType_SelectedIndexChanged(object sender, EventArgs e) { UpdateDirectives(); if (ti.TransformationCheckedOutByUserID <= 0) { // Show checkout info corresponding to selected type TransformationTypeEnum type = TransformationInfoProvider.GetTransformationTypeEnum(drpType.SelectedValue); string path = Server.MapPath(TransformationInfoProvider.GetTransformationUrl(ti.TransformationFullName, null, type)); lblCheckOutInfo.Text = string.Format(GetString("Transformation.CheckOutInfo"), path); } // Get the current code string code = ""; if (txtCode.Visible) { code = this.txtCode.Text; } else { code = this.tbWysiwyg.ResolvedValue; } switch (drpType.SelectedValue.ToLower()) { case "ascx": // Convert to ASCX syntax if (string.Equals(drpType.SelectedValue, "ascx", StringComparison.OrdinalIgnoreCase)) { code = MacroResolver.RemoveSecurityParameters(code, false, null); code = code.Replace("{% Register", "<%@ Register").Replace("{%", "<%#").Replace("%}", "%>"); } break; case "xslt": // No transformation break; default: // Convert to macro syntax code = code.Replace("<%@", "{%").Replace("<%#", "{%").Replace("<%=", "{%").Replace("<%", "{%").Replace("%>", "%}"); break; } // Move the content if necessary if (string.Equals(drpType.SelectedValue, "html", StringComparison.OrdinalIgnoreCase)) { // Move from text to WYSIWYG if (txtCode.Visible) { this.tbWysiwyg.ResolvedValue = code; this.tbWysiwyg.Visible = true; this.txtCode.Text = string.Empty; this.txtCode.Visible = false; } } else { // Move from WYSIWYG to text if (tbWysiwyg.Visible) { code = HttpUtility.HtmlDecode(code); this.txtCode.Text = code; this.txtCode.Visible = true; this.tbWysiwyg.ResolvedValue = string.Empty; this.tbWysiwyg.Visible = false; } else { this.txtCode.Text = code; } } }
protected void Page_Init(object sender, EventArgs e) { mTransformationName = GetString("DocumentType_Edit_Transformation_Edit.NewTransformation"); GetParameters(); user = CMSContext.CurrentUser; // Get CMS master page mCurrentMaster = Page.Master as CMSMasterPage; // Check master page if (mCurrentMaster == null) { throw new Exception("Page using this control must have CMSMasterPage master page."); } // Initializes validator RequiredFieldValidatorTransformationName.ErrorMessage = GetString("DocumentType_Edit_Transformation_Edit.TransformationNameRequired"); // Initializes labels LabelsInit(); // Initialize drop down list DropDownListInit(); // Init transformation help link lnkHelp.NavigateUrl = helpElem.DocumentationUrl + "newedit_transformation_methods.htm"; lnkHelp.Target = "_target"; // Init transofrmation help icon helpElem.HelpName = "helpTopic"; helpElem.TopicName = "newedit_transformation_methods"; if (transformationId <= 0) { mCurrentMaster.Title.HelpTopicName = "newedit_transformation"; mCurrentMaster.Title.HelpName = "helpTopic"; } // Page has been opened in CMSDesk and only transformation code editing is allowed if (DialogMode) { // Sets dialog mode and validates input (return in case of error) if (SetDialogMode()) { return; } } else { if (transformationId <= 0) { // Initializes PageTitle string transformations = GetString("DocumentType_Edit_Transformation_Edit.Transformations"); string[,] pageTitleTabs = new string[2, 3]; pageTitleTabs[0, 0] = transformations; pageTitleTabs[0, 1] = string.Format("{0}?{1}={2}", ListPage, ParameterName, mClassId); pageTitleTabs[1, 0] = mTransformationName; mCurrentMaster.Title.Breadcrumbs = pageTitleTabs; } } if (UseClassSelector) { plcDocTypeFilter.Visible = true; filter.IsLiveSite = IsLiveSite; } if (ti.TransformationID != 0) { if (ti.TransformationCheckedOutByUserID > 0) { // Disable textboxes when disabled txtCode.Editor.ReadOnly = false; txtCSS.Enabled = false; string username = null; UserInfo ui = UserInfoProvider.GetUserInfo(ti.TransformationCheckedOutByUserID); if (ui != null) { username = HTMLHelper.HTMLEncode(ui.FullName); } // Checked out by current machine if (string.Equals(ti.TransformationCheckedOutMachineName, HTTPHelper.MachineName, StringComparison.OrdinalIgnoreCase)) { lblCheckOutInfo.Text = string.Format(GetString("Transformation.CheckedOut"), Server.MapPath(ti.TransformationCheckedOutFilename)); } else { lblCheckOutInfo.Text = string.Format(GetString("Transformation.CheckedOutOnAnotherMachine"), ti.TransformationCheckedOutMachineName, username); } } else { lblCheckOutInfo.Text = string.Format(GetString("Transformation.CheckOutInfo"), Server.MapPath(TransformationInfoProvider.GetTransformationUrl(ti.TransformationFullName, null, ti.TransformationType))); } } pnlCheckOutInfo.Visible = (transformationId > 0); InitHeaderActions(ti); // Hide generate button DDL for code if not coupled document or custom table if (!string.IsNullOrEmpty(mClassName)) { DataClassInfo classInfo = DataClassInfoProvider.GetDataClass(mClassName); // Set corret help topic for custom tables if (classInfo.ClassIsCustomTable) { mCurrentMaster.Title.HelpTopicName = "customtable_edit_newedit_transformation"; } if ((classInfo.ClassIsCustomTable) || (classInfo.ClassIsDocumentType && classInfo.ClassIsCoupledClass)) { btnDefaultTransformation.Visible = true; // Hide code definition DDL if XSLT transformation type is selected drpTransformationCode.Visible = (drpType.SelectedValue == TransformationTypeEnum.Ascx.ToString()); } else { drpTransformationCode.Visible = false; btnDefaultTransformation.Visible = false; } } this.txtCode.Editor.Width = new Unit("99%"); this.txtCode.Editor.Height = new Unit("300px"); this.txtCode.NamespaceUsings = new List <string>() { "Transformation" }; }