db model update

master
ZGGSONG 3 years ago
parent 4ce83087f3
commit 93dcc82a20

@ -18,6 +18,8 @@ namespace Ksat.Supplyment.Library.Model.Uploader
[Required]
public string UploaderID { get; set; }
public string Tag { get; set; }
[Required]
public DateTime CreateAt { get; set; }

@ -18,6 +18,8 @@ namespace Ksat.Supplyment.Library.Model.Uploader
[Required]
public string UploaderID { get; set; }
public string Tag { get; set; }
[Required]
public DateTime CreateAt { get; set; }

@ -18,6 +18,8 @@ namespace Ksat.Supplyment.Library.Model.Uploader
[Required]
public string UploaderID { get; set; }
public string Tag { get; set; }
[Required]
public DateTime CreateAt { get; set; }

@ -25,6 +25,8 @@ namespace Ksat.Supplyment.Library.Model.Uploader
/// </summary>
public string ErrorInfo;
public string Tag { get; set; }
public T Request;
}
}

@ -2,7 +2,6 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Ksat.Supplyment.Library.Model.Uploader;
using Ksat.Supplyment.Library.Model;
@ -283,11 +282,13 @@ namespace Ksat.Supplyment.Library.Uploader
}
}
private void cacheRequest(List<T> datas)
private void cacheRequest(List<Tuple<T, string>> datas)
{
try
{
using (var db = new CodeFirstDbContext())
{
//sLog.Formf($"cache requests,{datas.Count()}");
//sLog.Formf($@"cache requests,{datas.Count()}");
var caches = datas.Select((data) =>
new UploadCache
{
@ -296,13 +297,19 @@ namespace Ksat.Supplyment.Library.Uploader
RetryAt = new DateTime(1970, 1, 1),
RetryCount = 0,
ErrorInfo = "",
RequestData = mOperator.ConvertRequestToCachel(data)
Tag = data.Item2,
RequestData = mOperator.ConvertRequestToCachel(data.Item1)
}
);
db.UploadCaches.AddRange(caches);
db.SaveChanges();
}
}
catch (Exception ex)
{
//sLog.FormErrorf(ex.Message);
}
}
/// <summary>
/// 缓存请求数据到数据库
@ -378,7 +385,7 @@ namespace Ksat.Supplyment.Library.Uploader
/// <summary>
/// 添加上传请求
/// </summary>
public void AddUploadRequest(T data)
public void AddUploadRequest(T data, string tag)
{
if (!Interlocked.Equals(mIsCanceled, 1))
{
@ -389,6 +396,7 @@ namespace Ksat.Supplyment.Library.Uploader
RetryAt = new DateTime(1970, 1, 1),
RetryCount = 0,
ErrorInfo = "",
Tag = tag,
Request = data
};
if (mDatas.Count >= MaxOperatingQueueSize)
@ -405,7 +413,7 @@ namespace Ksat.Supplyment.Library.Uploader
else
{
//sLog.Formf("task canceled");
cacheRequest(new List<T>() { data });
cacheRequest(new List<Tuple<T, string>>() { new Tuple<T, string>(data, tag) });
}
}
}

