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); } }
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(_clientDirectoryName)) throw new InvalidOperationException("ClientDirectoryName is not assigned!"); if (string.IsNullOrEmpty(_clientVirtualParentDirPath)) throw new InvalidOperationException("ClientVirtualParentDirPath is not assigned!"); string clientVirtualSavingPath = VirtualPathUtility.Combine(VirtualPathUtility.AppendTrailingSlash(_clientVirtualPath), _clientDirectoryName); if (BXSecureIO.FileExists(clientVirtualSavingPath) || BXSecureIO.DirectoryExists(clientVirtualSavingPath)) { ShowError(String.Format("{0}", GetMessage("FS_ENTITY_ALREADY_EXISTS"))); return; } string menuTypeId = null; MenuTypeInfo info = null; if (chbxAddToMenu.Checked && ((info = CheckMenuTypeInfo(out menuTypeId)) == null || menuTypeId == null)) { ShowError(GetMessageRaw("Error.YourAccountDontHasTheRightToModifyMenu")); return; } BXSecureIO.DirectoryCreate(clientVirtualSavingPath); BXSectionInfo dirInfo = BXSectionInfo.GetSection(clientVirtualSavingPath); dirInfo.Name = _clientTitle; if (_keywords == null) throw new InvalidOperationException("Keywords is not assinned!"); 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; dirInfo.Keywords[keywordKey] = keywordValue; } dirInfo.Save(); if (chbxAddToMenu.Checked) AddToMenu(menuTypeId, info, clientVirtualSavingPath); string defaultPagePath = BXPath.Combine(clientVirtualSavingPath, _defaultPageName + ".aspx"); try { try { string content = Bitrix.Services.Text.BXDefaultFiles.BuildAspx(!string.IsNullOrEmpty(_clientTitle) ? Encode(_clientTitle) : Encode(GetMessage("DEFAULT_TITLE")), defaultPagePath, null); BXSecureIO.FileWriteAllText(defaultPagePath, content, BXConfigurationUtility.DefaultEncoding); } catch { ShowError(String.Format("{0}: '{1}'!", GetMessage("CREATION_OF_DEFAULT_PAGE_IS_FILED"), defaultPagePath)); return; } BXUndoSectionCreationOperation undoOperation = new BXUndoSectionCreationOperation(); undoOperation.SectionVirtualPath = clientVirtualSavingPath; undoOperation.MenuTypeId = menuTypeId; BXUndoInfo undo = new BXUndoInfo(); undo.Operation = undoOperation; undo.Save(); BXDialogGoodbyeWindow goodbye = new BXDialogGoodbyeWindow(string.Format( GetMessageRaw("NewFolderIsSuccessfullyCreated"), string.Concat(undo.GetClientScript(), " return false;"), "#"), -1, BXDialogGoodbyeWindow.LayoutType.Success); BXDialogGoodbyeWindow.SetCurrent(goodbye); if (chbxEditAfterSave.Checked) { SwitchToDialog( string.Format("{0}?path={1}&clientType=WindowManager&returnUrl={2}&forcedRedirection=&noundo=", VirtualPathUtility.ToAbsolute("~/bitrix/dialogs/VisualPageEditor.aspx"), HttpUtility.UrlEncode(defaultPagePath), HttpUtility.UrlEncode(BXSite.GetUrlForPath(VirtualPathUtility.AppendTrailingSlash(clientVirtualSavingPath), null)) ), null, GetMessage("NEW_FOLDER_IS_SUCCESSFULLY_CREATED_LOADING_EDITOR"), BXDialogGoodbyeWindow.LayoutType.Success, 2000 ); return; } } catch (System.Threading.ThreadAbortException /*ex*/) { //...игнорируем, вызвано response.End(); } catch (Exception ex) { throw ex; } Redirect(BXSite.GetUrlForPath(defaultPagePath, null), GetMessage("NEW_FOLDER_IS_SUCCESSFULLY_CREATED_REDIRECTION"), BXDialogGoodbyeWindow.LayoutType.Success); return; } catch (System.Threading.ThreadAbortException /*ex*/) { //...игнорируем, вызвано Close(); } catch (Exception ex) { Close(ex.Message, BXDialogGoodbyeWindow.LayoutType.Error, -1); } }