private async void BtnTest_Click(object sender, RoutedEventArgs e)
        {
            var credManager = new CredentialManager();
            var creds = credManager.GetUserCredentials();

            IExchangeResponse result = null;

            await Task.Run(() =>
            {
                var connector = new ExchangeConnector();

                result = connector.PerformExchangeRequest(creds,
                    AccountSettingsViewModel.Instance.ServerUrl, string.Empty, ExchangeRequestType.DeleteGroup, null);
            });
        }
        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);
            }
        }
        private static async Task<bool> ValidateAlias(UserCredentials credentials, string alias)
        {
            IExchangeResponse result = null;

            await Task.Run(() =>
            {
                var connector = new ExchangeConnector();

                result = connector.PerformExchangeRequest(credentials,
                    AccountSettingsViewModel.Instance.ServerUrl, alias, ExchangeRequestType.ValidateAlias);
            });

            return result != null && ((AliasValidationEnvelope) result).Body.Response.IsAliasUnique;
        }
        private static async Task<SetMemberEnvelope> AddMembersToGroup(UserCredentials credentials, string alias,
            IEnumerable<string> members)
        {
            IExchangeResponse result = null;

            // add a loop here and add error messages
            await Task.Run(() =>
            {
                var connector = new ExchangeConnector();

                result = connector.PerformExchangeRequest(credentials,
                    AccountSettingsViewModel.Instance.ServerUrl, alias, ExchangeRequestType.AddMember, members);
            });

            return (SetMemberEnvelope)result;
        }
        private static async Task<string> CreateGroup(UserCredentials credentials, string alias, string owner)
        {
            IExchangeResponse result = null;

            await Task.Run(() =>
            {
                var connector = new ExchangeConnector();

                result = connector.PerformExchangeRequest(credentials,
                    AccountSettingsViewModel.Instance.ServerUrl, alias, ExchangeRequestType.CreateGroup, new List<string> { owner });
            });


            if (result != null)
            {
                if (((GroupCreationEnvelope)result).Body.CreateUnifiedGroupResponseMessage.GroupIdentity != null &&
                    ((GroupCreationEnvelope)result).Body.CreateUnifiedGroupResponseMessage.GroupIdentity.Type.ToLower() == "smtpaddress")
                {
                    return ((GroupCreationEnvelope)result).Body.CreateUnifiedGroupResponseMessage.GroupIdentity.Value;
                }
                return string.Empty;
            }
            return string.Empty;
        }
Пример #6
0
        private async Task<object> GetGroupInformation(UserCredentials credentials, string groupQualifiedName)
        {
            IExchangeResponse result = null;

            await Task.Run(() =>
            {
                var connector = new ExchangeConnector();

                result = connector.PerformExchangeRequest(credentials,
                    AccountSettingsViewModel.Instance.ServerUrl, groupQualifiedName, ExchangeRequestType.GetUnifiedGroupDetails);
            });

            return (GetUnifiedGroupEnvelope) result;
        }
Пример #7
0
        private static BulkAddMembersResult AddMembersToGroupSingleBatch(UserCredentials credentials, string alias,
            IEnumerable<string> members)
        {
            var memberList = members.ToList();
            var connector = new ExchangeConnector();

            IExchangeResponse result = connector.PerformExchangeRequest(credentials,
                AccountSettingsViewModel.Instance.ServerUrl, alias, ExchangeRequestType.AddMember, memberList);

            var addMemberResult = new BulkAddMembersResult
            {
                StatusCode = result != null
                    ? ((SetMemberEnvelope)result).Body.SetUnifiedGroupMembershipResponseMessage.ResponseCode
                    : string.Empty,

                MemberCount = memberList.Count
            };

            if (addMemberResult.StatusCode.ToLower() != "noerror" && addMemberResult.StatusCode.ToLower() != "errorinvalidid")
            {
                addMemberResult.FailedMembers = memberList;
            }
            else if (result != null)
            {
                addMemberResult.FailedMembers = ((SetMemberEnvelope)result).Body.SetUnifiedGroupMembershipResponseMessage.FailedMembers;

                addMemberResult.InvalidMembers = ((SetMemberEnvelope)result).Body.SetUnifiedGroupMembershipResponseMessage.InvalidMembers;
            }

            return addMemberResult;
        }