void wizard_ButtonClick(object sender, BXPageAsDialogButtonClickEventArgs e) { try { if (!BXUser.IsCanOperate(BXRoleOperation.Operations.FileManage)) { Close(GetMessage("ACCESS_DENIED"), BXDialogGoodbyeWindow.LayoutType.Error, -1); return; } if (!IsValid) return; if (e.ButtonEntry != BXPageAsDialogButtonEntry.Done) return; if (string.IsNullOrEmpty(_clientFileName)) { ShowError(GetMessage("EmptyFileName")); return; } string initClientFileName = _clientFileName; if (_clientFileName.EndsWith(".")) _clientFileName = _clientFileName.Remove(_clientFileName.Length - 1); string fnExt = VirtualPathUtility.GetExtension(_clientFileName); if (string.IsNullOrEmpty(fnExt)) { _clientFileName = string.Format("{0}.aspx", _clientFileName); } else if (string.Compare(fnExt, ".aspx", StringComparison.Ordinal) != 0) { _clientFileName = string.Format("{0}.aspx", _clientFileName); } //имя string pageNameExtensionless = _clientFileName.Remove(_clientFileName.Length - 5); tbxPageName.Text = pageNameExtensionless; _clientVirtualPath = VirtualPathUtility.Combine(VirtualPathUtility.AppendTrailingSlash(_clientVirtualDirPath), _clientFileName); if (BXSecureIO.FileExists(_clientVirtualPath)) { ShowError(String.Format("{0}: {1}", GetMessage("FileAlreadyExists"), _clientVirtualPath)); return; } string menuTypeId = null; MenuTypeInfo info = null; if (chbxAddToMenu.Checked && ((info = CheckMenuTypeInfo(out menuTypeId)) == null || menuTypeId == null)) { ShowError(GetMessageRaw("Error.YourAccountDontHasTheRightToModifyMenu")); return; } string content = Bitrix.Services.Text.BXDefaultFiles.BuildAspx(!string.IsNullOrEmpty(tbxTitle.Text) ? Encode(tbxTitle.Text) : GetMessage("NoTitle"), _clientVirtualPath, null); Bitrix.DataTypes.BXParamsBag<string> keywordBag = new Bitrix.DataTypes.BXParamsBag<string>(); foreach (string keywordKey in _keywords.Keys) { if (!IsKeywordValueChanged(keywordKey)) continue; string keywordValue = string.Empty; _keywords[keywordKey].TryGetValue("value", out keywordValue); if (string.IsNullOrEmpty(keywordValue)) continue; keywordBag.Add(keywordKey, keywordValue); } content = BXParser.PersistPageKeywords(content, keywordBag); BXSecureIO.FileWriteAllText(_clientVirtualPath, content, Bitrix.Configuration.BXConfigurationUtility.DefaultEncoding); if (chbxAddToMenu.Checked) AddToMenu(menuTypeId, info, pageNameExtensionless); BXUndoPageCreationOperation undoOperation = new BXUndoPageCreationOperation(); undoOperation.FileVirtualPath = _clientVirtualPath; undoOperation.MenuTypeId = menuTypeId; BXUndoInfo undo = new BXUndoInfo(); undo.Operation = undoOperation; undo.Save(); BXDialogGoodbyeWindow goodbye = new BXDialogGoodbyeWindow(string.Format( GetMessageRaw("NewPageIsSuccessfullyCreated"), string.Concat(undo.GetClientScript(), " return false;"), "#"), -1, BXDialogGoodbyeWindow.LayoutType.Success); BXDialogGoodbyeWindow.SetCurrent(goodbye); if (chbxEditAfterSave.Checked) { BXDialogSettings dlgSetting = new BXDialogSettings(); dlgSetting.Height = 604; dlgSetting.Width = 968; dlgSetting.MinHeight = 400; dlgSetting.MinWidth = 780; SwitchToDialog(string.Format("{0}?path={1}&clientType=WindowManager&forcedRedirection=&noundo=", VirtualPathUtility.ToAbsolute("~/bitrix/dialogs/VisualPageEditor.aspx"), HttpUtility.UrlEncode(_clientVirtualPath)), dlgSetting, GetMessage("NewPageIsSuccessfullyCreatedShowEditDialog"), BXDialogGoodbyeWindow.LayoutType.Success, 2000); return; } Redirect(BXSite.GetUrlForPath(_clientVirtualPath, null), string.Empty, BXDialogGoodbyeWindow.LayoutType.Success); return; } catch (System.Threading.ThreadAbortException) { //...игнорируем, вызвано Close(); } catch (Exception ex) { Close(ex.Message, BXDialogGoodbyeWindow.LayoutType.Error, -1); } }
protected void Behaviour_Save(object sender, EventArgs e) { BXUser.DemandOperations(BXRoleOperation.Operations.ProductSettingsManage); if(!IsValid || ErrorsCount > 0) return; try { #region Processing of the template string siteTemplateName = GetOwnerSiteTemplateName(); string sourcePath = string.IsNullOrEmpty(siteTemplateName) ? BXPath.Combine( GetComponentTemplatesPath(null), TemplateName ) : BXPath.Combine( GetSiteComponentTemplatesPath(siteTemplateName, null), TemplateName ); string destinationSiteTemplateName = SiteTemplateNameForNewItem; string destinationSiteTemplatePath = GetSiteTemplatePath(destinationSiteTemplateName); if (!BXSecureIO.DirectoryExists(destinationSiteTemplatePath)) { ShowError(string.Format(GetMessageRaw("ERROR_FORMATTED_SITE_TEMPLATE_IS_NOT_FOUND"), destinationSiteTemplateName)); return; } string destinationPath = BXPath.Combine( GetSiteComponentTemplatesPath(destinationSiteTemplateName, null), NameForNewItem ); if (BXSecureIO.DirectoryExists(destinationPath)) { ShowError(string.Format(GetMessageRaw("ERROR_FORMATTED_COMPONENT_TEMPLATE_ALREADY_EXISTS"), NameForNewItem, destinationSiteTemplateName)); return; } BXSecureIO.DirectoryCopy(sourcePath, destinationPath); #endregion BXUndoCTCopyOperation undo = new BXUndoCTCopyOperation(); undo.TemplateVirtualPath = VirtualPathUtility.AppendTrailingSlash(destinationPath); #region Processing of dependencies string dependenciesFileName = "dependencies.config"; string dependenciesFilePath = VirtualPathUtility.Combine( VirtualPathUtility.AppendTrailingSlash(destinationPath), dependenciesFileName ); if (BXSecureIO.FileExists(dependenciesFilePath)) { List<Dictionary<string, string>> dependencyList = null; using (TextReader tr = BXSecureIO.FileReadToTextReader(dependenciesFilePath)) { XmlReaderSettings xrSettings = new XmlReaderSettings(); xrSettings.IgnoreComments = true; xrSettings.IgnoreProcessingInstructions = true; xrSettings.IgnoreWhitespace = true; using (XmlReader xr = XmlReader.Create(tr, xrSettings)) { string name = null, template = null; while (xr.Read()) { if (xr.NodeType != XmlNodeType.Element || !string.Equals(xr.Name, "component", StringComparison.InvariantCultureIgnoreCase)) continue; name = xr.MoveToAttribute("name") ? xr.Value : null; template = xr.MoveToAttribute("template") ? xr.Value : null; if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(template)) { Dictionary<string, string> dependencyDic = new Dictionary<string, string>(); dependencyDic.Add("name", name); dependencyDic.Add("template", template); if (dependencyList == null) dependencyList = new List<Dictionary<string, string>>(); dependencyList.Add(dependencyDic); } xr.MoveToElement(); } } } if (dependencyList != null) { string parentMacroParameter = "%PARENT%"; foreach (Dictionary<string, string> dependency in dependencyList) { string name = dependency["name"], template = dependency["template"]; string sourceDir = BXComponentManager.GetTemplateVirtualDir(name, template.Replace(parentMacroParameter, TemplateName), siteTemplateName, null); if (string.IsNullOrEmpty(sourceDir)) continue; //string destinationDir = BXPath.Combine(GetSiteComponentTemplatesPath(destinationSiteTemplateName, name), template.Replace(parentMacroParameter, NameForNewItem)); string destinationDir = BXPath.Combine(destinationPath, GetComponentTemplatePartialPath(name, template.Replace(parentMacroParameter, NameForNewItem))); if (BXSecureIO.DirectoryExists(destinationDir)) continue; BXSecureIO.DirectoryEnsureExists(destinationDir); BXSecureIO.DirectoryCopy(sourceDir, destinationDir); } } if (BXSecureIO.FileExists(dependenciesFilePath)) BXSecureIO.FileDelete(dependenciesFilePath); } #endregion #region Pocessing of the target file if (chbxApply.Checked && (IsDefaultSiteActive ? rbtnDefaultSiteTemplate.Checked : rbtnActiveSiteTemplate.Checked)) { undo.PageUndo = new BXUndoPageModificationOperation(); IList<BXSite> sites = BXSite.GetSitesForPath(TargetFileAppRelPath); undo.PageUndo.SiteId = (sites.Count > 0 ? sites[0] : BXSite.DefaultSite).Id; undo.PageUndo.FileVirtualPath = TargetFileAppRelPath; undo.PageUndo.FileEncodingName = BXConfigurationUtility.DefaultEncoding.WebName; undo.PageUndo.FileContent = BXSecureIO.FileReadAllText(undo.PageUndo.FileVirtualPath, BXConfigurationUtility.DefaultEncoding); BXPageProxy page = BXPageProxy.Create(TargetFileAppRelPath); BXComponentProxy proxy = page.ResolveControlId(TargetElementID); proxy.Parameters["Template"].SelectedValue = NameForNewItem; if (page.IsDirty) page.Save(); } #endregion BXUndoInfo undoInfo = new BXUndoInfo(); undoInfo.Operation = undo; undoInfo.Save(); BXDialogGoodbyeWindow goodbye = new BXDialogGoodbyeWindow(string.Format( GetMessageRaw("NewTemplateIsSuccessfullyCreated"), string.Concat(undoInfo.GetClientScript(), " return false;"), "#"), -1, BXDialogGoodbyeWindow.LayoutType.Success); BXDialogGoodbyeWindow.SetCurrent(goodbye); #region Redirect to new template modification and completion if (chbxGo2Modification.Checked) { string componentTemplateFileName = VirtualPathUtility.GetFileName(TemplatePath); string destinationTemplateFilePath = VirtualPathUtility.Combine(VirtualPathUtility.AppendTrailingSlash(destinationPath), componentTemplateFileName); if (!BXSecureIO.FileExists(destinationTemplateFilePath)) { ShowError(string.Format(GetMessageRaw("ERROR_FORMATTED_COMPONENT_TEMPLATE_IS_NOT_FOUND_IN_SITE_TEMPLATE"), NameForNewItem, destinationSiteTemplateName)); return; } /*string redirectionUrl = string.Format( "{0}?path={1}&{2}={3}", VirtualPathUtility.ToAbsolute("~/bitrix/admin/FileManEdit.aspx"), HttpUtility.UrlEncode(destinationTemplateFilePath), BXConfigurationUtility.Constants.BackUrl, HttpUtility.UrlEncode(BackUrl)); Redirect(redirectionUrl, string.Format("{0}. {1}...", GetMessageRaw("OPERATION_COMPLETED_SUCCESSFULLY"), GetMessageRaw("EDITOR_OPENING")), BXDialogGoodbyeWindow.LayoutType.Success, 800); */ BXDialogSettings dlgSetting = new BXDialogSettings(); dlgSetting.Height = 604; dlgSetting.Width = 968; dlgSetting.MinHeight = 400; dlgSetting.MinWidth = 780; SwitchToDialog( string.Format( "{0}?path={1}&clientType=WindowManager&vpe_mode=PlainText&noundo=", VirtualPathUtility.ToAbsolute("~/bitrix/dialogs/VisualPageEditor.aspx"), HttpUtility.UrlEncode(destinationTemplateFilePath)), dlgSetting, GetMessage("NewTemplateIsSuccessfullyCreatedShowEditDialog"), BXDialogGoodbyeWindow.LayoutType.Success, 2000); } Refresh(string.Empty, BXDialogGoodbyeWindow.LayoutType.Success, -1); #endregion } catch (System.Threading.ThreadAbortException) { //...игнорируем, вызвано Close(); } catch (Exception exc) { Close(exc.Message, BXDialogGoodbyeWindow.LayoutType.Error, -1); } }