Esempio n. 1
0
 private void btnRename_Click(object sender, RoutedEventArgs e)
 {
     if (S3Manager != null && !string.IsNullOrWhiteSpace(Bucket) && !string.IsNullOrWhiteSpace(FileName) &&
         !string.IsNullOrWhiteSpace(txtRename.Text.Trim()))
     {
         var res = S3Helper.Move(S3Manager, Bucket, FileName, Bucket, txtRename.Text.Trim());
         if (!res.IsSuccess)
         {
             MessageBox.Show(res.Msg);
         }
     }
     this.Close();
 }
Esempio n. 2
0
        private void Delete()
        {
            //1.获得表中选中的数据
            if (dgResult.ItemsSource == null && dgResult.SelectedItems.Count <= 0)
            {
                return;
            }

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

            foreach (var item in dgResult.SelectedItems)
            {
                MyFileInfo info = (MyFileInfo)item;
                if (info != null)
                {
                    list.Add(info);
                }
            }
            if (list.Count > 0)
            {
                string           msg          = string.Join(",\r\n", list.Select(q => q.FileName));
                MessageBoxResult confirmToDel = MessageBox.Show("确认要删除所选行吗?\r\n" + msg, "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);

                if (confirmToDel != MessageBoxResult.Yes)
                {
                    return;
                }


                //执行批量删除
                List <string> ops = new List <string>();
                foreach (var key in list)
                {
                    S3Helper.Delete(_client, S3Cfg.BucketName, key.FileName);
                }


                Search();
                Thread.Sleep(10);
            }
        }
Esempio n. 3
0
        private void Preview()
        {
            if (dgResult.ItemsSource == null && dgResult.SelectedItems.Count <= 0)
            {
                return;
            }

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

            foreach (var item in dgResult.SelectedItems)
            {
                MyFileInfo info = (MyFileInfo)item;
                if (info != null)
                {
                    list.Add(info);
                }
            }
            if (list.Count > 0)
            {
                string tempfile = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), S3Helper.RemoveWindowsFileNameSpicalChar(list[0].FileName));


                System.Threading.ThreadPool.QueueUserWorkItem((state) =>
                {
                    bool res = S3Helper.Download(_client, S3Cfg.BucketName, list[0].FileName, tempfile);

                    Dispatcher.Invoke(new Action(() =>
                    {
                        if (res)
                        {
                            System.Diagnostics.Process.Start(tempfile);
                        }
                    }));
                });
            }
        }
Esempio n. 4
0
        private void Search()
        {
            if (btnSearch.IsEnabled == false)
            {
                return;
            }

            btnSearch.IsEnabled = false;



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

            if (!string.IsNullOrWhiteSpace(SyncTargetBucketsComboBox.Text))
            {
                S3Cfg.BucketName = SyncTargetBucketsComboBox.Text;
            }
            startWith = txtStartWith.Text.Trim();
            ThreadPool.QueueUserWorkItem((state) =>
            {
                //ListResult listResult = bucketManager.ListFiles(bucket, startWith, marker, 5000, "");
                ListObjectsRequest request = new ListObjectsRequest();
                request.BucketName         = S3Cfg.BucketName;
                request.Marker             = marker;
                request.Prefix             = startWith;
                request.MaxKeys            = 1000;
                // request.Delimiter = null;
                ListObjectsResponse response = _client.ListObjects(request);


                Dispatcher.Invoke(new Action(() =>
                {
                    if (response.HttpStatusCode == HttpStatusCode.OK && response.S3Objects.Count > 0)
                    {
                        marker = response.NextMarker;
                        foreach (S3Object item in response.S3Objects)
                        {
                            // item.EndUser
                            var f = new MyFileInfo
                            {
                                FileName    = item.Key,
                                FileType    = S3Helper.GetFileType(item.Key),
                                StorageType = item.StorageClass.Value,
                                FileSize    = S3Helper.GetFileSize(item.Size),
                                EndUser     = item.Owner.DisplayName,
                                CreateDate  = item.LastModified.ToString("yyyy/MM/dd HH:mm:ss")
                            };
                            myFileInfoList.Add(f);
                        }

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


                            if (!string.IsNullOrWhiteSpace(txtEndWith.Text))
                            {
                                list = myFileInfoList.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 <MyFileInfo>();
                            }
                            //  dgResult.ItemsSource = list;
                        }
                        else
                        {
                            marker = string.Empty;
                            dgResult.ItemsSource = new List <MyFileInfo>();
                        }

                        btnSearch.IsEnabled = true;
                    }
                }));
            });
        }
Esempio n. 5
0
        private void btnUpload_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new System.Windows.Forms.OpenFileDialog
            {
                Multiselect = true,
                Title       = @"选择上传文件"
            };

            if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            uploadResult = new StringBuilder();

            fileUploadFiles = ofd.FileNames;

            if (fileUploadFiles.Length <= 0)
            {
                return;
            }


            bool?result;


            if (fileUploadFiles.Length > 100)
            {
                MessageBox.Show("每次上传文件不得大于100个");
                return;
            }
            foreach (string file in fileUploadFiles)
            {
                var fileInfo = new System.IO.FileInfo(file);

                if (fileInfo.Length > 1024 * 1024 * 100)
                {
                    MessageBox.Show("单个文件大小不得大于100M");
                    return;
                }
            }

            btnUpload.Content   = "正在上传......";
            btnUpload.IsEnabled = false;
            result = true;


            LoadProgressBar();
            Dispatcher.Invoke(new Action(() =>
            {
                foreach (string file in fileUploadFiles)
                {
                    var uploadRes = S3Helper.Upload(_client, S3Cfg.BucketName, Path.GetFileName(file), file, cbOverlay.IsChecked == true);
                    result        = result & uploadRes.IsSuccess;
                    if (!uploadRes.IsSuccess)
                    {
                        uploadResult.Append(uploadRes.Msg);
                    }
                }
                pb1.Visibility = Visibility.Hidden;
            }));
            if (result == true)
            {
                MessageBox.Show("上传成功!");
            }
            else
            {
                MessageBox.Show(uploadResult.ToString());
            }
            btnUpload.Content   = "上传";
            btnUpload.IsEnabled = true;
            Search();
        }