Esempio n. 1
0
 void ICollection.CopyTo(Array array, int index)
 {
     if (array is T[] arrayAs)
     {
         _InternalQueue.CopyTo(arrayAs, index);
     }
     else
     {
         throw new ArgumentNullException(nameof(array));
     }
 }
        public static void Test7_Exceptions()
        {
            ConcurrentQueue<int> queue = null;
            Assert.Throws<ArgumentNullException>(
               () => queue = new ConcurrentQueue<int>((IEnumerable<int>)null));
            // "Test7_Exceptions:  The constructor didn't throw ANE when null collection passed");

            queue = new ConcurrentQueue<int>();
            //CopyTo
            Assert.Throws<ArgumentNullException>( () => queue.CopyTo(null, 0));
            // "Test7_Exceptions:  CopyTo didn't throw ANE when null array passed");
            Assert.Throws<ArgumentOutOfRangeException>( () => queue.CopyTo(new int[1], -1));
            // "Test7_Exceptions:  CopyTo didn't throw AORE when negative array index passed");
        }
Esempio n. 3
0
        public static void Test7_Exceptions()
        {
            ConcurrentQueue <int> queue = null;

            Assert.Throws <ArgumentNullException>(
                () => queue = new ConcurrentQueue <int>((IEnumerable <int>)null));
            // "Test7_Exceptions:  The constructor didn't throw ANE when null collection passed");

            queue = new ConcurrentQueue <int>();
            //CopyTo
            Assert.Throws <ArgumentNullException>(() => queue.CopyTo(null, 0));
            // "Test7_Exceptions:  CopyTo didn't throw ANE when null array passed");
            Assert.Throws <ArgumentOutOfRangeException>(() => queue.CopyTo(new int[1], -1));
            // "Test7_Exceptions:  CopyTo didn't throw AORE when negative array index passed");
        }
        public void CopyTo_AllItemsCopiedAtCorrectLocation(int count, bool viaInterface)
        {
            var q = new ConcurrentQueue <int>(Enumerable.Range(0, count));
            var c = (ICollection)q;

            int[] arr = new int[count];

            if (viaInterface)
            {
                c.CopyTo(arr, 0);
            }
            else
            {
                q.CopyTo(arr, 0);
            }
            //Assert.AreEqual(q, arr);
            if (!q.SequenceEqual(arr))
            {
                Assert.Fail("The copy was unsuccessful");
            }

            if (count > 1)
            {
                int toRemove  = count / 2;
                int remaining = count - toRemove;
                for (int i = 0; i < toRemove; i++)
                {
                    int item;
                    Assert.IsTrue(q.TryDequeue(out item));
                    Assert.AreEqual(i, item);
                }

                if (viaInterface)
                {
                    c.CopyTo(arr, 1);
                }
                else
                {
                    q.CopyTo(arr, 1);
                }

                Assert.AreEqual(0, arr[0]);
                for (int i = 0; i < remaining; i++)
                {
                    Assert.AreEqual(arr[1 + i], i + toRemove);
                }
            }
        }
Esempio n. 5
0
        public int Save(Server S, string s = "")
        {
            string Identifier = AlphaNum.Replace(s.Trim().ToLower(), "");

            if (Identifier == string.Empty)
            {
                Identifier = S.Id.ToString();
            }

            SongData[] Data;
            if (CurrentSong != null)
            {
                Data    = new SongData[SongQueue.Count + 1];
                Data[0] = CurrentSong.Song;
                SongQueue.CopyTo(Data, 1);
            }
            else
            {
                Data = Songs;
            }

            using (BinaryWriter Writer = new BinaryWriter(File.Open(Bot.MainDir + "data.playlist." + Identifier + ".txt", FileMode.Create)))
            {
                Writer.Write(Data.Length);
                for (int i = 0; i < Data.Length; i++)
                {
                    Writer.Write(Data[i].Query);
                    Writer.Write(Data[i].Local);
                }
            }

            return(Data.Length);
        }
