/// <summary> /// Sends the e-mail. If <paramref name="suppressException"/> is <c>true</c>, record any exception that occurs but do not /// let it propagate out of this function. When <c>false</c>, record the exception and re-throw it. The caller is /// responsible for disposing the <paramref name="mail"/> object. /// </summary> /// <param name="mail">The mail message to send.</param> /// <param name="suppressException">If <c>true</c>, record any exception that occurs but do not /// let it propagate out of this function. When <c>false</c>, record the exception and re-throw it.</param> private void SendEmail(MailMessage mail, bool suppressException) { try { if (mail == null) { throw new ArgumentNullException("mail"); } using (SmtpClient smtpClient = new SmtpClient()) { var appSettings = AppSetting.Instance; smtpClient.EnableSsl = appSettings.SendEmailUsingSsl; string smtpServer = appSettings.SmtpServer; int smtpServerPort; if (!Int32.TryParse(appSettings.SmtpServerPort, out smtpServerPort)) { smtpServerPort = Int32.MinValue; } // Specify SMTP server if it is specified in the gallery settings. The server might have been assigned via web.config, // so only update this if we have a setting. if (!String.IsNullOrEmpty(smtpServer)) { smtpClient.Host = smtpServer; } // Specify port number if it is specified in the gallery settings and it's not the default value of 25. The port // might have been assigned via web.config, so only update this if we have a setting. if ((smtpServerPort > 0) && (smtpServerPort != 25)) { smtpClient.Port = smtpServerPort; } if (String.IsNullOrEmpty(smtpClient.Host)) { throw new WebException(@"Cannot send e-mail because a SMTP Server is not specified. This can be configured in any of the following places: (1) Site Admin - General page (preferred), or (2) web.config (Ex: configuration/system.net/mailSettings/smtp/network host='your SMTP server')."); } smtpClient.Send(mail); } } catch (Exception ex) { AppEventController.LogError(ex); if (!suppressException) { throw; } } }
/// <summary> /// Render the treeview with the first two levels of albums that are viewable to the logged on user. /// </summary> /// <param name="tvOptions">The treeview options.</param> /// <returns>Task<TreeView>.</returns> private async Task <TreeView> Generate(TreeViewOptions tvOptions) { Options = tvOptions; Tree.EnableCheckBoxPlugin = Options.EnableCheckboxPlugin; foreach (IAlbum rootAlbum in await GetTopAlbums()) { if (!Options.UserController.IsUserAuthorized(SecurityActions.ViewAlbumOrMediaObject, await Options.UserController.GetGalleryServerRolesForUser(), rootAlbum.Id, rootAlbum.GalleryId, rootAlbum.IsPrivate, rootAlbum.IsVirtualAlbum)) { continue; } // Add root node. TreeNode rootNode = new TreeNode(); string albumTitle = GetTopAlbumTitle(rootAlbum); rootNode.Text = albumTitle; rootNode.ToolTip = albumTitle; rootNode.Id = String.Concat("tv_", rootAlbum.Id.ToString(CultureInfo.InvariantCulture)); rootNode.DataId = rootAlbum.Id.ToString(CultureInfo.InvariantCulture); rootNode.Expanded = (Options.NumberOfLevels > 1); if (rootAlbum.Parent is NullGalleryObject) { rootNode.AddCssClass("jstree-root-node"); } if (!String.IsNullOrEmpty(Options.NavigateUrl)) { //var url = rootAlbum.IsVirtualAlbum ? Options.NavigateUrl : Utils.AddQueryStringParameter(Options.NavigateUrl, String.Concat("aid=", rootAlbum.Id.ToString(CultureInfo.InvariantCulture))); var url = rootAlbum.IsVirtualAlbum ? Options.NavigateUrl : string.Concat(Options.NavigateUrl, "?aid=", rootAlbum.Id.ToString(CultureInfo.InvariantCulture)); rootNode.NavigateUrl = url; } // If it has a nav URL, it's always selectable & won't have a checkbox. If not, then it's selectable if the user has permission if (string.IsNullOrEmpty(rootNode.NavigateUrl)) { rootNode.Selectable = !rootAlbum.IsVirtualAlbum && Options.UserController.IsUserAuthorized(Options.RequiredSecurityPermissions, await GetRoles(), rootAlbum.Id, rootAlbum.GalleryId, rootAlbum.IsPrivate, SecurityActionsOption.RequireOne, rootAlbum.IsVirtualAlbum); if (Options.EnableCheckboxPlugin) { rootNode.ShowCheckBox = rootNode.Selectable; } } else { rootNode.Selectable = true; } // Select and check this node if needed. if (Options.SelectedAlbumIds.Contains(rootAlbum.Id)) { rootNode.Selected = true; } Tree.Nodes.Add(rootNode); // Add the first level of albums below the root album. var childAlbums = rootAlbum.GetChildGalleryObjects(GalleryObjectType.Album, !Options.UserController.IsAuthenticated); if (Options.NumberOfLevels == 1) { rootNode.HasChildren = childAlbums.Any(); } else { BindAlbumToTreeview(childAlbums.ToSortedList(), rootNode, false); } // Only display the root node if it is selectable or we added any children to it; otherwise, remove it. //if (!rootNode.Selectable && rootNode.Nodes.Count == 0) //{ // Tree.Nodes.Remove(rootNode); //} } // Make sure all specified albums are visible and checked. try { foreach (var albumId in Options.SelectedAlbumIds.Where(id => id > int.MinValue)) { var album = Factory.LoadAlbumInstance(new AlbumLoadOptions(albumId)); if (Options.UserController.IsUserAuthorized(Options.RequiredSecurityPermissions, await GetRoles(), album.Id, album.GalleryId, album.IsPrivate, SecurityActionsOption.RequireOne, album.IsVirtualAlbum)) { BindSpecificAlbumToTreeview(album); } } } catch (InvalidAlbumException ex) { // One of the albums we want to select doesn't exist. Log the event but otherwise continue on gracefully. if (!ex.Data.Contains("Tree_SelectedAlbum_Info")) { ex.Data.Add("Tree_SelectedAlbum_Info", $"Album {ex.AlbumId} was one of the SelectedAlbumIds of the TreeViewOptions object. It may have been deleted by another user just before this code ran."); } AppEventController.LogError(ex); } return(Tree); }