THupload-Oss
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

175 Zeilen
6.5KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using log4net;
  5. using System.Linq;
  6. using System.Runtime.InteropServices;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using Aliyun.OSS;
  11. using Newtonsoft.Json;
  12. using uPLibrary.Networking.M2Mqtt;
  13. using uPLibrary.Networking.M2Mqtt.Messages;
  14. using System.Reflection;
  15. using System.Net.NetworkInformation;
  16. using static THUploadOss.Common;
  17. using static System.Net.Mime.MediaTypeNames;
  18. namespace THUploadOss
  19. {
  20. public partial class Common
  21. {
  22. public static int StsrtDownload = -1; //注意全局变量要使用static
  23. public static int DownloadFinsh = -1;
  24. public static string ConfigPath = "./config.ini";
  25. public static string RequestId;
  26. public static int Status = (int)UPLOAD_STATUS.Preparation;
  27. public static double UploadPercent = 0;
  28. public static double DownloadPercent = 0;
  29. public struct FileStates
  30. {
  31. public string fileName;//文件名
  32. public string url;
  33. public int status;// 状态:待上传 5 上传中 10 完成 15 失败 20 取消 25
  34. public string progress;
  35. public string fileType;//pic video
  36. }
  37. public static object lockFileList = new object();
  38. public static List<FileStates> FileList = new List<FileStates>();
  39. public enum UPLOAD_STATUS
  40. {
  41. Preparation = 5,
  42. Uploading = 10,
  43. Complete = 15,
  44. Ccancellation = 20,
  45. Fail = 25
  46. }
  47. public enum TRMP {
  48. RTMP_OK = 0,
  49. RTMP_START_ACTION_FAIL = 1,
  50. RTMP_STOP_ACTION_FAIL = 2
  51. }
  52. public static string[] RTMP_RESULT = { "执行成功",
  53. "启动失败,接口调用异常",
  54. "停止失败,接口调用异常 "};
  55. public enum UPLOAD
  56. {
  57. UPLOAD_OK = 0,
  58. UPLOAD_START_FAIL = 1,
  59. UPLOAD_STOP_FAIL = 2
  60. }
  61. public static string[] UPLOAD_RESULT = {"执行成功",
  62. "任务正在执行, 请稍后再试",
  63. "任务停止失败, 任务不存在"};
  64. [DllImport("kernel32")]
  65. public static extern long GetPrivateProfileString(string section, string key, string defaultValue, StringBuilder retVal, int size, string filePath);
  66. [DllImport("kernel32")]
  67. private static extern long WritePrivateProfileString(string section, string key, string value, string filePath);
  68. [DllImport("kernel32.dll")]
  69. public static extern IntPtr GetConsoleWindow();
  70. [DllImport("user32.dll")]
  71. public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  72. }
  73. internal class Program
  74. {
  75. [DllImport("kernel32.dll")]
  76. static extern IntPtr GetStdHandle(int nStdHandle);
  77. [DllImport("kernel32.dll", SetLastError = true)]
  78. static extern bool SetConsoleTitle(string lpConsoleTitle);
  79. const int STD_INPUT_HANDLE = -10;
  80. const uint ENABLE_QUICK_EDIT_MODE = 0x0040;
  81. [DllImport("kernel32.dll", SetLastError = true)]
  82. internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint mode);
  83. [DllImport("kernel32.dll", SetLastError = true)]
  84. internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint mode);
  85. public static void THMqttClinetThread()
  86. {
  87. Logger.WriteInfo("THMqttClinetThread thread starts");
  88. StringBuilder mqtt = new StringBuilder(50);
  89. GetPrivateProfileString("SWITCH", "mqtt", "配置文件存在,读取未成功!", mqtt, 255, ConfigPath);
  90. if (mqtt.ToString() == "true")
  91. {
  92. THMqttClinet tHMqttClinet = new THMqttClinet();
  93. bool ret = tHMqttClinet.InitMqttClient();
  94. while (ret)
  95. {
  96. if (tHMqttClinet.mqttClient.IsConnected)
  97. {
  98. tHMqttClinet.PublishUploadTopic();
  99. }
  100. else
  101. {
  102. tHMqttClinet.MqttConnect();
  103. }
  104. }
  105. }
  106. else {
  107. THHttpServe tHHttpServe = new THHttpServe();
  108. bool ret = tHHttpServe.InitHttpServer();
  109. while (ret)
  110. {
  111. tHHttpServe.UploadStatus();
  112. }
  113. }
  114. }
  115. public static void THDownloadFileThread()
  116. {
  117. Logger.WriteInfo("THDownloadFileThread thread starts");
  118. THDownloadFile tHDownloadFile = new THDownloadFile();//定期删除文件
  119. bool ret = tHDownloadFile.InitDownloadFile();
  120. while (ret)
  121. {
  122. tHDownloadFile.DownloadAllFile();
  123. }
  124. }
  125. public static void THUploadFileThread()
  126. {
  127. Logger.WriteInfo("THUploadFileThread thread starts");
  128. THUploadFile tHUploadFile = new THUploadFile();//断线重传
  129. tHUploadFile.InitUploadFile();
  130. while (true)
  131. {
  132. tHUploadFile.UploadFile();
  133. }
  134. }
  135. static void Main(string[] args)
  136. {
  137. //IntPtr handle = GetConsoleWindow();
  138. //ShowWindow(handle, 0);//隐藏控制台
  139. IntPtr hStdin = GetStdHandle(STD_INPUT_HANDLE);
  140. uint mode;
  141. GetConsoleMode(hStdin, out mode);
  142. mode &= ~ENABLE_QUICK_EDIT_MODE;
  143. SetConsoleMode(hStdin, mode);//关闭控制台的快速编辑模式
  144. // 获取标准输出句柄
  145. Logger.WriteInfo("=====================================STARP=================================================");
  146. IntPtr handle = GetStdHandle(-11);
  147. SetConsoleTitle("MediaTool 1.0.1");
  148. ThreadStart THMqttClinetchildref = new ThreadStart(THMqttClinetThread);
  149. Thread THMqttClinetChildThread = new Thread(THMqttClinetchildref);
  150. THMqttClinetChildThread.Start();
  151. ThreadStart THDownloadFilechildref = new ThreadStart(THDownloadFileThread);
  152. Thread THDownloadFileChildThread = new Thread(THDownloadFilechildref);
  153. THDownloadFileChildThread.Start();
  154. ThreadStart THUploadFilechildref = new ThreadStart(THUploadFileThread);
  155. Thread THUploadFileChildThread = new Thread(THUploadFilechildref);
  156. THUploadFileChildThread.Start();
  157. }
  158. }
  159. }