Esempio n. 1
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;
                }));
            });
        }
Esempio n. 2
0
        /// <summary>
        /// 预览
        /// </summary>
        private void Preview()
        {
            if (dgResult.ItemsSource == null && dgResult.SelectedItems.Count <= 0)
            {
                return;
            }

            List <QiNiuFileInfo> list = new List <QiNiuFileInfo>();

            foreach (var item in dgResult.SelectedItems)
            {
                QiNiuFileInfo info = (QiNiuFileInfo)item;
                if (info != null)
                {
                    list.Add(info);
                }
            }
            if (list.Count > 0)
            {
                string address = string.Empty;

                if (list[0].FileType.StartsWith("text") || list[0].FileType.StartsWith("application"))
                {
                    address = GetPrivateUrl(list[0].FileName);
                    if (string.IsNullOrWhiteSpace(address))
                    {
                        return;
                    }



                    string tempfile = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), QiNiuHelper.RemoveWindowsFileNameSpicalChar(list[0].FileName));


                    System.Threading.ThreadPool.QueueUserWorkItem((state) =>
                    {
                        System.Net.WebClient wc = new System.Net.WebClient();

                        wc.DownloadFile(address, tempfile);

                        Dispatcher.Invoke(new Action(() =>
                        {
                            System.Diagnostics.Process.Start(tempfile);
                        }));
                    });

                    return;
                }
                //if (list[0].FileType.StartsWith("text"))
                // {
                //     address = GetPrivateUrl(list[0].FileName);
                //     if (string.IsNullOrWhiteSpace(address))
                //     {
                //         return;
                //     }

                //     System.Threading.ThreadPool.QueueUserWorkItem((state) =>
                //     {
                //         System.Net.WebClient wc = new System.Net.WebClient();
                //         string s = wc.DownloadString(address);

                //         Dispatcher.Invoke(new Action(() =>
                //         {
                //             new TextWindow
                //             {
                //                 WindowStartupLocation = WindowStartupLocation.CenterOwner,
                //                 Owner = this,
                //                 TxtContent = s
                //             }.ShowDialog();
                //         }));
                //     });

                //     return;
                // }
                if (list[0].FileType.StartsWith("image"))
                {
                    address = GetPrivateUrl(list[0].FileName + "?imageView2/2/w/600/h/400/interlace/1/q/100");
                    if (string.IsNullOrWhiteSpace(address))
                    {
                        return;
                    }
                }

                new PreviewWindow
                {
                    WindowStartupLocation = WindowStartupLocation.CenterOwner,
                    Owner           = this,
                    PreviewFilePath = address
                }.ShowDialog();
            }
        }