Пример #1
0
        private void workerReadIdentities_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
        {
            UIContext.Instance.ProgressDoStep();
            var state    = (Tuple <int, Identity[], EventWaitHandle>)e.UserState;
            int startIdx = state.Item1;

            Identity[]      loadedIdentities = state.Item2;
            EventWaitHandle ev = state.Item3;

            List <string> domains = new List <string>();

            string selectedDomain = cmbDomains.SelectedItem as string;

            int oldCount = this.cachedUsers.Count;

            foreach (Identity identity in loadedIdentities)
            {
                if (identity != null && identity.Type == IdentityType.WindowsUser)
                {
                    if (!domains.Contains(identity.Domain))
                    {
                        domains.Add(identity.Domain);
                    }

                    if (selectedDomainIndex == 0 || Util.StrEqual(identity.Domain, selectedDomain, true))
                    {
                        this.cachedUsers.Add(identity);
                        this.Invoke(new Action(() => this.lvUsers.Groups.Add(identity.Domain, identity.Domain)));
                    }
                }

                //UIContext.Instance.ProgressDoStep();
            }

            loadingPanel.ProgressUpdateValue(loadedIdentities.Length, UpdateMode.IncrementCurrent);

            this.Invoke(new Action(() =>
            {
                PopulateUsers(false, true);

                blockSelectedChange = true;
                try
                {
                    cmbDomains.Items.AddRange(domains.ToArray());
                    cmbDomains.SelectedIndex = selectedDomainIndex;
                }
                catch (Exception ex)
                {
                    string message = ex.Message;
                }
                finally
                {
                    blockSelectedChange = false;
                }

                int addedUsers    = this.cachedUsers.Count - oldCount;
                int filteredCount = loadedIdentities.Length - addedUsers;
                if (addedUsers > 0)
                {
                    UIContext.Instance.LogMessage(new IconListEntry(Resources.Information,
                                                                    string.Format("Loaded next {0} users, filtered out {1} users (not windows users) / Current total count of loaded users: {2}",
                                                                                  addedUsers, filteredCount, cachedUsers.Count)));
                }
                else if (filteredCount > 0)
                {
                    UIContext.Instance.LogMessage(new IconListEntry(Resources.Information,
                                                                    string.Format("Loading of users filtered out {0} users (not windows users) / Current total count of loaded users: {1}",
                                                                                  filteredCount, cachedUsers.Count)));
                }
            }));

            BackgroundWorker worker = (sender as BackgroundWorker);

            if (ev == null && (worker.CancellationPending || !worker.IsBusy))
            {
                ev = progressChangedCompleted;
            }

            if (ev != null)
            {
                ev.Set();
            }
        }