StoreDistributionListInformation() private method

Stores the DL information in a local file.
private StoreDistributionListInformation ( DistributionList distributionList ) : string
distributionList Hummingbird.Models.DistributionList Existing distribution list model.
return string
        private async void btnCreateBackup_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(TxtDlAlias.Text))
            {
                var credManager = new CredentialManager();
                var userCredentials = credManager.GetUserCredentials();

                if (userCredentials != null)
                {
                    // Disabling pieces of UI that might interfere.
                    DlGroupMigrationViewModel.Instance.BackupControlsEnabled = false;
                    DlGroupMigrationViewModel.Instance.RestoreControlsEnabled = false;

                    TxtBackupStatus.Text = "Identifying alias...";

                    var adConnector = new ActiveDirectoryConnector();
                    var dl = new DistributionList {Name = TxtDlAlias.Text};
                    var owner = string.Empty;
                    bool isValidDl;
                    if (!AccountSettingsViewModel.Instance.IsInternal)
                    {
                        // The user is external.
                        var connector = new ExchangeConnector();
                        owner = connector.GetExternalDistributionListOwner(TxtDlAlias.Text, userCredentials, out isValidDl);
                    }
                    else
                    {
                        // The user is internal
                        var dlDetails = await adConnector.GetDistributionListOwner(TxtDlAlias.Text);
                        owner = dlDetails.Item1;
                        isValidDl = dlDetails.Item2;
                    }

                    bool resolveMembers = !string.IsNullOrWhiteSpace(owner);

                    if (!isValidDl)
                    {
                        var result =
                            ModernDialog.ShowMessage(
                                "The alias you provided doesn't map to a valid DL.",
                                "Hummingbird", MessageBoxButton.OK);
                        resolveMembers = false;
                    }
                    else if (!resolveMembers)
                    {
                        var result =
                            ModernDialog.ShowMessage(
                                "The group owner couldn't be found. If you attempt to retrieve members for the group, the backup will be missing the Owner property. Continue?",
                                "Hummingbird", MessageBoxButton.YesNo);
                        resolveMembers = result == MessageBoxResult.Yes;
                    }

                    if (resolveMembers)
                    {
                        dl.Owner = owner;

                        TxtBackupStatus.Text = "getting members...";

                        var members = await adConnector.GetDistributionListMembers(TxtDlAlias.Text);
                        if (members != null)
                        {
                            dl.Members = members;

                            var fsOperator = new FileSystemOperator();
                            var filePath = fsOperator.StoreDistributionListInformation(dl);

                            if (!string.IsNullOrWhiteSpace(filePath))
                            {
                                var result =
                                    ModernDialog.ShowMessage(
                                        "A backup was created for the distribution list. Do you want to open File Explorer to find its location?",
                                        "Hummingbird", MessageBoxButton.YesNo);

                                if (result == MessageBoxResult.Yes)
                                {
                                    Process.Start("explorer.exe", string.Concat("/select, ", filePath));
                                }
                            }
                            else
                            {
                                ModernDialog.ShowMessage(
                                    "We couldn't create a backup file for this distribution list. Please try again.", "Hummingbird",
                                    MessageBoxButton.OK);
                            }
                        }
                        else
                        {
                            ModernDialog.ShowMessage(
                                "We couldn't retrieve members of the distribution list. Check your credentials and try again.", "Hummingbird",
                                MessageBoxButton.OK);
                        }
                    }

                    // Re-enable the pieces of UI that might interfere.
                    DlGroupMigrationViewModel.Instance.BackupControlsEnabled = true;
                    DlGroupMigrationViewModel.Instance.RestoreControlsEnabled = true;
                }
                else
                {
                    ModernDialog.ShowMessage(
                        "No credentials were provided. Open Settings and add your credentials.", "Hummingbird",
                        MessageBoxButton.OK);
                }
            }
            else
            {
                ModernDialog.ShowMessage("You must include an alias.", "Hummingbird", MessageBoxButton.OK);
            }
        }
Esempio n. 2
0
        private async void BtnPerformGroupGrab_OnClick(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(TxtBackupGroupBox.Text))
            {
                DlGroupMigrationViewModel.Instance.BulkAddControlsEnabled = false;

                try
                {
                    var credManager = new CredentialManager();
                    var credentials = credManager.GetUserCredentials();

                    var gugResults = await GetGroupInformation(credentials, TxtBackupGroupBox.Text);

                    GetUnifiedGroupEnvelope gugEnvelope = (GetUnifiedGroupEnvelope) gugResults;

                    GroupSimplifier simplifier = new GroupSimplifier();
                    var dl =
                        simplifier.SimplifyGroup(gugEnvelope.Body.GetUnifiedGroupMembersResponseMessage.MembersInfo.Members,
                            TxtBackupGroupBox.Text);

                    var fsOperator = new FileSystemOperator();
                    var filePath = fsOperator.StoreDistributionListInformation(dl);

                    if (!string.IsNullOrWhiteSpace(filePath))
                    {
                        var result =
                            ModernDialog.ShowMessage(
                                "Group backup created. Open Windows Explorer for its location?",
                                "Hummingbird", MessageBoxButton.YesNo);

                        if (result == MessageBoxResult.Yes)
                        {
                            Process.Start("explorer.exe", string.Concat("/select, ", filePath));
                        }
                    }
                    else
                    {
                        ModernDialog.ShowMessage(
                            "We couldn't create the backup file for this group.", "Hummingbird",
                            MessageBoxButton.OK);
                    }
                    //if (membersAdded.ToLower() == "noerror")
                    //{
                    //    ModernDialog.ShowMessage("Bulk add complete!", "Hummingbird",
                    //        MessageBoxButton.OK);

                    //    TxtGroupAddress.Text = string.Empty;
                    //    TxtPath.Text = string.Empty;
                    //    DlGroupMigrationViewModel.Instance.BulkAddDistributionList = new DistributionList();
                    //}
                }
                catch (Exception ex)
                {
                    ModernDialog.ShowMessage(
                        "An error occured and we couldn't complete the request. Please contact the developer.",
                        "Hummingbird",
                        MessageBoxButton.OK);
                }
            }
            else
            {
                ModernDialog.ShowMessage(
                    "Missing key pieces of information. Check that you have both the members and group address entered.",
                    "Hummingbird", MessageBoxButton.OK);
            }

            DlGroupMigrationViewModel.Instance.BulkAddControlsEnabled = true;
        }