예제 #1
0
        public void FirstLastTest()
        {
            var master = new SortSet <int, int>(0.25, 32);

            for (var i = 0; i < 65536; i++)
            {
                master.Add(i, i);
            }

            Assert.AreEqual(0, master.First());
            Assert.AreEqual(65535, master.Last());

            for (var i = 0; i < 65536; i++)
            {
                Assert.AreEqual(i, master.First());
                Assert.AreEqual(i, master.Shift());
            }

            Assert.AreEqual(0, master.Count);

            master = new SortSet <int, int>(0.25, 32);
            for (var i = 0; i < 65536; i++)
            {
                master.Add(i, i);
            }
            for (var i = 0; i < 65536; i++)
            {
                Assert.AreEqual(65535 - i, master.Last());
                Assert.AreEqual(65535 - i, master.Pop());
            }
        }
예제 #2
0
        public void PopEmptySortSet()
        {
            var master = new SortSet <int, int>(0.25, 32);

            ExceptionAssert.Throws <InvalidOperationException>(() =>
            {
                master.Pop();
            });
        }
예제 #3
0
        /// <summary>
        /// 执行下载
        /// 因为会在多处调用,所以单独封装起来
        /// </summary>
        private void ExecuteDownload()
        {
            if (downloadSortSet.Count > 0)
            {
                var item = downloadSortSet.Pop(); // 从末尾弹出一个,因为末尾的是优先级最高的
                if (null != item)
                {
                    // 更新一下当前数量,以及文件名称
                    UpdateInfo.CurrentIndex = updateInfo.TaskQueueCount - downloadSortSet.Count; // 总数减去剩余的
                    UpdateInfo.FileName     = item.FileName;

                    // 创建uri并进行下载
                    Uri uri = new Uri(item.Url);
                    if (item.DownloadResType == DownloadResType.StringContent)
                    {
                        httpClient.GetString(uri, _response =>
                        {
                            if (true == _response.IsSuccessStatusCode)
                            {
                                DownloadSuccessExecute(item, _response.Data);
                            }
                            else
                            {
                                DownloadFailExecute(item, (int)_response.StatusCode);
                            }
                        });
                    }
                    else if (item.DownloadResType == DownloadResType.AssetBundle ||
                             item.DownloadResType == DownloadResType.ByteArray)
                    {
                        cacheBytes.Clear();
                        httpClient.GetByteArray(uri, HttpCompletionOption.StreamResponseContent, _response =>
                        {
                            if (false == _response.IsSuccessStatusCode)
                            {
                                DownloadFailExecute(item, (int)_response.StatusCode);
                            }
                            else
                            {
                                cacheBytes.AddRange(_response.Data);
                                if (true == _response.PercentageComplete >= 100)
                                {
                                    if (true == _response.IsSuccessStatusCode)
                                    {
                                        DownloadSuccessExecute(item, cacheBytes.ToArray());
                                    }
                                }
                                else
                                {
                                    DownloadProgressExecute(item, _response.PercentageComplete, _response.Data.Length);
                                }
                            }
                        });
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// 尾部推出测试
        /// </summary>
        public void PopTest()
        {
            var master = new SortSet <int, int>(0.25, 32);

            for (var i = 0; i < 100; i++)
            {
                master.Add(i, i);
            }

            for (var i = 0; i < 65536; i++)
            {
                Assert.AreEqual(65535 - i, master.Pop());
            }

            Assert.AreEqual(0, master.Count);
        }