Esempio n. 6
0
        public void Synchronize()
        {
            var newFrontResourcesBuffer = new Action[_backResourceLoadBuffer.Count];

            _backResourceLoadBuffer.CopyTo(newFrontResourcesBuffer, 0);
            _backResourceLoadBuffer = new ConcurrentQueue <Action>();
            KeyValuePair <IRenderTarget, RenderPipeline[]>[] newFrontDrawCallBatchBuffer;
            lock (_backBufferLock)
            {
                newFrontDrawCallBatchBuffer =
                    _backPipelineRunsBuffer.ToArray()
                    .Select(kvp => new KeyValuePair <IRenderTarget, RenderPipeline[]>(kvp.Key, kvp.Value.ToArray()))
                    .ToArray();
                _backPipelineRunsBuffer = new Dictionary <IRenderTarget, List <RenderPipeline> >();
            }
            lock (_swapLock)
            {
                _frontResourceLoadBuffer = newFrontResourcesBuffer;
                _frontPipelineRunsBuffer = newFrontDrawCallBatchBuffer;
                // Swap all buffers in all enqueued GLDrawCallBuffers
                foreach (var pipeline in _frontPipelineRunsBuffer.SelectMany(kvp => kvp.Value))
                {
                    pipeline.SwapDrawCallBuffers();
                }
                OnSyncronize?.Invoke(this, EventArgs.Empty);
                Monitor.Pulse(_swapLock);
            }
        }
