Ejemplo n.º 1
0
        /// <summary>
        /// 查询
        /// </summary>
        private void Search()
        {
            if (string.IsNullOrWhiteSpace(marker))
            {
                num = 1;
                btnSearch.Content = "查询";
            }
            else
            {
                btnSearch.Content = "加载更多";
            }
            bucket = SyncTargetBucketsComboBox.Text;
            ListResult listResult = bucketManager.ListFiles(bucket, txtStartWith.Text, marker, 1000, "");

            // DomainsResult domainsResult = bucketManager.Domains(SyncTargetBucketsComboBox.Text);
            domainsResult = bucketManager.Domains(bucket);

            if (listResult.Result.Items.Count >= 1000)
            {
                btnSearch.Content = "加载更多";
            }
            else
            {
                num               = 1;
                marker            = "";
                btnSearch.Content = "查询";
            }

            if (qiNiuFileInfoList == null || num == 1)
            {
                qiNiuFileInfoList = new List <QiNiuFileInfo>();
            }



            foreach (ListItem item in listResult.Result.Items)
            {
                // item.EndUser
                QiNiuFileInfo f = new QiNiuFileInfo
                {
                    Num         = num,
                    FileName    = item.Key,
                    FileType    = item.MimeType,
                    StorageType = QiNiuHelper.GetStorageType(item.FileType),
                    FileSize    = QiNiuHelper.GetFileSize(item.Fsize),
                    EndUser     = item.EndUser,
                    CreateDate  = QiNiuHelper.GetDataTime(item.PutTime)
                };
                qiNiuFileInfoList.Add(f);
                num++;
            }
            marker = listResult.Result.Marker;


            if (qiNiuFileInfoList.Count > 0)
            {
                dgResult.ItemsSource = !string.IsNullOrWhiteSpace(txtEndWith.Text)
                    ? qiNiuFileInfoList.Where(f => f.FileName.EndsWith(txtEndWith.Text.Trim()))
                    : qiNiuFileInfoList;
            }
            else
            {
                dgResult.ItemsSource = new List <QiNiuFileInfo>();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 查询
        /// </summary>
        private void Search()
        {
            if (btnSearch.IsEnabled == false)
            {
                return;
            }

            btnSearch.IsEnabled = false;



            if (string.IsNullOrWhiteSpace(marker))
            {
                num = 1;
                qiNiuFileInfoList = new List <QiNiuFileInfo>();
            }

            bucket    = SyncTargetBucketsComboBox.Text;
            startWith = txtStartWith.Text.Trim();
            ThreadPool.QueueUserWorkItem((state) =>
            {
                ListResult listResult = bucketManager.ListFiles(bucket, startWith, marker, 5000, "");
                Dispatcher.Invoke(new Action(() =>
                {
                    if (listResult != null && listResult.Result != null && listResult.Result.Marker != null)
                    {
                        marker = listResult.Result.Marker;
                    }
                    else
                    {
                        marker = string.Empty;
                    }
                    if (listResult?.Result?.Items != null)
                    {
                        foreach (ListItem item in listResult.Result.Items)
                        {
                            // item.EndUser
                            QiNiuFileInfo f = new QiNiuFileInfo
                            {
                                FileName    = item.Key,
                                FileType    = item.MimeType,
                                StorageType = QiNiuHelper.GetStorageType(item.FileType),
                                FileSize    = QiNiuHelper.GetFileSize(item.Fsize),
                                EndUser     = item.EndUser,
                                CreateDate  = QiNiuHelper.GetDataTime(item.PutTime)
                            };
                            qiNiuFileInfoList.Add(f);
                        }

                        if (qiNiuFileInfoList.Count > 0)
                        {
                            //dgResult.ItemsSource = !string.IsNullOrWhiteSpace(txtEndWith.Text)
                            //    ? qiNiuFileInfoList.Where(f => f.FileName.EndsWith(txtEndWith.Text.Trim()))
                            //    : qiNiuFileInfoList;
                            var list = qiNiuFileInfoList;


                            if (!string.IsNullOrWhiteSpace(txtEndWith.Text))
                            {
                                list = qiNiuFileInfoList.Where(f => f.FileName.EndsWith(txtEndWith.Text.Trim())).ToList();
                            }
                            if (list.Count > 0)
                            {
                                // dgResult.ItemsSource = list.OrderBy(t => t.CreateDate).ToList();
                                num  = 1;
                                list = list.OrderByDescending(t => t.CreateDate).ToList();
                                foreach (var s in list)
                                {
                                    s.Num = num++;
                                }
                                dgResult.ItemsSource = list;
                            }
                            else
                            {
                                dgResult.ItemsSource = new List <QiNiuFileInfo>();
                            }
                            //  dgResult.ItemsSource = list;
                        }
                        else
                        {
                            dgResult.ItemsSource = new List <QiNiuFileInfo>();
                        }
                    }
                    else
                    {
                        MessageBox.Show("未能加载数据!");
                    }
                    btnSearch.IsEnabled = true;
                }));
            });
        }