示例#1
0
        private bool ContainsEnumTest(Principal principal)
        {
            CheckDisposed();

            if (principal == null)
            {
                throw new ArgumentNullException("principal");
            }

            // Yes, this is potentially quite expensive.  Contains is unfortunately
            // an expensive operation to perform.
            lock (_resultSet)
            {
                ResultSetBookmark bookmark = null;

                try
                {
                    GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalCollection", "ContainsEnumTest: bookmarking");

                    bookmark = _resultSet.BookmarkAndReset();

                    PrincipalCollectionEnumerator containmentEnumerator =
                        new PrincipalCollectionEnumerator(
                            _resultSet,
                            this,
                            _removedValuesCompleted,
                            _removedValuesPending,
                            _insertedValuesCompleted,
                            _insertedValuesPending);

                    while (containmentEnumerator.MoveNext())
                    {
                        Principal p = containmentEnumerator.Current;

                        if (p.Equals(principal))
                        {
                            return(true);
                        }
                    }
                }
                finally
                {
                    if (bookmark != null)
                    {
                        GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalCollection", "ContainsEnumTest: restoring from bookmark");
                        _resultSet.RestoreBookmark(bookmark);
                    }
                }
            }

            return(false);
        }
示例#2
0
        private bool ContainsEnumTest(Principal principal)
        {
            bool flag;

            this.CheckDisposed();
            if (principal != null)
            {
                lock (this.resultSet)
                {
                    ResultSetBookmark resultSetBookmark = null;
                    try
                    {
                        resultSetBookmark = this.resultSet.BookmarkAndReset();
                        PrincipalCollectionEnumerator principalCollectionEnumerator = new PrincipalCollectionEnumerator(this.resultSet, this, this.removedValuesCompleted, this.removedValuesPending, this.insertedValuesCompleted, this.insertedValuesPending);
                        while (principalCollectionEnumerator.MoveNext())
                        {
                            Principal current = principalCollectionEnumerator.Current;
                            if (!current.Equals(principal))
                            {
                                continue;
                            }
                            flag = true;
                            return(flag);
                        }
                    }
                    finally
                    {
                        if (resultSetBookmark != null)
                        {
                            this.resultSet.RestoreBookmark(resultSetBookmark);
                        }
                    }
                    return(false);
                }
                return(flag);
            }
            else
            {
                throw new ArgumentNullException("principal");
            }
        }
示例#3
0
        void ICollection.CopyTo(Array array, int index)
        {
            CheckDisposed();

            // Parameter validation
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            if (array == null)
            {
                throw new ArgumentNullException("array");
            }

            if (array.Rank != 1)
            {
                throw new ArgumentException(SR.PrincipalCollectionNotOneDimensional);
            }

            if (index >= array.GetLength(0))
            {
                throw new ArgumentException(SR.PrincipalCollectionIndexNotInArray);
            }

            ArrayList tempArray = new ArrayList();

            lock (_resultSet)
            {
                ResultSetBookmark bookmark = null;

                try
                {
                    GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalCollection", "CopyTo: bookmarking");

                    bookmark = _resultSet.BookmarkAndReset();

                    PrincipalCollectionEnumerator containmentEnumerator =
                        new PrincipalCollectionEnumerator(
                            _resultSet,
                            this,
                            _removedValuesCompleted,
                            _removedValuesPending,
                            _insertedValuesCompleted,
                            _insertedValuesPending);

                    int arraySize     = array.GetLength(0) - index;
                    int tempArraySize = 0;

                    while (containmentEnumerator.MoveNext())
                    {
                        tempArray.Add(containmentEnumerator.Current);
                        checked { tempArraySize++; }

                        // Make sure the array has enough space, allowing for the "index" offset.
                        // We check inline, rather than doing a PrincipalCollection.Count upfront,
                        // because counting is just as expensive as enumerating over all the results, so we
                        // only want to do it once.
                        if (arraySize < tempArraySize)
                        {
                            GlobalDebug.WriteLineIf(GlobalDebug.Warn,
                                                    "PrincipalCollection",
                                                    "CopyTo: array too small (has {0}, need >= {1}",
                                                    arraySize,
                                                    tempArraySize);

                            throw new ArgumentException(SR.PrincipalCollectionArrayTooSmall);
                        }
                    }
                }
                finally
                {
                    if (bookmark != null)
                    {
                        GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalCollection", "CopyTo: restoring from bookmark");
                        _resultSet.RestoreBookmark(bookmark);
                    }
                }
            }

            foreach (object o in tempArray)
            {
                array.SetValue(o, index);
                checked { index++; }
            }
        }
示例#4
0
 void System.Collections.ICollection.CopyTo(Array array, int index)
 {
     this.CheckDisposed();
     if (index >= 0)
     {
         if (array != null)
         {
             if (array.Rank == 1)
             {
                 if (index < array.GetLength(0))
                 {
                     ArrayList arrayLists = new ArrayList();
                     lock (this.resultSet)
                     {
                         ResultSetBookmark resultSetBookmark = null;
                         try
                         {
                             resultSetBookmark = this.resultSet.BookmarkAndReset();
                             PrincipalCollectionEnumerator principalCollectionEnumerator = new PrincipalCollectionEnumerator(this.resultSet, this, this.removedValuesCompleted, this.removedValuesPending, this.insertedValuesCompleted, this.insertedValuesPending);
                             int length = array.GetLength(0) - index;
                             int num    = 0;
                             while (principalCollectionEnumerator.MoveNext())
                             {
                                 arrayLists.Add(principalCollectionEnumerator.Current);
                                 num++;
                                 if (length >= num)
                                 {
                                     continue;
                                 }
                                 throw new ArgumentException(StringResources.PrincipalCollectionArrayTooSmall);
                             }
                         }
                         finally
                         {
                             if (resultSetBookmark != null)
                             {
                                 this.resultSet.RestoreBookmark(resultSetBookmark);
                             }
                         }
                     }
                     foreach (object arrayList in arrayLists)
                     {
                         array.SetValue(arrayList, index);
                         index++;
                     }
                     return;
                 }
                 else
                 {
                     throw new ArgumentException(StringResources.PrincipalCollectionIndexNotInArray);
                 }
             }
             else
             {
                 throw new ArgumentException(StringResources.PrincipalCollectionNotOneDimensional);
             }
         }
         else
         {
             throw new ArgumentNullException("array");
         }
     }
     else
     {
         throw new ArgumentOutOfRangeException("index");
     }
 }