/// <summary> /// Determines whether is time to send digest for board. /// </summary> /// <param name="boardSettings">The board settings.</param> /// <returns> /// The is time to send digest for board. /// </returns> private static bool IsTimeToSendDigestForBoard([NotNull] YafLoadBoardSettings boardSettings) { CodeContracts.VerifyNotNull(boardSettings, "boardSettings"); if (!boardSettings.AllowDigestEmail) { return(false); } var lastSend = DateTime.MinValue; var sendEveryXHours = boardSettings.DigestSendEveryXHours; if (boardSettings.LastDigestSend.IsSet()) { try { lastSend = Convert.ToDateTime(boardSettings.LastDigestSend, CultureInfo.InvariantCulture); } catch (Exception) { lastSend = DateTime.MinValue; } } #if (DEBUG) // haven't sent in X hours or more and it's 12 to 5 am. var sendDigest = lastSend < DateTime.Now.AddHours(-sendEveryXHours); #else // haven't sent in X hours or more and it's 12 to 5 am. var sendDigest = lastSend < DateTime.Now.AddHours(-sendEveryXHours) && DateTime.Now < DateTime.Today.AddHours(6); #endif if (!sendDigest && !boardSettings.ForceDigestSend) { return(false); } // && DateTime.Now < DateTime.Today.AddHours(5)) // we're good to send -- update latest send so no duplication... boardSettings.LastDigestSend = DateTime.Now.ToString(CultureInfo.InvariantCulture); boardSettings.ForceDigestSend = false; boardSettings.SaveGuestUserIdBackup(); boardSettings.SaveRegistry(); return(true); }
/// <summary> /// Save the Settings /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void UpdateClick(object sender, EventArgs e) { var moduleController = new ModuleController(); moduleController.UpdateModuleSetting(this.ModuleId, "forumboardid", this.BoardID.SelectedValue); moduleController.UpdateModuleSetting(this.ModuleId, "RemoveTabName", this.RemoveTabName.SelectedValue); moduleController.UpdateModuleSetting( this.ModuleId, "InheritDnnLanguage", this.InheritDnnLanguage.Checked.ToString()); var boardSettings = new YafLoadBoardSettings(this.BoardID.SelectedValue.ToType <int>()) { DNNPageTab = this.TabId, DNNPortalId = this.PortalId, BaseUrlMask = "http://{0}/".FormatWith( HttpContext.Current .Request .ServerVariables[ "SERVER_NAME"]) }; // save the settings to the database boardSettings.SaveRegistry(); string message; // Import Users & Roles UserImporter.ImportUsers( this.BoardID.SelectedValue.ToType <int>(), this.PortalSettings.PortalId, this.PortalSettings.GUID, out message); // Reload forum settings YafContext.Current.BoardSettings = null; YafBuildLink.Redirect(ForumPages.forum); }
/// <summary> /// The send digest. /// </summary> private void SendDigest() { try { var boardIds = this.GetRepository <Board>().ListTyped().Select(b => b.ID); foreach (var boardId in boardIds) { var boardSettings = new YafLoadBoardSettings(boardId); if (!IsTimeToSendDigestForBoard(boardSettings)) { continue; } if (Config.BaseUrlMask.IsNotSet()) { // fail... this.Logger.Error( "DigestSendTask: Failed to send digest because BaseUrlMask value is not set in your appSettings."); return; } // get users with digest enabled... var usersWithDigest = LegacyDb.UserFind(boardId, false, null, null, null, null, true) .Where(x => !x.IsGuest && (x.IsApproved ?? false)); var typedUserFinds = usersWithDigest as IList <TypedUserFind> ?? usersWithDigest.ToList(); if (typedUserFinds.Any()) { // start sending... this.SendDigestToUsers(typedUserFinds, boardId, boardSettings); } } } catch (Exception ex) { this.Logger.Error(ex, "Error In {0} Task".FormatWith(TaskName)); } }
/// <summary> /// The send digest. /// </summary> private void SendDigest() { try { var boardIds = this.GetRepository <Board>().ListTyped().Select(b => b.ID); boardIds.ForEach( boardId => { var boardSettings = new YafLoadBoardSettings(boardId); if (!IsTimeToSendDigestForBoard(boardSettings)) { return; } // get users with digest enabled... var usersWithDigest = this.GetRepository <User>() .FindUserTyped(false, boardId, dailyDigest: true).Where( x => x.IsGuest != null && !x.IsGuest.Value && (x.IsApproved ?? false)); var typedUserFinds = usersWithDigest as IList <User> ?? usersWithDigest.ToList(); if (typedUserFinds.Any()) { // start sending... this.SendDigestToUsers(typedUserFinds, boardSettings); } else { this.Get <ILogger>().Info("no user found"); } }); } catch (Exception ex) { this.Get <ILogger>().Error(ex, $"Error In {TaskName} Task"); } }
/// <summary> /// The send digest. /// </summary> private void SendDigest() { try { var boardIds = this.GetRepository <Board>().ListTyped().Select(b => b.ID); foreach (var boardId in boardIds) { var boardSettings = new YafLoadBoardSettings(boardId); if (!IsTimeToSendDigestForBoard(boardSettings)) { continue; } // get users with digest enabled... var usersWithDigest = this.GetRepository <User>().FindUserTyped(filter: false, boardId: boardId, dailyDigest: true) .Where(x => !x.IsGuest && (x.IsApproved ?? false)); var typedUserFinds = usersWithDigest as IList <User> ?? usersWithDigest.ToList(); if (typedUserFinds.Any()) { // start sending... this.SendDigestToUsers(typedUserFinds, boardSettings); } else { this.Get <ILogger>().Info("no user found"); } } } catch (Exception ex) { this.Get <ILogger>().Error(ex, "Error In {0} Task".FormatWith(TaskName)); } }
/// <summary> /// Handles the OnClick event of the ImportForums control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void ImportForums_OnClick(object sender, EventArgs e) { // First Create new empty forum var newBoardId = this.CreateBoard(false, "Import Board"); Data.ImportActiveForums(this.ActiveForums.SelectedValue.ToType <int>(), newBoardId); this.MigrateAttachments(); var moduleController = new ModuleController(); moduleController.UpdateModuleSetting(this.ModuleId, "forumboardid", (newBoardId + 1).ToString()); moduleController.UpdateModuleSetting(this.ModuleId, "RemoveTabName", this.RemoveTabName.SelectedValue); moduleController.UpdateModuleSetting( this.ModuleId, "InheritDnnLanguage", this.InheritDnnLanguage.Checked.ToString()); var boardSettings = new YafLoadBoardSettings(newBoardId + 1) { DNNPageTab = this.TabId, DNNPortalId = this.PortalId, BaseUrlMask = "http://{0}/".FormatWith( HttpContext.Current.Request.ServerVariables[ "SERVER_NAME"]) }; // save the settings to the database boardSettings.SaveRegistry(); // Reload forum settings YafContext.Current.BoardSettings = null; this.Response.Redirect(Globals.NavigateURL(), true); }
/// <summary> /// Save the Settings /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void UpdateClick(object sender, EventArgs e) { var config = new ConfigHelper(); // Check if BaskeUrlMask is set and if not automatically write it if (config.GetConfigValueAsString("YAF.BaseUrlMask").IsNotSet() && config.TrustLevel >= AspNetHostingPermissionLevel.High) { var urlKey = "http://{0}/".FormatWith( HttpContext.Current.Request.ServerVariables["SERVER_NAME"]); config.WriteAppSetting("YAF.BaseUrlMask", urlKey); } var objModules = new ModuleController(); objModules.UpdateModuleSetting(this.ModuleId, "forumboardid", this.BoardID.SelectedValue); objModules.UpdateModuleSetting(this.ModuleId, "forumcategoryid", this.CategoryID.SelectedValue); objModules.UpdateModuleSetting(this.ModuleId, "RemoveTabName", this.RemoveTabName.SelectedValue); objModules.UpdateModuleSetting( this.ModuleId, "InheritDnnLanguage", this.InheritDnnLanguage.Checked.ToString()); var boardSettings = new YafLoadBoardSettings(this.BoardID.SelectedValue.ToType <int>()) { DNNPageTab = this.TabId }; // save the settings to the database boardSettings.SaveRegistry(); // Reload forum settings YafContext.Current.BoardSettings = null; YafBuildLink.Redirect(ForumPages.forum); }
/// <summary> /// Determines whether is time to send digest for board. /// </summary> /// <param name="boardSettings">The board settings.</param> /// <returns> /// The is time to send digest for board. /// </returns> private bool IsTimeToSendDigestForBoard([NotNull] YafLoadBoardSettings boardSettings) { CodeContracts.ArgumentNotNull(boardSettings, "boardSettings"); if (boardSettings.AllowDigestEmail) { DateTime lastSend = DateTime.MinValue; bool sendDigest = false; int sendEveryXHours = boardSettings.DigestSendEveryXHours; if (boardSettings.LastDigestSend.IsSet()) { lastSend = Convert.ToDateTime(boardSettings.LastDigestSend); } #if (DEBUG) // haven't sent in X hours or more and it's 12 to 5 am. sendDigest = lastSend < DateTime.Now.AddHours(-sendEveryXHours); #else // haven't sent in X hours or more and it's 12 to 5 am. sendDigest = lastSend < DateTime.Now.AddHours(-sendEveryXHours) && DateTime.Now < DateTime.Today.AddHours(6); #endif if (sendDigest || boardSettings.ForceDigestSend) { // && DateTime.Now < DateTime.Today.AddHours(5)) // we're good to send -- update latest send so no duplication... boardSettings.LastDigestSend = DateTime.Now.ToString(); boardSettings.ForceDigestSend = false; boardSettings.SaveRegistry(); return(true); } } return(false); }
/// <summary> /// Sends the digest to users. /// </summary> /// <param name="usersWithDigest">The users with digest.</param> /// <param name="boardId">The board id.</param> /// <param name="boardSettings">The board settings.</param> private void SendDigestToUsers(IEnumerable<TypedUserFind> usersWithDigest, int boardId, YafLoadBoardSettings boardSettings) { foreach (var user in usersWithDigest) { string digestHtml = string.Empty; try { digestHtml = this.Get<IDigest>().GetDigestHtml(user.UserID ?? 0, boardId, boardSettings.WebServiceToken); } catch (Exception e) { this.Logger.Error(e, "Error In Creating Digest for User {0}".FormatWith(user.UserID)); } if (!digestHtml.IsSet()) { continue; } if (user.ProviderUserKey == null) { continue; } var membershipUser = UserMembershipHelper.GetUser(user.ProviderUserKey); if (membershipUser == null || membershipUser.Email.IsNotSet()) { continue; } // send the digest... this.Get<IDigest>().SendDigest( digestHtml, boardSettings.Name, boardSettings.ForumEmail, membershipUser.Email, user.DisplayName, true); } }
/// <summary> /// The send digest. /// </summary> private void SendDigest() { try { var boardIds = this.GetRepository<Board>().ListTyped().Select(b => b.ID); foreach (var boardId in boardIds) { var boardSettings = new YafLoadBoardSettings(boardId); if (!this.IsTimeToSendDigestForBoard(boardSettings)) { continue; } if (Config.BaseUrlMask.IsNotSet()) { // fail... this.Logger.Error("DigestSendTask: Failed to send digest because BaseUrlMask value is not set in your appSettings."); return; } // get users with digest enabled... var usersWithDigest = LegacyDb.UserFind(boardId, false, null, null, null, null, true).Where(x => !x.IsGuest && (x.IsApproved ?? false)); if (usersWithDigest.Any()) { // start sending... this.SendDigestToUsers(usersWithDigest, boardId, boardSettings); } } } catch (Exception ex) { this.Logger.Error(ex, "Error In {0} Task".FormatWith(TaskName)); } }
/// <summary> /// The send digest. /// </summary> private void SendDigest() { try { var boardIds = this.GetRepository<Board>().ListTyped().Select(b => b.ID); foreach (var boardId in boardIds) { var boardSettings = new YafLoadBoardSettings(boardId); if (!IsTimeToSendDigestForBoard(boardSettings)) { continue; } // get users with digest enabled... var usersWithDigest = this.GetRepository<User>().FindUserTyped(filter: false, boardId: boardId, dailyDigest: true) .Where(x => !x.IsGuest && (x.IsApproved ?? false)); var typedUserFinds = usersWithDigest as IList<User> ?? usersWithDigest.ToList(); if (typedUserFinds.Any()) { // start sending... this.SendDigestToUsers(typedUserFinds, boardSettings); } } } catch (Exception ex) { this.Logger.Error(ex, "Error In {0} Task".FormatWith(TaskName)); } }
/// <summary> /// Sends the digest to users. /// </summary> /// <param name="usersWithDigest">The users with digest.</param> /// <param name="boardId">The board id.</param> /// <param name="boardSettings">The board settings.</param> private void SendDigestToUsers(IEnumerable <TypedUserFind> usersWithDigest, int boardId, YafLoadBoardSettings boardSettings) { foreach (var user in usersWithDigest) { string digestHtml = string.Empty; try { digestHtml = this.Get <IDigest>().GetDigestHtml(user.UserID ?? 0, boardId, boardSettings.WebServiceToken); } catch (Exception e) { this.Logger.Error(e, "Error In Creating Digest for User {0}".FormatWith(user.UserID)); } if (!digestHtml.IsSet()) { continue; } if (user.ProviderUserKey == null) { continue; } var membershipUser = UserMembershipHelper.GetUser(user.ProviderUserKey); if (membershipUser == null || membershipUser.Email.IsNotSet()) { continue; } // send the digest... this.Get <IDigest>().SendDigest( digestHtml, boardSettings.Name, boardSettings.ForumEmail, membershipUser.Email, user.DisplayName, true); } }
/// <summary> /// The initialize component. /// </summary> private void InitializeComponent() { if (AJAX.IsInstalled()) { AJAX.RegisterScriptManager(); } this.forum1 = new Forum(); this.pnlModuleContent.Controls.Add(this.forum1); this.Load += this.DotNetNukeModule_Load; this.forum1.PageTitleSet += this.Forum1_PageTitleSet; // This will create an error if there is no setting for forumboardid if (this.Settings["forumboardid"] != null) { this.forum1.BoardID = this.Settings["forumboardid"].ToType <int>(); var boardSettingsTabId = YafContext.Current.BoardSettings != null && YafContext.Current.BoardSettings.BoardID.Equals(this.forum1.BoardID) ? YafContext.Current.BoardSettings.DNNPageTab : new YafLoadBoardSettings(this.forum1.BoardID).DNNPageTab; if (boardSettingsTabId.Equals(-1) || !boardSettingsTabId.Equals(this.TabId) && !this.CurrentPortalSettings.ContentLocalizationEnabled) { if (HttpContext.Current.User.Identity.IsAuthenticated && UserController.GetCurrentUserInfo().IsSuperUser) { this.Response.Redirect( this.ResolveUrl( "~/tabid/{0}/ctl/Edit/mid/{1}/Default.aspx".FormatWith( this.PortalSettings.ActiveTab.TabID, this.ModuleId))); } /*else * { * boardSettings.DNNPageTab = this.TabId; * * // save the settings to the database * boardSettings.SaveRegistry(); * * // Reload forum settings * YafContext.Current.BoardSettings = null; * }*/ } if (YafContext.Current.BoardSettings.DNNPortalId.Equals(-1)) { var boardSettings = new YafLoadBoardSettings(this.forum1.BoardID) { DNNPageTab = this.TabId, DNNPortalId = this.PortalId }; // save the settings to the database boardSettings.SaveRegistry(); } // Inherit Language from Dnn? var ineritDnnLanguage = true; if (this.Settings["InheritDnnLanguage"] != null) { ineritDnnLanguage = this.Settings["InheritDnnLanguage"].ToType <bool>(); } if (ineritDnnLanguage) { SetDnnLangToYaf(); } } else { if (HttpContext.Current.User.Identity.IsAuthenticated && UserController.GetCurrentUserInfo().IsSuperUser) { this.Response.Redirect( this.ResolveUrl( "~/tabid/{0}/ctl/Edit/mid/{1}/Default.aspx".FormatWith( this.PortalSettings.ActiveTab.TabID, this.ModuleId))); } else { this.pnlModuleContent.Controls.Clear(); this.pnlModuleContent.Controls.Add( new Literal { Text = "<div class=\"dnnFormMessage dnnFormInfo\">Please login as Superuser (host) and Setup the forum first.</div>" }); } } }
/// <summary> /// The send digest. /// </summary> private void SendDigest() { try { var boardIds = CommonDb.board_list(YafContext.Current.PageModuleID, null).AsEnumerable().Select(b => b.Field<int>("BoardID")); foreach (var boardId in boardIds) { var boardSettings = new YafLoadBoardSettings(boardId); if (!this.IsTimeToSendDigestForBoard(boardSettings)) { continue; } if (Config.BaseUrlMask.IsNotSet()) { // fail... CommonDb.eventlog_create(YafContext.Current.PageModuleID, null, "DigestSendTask", "Failed to send digest because BaseUrlMask value is not set in your appSettings."); return; } // get users with digest enabled... var usersWithDigest = CommonDb.UserFind(YafContext.Current.PageModuleID, boardId, false, null, null, null, null, true).Where(x => !x.IsGuest && (x.IsApproved ?? false)); if (usersWithDigest.Any()) { // start sending... this.SendDigestToUsers(usersWithDigest, boardId, boardSettings); } } } catch (Exception ex) { this.Logger.Error(ex, "Error In {0} Task.".FormatWith(TaskName)); } }