Example #1
0
 public AliyunOssSource(AliyunOSSTransfer aliyunTransfer, string bucketName
     , string sourceRoot)
 {
     AliyunTransfer = aliyunTransfer;
     BucketName = bucketName;
     SourceRoot = sourceRoot;
 }
        public void can_download_utf_feed()
        {
            var aot = new AliyunOSSTransfer(OssEndPoint, AccessKeyId, AccessKeySecret);
            var aos = new AliyunOssSource(aot, BucketName, SourceRoot);
            var str = aos.GetUpdatesFeed();

            string expected = "<?xml version=";
            Assert.AreEqual(expected, str.Substring(0, expected.Length));
        }
        public void can_download_file()
        {
            string filePath = Directory.GetCurrentDirectory() + @"\UpdateFeed.xml";
            File.Delete(filePath);

            var aot = new AliyunOSSTransfer(OssEndPoint, AccessKeyId, AccessKeySecret);
            var aos = new AliyunOssSource(aot, BucketName, SourceRoot);

            Assert.IsTrue(aos.GetData("UpdateFeed.xml", "", null, ref filePath));
            Assert.IsTrue(File.Exists(filePath));

            string fileContent = File.ReadAllText(filePath);
            string expected = "<?xml version=";
            Assert.AreEqual(expected, fileContent.Substring(0, expected.Length));
        }
        public void can_upload_file()
        {
            string filePath = Directory.GetCurrentDirectory() + @"\test.xml";
            File.WriteAllText(filePath, "test");

            var aot = new AliyunOSSTransfer(OssEndPoint, AccessKeyId, AccessKeySecret);
            var aos = new AliyunOssSource(aot, BucketName, SourceRoot);

            string OssTestXml = SourceRoot + "/test.xml";
            aot.DeleteObject(BucketName, OssTestXml);
            Assert.AreEqual(aot.GetObjectSize(BucketName, OssTestXml), 0);

            Assert.IsTrue(aos.DeployData("test.xml", "", null, filePath));
            Assert.AreEqual(aot.GetObjectSize(BucketName, OssTestXml), new FileInfo(filePath).Length);

            aot.DeleteObject(BucketName, OssTestXml);
            File.Delete(filePath);
        }
Example #5
0
        private void btnUploadFiles_Click(object sender, EventArgs e)
        {
            try
            {
                if (_serverProfile == null)
                {
                    MessageBox.Show("���ȼ��ط���������!");
                    return;
                }

                //�����ʱĿ¼
                if (Directory.Exists(_uploadTempDirectory)) { Directory.Delete(_uploadTempDirectory, true); }

                var aot = new AliyunOSSTransfer(_serverProfile.OssEndPoint
                    , _serverProfile.OssAccessKeyID, _serverProfile.OssAccessKeySecret);
                var aos = new AliyunOssSource(aot, _serverProfile.OssBucketName, _serverProfile.OssSourceRoot);

                int uploadProgressSubItemIndex = 5;                 //���ź���C#��bug��û�а취����ColumnName��������
                foreach (ListViewItem thisItem in lstFiles.Items)
                {
                    //������ϴε��ϴ���־
                    thisItem.SubItems[uploadProgressSubItemIndex].Text = "-.-";

                    //û��ѡ�е��ļ����ϴ�
                    if (!thisItem.Checked)
                    {
                        thisItem.SubItems[uploadProgressSubItemIndex].Text = "���ϴ�";
                        continue;
                    }

                    //���̸߳���listView������
                    Action<string> notifySubitemProgressText = (notifyText) =>
                    {
                        lstFiles.BeginInvoke((MethodInvoker)delegate ()
                        {
                            thisItem.SubItems[uploadProgressSubItemIndex].Text = notifyText;
                        });
                    };

                    //���½���
                    Action<UpdateProgressInfo> onProgress = (updateProgressInfo) =>
                    {
                        notifySubitemProgressText(string.Format("{0}%", updateProgressInfo.Percentage));
                    };

                    FileInfoEx fileInfo = (FileInfoEx)thisItem.Tag;

                    //���ļ���������ʱ�ļ������棬����Ҫ�ϴ����ļ���ռ��
                    Directory.CreateDirectory(_uploadTempDirectory);
                    string tempFilePath = _uploadTempDirectory + fileInfo.FileInfo.Name;
                    File.Copy(fileInfo.FileInfo.FullName, tempFilePath, true);

                    //�߳��ϴ����������ܼ�ʱ���½���
                    Thread uploadThread = new Thread(delegate ()
                    {
                        if (aos.DeployData(fileInfo.FileInfo.Name, "", onProgress, tempFilePath) == false)
                        {
                            notifySubitemProgressText("ʧ��");
                        }
                    });
                    uploadThread.Start();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("�ϴ��ļ�����:%s", ex.Message));
            }
        }