@ -1 +1 @@
<mxfile host="Electron" modified="2021-12-02T08:51:57.547Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/14.9.6 Chrome/89.0.4389.128 Electron/12.0.16 Safari/537.36" etag="woK_veF71DVR6v2Ub5GA" version="14.9.6" type="device"><diagram id="gKco9Rzae7YVhnx6VEaf" name="第 1 页">5VzbcqM4EP0aHrOFkATiEdt4tmr2MjV52NmnLWIrNrtgORjH9nz9SkKYm5wh4wTZTtWUB1oIwVH3Uau7iQXH6f5TFq2Xv7M5TSzHnu8tOLEcB2AM+H9CclASUEoWWTxXskpwH3+nSmgr6Tae003jwpyxJI/XTeGMrVZ0ljdkUZaxXfOyR5Y0R11HC9oR3M+ipCv9K57ny0JKHK+S/0rjxbIcGbh+0ZJG5cXqTTbLaM52NREMLTjOGMuLo3Q/polAr8Sl6Dc90Xp8sIyu8j4d9p8/fU3/+YxX0bf7pzD6cvc13NzB4i7PUbJVL6weNj+UCNA5B0SdsixfsgVbRUlYSUcZ267mVAxj87Pqmt8YW3Mh4MJ/aZ4f1OxG25xx0TJPE9VajCkGOvluSrRh22xGX3ihUkeibEHzF65zjjPAdZeylObZgffLaBLl8XPzOSKlQ4vjdRXM/EAh/QrUQRf10LVIaAVYHPjIGrlWyH9H4l+ILRJYAejMTIW7AHG3jHN6v44kPDtujjqMn2mW0/3LKHdRUR0colS5NGakzneVZYBS3Zc1q3DtdwISapC8bv11euovM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bNy6GvpM5Ms7La8Ds90dRK6uUo71Nu5t/VTNRB/XHtOoTfOZyclf2oT5baK2Hzy8h7Khy9e/z5bKKTbQrki66+yczIC8dpohwpjygI5oimHM8h3xDTf4ZuLxKO+pcXI6BYJnSgubq3WsthF6LMrCuZ1pS0DxwkAaMVWzBfIYQ1rXLkO980mIaPZJKSv5RZVx7bSYVGHfAlVWQC0v7Izvd9HOr+9myE4XdZ9zAfUv1ISTX6t1+kV8iwieYyTZHxMfsBHMqOzGZdv8oz9R2stDwQjbL/RHLa/ZTD/pSS+uRIv3LfECxutrcPdfVqZRAuQRZBYOblRkO72dsj4GHBaiyXSFINqNfb9HL6bK2rGvb/uNVpNjnX1VeWeRBB/wLVV6m3AVVfGfvnvuR6fGaJ2Wul6bLxAA2uI4Lq0HA/FyydyqqhVRVbmVI/3KJ5Mdaum69XZ3nath4d/kO3tFIc4A4Qq8Ks+bH43R+xNrLXlGnuOaWt1NVEJzUf5RPwSUH2LazqneGnRbLe7M/7jzw5E/IXzJhZREi9W/HjGX1yksUcClngWJYFqSOP5vKBIuom/Rw/yVoIklXXz++KRhSfiXpwVNwVBgs7Cs2Ir+jbYwzJ/WpKApn4BarB3Xo89P63+YlbBJ9UfHoPh/w==</diagram></mxfile>
<mxfile host="Electron" modified="2021-12-06T08:17:34.423Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/15.8.7 Chrome/91.0.4472.164 Electron/13.6.2 Safari/537.36" etag="fVc7EqHxVila5JiJz8jX" version="15.8.7" type="device"><diagram id="gKco9Rzae7YVhnx6VEaf" name="第 1 页">3Vxbc5s6EP41POYMAgnEI74kZ9qeTqZ5OO1Th9iKzSlYDsZJ3F9/JCHMTUlIYyORTsfBKxDi0+6n1e5iy52mT1dZtF3/Q5cksRx7+WS5M8txAMYe+8Mlh0ISOKAQrLJ4KU+qBDfxbyKFtpTu4yXZNU7MKU3yeNsULuhmQxZ5QxZlGX2Up8nu7mjSvOs2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/a/DAQ+brb0JiMDvKK+ek9GaoC5UEno7uJMNEMzjQZAWxOhqIQ6ESTwb5WPz5XLLTVj/u58/8B</diagram></mxfile>

@ -8,8 +8,8 @@ namespace S3Demo.Model
{
public class ReqData
{
public string ruleName { get; set; }
public int picReq { get; set; }
public string s3Flag { get; set; }
public int dbFlag { get; set; }
}
public class RespData
{
@ -18,36 +18,8 @@ namespace S3Demo.Model
/// </summary>
public int code { get; set; }
/// <summary>
/// 错误代码
/// </summary>
public int errorcode { get; set; }
/// <summary>
/// 是否有翻页?
/// </summary>
public bool hasPage { get; set; }
/// <summary>
/// 接口返回message
/// </summary>
public string message { get; set; }
public Result result { get; set; }
}
public class Result
{
/// <summary>
/// true 逻辑判断成功 code=200 && successful=true 接口调用成功
/// </summary>
public bool successful { get; set; }
/// <summary>
/// Ok/Info Detail
/// </summary>
public string message { get; set; }
/// <summary>
/// 小板条码
/// </summary>
public List<string> snDetails { get; set; }
/// <summary>
/// 绑定信息
/// </summary>
public string emappings { get; set; }
}
}

