/// <summary> /// The import statics. /// </summary> private void ImportStatics() { var loadWrapper = new Action <string, Action <Stream> >( (file, streamAction) => { var fullFile = this.Get <HttpRequestBase>().MapPath(file); if (!File.Exists(fullFile)) { return; } // import into board... using (var stream = new StreamReader(fullFile)) { streamAction(stream.BaseStream); stream.Close(); } }); this.Get <IRaiseEvent>().Raise(new ImportStaticDataEvent(this.PageBoardID)); // load default bbcode if available... loadWrapper(_BbcodeImport, s => DataImport.BBCodeExtensionImport(this.PageBoardID, s)); // load default extensions if available... loadWrapper(_FileImport, s => DataImport.FileExtensionImport(this.PageBoardID, s)); // load default topic status if available... loadWrapper(_TopicStatusImport, s => DataImport.TopicStatusImport(this.PageBoardID, s)); // load default spam word if available... loadWrapper(_SpamWordsImport, s => DataImport.SpamWordsImport(this.PageBoardID, s)); }
/// <summary> /// Try to Import from selected File /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Import_OnClick([NotNull] object sender, [NotNull] EventArgs e) { // import selected file (if it's the proper format)... if (!this.importFile.PostedFile.ContentType.StartsWith("text")) { this.PageContext.AddLoadMessage( this.GetTextFormatted("IMPORT_FAILED", this.importFile.PostedFile.ContentType), MessageTypes.danger); } try { var importedCount = DataImport.FileExtensionImport( this.PageContext.PageBoardID, this.importFile.PostedFile.InputStream); this.PageContext.AddLoadMessage( importedCount > 0 ? this.GetTextFormatted("IMPORT_SUCESS", importedCount) : this.GetText("ADMIN_EXTENSIONS_IMPORT", "IMPORT_NOTHING"), importedCount > 0 ? MessageTypes.success : MessageTypes.warning); } catch (Exception x) { this.PageContext.AddLoadMessage( string.Format(this.GetText("ADMIN_EXTENSIONS_IMPORT", "IMPORT_FAILED"), x.Message), MessageTypes.danger); } }
/// <summary> /// Try to Import from selected File /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Import_OnClick([NotNull] object sender, [NotNull] EventArgs e) { // import selected file (if it's the proper format)... if (!this.importFile.PostedFile.ContentType.StartsWith("text")) { this.PageContext.AddLoadMessage( this.GetText("ADMIN_EXTENSIONS_IMPORT", "IMPORT_FAILED").FormatWith( "Invalid upload format specified: " + this.importFile.PostedFile.ContentType)); } try { int importedCount = DataImport.FileExtensionImport( this.PageContext.PageBoardID, this.importFile.PostedFile.InputStream); this.PageContext.LoadMessage.AddSession( importedCount > 0 ? this.GetText("ADMIN_EXTENSIONS_IMPORT", "IMPORT_SUCESS").FormatWith(importedCount) : this.GetText("ADMIN_EXTENSIONS_IMPORT", "IMPORT_NOTHING"), importedCount > 0 ? MessageTypes.Success : MessageTypes.Warning); YafBuildLink.Redirect(ForumPages.admin_extensions); } catch (Exception x) { this.PageContext.AddLoadMessage( this.GetText("ADMIN_EXTENSIONS_IMPORT", "IMPORT_FAILED").FormatWith(x.Message)); } }
/// <summary> /// Try to Import from selected File /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Import_OnClick([NotNull] object sender, [NotNull] EventArgs e) { // import selected file (if it's the proper format)... if (!this.importFile.PostedFile.ContentType.StartsWith(value: "text")) { this.PageContext.AddLoadMessage( message: string.Format( format: this.GetText(page: "ADMIN_EXTENSIONS_IMPORT", tag: "IMPORT_FAILED"), arg0: "Invalid upload format specified: " + this.importFile.PostedFile.ContentType)); } try { var importedCount = DataImport.FileExtensionImport( boardId: this.PageContext.PageBoardID, inputStream: this.importFile.PostedFile.InputStream); this.PageContext.AddLoadMessage( message: importedCount > 0 ? string.Format(format: this.GetText(page: "ADMIN_EXTENSIONS_IMPORT", tag: "IMPORT_SUCESS"), arg0: importedCount) : this.GetText(page: "ADMIN_EXTENSIONS_IMPORT", tag: "IMPORT_NOTHING"), messageType: importedCount > 0 ? MessageTypes.success : MessageTypes.warning); } catch (Exception x) { this.PageContext.AddLoadMessage( message: string.Format(format: this.GetText(page: "ADMIN_EXTENSIONS_IMPORT", tag: "IMPORT_FAILED"), arg0: x.Message), messageType: MessageTypes.danger); } }
/// <summary> /// The import_ on click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void Import_OnClick(object sender, EventArgs e) { // import selected file (if it's the proper format)... if (this.importFile.PostedFile.ContentType == "text/xml") { try { int importedCount = DataImport.FileExtensionImport(PageContext.PageBoardID, this.importFile.PostedFile.InputStream); if (importedCount > 0) { PageContext.LoadMessage.AddSession("{0} new extension(s) imported successfully.".FormatWith(importedCount)); } else { PageContext.LoadMessage.AddSession("Nothing imported: no new extensions were found in the upload.".FormatWith(importedCount)); } YafBuildLink.Redirect(ForumPages.admin_extensions); } catch (Exception x) { PageContext.AddLoadMessage("Failed to import: " + x.Message); } } }
/// <summary> /// Creates the board in the database. /// </summary> /// <param name="boardName">Name of the board.</param> /// <param name="boardMembershipAppName">Name of the board membership application.</param> /// <param name="boardRolesAppName">Name of the board roles application.</param> /// <param name="langFile">The language file.</param> /// <param name="newAdmin">The new admin.</param> /// <returns>Returns the Board ID of the new Board.</returns> private int CreateBoardDatabase( string boardName, string boardMembershipAppName, string boardRolesAppName, string langFile, MembershipUser newAdmin) { var newBoardId = YafContext.Current.GetRepository <Board>() .Create( boardName, "en-US", langFile, boardMembershipAppName, boardRolesAppName, newAdmin.UserName, newAdmin.Email, newAdmin.ProviderUserKey.ToString(), this.PortalSettings.UserInfo.IsSuperUser, global::YAF.Classes.Config.CreateDistinctRoles && global::YAF.Classes.Config.IsAnyPortal ? "YAF " : string.Empty); var loadWrapper = new Action <string, Action <Stream> >( (file, streamAction) => { var fullFile = YafContext.Current.Get <HttpRequestBase>().MapPath(file); if (!File.Exists(fullFile)) { return; } // import into board... using (var stream = new StreamReader(fullFile)) { streamAction(stream.BaseStream); stream.Close(); } }); // load default bbcode if available... loadWrapper("install/bbCodeExtensions.xml", s => DataImport.BBCodeExtensionImport(newBoardId, s)); // load default extensions if available... loadWrapper("install/fileExtensions.xml", s => DataImport.FileExtensionImport(newBoardId, s)); // load default topic status if available... loadWrapper("install/TopicStatusList.xml", s => DataImport.TopicStatusImport(newBoardId, s)); // load default spam word if available... loadWrapper("install/SpamWords.xml", s => DataImport.SpamWordsImport(newBoardId, s)); return(newBoardId); }
/// <summary> /// Creates the board in the database. /// </summary> /// <param name="boardName">Name of the board.</param> /// <param name="boardMembershipAppName">Name of the board membership application.</param> /// <param name="boardRolesAppName">Name of the board roles application.</param> /// <param name="langFile">The language file.</param> /// <param name="newAdmin">The new admin.</param> /// <returns></returns> private int DbCreateBoard( string boardName, string boardMembershipAppName, string boardRolesAppName, string langFile, MembershipUser newAdmin) { int newBoardID = this.GetRepository <Board>() .Create( boardName, this.Culture.SelectedItem.Value, langFile, boardMembershipAppName, boardRolesAppName, newAdmin.UserName, newAdmin.Email, newAdmin.ProviderUserKey.ToString(), this.PageContext().IsHostAdmin, Config.CreateDistinctRoles && Config.IsAnyPortal ? "YAF " : string.Empty); var loadWrapper = new Action <string, Action <Stream> >( (file, streamAction) => { var fullFile = this.Get <HttpRequestBase>().MapPath(file); if (!File.Exists(fullFile)) { return; } // import into board... using (var stream = new StreamReader(fullFile)) { streamAction(stream.BaseStream); stream.Close(); } }); // load default bbcode if available... loadWrapper("install/bbCodeExtensions.xml", s => DataImport.BBCodeExtensionImport(newBoardID, s)); // load default extensions if available... loadWrapper("install/fileExtensions.xml", s => DataImport.FileExtensionImport(newBoardID, s)); // load default topic status if available... loadWrapper("install/TopicStatusList.xml", s => DataImport.TopicStatusImport(newBoardID, s)); // load default spam word if available... loadWrapper("install/SpamWords.xml", s => DataImport.SpamWordsImport(newBoardID, s)); return(newBoardID); }
/// <summary> /// The import statics. /// </summary> private void ImportStatics() { var loadWrapper = new Action <string, Action <Stream> >( (file, streamAction) => { var fullFile = this.Get <HttpRequestBase>().MapPath(file); if (!File.Exists(fullFile)) { return; } // import into board... using (var stream = new StreamReader(fullFile)) { streamAction(stream.BaseStream); stream.Close(); } }); var boards = this.GetRepository <Board>().ListTyped(); // Upgrade all Boards boards.ForEach( board => { this.Get <IRaiseEvent>().Raise(new ImportStaticDataEvent(board.ID)); // load default bbcode if available... loadWrapper(BbcodeImport, s => DataImport.BBCodeExtensionImport(board.ID, s)); // load default extensions if available... loadWrapper(FileImport, s => DataImport.FileExtensionImport(board.ID, s)); // load default spam word if available... loadWrapper(SpamWordsImport, s => DataImport.SpamWordsImport(board.ID, s)); }); }