/// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnConfirm_Click(object sender, EventArgs e)
        {
            var input = CheckInput();

            if (!input.Item1)
            {
                MessageUtil.ShowError(input.Item2);
                return;
            }

            try
            {
                var task = Task.Run(() =>
                {
                    UploadFileInfo info = new UploadFileInfo();
                    info.Name           = this.txtName.Text;
                    info.LocalPath      = this.txtFile.Text;
                    info.Remark         = this.txtRemark.Text;

                    var result = CallerFactory <IAttachmentService> .GetInstance(CallerType.WebApi).UploadAsync(info);
                    return(result);
                });

                this.attachment = await task;

                MessageUtil.ShowInfo(string.Format("上传文件:{0} 成功", attachment.Name));
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageUtil.ShowError(ex.Message);
            }
        }
        /// <summary>
        /// 设置图片
        /// </summary>
        /// <param name="id">附件ID</param>
        private void SetImage(string id)
        {
            var imageStream = CallerFactory <IAttachmentService> .GetInstance(CallerType.WebApi).Download(id);

            var image = Image.FromStream(imageStream);

            this.picView.Image = image;
            this.picView.Properties.ZoomPercent = 50;
        }
Beispiel #3
0
        public void FindInWin()
        {
            var data = CallerFactory <IAttachmentService> .GetInstance(CallerType.Win).FindAll();

            Assert.IsTrue(data.Count() > 0);

            foreach (var item in data)
            {
                Console.WriteLine("id:{0}, name:{1}", item.Id, item.Name);
            }
        }
Beispiel #4
0
        public void TestFindByFolder()
        {
            string folder = "2017-07";

            var data = CallerFactory <IAttachmentService> .GetInstance(CallerType.Win).FindByFolder(folder);

            Assert.IsTrue(data.Count() > 0);
            foreach (var item in data)
            {
                Console.WriteLine("id:{0}, name:{1}", item.Id, item.Name);
            }
        }
Beispiel #5
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="ids"></param>
 public void Init(List <string> ids)
 {
     if (ids != null && ids.Count > 0)
     {
         this.attachments = CallerFactory <IAttachmentService> .GetInstance(CallerType.Win).FindListInIds(ids).ToList();
     }
     else
     {
         this.attachments = new List <Attachment>();
     }
     this.bsAttachment.DataSource = attachments;
 }
Beispiel #6
0
        /// <summary>
        /// 初始化文件夹树
        /// </summary>
        private void InitFolders()
        {
            var folders = CallerFactory <IAttachmentService> .GetInstance(CallerType.Win).GetFolders().OrderByDescending(r => r);

            var topNode = this.folderTree.Nodes.Add("-1", "root");

            foreach (var item in folders)
            {
                topNode.Nodes.Add(item);
            }

            this.folderTree.ExpandAll();
        }
Beispiel #7
0
        /// <summary>
        /// 删除附件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuDelete_Click(object sender, EventArgs e)
        {
            var select = GetCurrentSelect();

            if (select == null)
            {
                return;
            }

            if (MessageUtil.ConfirmYesNo("是否删除指定附件:" + select.Name) == DialogResult.Yes)
            {
                CallerFactory <IAttachmentService> .GetInstance(CallerType.WebApi).Delete(select.Id);
            }
        }
Beispiel #8
0
        public void TestUpload2()
        {
            string filePath = AppDomain.CurrentDomain.BaseDirectory + "\\文档.doc";

            UploadFileInfo info = new UploadFileInfo();

            info.Name      = "兔斯基";
            info.Remark    = "qwert";
            info.LocalPath = filePath;

            var result = CallerFactory <IAttachmentService> .GetInstance(CallerType.WebApi).Upload(info);

            var attachment = result;

            Assert.AreEqual(info.Name, attachment.Name);
        }
Beispiel #9
0
        public void TestUpload4()
        {
            string filePath = "E:/Test/dashboard.ejs";

            UploadFileInfo info = new UploadFileInfo();

            info.Name      = "兔斯基";
            info.Remark    = "qwert";
            info.MD5Hash   = Hasher.GetFileMD5Hash(filePath);
            info.LocalPath = filePath;

            var result = CallerFactory <IAttachmentService> .GetInstance(CallerType.WebApi).Upload(info);

            var attachment = result;

            Assert.AreEqual(info.Name, attachment.Name);
        }
