Ejemplo n.º 1
0
        /// <summary>
        /// Updates the group
        /// </summary>
        private void StartUpdatingNewGroup()
        {
            ExchCmds powershell = null;

            try
            {
                powershell = new ExchCmds(Config.ExchangeURI, Config.Username, Config.Password, Config.ExchangeConnectionType, Config.PrimaryDC);

                string displayName = txtDisplayName.Text;
                string emailAddress = txtEmailAddress.Text.Replace(" ", string.Empty) + "@" + ddlDomains.SelectedItem.Value;

                // Our string seperator to split the owners and members information
                string[] separators = { "||" };

                // Compile a list of owners
                List<string> newOwners = hfOriginalOwners.Value.Split(separators, StringSplitOptions.RemoveEmptyEntries).ToList();
                List<string> ownerAdded = hfModifiedOwners.Value.Split(separators, StringSplitOptions.RemoveEmptyEntries).ToList();
                List<string> ownerRemoved = hfRemovedOwners.Value.Split(separators, StringSplitOptions.RemoveEmptyEntries).ToList();
                
                // Now lets see who was added or removed from the owners section
                newOwners.RemoveAll(ownerRemoved.Contains);  // removes everything from original owners that was in the removed list
                newOwners.AddRange(ownerAdded); // Adds everything that was in the ownerAdded list (except duplicates)
               

                // Compile a list of members
                List<string> newMembers = hfModifiedMembership.Value.Split(separators, StringSplitOptions.RemoveEmptyEntries).ToList();
                List<string> removedMembers = hfRemovedMembership.Value.Split(separators, StringSplitOptions.RemoveEmptyEntries).ToList();

                // Go through membership approval settings
                string memberJoinRestriction = "Open";
                if (rbMembershipApprovalJoinClosed.Checked)
                    memberJoinRestriction = "Closed";
                else if (rbMembershipApprovalJoinApproval.Checked)
                    memberJoinRestriction = "ApprovalRequired";

                string memberDepartRestriction = "Open";
                if (rbMembershipApprovalLeaveClosed.Checked)
                    memberDepartRestriction = "Closed";

                //
                // Go through delivery management settings
                //
                bool requireSenderAuthentication = true;
                if (rbDeliveryManagementInsideOutside.Checked)
                    requireSenderAuthentication = false;

                // Compile the list of "Allowed senders" (if any)
                List<string> allowedSenders = new List<string>();
                foreach (ListItem li in lstDeliveryManagementRestrict.Items)
                {
                    if (li.Selected)
                        allowedSenders.Add(li.Value);
                }
                if (allowedSenders.Count < 1)
                    allowedSenders = null; // Clear (null) the list if it is empty

                //
                // Go through message approval settings
                //
                string notify = "Never";
                if (rbMessageApprovalNotifyAll.Checked)
                    notify = "Always";
                else if (rbMessageApprovalNotifyInternal.Checked)
                    notify = "Internal";

                // Compile the list of "Group Moderators" (if any)
                List<string> groupModerators = new List<string>();
                foreach (ListItem li in lstGroupModerators.Items)
                {
                    if (li.Selected)
                        groupModerators.Add(li.Value);
                }
                if (groupModerators.Count < 1)
                    groupModerators = null; // Clear (null) the list if it is empty

                // Compile the list of senders that don't require approval
                List<string> bypassModerationSenders = new List<string>();
                foreach (ListItem li in lstSendersDontRequireApproval.Items)
                {
                    if (li.Selected)
                        bypassModerationSenders.Add(li.Value);
                }
                if (bypassModerationSenders.Count < 1)
                    bypassModerationSenders = null; // Clear (null) the list if it is empty

                // Update Group
                powershell.Set_DistributionGroup(displayName, CPContext.SelectedCompanyCode, hfCurrentEmailAddress.Value, emailAddress, memberJoinRestriction, memberDepartRestriction, 
                    cbMustBeApprovedByAModerator.Checked, notify, newOwners, groupModerators, allowedSenders, bypassModerationSenders, cbGroupHidden.Checked, requireSenderAuthentication);

                // Update SQL
                SQLExchange.UpdateDistributionGroup("CN=" + emailAddress + "," + Retrieve.GetCompanyExchangeOU, hfCurrentEmailAddress.Value, emailAddress, displayName, cbGroupHidden.Checked);

                // Update notification
                notification1.SetMessage(controls.notification.MessageType.Warning, Resources.LocalizedText.NotificationWarningUpdateGroup);

                // Add the new members
                foreach (string added in newMembers)
                {
                    powershell.Add_DistributionGroupMember(emailAddress, added);
                }

                // Remove members that are no longer part of the group
                foreach (string removed in removedMembers)
                {
                    powershell.Remove_DistributionGroupMember(emailAddress, removed);
                }


                // Update notification
                notification1.SetMessage(controls.notification.MessageType.Success, Resources.LocalizedText.NotificationSuccessUpdateGroup);
            }
            catch (Exception ex)
            {
                notification1.SetMessage(controls.notification.MessageType.Error, ex.ToString());
            }
            finally
            {
                if (powershell != null)
                    powershell.Dispose();

                // Refresh the distribution group view
                GetDistributionGroups();
            }
        }