@ -1,19 +1,20 @@
using Amazon;
using System;
using System.IO;
using Newtonsoft.Json;
using Amazon;
using Amazon.Runtime;
using Amazon.S3;
using System;
using S3Demo.Storage;
using S3Demo.Model;
using System.IO;
using Ksat.Supplyment.Library.Model;
using Newtonsoft.Json;
using Ksat.Supplyment.Library.Uploader;
using Ksat.Supplyment.Library.Model.Uploader;
namespace S3Demo
{
public class Run
{
//请求接口
private static string url = "http://127.0.0.1:9000/api/workflowcenter/anonymous/v1/trackgo/track";
private static string url = "http://172.17.204.180:9000/api/tri/trackin";
private static BasicAWSCredentials credentials = new BasicAWSCredentials("admin", "admin123.");
//private static BasicAWSCredentials credentials = new BasicAWSCredentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
private static string bucketName = "minio/test";
@ -45,23 +46,9 @@ namespace S3Demo
public static void Main()
{
/// 写入数据库操作
//using (var dev = new CodeFirstDbContext())
//{
// dev.UploadCaches.Add(new Ksat.Supplyment.Library.Model.Uploader.UploadCache() {
// Id = 1,
// UploaderID = "02",
// CreateAt = DateTime.Now.AddHours(-1),
// RetryAt = DateTime.Now,
// RetryCount = 1,
// ErrorInfo = "null",
// RequestData = "testInfo"
// });
// var i = dev.SaveChanges();
// Console.WriteLine(i);
//}
try
{
#region 目录监控
foreach (var path in paths)
{
FileSystemWatcher watch = new FileSystemWatcher()
@ -79,6 +66,13 @@ namespace S3Demo
// 开始监控
watch.EnableRaisingEvents = true;
}
#endregion
//Uploader<string> uploader = new Uploader<string>("字符串测试", new UploaderOperator());
//for (var i = 0; i < 20; i++)
//{
// uploader.AddUploadRequest($"hello{i}");
//}
#region S3相关测试
/*
@ -135,8 +129,68 @@ namespace S3Demo
Console.ReadKey();
}
#region 上传测试
public class UploaderOperator : IUploaderOperator<string>
{
public string ConvertCacheToRequest(string cache)
{
return cache;
}
public string ConvertRequestToCachel(string requestData)
{
return requestData;
}
public bool ShouldRetryRequest(UploadModel<string> requestModel, out string cancelReason)
{
cancelReason = null;
if (requestModel.RetryCount >= 2)
{
cancelReason = "已经两次fail了";
return false;
}
return true;
}
public bool ShouldStartRequest(UploadModel<string> requestModel, out string cancelReason)
{
cancelReason = null;
return true;
}
public IUploaderRequest<string> UploadData(string data)
{
var request = new UploadRequest();
request.RequestData = data;
return request;
}
}
public class UploadRequest : IUploaderRequest<string>
{
private string mRequestData;
public string RequestData { get => mRequestData; set => mRequestData = value; }
public event UploadFinishHandler UploadFinish;
public void Start()
{
Console.WriteLine($"{DateTime.UtcNow.ToString("mm:ss.fff")} task {RequestData} Started");
System.Threading.Thread.Sleep(100);
var random = new Random();
UploadFinish(this, random.Next() % 2 == 0, "task failed");
}
public void Cancel()
{
}
}
#endregion
/// <summary>
/// 监控到创建文件
/// 创建事件及主要逻辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
@ -155,32 +209,34 @@ namespace S3Demo
string dt_fomat = DateTime.ParseExact(datetime, "yyyyMMddHHmmssfff", System.Globalization.CultureInfo.CurrentCulture).ToString("yyyy-MM-dd HH:mm:ss:fff");
string code = fileName.Substring(fileName.Length - 6, 2);
string sn = fileName.Substring(9, 14);
string now = DateTime.Now.ToString("yyyyMMddHHmmssfff");
String[] tags = new String[] { sn, dt_fomat, code };
string S3Path = lineName + "/" + equipmentName + "/" + date + "/" + fileName;
//发送太快会出问题
//没有使用异步线程,可能没有足够的时间等待返回结果 [说明](https://www.cnblogs.com/lnwuyaowei/p/12672866.html)
string flag = ObjectModel.Putobjectswithtags(bucketName, S3Path, e.FullPath, tags, credentials, conf).Result;
if (flag.Equals("OK"))
string s3Flag = ObjectModel.Putobjectswithtags(bucketName, S3Path, e.FullPath, tags, credentials, conf).Result;
if (s3Flag.Equals("OK"))
{
//保存至数据库
using (var dev = new CodeFirstDbContext())
{
dev.UploadFinishs.Add(new Ksat.Supplyment.Library.Model.Uploader.UploadFinish()
dev.UploadFinishs.Add(new UploadFinish()
{
UploaderID = lineName,
Tag = sn,
CreateAt = DateTime.ParseExact(datetime, "yyyyMMddHHmmssfff", System.Globalization.CultureInfo.CurrentCulture),
RetryAt = DateTime.Now,
RetryAt = DateTime.ParseExact(now, "yyyyMMddHHmmssfff", System.Globalization.CultureInfo.CurrentCulture),
RetryCount = 1,
RequestData = S3Path
});
int saveInfo = dev.SaveChanges();//1: 保存至数据库成功,否则保存失败
ReqData req = new ReqData();
RespData resp = new RespData();
req.ruleName = "picSave";
req.picReq = saveInfo;
resp = JsonConvert.DeserializeObject<RespData>(HttpModel.PostUrl(url, JsonConvert.SerializeObject(req)));
Console.WriteLine("resp: " + resp.code + " " + resp.message);
int dbFlag = dev.SaveChanges();//1: 保存至数据库成功,否则保存失败
//ReqData req = new ReqData();
//RespData resp = new RespData();
//req.s3Flag = s3Flag;
//req.dbFlag = dbFlag;
//resp = JsonConvert.DeserializeObject<RespData>(HttpModel.PostUrl(url, JsonConvert.SerializeObject(req)));
//Console.WriteLine("resp: " + resp.code + " " + resp.message);
}
}
Console.WriteLine("S3对象存储路径: " + bucketName + "/" + S3Path);

@ -79,7 +79,7 @@
<Compile Include="Model\BucketModel.cs" />
<Compile Include="Model\HttpModel.cs" />
<Compile Include="Model\ObjectModel.cs" />
<Compile Include="Model\Request.cs" />
<Compile Include="Model\DataModel.cs" />
<Compile Include="Storage\CreateBucket.cs" />
<Compile Include="Storage\ListObjects.cs" />
<Compile Include="Run.cs" />

Loading…
Cancel
Save