|
@@ -5,17 +5,23 @@
|
|
* ==============================================================================*/
|
|
* ==============================================================================*/
|
|
|
|
|
|
using System;
|
|
using System;
|
|
|
|
+using System.Diagnostics;
|
|
using System.IO;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Reflection;
|
|
using Aliyun.OSS;
|
|
using Aliyun.OSS;
|
|
using Aliyun.OSS.Common;
|
|
using Aliyun.OSS.Common;
|
|
|
|
+using Aliyun.OSS.Util;
|
|
using ICSharpCode.SharpZipLib.Zip;
|
|
using ICSharpCode.SharpZipLib.Zip;
|
|
using Newtonsoft.Json.Linq;
|
|
using Newtonsoft.Json.Linq;
|
|
using SAGA.DotNetUtils.FileOperate;
|
|
using SAGA.DotNetUtils.FileOperate;
|
|
using SAGA.DotNetUtils.Http;
|
|
using SAGA.DotNetUtils.Http;
|
|
using Update.Core.Entities;
|
|
using Update.Core.Entities;
|
|
using PackageUploader.Compress;
|
|
using PackageUploader.Compress;
|
|
|
|
+using PackageUploader.Http;
|
|
|
|
+using SAGA.DotNetUtils.Others;
|
|
|
|
+using Update;
|
|
|
|
+using HttpUtils = Update.HttpUtils;
|
|
|
|
|
|
namespace PackageUploader
|
|
namespace PackageUploader
|
|
{
|
|
{
|
|
@@ -176,30 +182,42 @@ namespace PackageUploader
|
|
{
|
|
{
|
|
bool result = true;
|
|
bool result = true;
|
|
string fileName = Path.GetFileName(compressPath);
|
|
string fileName = Path.GetFileName(compressPath);
|
|
- string key = $"{Const.OSSKeyPath}{fileName}";
|
|
|
|
m_UploadAction = action;
|
|
m_UploadAction = action;
|
|
- OssClient client = new OssClient(Const.Endpoint, Const.AccessKeyId, Const.AccessKeySecret);
|
|
|
|
|
|
+ var url = HttpUtils.GetUploadUrl(fileName);
|
|
try
|
|
try
|
|
{
|
|
{
|
|
using (var fs = new MemoryStream(FileStreamOperate.ReadFile(compressPath)))
|
|
using (var fs = new MemoryStream(FileStreamOperate.ReadFile(compressPath)))
|
|
{
|
|
{
|
|
- string bucketName = Const.BucketName;
|
|
|
|
|
|
+ PutFlieContent fileContent = new PutFlieContent(url, fs);
|
|
|
|
+ #region 进度条管理
|
|
|
|
+ fileContent.TransferProgress += (sender, args) =>
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ var currentData = Math.Round(args.TransferredBytes * 100d / args.TotalBytes, 3);
|
|
|
|
+ Debug.WriteLine("ProgressCallback - TotalBytes:{0}M, TransferredBytes:{1}M,上传百分比:{2}%",
|
|
|
|
+ args.TotalBytes / 1024 / 1024, args.TransferredBytes / 1024 / 1024, currentData);
|
|
|
|
+ UploadProgressCallback(sender, args);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
|
|
- var putObjectRequest = new PutObjectRequest(bucketName, key, fs);
|
|
|
|
- putObjectRequest.StreamTransferProgress += UploadProgressCallback;
|
|
|
|
- client.PutObject(putObjectRequest);
|
|
|
|
|
|
+ throw;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ #endregion
|
|
|
|
+ var resultStr = fileContent.PutContent();
|
|
|
|
+ JObject rj = JObject.Parse(resultStr);
|
|
|
|
+ if (rj["Result"].ToString() == "success")
|
|
|
|
+ {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ throw new Exception(rj["ResultMsg"].ToString());
|
|
}
|
|
}
|
|
- Console.WriteLine("Put object:{0} succeeded", key);
|
|
|
|
- }
|
|
|
|
- catch (OssException ex)
|
|
|
|
- {
|
|
|
|
- Console.WriteLine(@"Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
|
|
|
|
- ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
|
|
|
|
- result = false;
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
{
|
|
{
|
|
- Console.WriteLine($@"Failed with error info: { ex.Message}");
|
|
|
|
|
|
+ MessageShowBase.Infomation("Revit文件上传载失败!\r\n" + ex.Message + "\r\n" + ex.StackTrace);
|
|
result = false;
|
|
result = false;
|
|
}
|
|
}
|
|
return result;
|
|
return result;
|
|
@@ -209,7 +227,7 @@ namespace PackageUploader
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="sender"></param>
|
|
/// <param name="args"></param>
|
|
/// <param name="args"></param>
|
|
- private static void UploadProgressCallback(object sender, StreamTransferProgressArgs args)
|
|
|
|
|
|
+ private static void UploadProgressCallback(object sender, StreamProgressArgs args)
|
|
{
|
|
{
|
|
var currentData = Math.Round(args.TransferredBytes * 100d / args.TotalBytes, 3);
|
|
var currentData = Math.Round(args.TransferredBytes * 100d / args.TotalBytes, 3);
|
|
m_UploadAction?.Invoke(string.Format("UploadCallback - TotalBytes:{0}M, TransferredBytes:{1}M,UploadPrecent:{2}%",
|
|
m_UploadAction?.Invoke(string.Format("UploadCallback - TotalBytes:{0}M, TransferredBytes:{1}M,UploadPrecent:{2}%",
|
|
@@ -224,7 +242,7 @@ namespace PackageUploader
|
|
/// <param name="md5"></param>
|
|
/// <param name="md5"></param>
|
|
public static string SaveVision(string key, string value)
|
|
public static string SaveVision(string key, string value)
|
|
{
|
|
{
|
|
- string url = $"{Const.URL}/image-service/common/file_upload?systemId={Const.RevitServiceId}&secret={Const.RevitServiceSecret}&key={key}&overwrite=true";
|
|
|
|
|
|
+ string url = HttpUtils.GetUploadUrl(key);
|
|
RestClient client = new RestClient(url, HttpVerb.POST, value);
|
|
RestClient client = new RestClient(url, HttpVerb.POST, value);
|
|
string request = client.PostRequest();
|
|
string request = client.PostRequest();
|
|
return request;
|
|
return request;
|
|
@@ -235,7 +253,7 @@ namespace PackageUploader
|
|
public static void DeleteCompress()
|
|
public static void DeleteCompress()
|
|
{
|
|
{
|
|
string compressName = $"{ReadVision()}_{Const.Key}.zip";
|
|
string compressName = $"{ReadVision()}_{Const.Key}.zip";
|
|
- string url = $"{Const.URL}/image-service/common/files_delete?systemId={Const.RevitServiceId}&secret={Const.RevitServiceSecret}";
|
|
|
|
|
|
+ string url =HttpUtils.DeleteUrl();
|
|
JArray jArray = new JArray();
|
|
JArray jArray = new JArray();
|
|
jArray.Add(compressName);
|
|
jArray.Add(compressName);
|
|
JObject jObject = new JObject
|
|
JObject jObject = new JObject
|
|
@@ -255,7 +273,7 @@ namespace PackageUploader
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
public static Version ReadVision()
|
|
public static Version ReadVision()
|
|
{
|
|
{
|
|
- string url = $"{Const.URL}/image-service/common/file_get/{Const.Key}?systemId={Const.RevitServiceId}";
|
|
|
|
|
|
+ string url = HttpUtils.GetDownloadUrl(Update.Const.Key);
|
|
|
|
|
|
Packages packages = null;
|
|
Packages packages = null;
|
|
try
|
|
try
|