Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mall.oytour.com
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
mall.oytour.com
Commits
b934dc6e
Commit
b934dc6e
authored
Oct 14, 2020
by
liudong1993
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
转图片优化
parent
a5db7935
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
345 additions
and
21 deletions
+345
-21
TransferUploadObject.cs
Mall.Education/AliOSS/TransferUploadObject.cs
+25
-0
Program.cs
Mall.Education/Program.cs
+1
-1
ProjectInstaller.Designer.cs
Mall.Education/ProjectInstaller.Designer.cs
+2
-2
ImageConverters.cs
Mall.Education/RabbitMQ/ImageConverters.cs
+207
-8
RabbiMQManager.cs
Mall.Education/RabbitMQ/RabbiMQManager.cs
+25
-6
RebornTimerServer.Designer.cs
Mall.Education/RebornTimerServer.Designer.cs
+2
-2
RebornTimerServer.cs
Mall.Education/RebornTimerServer.cs
+2
-2
TransferUploadObject.cs
Mall.Education/TXCOS/TransferUploadObject.cs
+81
-0
No files found.
Mall.Education/AliOSS/TransferUploadObject.cs
View file @
b934dc6e
...
...
@@ -48,6 +48,31 @@ namespace COSSnippet
}
}
/// <summary>
/// 文件是否存在
/// </summary>
/// <param name="AliFileName"></param>
public
bool
SelectFile
(
string
AliFileName
)
{
// 创建OssClient实例。
var
client
=
new
OssClient
(
endpoint
,
accessKeyId
,
accessKeySecret
);
try
{
// 判断文件是否存在。
var
exist
=
client
.
DoesObjectExist
(
bucketName
,
AliFileName
);
return
exist
;
}
catch
(
Aliyun
.
OSS
.
Common
.
OssException
ex
)
{
Console
.
WriteLine
(
"Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}"
,
ex
.
ErrorCode
,
ex
.
Message
,
ex
.
RequestId
,
ex
.
HostId
);
}
catch
(
Exception
ex
)
{
Console
.
WriteLine
(
"Failed with error info: {0}"
,
ex
.
Message
);
}
return
false
;
}
/// <summary>
/// 删除文件
/// </summary>
...
...
Mall.Education/Program.cs
View file @
b934dc6e
...
...
@@ -19,7 +19,7 @@ namespace Mall.Education
ServiceBase
[]
ServicesToRun
;
ServicesToRun
=
new
ServiceBase
[]
{
new
RebornTimer
Server
(),
new
EducationToImage
Server
(),
};
ServiceBase
.
Run
(
ServicesToRun
);
//Console.WriteLine("进来了");
...
...
Mall.Education/ProjectInstaller.Designer.cs
View file @
b934dc6e
...
...
@@ -39,8 +39,8 @@
//
// serviceInstaller1
//
this
.
serviceInstaller1
.
Description
=
"
RebornTimerService定时器
服务"
;
this
.
serviceInstaller1
.
ServiceName
=
"
RebornTimer
Server"
;
this
.
serviceInstaller1
.
Description
=
"
EducationToImageServer
服务"
;
this
.
serviceInstaller1
.
ServiceName
=
"
EducationToImage
Server"
;
this
.
serviceInstaller1
.
StartType
=
System
.
ServiceProcess
.
ServiceStartMode
.
Automatic
;
//
// ProjectInstaller
...
...
Mall.Education/RabbitMQ/ImageConverters.cs
View file @
b934dc6e
This diff is collapsed.
Click to expand it.
Mall.Education/RabbitMQ/RabbiMQManager.cs
View file @
b934dc6e
...
...
@@ -10,6 +10,7 @@ using COSSnippet;
using
Mall.Education.Helper
;
using
System.Collections.Generic
;
using
FluentScheduler
;
using
System.Linq
;
namespace
Mall.Education.RabbitMQ
{
...
...
@@ -128,6 +129,7 @@ namespace Mall.Education.RabbitMQ
if
(
PageNum
>
0
)
{
//List<string> DelFile = new List<string>();
List
<
GoodsImage
>
goodsImages
=
new
List
<
GoodsImage
>();
//开始上传图片至服务器
if
(
GoodsModel
.
PathType
==
1
)
...
...
@@ -136,7 +138,10 @@ namespace Mall.Education.RabbitMQ
for
(
var
i
=
1
;
i
<=
PageNum
;
i
++)
{
string
newName
=
FileName
+
"_"
+
i
.
ToString
(
"000"
)
+
"."
+
imageFormat
.
ToString
();
m
.
TransferUploadFile
(
tempDir
+
"/"
+
newName
,
FileDirNot
+
newName
);
if
(!
m
.
SelectFile
(
FileDirNot
+
newName
))
{
m
.
TransferUploadFile
(
tempDir
+
"/"
+
newName
,
FileDirNot
+
newName
);
}
//上传之后 写入商品课程图片数据
goodsImages
.
Add
(
new
GoodsImage
...
...
@@ -146,7 +151,8 @@ namespace Mall.Education.RabbitMQ
});
//上传之后 删除本地临时文件
File
.
Delete
(
tempDir
+
"/"
+
newName
);
//File.Delete(tempDir + "/" + newName);
//DelFile.Add(tempDir + "/" + newName);
}
}
else
if
(
GoodsModel
.
PathType
==
2
)
{
...
...
@@ -154,7 +160,10 @@ namespace Mall.Education.RabbitMQ
for
(
var
i
=
1
;
i
<=
PageNum
;
i
++)
{
string
newName
=
FileName
+
"_"
+
i
.
ToString
(
"000"
)
+
"."
+
imageFormat
.
ToString
();
upload
.
TransferUploadFile
(
tempDir
+
"/"
+
newName
,
FileDirNot
+
newName
);
if
(!
upload
.
SelectFile
(
FileDirNot
+
newName
))
{
upload
.
TransferUploadFile
(
tempDir
+
"/"
+
newName
,
FileDirNot
+
newName
);
}
//上传之后 写入商品课程图片数据
goodsImages
.
Add
(
new
GoodsImage
...
...
@@ -164,7 +173,8 @@ namespace Mall.Education.RabbitMQ
});
//上传之后 删除本地临时文件
File
.
Delete
(
tempDir
+
"/"
+
newName
);
//File.Delete(tempDir + "/" + newName);
//DelFile.Add(tempDir + "/" + newName);
}
}
...
...
@@ -173,6 +183,15 @@ namespace Mall.Education.RabbitMQ
if
(
flag
==
false
)
{
LogHelper
.
Write
(
"更新课程图片列表失败:CourseId:"
+
GoodsModel
.
CourseId
);
}
//if (DelFile.Any()) {
// System.Threading.Tasks.Task.Run(() => {
// System.Threading.Thread.Sleep(100000);
// foreach (var item in DelFile) {
// File.Delete(item);
// }
// });
//}
}
}
}
...
...
@@ -198,7 +217,7 @@ namespace Mall.Education.RabbitMQ
{
LogHelper
.
Write
(
ex
,
"DelTemporaryFile"
);
}
}).
ToRun
Every
(
1
).
Days
().
At
(
1
,
10
);
}).
ToRun
Now
().
AndEvery
(
1
).
Hours
(
);
}
...
...
@@ -219,7 +238,7 @@ namespace Mall.Education.RabbitMQ
}
foreach
(
FileInfo
fi
in
dir
.
GetFiles
())
{
if
(
fi
.
CreationTime
<
DateTime
.
Now
.
Add
Day
s
(-
1
))
if
(
fi
.
CreationTime
<
DateTime
.
Now
.
Add
Hour
s
(-
1
))
fi
.
Delete
();
}
}
...
...
Mall.Education/RebornTimerServer.Designer.cs
View file @
b934dc6e
namespace
Mall.Education
{
partial
class
RebornTimer
Server
partial
class
EducationToImage
Server
{
/// <summary>
/// 必需的设计器变量。
...
...
@@ -29,7 +29,7 @@
private
void
InitializeComponent
()
{
components
=
new
System
.
ComponentModel
.
Container
();
this
.
ServiceName
=
"
RebornTimer
Server"
;
this
.
ServiceName
=
"
EducationToImage
Server"
;
}
#
endregion
...
...
Mall.Education/RebornTimerServer.cs
View file @
b934dc6e
...
...
@@ -12,9 +12,9 @@ using System.Threading.Tasks;
namespace
Mall.Education
{
partial
class
RebornTimer
Server
:
ServiceBase
partial
class
EducationToImage
Server
:
ServiceBase
{
public
RebornTimer
Server
()
public
EducationToImage
Server
()
{
InitializeComponent
();
}
...
...
Mall.Education/TXCOS/TransferUploadObject.cs
View file @
b934dc6e
...
...
@@ -118,6 +118,87 @@ namespace COSSnippet
//.cssg-snippet-body-end
}
/// <summary>
/// 查询文件
/// </summary>
/// <param name="cosFileName"></param>
public
bool
SelectFile
(
string
cosFileName
)
{
try
{
string
bucket
=
bucketName
;
//存储桶,格式:BucketName-APPID
string
key
=
cosFileName
;
//对象键
HeadObjectRequest
request
=
new
HeadObjectRequest
(
bucket
,
key
);
//执行请求
HeadObjectResult
result
=
cosXml
.
HeadObject
(
request
);
//请求成功
Console
.
WriteLine
(
result
.
GetResultInfo
());
LogHelper
.
Write
(
result
.
GetResultInfo
());
if
(
result
.
GetResultInfo
().
Contains
(
"200 OK"
))
{
return
true
;
}
else
{
return
false
;
}
}
catch
(
COSXML
.
CosException
.
CosClientException
clientEx
)
{
//请求失败
Console
.
WriteLine
(
"CosClientException: "
+
clientEx
);
}
catch
(
COSXML
.
CosException
.
CosServerException
serverEx
)
{
//请求失败
Console
.
WriteLine
(
"CosServerException: "
+
serverEx
.
GetInfo
());
}
return
false
;
}
/// 高级接口下载对象
public
void
TransferDownloadObject
(
string
filePath
,
string
fileName
,
string
cosPathName
)
{
//.cssg-snippet-body-start:[transfer-download-object]
// 初始化 TransferConfig
TransferConfig
transferConfig
=
new
TransferConfig
();
// 初始化 TransferManager
TransferManager
transferManager
=
new
TransferManager
(
cosXml
,
transferConfig
);
String
bucket
=
bucketName
;
//存储桶,格式:BucketName-APPID
String
cosPath
=
cosPathName
;
//对象在存储桶中的位置标识符,即称对象键
string
localDir
=
filePath
;
//本地文件夹
string
localFileName
=
fileName
;
//指定本地保存的文件名
// 下载对象
COSXMLDownloadTask
downloadTask
=
new
COSXMLDownloadTask
(
bucket
,
cosPath
,
localDir
,
localFileName
);
downloadTask
.
progressCallback
=
delegate
(
long
completed
,
long
total
)
{
Console
.
WriteLine
(
String
.
Format
(
"progress = {0:##.##}%"
,
completed
*
100.0
/
total
));
};
downloadTask
.
successCallback
=
delegate
(
CosResult
cosResult
)
{
COSXML
.
Transfer
.
COSXMLDownloadTask
.
DownloadTaskResult
result
=
cosResult
as
COSXML
.
Transfer
.
COSXMLDownloadTask
.
DownloadTaskResult
;
Console
.
WriteLine
(
result
.
GetResultInfo
());
string
eTag
=
result
.
eTag
;
};
downloadTask
.
failCallback
=
delegate
(
CosClientException
clientEx
,
CosServerException
serverEx
)
{
if
(
clientEx
!=
null
)
{
Console
.
WriteLine
(
"CosClientException: "
+
clientEx
);
}
if
(
serverEx
!=
null
)
{
Console
.
WriteLine
(
"CosServerException: "
+
serverEx
.
GetInfo
());
}
};
transferManager
.
Download
(
downloadTask
);
//.cssg-snippet-body-end
}
/// 高级接口上传二进制数据
public
void
TransferUploadBytes
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment