Esempio n. 1
0
        public static NameResolutionCollection ExResolveName(
            this ExchangeService service,
            AgentJobProcessorState <ExchangeSharedMailboxCrawlJobData> state,
            string nameToResolve,
            ResolveNameSearchLocation searchScope,
            bool returnContactDetails)
        {
            state.Status.Ping();

            return(ActionExtensions.ExecuteWithRetry(
                       () => PrepareRequest(service).ResolveName(nameToResolve, searchScope, returnContactDetails),
                       retryIntervalMilliseconds: retryInterval.Milliseconds,
                       isTransient: ex => TransientExceptionHandler(state, ex)));
        }
Esempio n. 2
0
        protected override void LoadContents()
        {
            if (txtName.Text.Length == 0)
            {
                return;
            }

            ResolveNameSearchLocation oResolveNameSearchLocation = ResolveNameSearchLocation.ContactsThenDirectory;

            switch (cmboResolveNameSearchLocation.Text)
            {
            case "DirectoryOnly":
                oResolveNameSearchLocation = ResolveNameSearchLocation.DirectoryOnly;
                break;

            case "DirectoryThenContacts":
                oResolveNameSearchLocation = ResolveNameSearchLocation.ContactsThenDirectory;
                break;

            case "ContactsOnly":
                oResolveNameSearchLocation = ResolveNameSearchLocation.ContactsOnly;
                break;

            case "ContactsThenDirectory":
                oResolveNameSearchLocation = ResolveNameSearchLocation.DirectoryThenContacts;
                break;
            }

            NameResolutionCollection oNameResolutionCollection = CurrentService.ResolveName(
                txtName.Text,
                oResolveNameSearchLocation,
                chkReturnContactDetails.Checked,
                PropertySet.FirstClassProperties
                );

            Dictionary <string, string> itemIdToDisplayName = new Dictionary <string, string>();

            ItemId[] toLookup = oNameResolutionCollection
                                .Where(nr => nr.Contact == null && nr.Mailbox.Id != null)
                                .Select(nr => nr.Mailbox.Id)
                                .ToArray();
            if (toLookup.Length > 0)
            {
                var itemsWithDisplayNames =
                    CurrentService.BindToItems(toLookup, new PropertySet(BasePropertySet.IdOnly, ContactSchema.DisplayName));
                foreach (GetItemResponse resp in itemsWithDisplayNames)
                {
                    if (resp.Result != ServiceResult.Error && resp.Item != null &&
                        resp.Item.TryGetProperty(ContactSchema.DisplayName, out string displayName))
                    {
                        itemIdToDisplayName[resp.Item.Id.UniqueId] = displayName;
                    }
                }
            }

            // Load new results
            foreach (NameResolution name in oNameResolutionCollection)
            {
                int             rowIdx      = ContentsGrid.Rows.Add();
                DataGridViewRow row         = ContentsGrid.Rows[rowIdx];
                string          displayName = null;
                if (name.Contact != null)
                {
                    name.Contact.TryGetProperty(ContactSchema.DisplayName, out displayName);
                }
                if (displayName == null && name.Mailbox.Id != null)
                {
                    itemIdToDisplayName.TryGetValue(name.Mailbox.Id.UniqueId, out displayName);
                }
                if (displayName != null)
                {
                    row.Cells[colNameDisplayName].Value = displayName;
                }

                row.Cells[colNameMailboxName].Value = name.Mailbox.Name;
                row.Cells[colNameAddress].Value     = name.Mailbox.Address;
                row.Cells[colNameMailboxType].Value = name.Mailbox.MailboxType;
                row.Cells[colNameRoutingType].Value = name.Mailbox.RoutingType;
                if (name.Mailbox.Id != null)
                {
                    row.Cells[colNameUniqueId].Value  = name.Mailbox.Id.UniqueId;
                    row.Cells[colNameContentId].Value = name.Mailbox.Id.UniqueId;
                }
                if (name.Contact != null && name.Contact.TryGetProperty(ContactSchema.DirectoryId, out string directoryId))
                {
                    row.Cells[colNameDirectoryId].Value = directoryId;
                    row.Cells[colNameContentId].Value   = directoryId;
                }
                row.Tag = name;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Call ResolveName and display results
        /// </summary>
        private void btnGo_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                //NameResolutionCollection oNameResolutionCollection = this.CurrentService.ResolveName(
                //    txtName.Text,
                //    ResolveNameSearchLocation.DirectoryThenContacts,
                //    chkReturnContactDetails.Checked
                //    );

                ResolveNameSearchLocation oResolveNameSearchLocation = ResolveNameSearchLocation.ContactsThenDirectory;
                switch (cmboResolveNameSearchLocation.Text)
                {
                case "DirectoryOnly":
                    oResolveNameSearchLocation = ResolveNameSearchLocation.DirectoryOnly;
                    break;

                case "DirectoryThenContacts":
                    oResolveNameSearchLocation = ResolveNameSearchLocation.ContactsThenDirectory;
                    break;

                case "ContactsOnly":
                    oResolveNameSearchLocation = ResolveNameSearchLocation.ContactsOnly;
                    break;

                case "ContactsThenDirectory":
                    oResolveNameSearchLocation = ResolveNameSearchLocation.DirectoryThenContacts;
                    break;
                }

                NameResolutionCollection oNameResolutionCollection = this.CurrentService.ResolveName(
                    txtName.Text,
                    oResolveNameSearchLocation,
                    chkReturnContactDetails.Checked
                    );

                // Clear out previous results
                lstNames.Items.Clear();

                // Load new results
                foreach (NameResolution name in oNameResolutionCollection)
                {
                    ListViewItem item = new ListViewItem();
                    item.Text = name.Mailbox.Name;
                    item.Tag  = name;
                    item.SubItems.Add(name.Mailbox.Address);
                    item.SubItems.Add(name.Mailbox.RoutingType);
                    if (name.Mailbox.Id != null)
                    {
                        item.SubItems.Add(name.Mailbox.Id.UniqueId);
                    }
                    else
                    {
                        item.SubItems.Add("");
                    }
                    lstNames.Items.Add(item);
                }

                // Select the first result by default
                if (lstNames.Items.Count > 0)
                {
                    this.lstNames.Items[0].Selected = true;
                    this.lstNames.Focus();
                }

                // Pressing <enter> will now execute the OK button
                this.AcceptButton = this.btnOK;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }