123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- namespace LYFZ.Software.MainBusiness.MultipleFileImport
- {
- public class frmFtpThread
- {
- static frmFtpThread single = null;
- System.Threading.Thread thread;
- /// <summary>
- /// 开始上传事件
- /// </summary>
- public delegate void StartUpDataHandler();
- public event StartUpDataHandler StartUpDataEvent;
- /// <summary>
- /// 结束上传时间
- /// </summary>
- public delegate void EndtartUpDataHandler();
- public event EndtartUpDataHandler EndtartUpDataEvent;
- List<FTPDataModel> FTPFileList = new List<FTPDataModel>();
- public frmFtpThread()
- {
-
- }
- public static frmFtpThread GetSingleton()
- {
- if(single==null)
- {
- single = new frmFtpThread();
- }
- return single;
- }
- public void SendDataToService(string jsonData)
- {
- FTPDataModel mod = new FTPDataModel()
- {
- b = false,
- strJson = jsonData
- };
- AddFTPFileDataToList(mod);
- }
- void AddFTPFileDataToList(FTPDataModel mod)
- {
- FTPFileList.Add(mod);
- StartThread();
- }
- public void StartThread()
- {
- try
- {
- if (thread == null || thread.ThreadState == ThreadState.Aborted)
- {
- ///线程启动处理;
- thread = new Thread(new ThreadStart(delegate()
- {
- for (int i = 0; i < FTPFileList.Count; i++)
- {
- if (!FTPFileList[i].b)
- {
- if (StartUpDataEvent != null)
- {
- StartUpDataEvent();
- }
- FTPFileList[i].b = true;
- HPSocketCS.Extended.RequestData requestData = new HPSocketCS.Extended.RequestData((int)LYFZ.Network.TCPNetworkServer.SerializerRequestCommand.FTPCommand);
- requestData.AttachedMessage = FTPFileList[i].strJson;
- HPSocketCS.Extended.ReturnData returnData = HPSocketCS.Extended.SerializerDataProcessed.HP_SendSerializerCommandToServer(requestData);
- FileUtil.WriteFile(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\Log\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt",returnData.ReturnStatus+"--"+ FTPFileList[i].strJson);
-
- if (EndtartUpDataEvent != null)
- {
- EndtartUpDataEvent();
- }
- }
- }
- }));
- thread.Start();
- }
- else if (thread.ThreadState == ThreadState.Stopped )
- {
- thread = null;
- StartThread();
- }
- }
- catch(Exception e) {
- MessageBoxCustom.Show("出现异常,请重新提交Ftp传片数据!!");
- FileUtil.WriteFile(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\Log\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt", e.Message);
- if (EndtartUpDataEvent != null)
- {
- EndtartUpDataEvent();
- }
- }
- }
- }
- class FTPDataModel {
- public string strJson { get; set; }
- public bool b { get; set; }
- }
- }
|