add SingletonHelper

master
ZGGSONG 3 years ago
parent d86ab95cc1
commit fb4fcc2ae6

@ -41,7 +41,6 @@ namespace S3Demo.Helper
//};
//for (int i = 0; i < tags.Count; i++)
//{
// //TODO: 优化添加标签参数细节
// putRequest.TagSet = new List<Tag> {
// new Tag { Key = keys[i], Value = tags[i] }
// };

@ -0,0 +1,30 @@
using System;
namespace S3Demo.Helper
{
/// <summary>
/// 单例模式
/// </summary>
/// <typeparam name="T">//new()new不支持非公共的无参构造函数 </typeparam>
// Token: 0x0200016F RID: 367
public abstract class SingletonHelper<T> where T : class
{
private static T sInstance;
/// <summary>
/// 创建获取实例
/// </summary>
/// <returns></returns>
public static T Instance()
{
Type typeFromHandle = typeof(T);
lock (typeFromHandle)
{
if (SingletonHelper<T>.sInstance == null)
{
SingletonHelper<T>.sInstance = (Activator.CreateInstance(typeof(T), true) as T);
}
}
return SingletonHelper<T>.sInstance;
}
}
}

@ -37,13 +37,11 @@ namespace S3Demo.Model.Uploader
public void Cancel()
{
//TODO:
mTask?.Dispose();
}
public void Start()
{
//TODO:
_ = objSend();
}
@ -53,7 +51,8 @@ namespace S3Demo.Model.Uploader
mTask = ObjectHelper.PutObjectsWithTagsAsync(client, bucketName, RequestData.Keyname, RequestData.Path, RequestData.Tags);
string res = await mTask;
UploadFinish(this, res.Equals("OK"), res);
Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")} s3Recv {RequestData.Keyname}==>{res}");
//TODO: 请求接口,上传状态
Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")} s3Recv {RequestData.Keyname} ==>{res}");
}
}
}

@ -1,17 +1,16 @@
using System;
using Newtonsoft.Json;
using Ksat.Supplyment.Library.Uploader;
namespace S3Demo.Model.Uploader
{
public class S3Uploader : Ksat.CommonModelLibrary.Utils.SingletonUtils<S3Uploader>,IDisposable
public class S3Uploader : S3Demo.Helper.SingletonHelper<S3Uploader>,IDisposable
{
private static Uploader<S3UploadModel> mUploader;
private static S3UploadOperator mOperator;
private S3Uploader()
{
mOperator = new S3UploadOperator();
mUploader = new Uploader<S3UploadModel>("xxx", mOperator);
mUploader = new Uploader<S3UploadModel>("S3Uploader", mOperator);
}
public void AddUploadTask(S3UploadModel reqData, string tag)

@ -52,7 +52,6 @@ namespace S3Demo
// RequestData = S3Path
// });
// int dbFlag = dev.SaveChanges();//1: 保存至数据库成功,否则保存失败
// //TODO: 请求接口
// //ReqData req = new ReqData();
// //RespData resp = new RespData();
// //req.s3Flag = s3Flag;

@ -50,9 +50,6 @@
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="KsatCommonModelLibrary">
<HintPath>..\vendor\KsatCommonModelLibrary.dll</HintPath>
</Reference>
<Reference Include="KsatLogging">
<HintPath>..\vendor\KsatLogging.dll</HintPath>
</Reference>
@ -85,6 +82,7 @@
<Compile Include="Helper\BucketModel.cs" />
<Compile Include="Helper\HttpHelper.cs" />
<Compile Include="Helper\ObjectHelper.cs" />
<Compile Include="Helper\SingletonHelper.cs" />
<Compile Include="Model\DataModel.cs" />
<Compile Include="Model\Uploader\S3Uploader.cs" />
<Compile Include="Model\Uploader\S3UploadModel.cs" />

Loading…
Cancel
Save