Example #1
0
        /// <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>
        ///     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 spam word if available...
                loadWrapper(SpamWordsImport, s => DataImport.SpamWordsImport(board.ID, 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)
        {
            try
            {
                // import selected file (if it's the proper format)...
                if (!this.importFile.PostedFile.ContentType.StartsWith("text"))
                {
                    this.PageContext.AddLoadMessage(
                        this.GetTextFormatted("MSG_IMPORTED_FAILEDX", this.importFile.PostedFile.ContentType),
                        MessageTypes.danger);

                    return;
                }

                var importedCount = DataImport.SpamWordsImport(
                    this.PageContext.PageBoardID,
                    this.importFile.PostedFile.InputStream);

                this.PageContext.AddLoadMessage(
                    importedCount > 0
                        ? string.Format(this.GetText("ADMIN_SPAMWORDS_IMPORT", "MSG_IMPORTED"), importedCount)
                        : this.GetText("ADMIN_SPAMWORDS_IMPORT", "MSG_NOTHING"),
                    importedCount > 0 ? MessageTypes.success : MessageTypes.warning);
            }
            catch (Exception x)
            {
                this.PageContext.AddLoadMessage(
                    this.GetTextFormatted("MSG_IMPORTED_FAILEDX", x.Message),
                    MessageTypes.danger);
            }
        }
Example #4
0
        /// <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_SPAMWORDS_IMPORT", "MSG_IMPORTED_FAILEDX")
                    .FormatWith(
                        "Invalid upload format specified: {0}".FormatWith(this.importFile.PostedFile.ContentType)));

                return;
            }

            try
            {
                int importedCount = DataImport.SpamWordsImport(
                    this.PageContext.PageBoardID,
                    this.importFile.PostedFile.InputStream);

                this.PageContext.LoadMessage.AddSession(
                    importedCount > 0
                             ? this.GetText("ADMIN_SPAMWORDS_IMPORT", "MSG_IMPORTED").FormatWith(importedCount)
                             : this.GetText("ADMIN_SPAMWORDS_IMPORT", "MSG_NOTHING"),
                    importedCount > 0 ? MessageTypes.Success : MessageTypes.Warning);

                YafBuildLink.Redirect(ForumPages.admin_spamwords);
            }
            catch (Exception x)
            {
                this.PageContext.AddLoadMessage(
                    this.GetText("ADMIN_SPAMWORDS_IMPORT", "MSG_IMPORTED_FAILEDX").FormatWith(x.Message));
            }
        }
Example #5
0
        /// <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)
        {
            try
            {
                // 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_SPAMWORDS_IMPORT", tag: "MSG_IMPORTED_FAILEDX"),
                            arg0: $"Invalid upload format specified: {this.importFile.PostedFile.ContentType}"));

                    return;
                }

                var importedCount = DataImport.SpamWordsImport(
                    boardId: this.PageContext.PageBoardID,
                    inputStream: this.importFile.PostedFile.InputStream);

                this.PageContext.AddLoadMessage(
                    message: importedCount > 0
                        ? string.Format(format: this.GetText(page: "ADMIN_SPAMWORDS_IMPORT", tag: "MSG_IMPORTED"), arg0: importedCount)
                        : this.GetText(page: "ADMIN_SPAMWORDS_IMPORT", tag: "MSG_NOTHING"),
                    messageType: importedCount > 0 ? MessageTypes.success : MessageTypes.warning);
            }
            catch (Exception x)
            {
                this.PageContext.AddLoadMessage(
                    message: string.Format(format: this.GetText(page: "ADMIN_SPAMWORDS_IMPORT", tag: "MSG_IMPORTED_FAILEDX"), arg0: 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);
        }
Example #7
0
        /// <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>
        /// Creates the board in the database.
        /// </summary>
        /// <param name="boardName">
        /// Name of the board.
        /// </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(
            [NotNull] string boardName,
            [NotNull] string langFile,
            [NotNull] AspNetUsers newAdmin)
        {
            CodeContracts.VerifyNotNull(boardName);
            CodeContracts.VerifyNotNull(langFile);
            CodeContracts.VerifyNotNull(newAdmin);

            var newBoardId = this.GetRepository <Board>().Create(
                boardName,
                this.PortalSettings.Email,
                "en-US",
                langFile,
                newAdmin.UserName,
                newAdmin.Email,
                newAdmin.Id,
                this.PortalSettings.UserInfo.IsSuperUser,
                Configuration.Config.CreateDistinctRoles && Configuration.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 spam word if available...
            loadWrapper("install/SpamWords.xml", s => DataImport.SpamWordsImport(newBoardId, s));

            return(newBoardId);
        }