Beispiel #10
0
        public void TestUploadSingleFile()
        {
            string filePath = AppDomain.CurrentDomain.BaseDirectory + "\\tsj192.jpg";

            UploadFileInfo info = new UploadFileInfo();

            info.Name      = "兔斯基";
            info.Remark    = "8dfs";
            info.LocalPath = filePath;
            info.MD5Hash   = Hasher.GetFileMD5Hash(filePath);

            var task = CallerFactory <IAttachmentService> .GetInstance(CallerType.WebApi).UploadAsync(info);

            //task.ContinueWith<Attachment>(r => Console)

            var attachment = task.Result;

            Assert.AreEqual(info.Name, attachment.Name);
        }
Beispiel #11
0
        /// <summary>
        /// 上传附件
        /// </summary>
        private async void StartUpload()
        {
            int fileCount = this.uploadFileList.Count;

            this.prgBar.Properties.Step = this.prgBar.Properties.Maximum / fileCount;
            this.prgBar.Position        = 0;

            foreach (var item in this.uploadFileList)
            {
                try
                {
                    this.prgBar.PerformStep();

                    if (item.Status == UploadStatus.Complete)
                    {
                        continue;
                    }

                    var task = CallerFactory <IAttachmentService> .GetInstance(CallerType.WebApi).UploadAsync(item);

                    var r = await task;

                    if (task.IsCompleted)
                    {
                        item.Status = UploadStatus.Complete;
                        item.Id     = r.Id;
                        this.attachmentList.Add(r);

                        this.uploadFileGrid.UpdateBindingData();
                    }
                    else
                    {
                        item.Status = UploadStatus.Error;
                    }
                }
                catch (Exception e)
                {
                    MessageUtil.ShowWarning(e.Message);
                }
            }

            this.prgBar.Position = this.prgBar.Properties.Maximum;
        }
Beispiel #12
0
        /// <summary>
        /// 删除附件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.lbAttachments.SelectedIndex == -1 || this.lbAttachments.SelectedItem == null)
            {
                return;
            }

            var attach = this.lbAttachments.SelectedItem as Attachment;

            if (MessageUtil.ConfirmYesNo("是否删除选定附件:" + attach.Name) == DialogResult.Yes)
            {
                bool result = CallerFactory <IAttachmentService> .GetInstance(CallerType.WebApi).Delete(attach.Id);

                if (result)
                {
                    this.attachments.Remove(attach);
                }
                else
                {
                    MessageUtil.ShowWarning("删除附件失败");
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            var fileInfo = this.uploadFileGrid.GetCurrentSelect();

            if (fileInfo == null)
            {
                return;
            }

            if (fileInfo.Status == UploadStatus.Error || fileInfo.Status == UploadStatus.No)
            {
                this.uploadFileList.Remove(fileInfo);
                this.uploadFileGrid.UpdateBindingData();
            }
            else
            {
                CallerFactory <IAttachmentService> .GetInstance(CallerType.WebApi).Delete(fileInfo.Id);

                this.uploadFileList.Remove(fileInfo);

                var attach = this.attachmentList.Single(r => r.Id == fileInfo.Id);
                this.attachmentList.Remove(attach);
            }
        }
Beispiel #14
0
 public void TestDownload()
 {
     string id     = "59648851672e2239b85b00d3";
     var    stream = CallerFactory <IAttachmentService> .GetInstance(CallerType.WebApi).Download(id);
 }
Beispiel #15
0
        /// <summary>
        /// 读取附件
        /// </summary>
        /// <param name="id">附件ID</param>
        /// <returns></returns>
        private Stream GetFile(string id)
        {
            var fileStream = CallerFactory <IAttachmentService> .GetInstance(CallerType.WebApi).Download(id);

            return(fileStream);
        }
Beispiel #16
0
        /// <summary>
        /// 获取指定文件夹下附件
        /// </summary>
        /// <param name="folder">文件夹</param>
        public void Init(string folder)
        {
            this.attachments = CallerFactory <IAttachmentService> .GetInstance(CallerType.Win).FindByFolder(folder).ToList();

            this.bsAttachment.DataSource = attachments;
        }