Esempio n. 7
0
 private void SaveLogs()
 {
     if (_saveLogsFailCount > LOG_FAIL_COUNT)
     {
         throw new Exception($"Logger failed to save logs {LOG_FAIL_COUNT} times");
     }
     if (!_loggerIsBusy)
     {
         _saveLogsFailCount = 0;
         var count = _logs.Count;
         if (count > 0)
         {
             _loggerIsBusy = true;
             var logsToSave = new string[count];
             _logs.CopyTo(logsToSave, 0);
             _logs.Clear();
             File.AppendAllLines(Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\Desktop\log.txt"), logsToSave);
             _loggerIsBusy = false;
         }
     }
     else
     {
         _saveLogsFailCount++;
     }
 }
Esempio n. 8
0
        public static ConcurrentQueue <T> CloneConcurrentQueue <T>(this ConcurrentQueue <T> queue)
        {
            var messages = new T[queue.Count];

            queue.CopyTo(messages, 0);

            return(new ConcurrentQueue <T>(messages));
        }
Esempio n. 9
0
 /// <summary>
 /// 从特定的 <see cref="T:System.Array"/> 索引处开始,将 <see cref="T:System.Collections.ICollection"/> 的元素复制到一个 <see cref="T:System.Array"/> 中。
 /// </summary>
 /// <param name="array">作为从 <see cref="T:System.Collections.ICollection"/> 复制的元素的目标位置的一维 <see cref="T:System.Array"/>。<see cref="T:System.Array"/> 必须具有从零开始的索引。</param>
 /// <param name="index"><paramref name="array"/> 中从零开始的索引,将在此处开始复制。</param>
 /// <exception cref="T:System.ArgumentNullException">
 ///   <paramref name="array"/> 为 null。</exception>
 ///
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 ///   <paramref name="index"/> 小于零。</exception>
 ///
 /// <exception cref="T:System.ArgumentException">
 ///   <paramref name="array"/> 是多维的。- 或 -源 <see cref="T:System.Collections.ICollection"/> 中的元素数目大于从 <paramref name="index"/> 到目标 <paramref name="array"/> 末尾之间的可用空间。</exception>
 ///
 /// <exception cref="T:System.ArgumentException">源 <see cref="T:System.Collections.ICollection"/> 的类型无法自动转换为目标 <paramref name="array"/> 的类型。</exception>
 void ICollection.CopyTo(Array array, int index)
 {
     if (!(array is T[]))
     {
         throw new ArgumentException("传入数据不是指定的类型,应传入T[]。");
     }
     _Q.CopyTo((T[])array, index);
 }
        public void ToArrayTest()
        {
            int[]  array = queue.ToArray();
            string s     = string.Empty;

            foreach (int i in array)
            {
                s += i;
            }
            Assert.AreEqual("0123456789", s, "#1 : " + s);
            queue.CopyTo(array, 0);
            s = string.Empty;
            foreach (int i in array)
            {
                s += i;
            }
            Assert.AreEqual("0123456789", s, "#2 : " + s);
        }
        public void ConcurrentQueue_FunctionsAsNormalQueue_ForSingleThreadedAccess(params int[] numbersToAdd)
        {
            // Because we're not doing anything interesting with the queue itself, it seems reasonable to just wrap all of the basic queue API tests into one test

            // Enqueue
            foreach (var number in numbersToAdd)
            {
                _concurrentQueue.Enqueue(number);
            }

            // Peek
            var head = _concurrentQueue.Peek();

            Assert.AreEqual(numbersToAdd.First(), head);

            // GetEnumerator<T>
            var index             = 0;
            var genericEnumerator = _concurrentQueue.GetEnumerator();

            while (index < numbersToAdd.Length && genericEnumerator.MoveNext())
            {
                Assert.AreEqual(numbersToAdd[index++], genericEnumerator.Current);
            }
            Assert.AreEqual(numbersToAdd.Length, index);

            // GetEnumerator
            index = 0;
            var nongenericEnumerator = ((IEnumerable)_concurrentQueue).GetEnumerator();

            while (index < numbersToAdd.Length && nongenericEnumerator.MoveNext())
            {
                Assert.AreEqual(numbersToAdd[index++], nongenericEnumerator.Current);
            }
            Assert.AreEqual(numbersToAdd.Length, index);

            // Count
            Assert.AreEqual(_concurrentQueue.Count, numbersToAdd.Length);

            // CopyTo
            var destinationArray = new int[numbersToAdd.Length];

            _concurrentQueue.CopyTo(destinationArray, 0);
            Assert.True(numbersToAdd.SequenceEqual(destinationArray));

            // Contains
            Assert.True(numbersToAdd.All(_concurrentQueue.Contains));

            // Dequeue
            head = _concurrentQueue.Dequeue();
            Assert.AreEqual(numbersToAdd.First(), head);
            Assert.True(_concurrentQueue.SequenceEqual(numbersToAdd.Skip(1)));

            // Clear
            _concurrentQueue.Clear();
            Assert.AreEqual(0, _concurrentQueue.Count);
            Assert.False(numbersToAdd.Any(_concurrentQueue.Contains));
        }
 public T[] ToArray()
 {
     T[] result = null;
     lock (syncObject)
     {
         result = new T[queue.Count];
         queue.CopyTo(result, 0);
     }
     return(result);
 }
Esempio n. 13
0
 public void Commit()
 {
     backupMessageArray = new object[messageQueue.Count];
     messageQueue.CopyTo(backupMessageArray, 0);
     while (messageQueue.Count > 0)
     {
         object result;
         if (messageQueue.TryDequeue(out result))
         {
             dispatcher.DispatchMessage(result);
         }
     }
     committed = true;
 }
Esempio n. 14
0
        public void ToArrayTest()
        {
            var array   = _queue.ToArray();
            var s       = string.Empty;
            var builder = new StringBuilder();

            builder.Append(s);
            foreach (var i in array)
            {
                builder.Append(i);
            }
            s = builder.ToString();
            Assert.AreEqual("0123456789", s, "#1 : " + s);
            _queue.CopyTo(array, 0);
            s       = string.Empty;
            builder = new StringBuilder();
            builder.Append(s);
            foreach (var i in array)
            {
                builder.Append(i);
            }
            s = builder.ToString();
            Assert.AreEqual("0123456789", s, "#2 : " + s);
        }
        private void LoadStorage()
        {
            string storage_path = Config.STORAGE_PATH;
            string storage_name = Config.STORAGE_NAME;
            string path_comb    = Path.Combine(storage_name, storage_path);

            using (Stream stream = File.Open(path_comb, FileMode.Create))
            {
                var formater = new BinaryFormatter();

                TransactionProtocol[] transact_array = new TransactionProtocol[transactions.Count];
                transactions.CopyTo(transact_array, 0);
                var list_transact = transact_array.OfType <TransactionProtocol>().ToList();
                formater.Serialize(stream, list_transact);
            }
        }
        private static void ExerciseFullApi(ConcurrentQueue <int> concurrentQueue, int[] numbersToAdd)
        {
            dynamic _;

            // Enqueue
            foreach (var number in numbersToAdd)
            {
                concurrentQueue.Enqueue(number);
            }

            // Peek
            try
            {
                _ = concurrentQueue.Peek();
            }
            catch (InvalidOperationException)
            {
            }

            var index             = 0;
            var genericEnumerator = concurrentQueue.GetEnumerator();

            while (index < numbersToAdd.Length && genericEnumerator.MoveNext())
            {
                _ = genericEnumerator.Current;
            }

            index = 0;
            var nongenericEnumerator = ((IEnumerable)concurrentQueue).GetEnumerator();

            while (index < numbersToAdd.Length && nongenericEnumerator.MoveNext())
            {
                _ = nongenericEnumerator.Current;
            }

            _ = concurrentQueue.Count;

            var destinationArray = new int[500];

            concurrentQueue.CopyTo(destinationArray, 0);
            _ = concurrentQueue.Contains(numbersToAdd.First());
            _ = concurrentQueue.DequeueOrDefault();
            concurrentQueue.Clear();
        }
Esempio n. 17
0
 public void Commit()
 {
     lock (sync)
     {
         backupMessageArray = new object[messageQueue.Count];
         messageQueue.CopyTo(backupMessageArray, 0);
         while (messageQueue.Count > 0)
         {
             object result;
             if (messageQueue.TryDequeue(out result))
             {
                 var @event     = result;
                 var @eventType = @event.GetType();
                 var method     = publishMethod.MakeGenericMethod(@eventType);
                 method.Invoke(this.eventAggregator, new object[] { @event });
             }
         }
         committed = true;
     }
 }
Esempio n. 18
0
        /**
         * return all sequence numbers whose last feedback time is larger than k*RTT
         *
         * @param RTT - the current round trip time
         * @param doFeedback - true if the k parameter should be increased and the time should
         * be reset (using {@link ReceiverLossListEntry#feedback()} )
         * @return
         */
        public List <long> getFilteredSequenceNumbers(long RTT, bool doFeedback)
        {
            List <long> result = new List <long>();

            ReceiverLossListEntry[] sorted = new ReceiverLossListEntry[backingList.Count];
            backingList.CopyTo(sorted, 0);
            Array.Sort(sorted);
            foreach (ReceiverLossListEntry e in sorted)
            {
                if ((Util.getCurrentTime() - e.getLastFeedbackTime()) > e.getK() * RTT)
                {
                    result.Add(e.GetSequenceNumber());
                    if (doFeedback)
                    {
                        e.Feedback();
                    }
                }
            }
            return(result);
        }
Esempio n. 19
0
 private void RegisterContinuation(CompletesContinuation continuationCompletes)
 {
     if (HasException.Get())
     {
         var currentContinuations = new CompletesContinuation[Continuations.Count];
         Continuations.CopyTo(currentContinuations, 0);
         var continuationsCount = Continuations.Count;
         for (var i = 0; i < continuationsCount; i++)
         {
             Continuations.TryDequeue(out _);
         }
         Continuations.Enqueue(continuationCompletes);
         foreach (var currentContinuation in currentContinuations)
         {
             Continuations.Enqueue(currentContinuation);
         }
     }
     else
     {
         Continuations.Enqueue(continuationCompletes);
     }
 }
Esempio n. 20
0
        public void WriteLogs()
        {
            int length;

            Log[] logs;
            lock (_queue)
            {
                length = _queue.Count;
                logs   = new Log[length];
                _queue.CopyTo(logs, 0);
            }

            _writer.WriteLogs(logs);

            lock (_queue)
            {
                for (var i = 0; i < length; i++)
                {
                    _queue.TryDequeue(out _);
                }
            }
        }
Esempio n. 21
0
        // Instantiates the queue w/ the enumerator ctor and validates the resulting copyto & toarray.
        public static void Test5_CtorAndCopyToAndToArray(int count)
        {
            int[] arr = new int[count];
            for (int i = 0; i < count; i++)
            {
                arr[i] = i;
            }
            ConcurrentQueue <int> s = new ConcurrentQueue <int>(arr);

            // try toarray.
            int[] sa1 = s.ToArray();
            Assert.Equal(arr.Length, sa1.Length);

            for (int i = 0; i < sa1.Length; i++)
            {
                Assert.Equal(arr[i], sa1[i]);
            }

            int[] sa2 = new int[count];
            s.CopyTo(sa2, 0);
            Assert.Equal(arr.Length, sa2.Length);

            for (int i = 0; i < sa2.Length; i++)
            {
                Assert.Equal(arr[i], sa2[i]);
            }

            object[] sa3 = new object[count]; // test array variance.
            ((System.Collections.ICollection)s).CopyTo(sa3, 0);
            Assert.Equal(arr.Length, sa3.Length);

            for (int i = 0; i < sa3.Length; i++)
            {
                Assert.Equal(arr[i], (int)sa3[i]);
            }
        }
Esempio n. 22
0
 public void CopyTo(T[] array, int arrayIndex)
 {
     _dataQueue.CopyTo(array, arrayIndex);
 }
Esempio n. 23
0
 public void CopyTo(T[] array, int index)
 {
     _queue.CopyTo(array, index);
 }
Esempio n. 24
0
        // Instantiates the queue w/ the enumerator ctor and validates the resulting copyto & toarray.
        public static void Test5_CtorAndCopyToAndToArray(int count)
        {
            int[] arr = new int[count];
            for (int i = 0; i < count; i++) arr[i] = i;
            ConcurrentQueue<int> s = new ConcurrentQueue<int>(arr);

            // try toarray.
            int[] sa1 = s.ToArray();
            Assert.Equal(arr.Length, sa1.Length);

            for (int i = 0; i < sa1.Length; i++)
            {
                Assert.Equal(arr[i], sa1[i]);
            }

            int[] sa2 = new int[count];
            s.CopyTo(sa2, 0);
            Assert.Equal(arr.Length, sa2.Length);

            for (int i = 0; i < sa2.Length; i++)
            {
                Assert.Equal(arr[i], sa2[i]);
            }

            object[] sa3 = new object[count]; // test array variance.
            ((System.Collections.ICollection)s).CopyTo(sa3, 0);
            Assert.Equal(arr.Length, sa3.Length);

            for (int i = 0; i < sa3.Length; i++)
            {
                Assert.Equal(arr[i], (int)sa3[i]);
            }
        }
Esempio n. 25
0
        // Instantiates the queue w/ the enumerator ctor and validates the resulting copyto & toarray.
        private static bool RunConcurrentQueueTest5_CtorAndCopyToAndToArray(int count)
        {
            TestHarness.TestLog("* RunConcurrentQueueTest5_CtorAndCopyToAndToArray()");

            int[] arr = new int[count];
            for (int i = 0; i < count; i++)
            {
                arr[i] = i;
            }
            ConcurrentQueue <int> s = new ConcurrentQueue <int>(arr);

            // try toarray.
            int[] sa1 = s.ToArray();
            if (sa1.Length != arr.Length)
            {
                TestHarness.TestLog("  > ToArray resulting array is diff length: got {0}, wanted {1}",
                                    sa1.Length, arr.Length);
                return(false);
            }
            for (int i = 0; i < sa1.Length; i++)
            {
                if (sa1[i] != arr[i])
                {
                    TestHarness.TestLog("  > ToArray returned an array w/ diff contents: got {0}, wanted {1}",
                                        sa1[i], arr[i]);
                    return(false);
                }
            }

            int[] sa2 = new int[count];
            s.CopyTo(sa2, 0);
            if (sa2.Length != arr.Length)
            {
                TestHarness.TestLog("  > CopyTo(int[]) resulting array is diff length: got {0}, wanted {1}",
                                    sa2.Length, arr.Length);
                return(false);
            }
            for (int i = 0; i < sa2.Length; i++)
            {
                if (sa2[i] != arr[i])
                {
                    TestHarness.TestLog("  > CopyTo(int[]) returned an array w/ diff contents: got {0}, wanted {1}",
                                        sa2[i], arr[i]);
                    return(false);
                }
            }

            object[] sa3 = new object[count]; // test array variance.
            ((System.Collections.ICollection)s).CopyTo(sa3, 0);
            if (sa3.Length != arr.Length)
            {
                TestHarness.TestLog("  > CopyTo(object[]) resulting array is diff length: got {0}, wanted {1}",
                                    sa3.Length, arr.Length);
                return(false);
            }
            for (int i = 0; i < sa3.Length; i++)
            {
                if ((int)sa3[i] != arr[i])
                {
                    TestHarness.TestLog("  > CopyTo(object[]) returned an array w/ diff contents: got {0}, wanted {1}",
                                        sa3[i], arr[i]);
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="array"></param>
 /// <param name="arrayIndex"></param>
 public void CopyTo(T[] array, int arrayIndex)
 {
     _cacheStruct.CopyTo(array, arrayIndex);
 }
Esempio n. 27
0
        // Instantiates the queue w/ the enumerator ctor and validates the resulting copyto & toarray.
        private static bool RunConcurrentQueueTest5_CtorAndCopyToAndToArray(int count)
        {
            TestHarness.TestLog("* RunConcurrentQueueTest5_CtorAndCopyToAndToArray()");

            int[] arr = new int[count];
            for (int i = 0; i < count; i++) arr[i] = i;
            ConcurrentQueue<int> s = new ConcurrentQueue<int>(arr);

            // try toarray.
            int[] sa1 = s.ToArray();
            if (sa1.Length != arr.Length)
            {
                TestHarness.TestLog("  > ToArray resulting array is diff length: got {0}, wanted {1}",
                    sa1.Length, arr.Length);
                return false;
            }
            for (int i = 0; i < sa1.Length; i++)
            {
                if (sa1[i] != arr[i])
                {
                    TestHarness.TestLog("  > ToArray returned an array w/ diff contents: got {0}, wanted {1}",
                        sa1[i], arr[i]);
                    return false;
                }
            }

            int[] sa2 = new int[count];
            s.CopyTo(sa2, 0);
            if (sa2.Length != arr.Length)
            {
                TestHarness.TestLog("  > CopyTo(int[]) resulting array is diff length: got {0}, wanted {1}",
                    sa2.Length, arr.Length);
                return false;
            }
            for (int i = 0; i < sa2.Length; i++)
            {
                if (sa2[i] != arr[i])
                {
                    TestHarness.TestLog("  > CopyTo(int[]) returned an array w/ diff contents: got {0}, wanted {1}",
                        sa2[i], arr[i]);
                    return false;
                }
            }

            object[] sa3 = new object[count]; // test array variance.
            ((System.Collections.ICollection)s).CopyTo(sa3, 0);
            if (sa3.Length != arr.Length)
            {
                TestHarness.TestLog("  > CopyTo(object[]) resulting array is diff length: got {0}, wanted {1}",
                    sa3.Length, arr.Length);
                return false;
            }
            for (int i = 0; i < sa3.Length; i++)
            {
                if ((int)sa3[i] != arr[i])
                {
                    TestHarness.TestLog("  > CopyTo(object[]) returned an array w/ diff contents: got {0}, wanted {1}",
                        sa3[i], arr[i]);
                    return false;
                }
            }

            return true;
        }
Esempio n. 28
0
 public void CopyTo(ILayer[] array, int arrayIndex)
 {
     _layers.CopyTo(array, arrayIndex);
 }
Esempio n. 29
0
 public static void CopyTo <T>(ConcurrentQueue <T> concurrentQueue, T[] array, int index)
 {
     ConcurrentCollectionHelper.Interleave();
     concurrentQueue.CopyTo(array, index);
 }
Esempio n. 30
0
 /// <summary>
 /// Retrieves a copy of the Error stack
 /// </summary>
 /// <returns>All errors thrown by functions using the message or flowcontrol system</returns>
 public static PsfExceptionRecord[] GetErrors()
 {
     PsfExceptionRecord[] temp = new PsfExceptionRecord[ErrorRecords.Count];
     ErrorRecords.CopyTo(temp, 0);
     return(temp);
 }
Esempio n. 31
0
 /// <summary>
 /// Retrieves a copy of the message log
 /// </summary>
 /// <returns>All messages logged this session.</returns>
 public static LogEntry[] GetLog()
 {
     LogEntry[] temp = new LogEntry[LogEntries.Count];
     LogEntries.CopyTo(temp, 0);
     return(temp);
 }
Esempio n. 32
0
 /// <summary>
 /// Copy semantics for fast array initialization and processing.
 /// </summary>
 /// <param name="array">Copy queue elements to array.</param>
 /// <param name="index">Copy queue elements to which index position.</param>
 public void CopyTo(Array array, int index)
 {
     _queue.CopyTo((TP[])array, index);
 }
Esempio n. 33
0
        public void CopyTo_AllItemsCopiedAtCorrectLocation(int count, bool viaInterface)
        {
            var q = new ConcurrentQueue<int>(Enumerable.Range(0, count));
            var c = (ICollection)q;
            int[] arr = new int[count];

            if (viaInterface)
            {
                c.CopyTo(arr, 0);
            }
            else
            {
                q.CopyTo(arr, 0);
            }
            Assert.Equal(q, arr);

            if (count > 1)
            {
                int toRemove = count / 2;
                int remaining = count - toRemove;
                for (int i = 0; i < toRemove; i++)
                {
                    int item;
                    Assert.True(q.TryDequeue(out item));
                    Assert.Equal(i, item);
                }

                if (viaInterface)
                {
                    c.CopyTo(arr, 1);
                }
                else
                {
                    q.CopyTo(arr, 1);
                }

                Assert.Equal(0, arr[0]);
                for (int i = 0; i < remaining; i++)
                {
                    Assert.Equal(arr[1 + i], i + toRemove);
                }
            }
        }
Esempio n. 34
0
 /// <summary>
 /// 获取改变的字段属性
 /// </summary>
 /// <returns></returns>
 internal string[] GetChangePropertys()
 {
     string[] columns = new string[_changePropertys.Count];
     _changePropertys.CopyTo(columns, 0);
     return(columns);
 }
Esempio n. 35
0
 public void CopyTo_Empty_Success()
 {
     var q = new ConcurrentQueue<int>();
     q.CopyTo(Array.Empty<int>(), 0);
 }