|
- using System;
- using System.Collections.Generic;
- using System.IO;
- using log4net;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using Aliyun.OSS;
- using Newtonsoft.Json;
- using uPLibrary.Networking.M2Mqtt;
- using uPLibrary.Networking.M2Mqtt.Messages;
- using System.Reflection;
- using System.Net.NetworkInformation;
- using static THUploadOss.Common;
- using static System.Net.Mime.MediaTypeNames;
-
- namespace THUploadOss
- {
-
- public partial class Common
- {
- public static int StsrtDownload = -1; //注意全局变量要使用static
- public static int DownloadFinsh = -1;
-
- public static string ConfigPath = "./config.ini";
- public static string RequestId;
- public static int Status = (int)UPLOAD_STATUS.Preparation;
- public static double UploadPercent = 0;
- public static double DownloadPercent = 0;
- public struct FileStates
- {
- public string fileName;//文件名
- public string url;
- public int status;// 状态:待上传 5 上传中 10 完成 15 失败 20 取消 25
- public string progress;
- public string fileType;//pic video
- }
- public static object lockFileList = new object();
-
- public static List<FileStates> FileList = new List<FileStates>();
-
- public enum UPLOAD_STATUS
- {
- Preparation = 5,
- Uploading = 10,
- Complete = 15,
- Ccancellation = 20,
- Fail = 25
- }
- public enum TRMP {
- RTMP_OK = 0,
- RTMP_START_ACTION_FAIL = 1,
- RTMP_STOP_ACTION_FAIL = 2
- }
- public static string[] RTMP_RESULT = { "执行成功",
- "启动失败,接口调用异常",
- "停止失败,接口调用异常 "};
- public enum UPLOAD
- {
- UPLOAD_OK = 0,
- UPLOAD_START_FAIL = 1,
- UPLOAD_STOP_FAIL = 2
- }
- public static string[] UPLOAD_RESULT = {"执行成功",
- "任务正在执行, 请稍后再试",
- "任务停止失败, 任务不存在"};
-
- [DllImport("kernel32")]
- public static extern long GetPrivateProfileString(string section, string key, string defaultValue, StringBuilder retVal, int size, string filePath);
- [DllImport("kernel32")]
- private static extern long WritePrivateProfileString(string section, string key, string value, string filePath);
-
- [DllImport("kernel32.dll")]
- public static extern IntPtr GetConsoleWindow();
-
- [DllImport("user32.dll")]
- public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
-
- }
-
- internal class Program
- {
- [DllImport("kernel32.dll")]
- static extern IntPtr GetStdHandle(int nStdHandle);
-
- [DllImport("kernel32.dll", SetLastError = true)]
- static extern bool SetConsoleTitle(string lpConsoleTitle);
-
- const int STD_INPUT_HANDLE = -10;
- const uint ENABLE_QUICK_EDIT_MODE = 0x0040;
- [DllImport("kernel32.dll", SetLastError = true)]
- internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint mode);
- [DllImport("kernel32.dll", SetLastError = true)]
- internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint mode);
- public static void THMqttClinetThread()
- {
- Logger.WriteInfo("THMqttClinetThread thread starts");
- StringBuilder mqtt = new StringBuilder(50);
- GetPrivateProfileString("SWITCH", "mqtt", "配置文件存在,读取未成功!", mqtt, 255, ConfigPath);
- if (mqtt.ToString() == "true")
- {
- THMqttClinet tHMqttClinet = new THMqttClinet();
- bool ret = tHMqttClinet.InitMqttClient();
- while (ret)
- {
- if (tHMqttClinet.mqttClient.IsConnected)
- {
- tHMqttClinet.PublishUploadTopic();
- }
- else
- {
- tHMqttClinet.MqttConnect();
- }
- }
- }
- else {
- THHttpServe tHHttpServe = new THHttpServe();
- bool ret = tHHttpServe.InitHttpServer();
- while (ret)
- {
- tHHttpServe.UploadStatus();
- }
- }
- }
- public static void THDownloadFileThread()
- {
- Logger.WriteInfo("THDownloadFileThread thread starts");
- THDownloadFile tHDownloadFile = new THDownloadFile();//定期删除文件
- bool ret = tHDownloadFile.InitDownloadFile();
- while (ret)
- {
- tHDownloadFile.DownloadAllFile();
- }
- }
- public static void THUploadFileThread()
- {
- Logger.WriteInfo("THUploadFileThread thread starts");
- THUploadFile tHUploadFile = new THUploadFile();//断线重传
- tHUploadFile.InitUploadFile();
- while (true)
- {
- tHUploadFile.UploadFile();
- }
- }
- static void Main(string[] args)
- {
- //IntPtr handle = GetConsoleWindow();
- //ShowWindow(handle, 0);//隐藏控制台
- IntPtr hStdin = GetStdHandle(STD_INPUT_HANDLE);
- uint mode;
- GetConsoleMode(hStdin, out mode);
- mode &= ~ENABLE_QUICK_EDIT_MODE;
- SetConsoleMode(hStdin, mode);//关闭控制台的快速编辑模式
- // 获取标准输出句柄
- Logger.WriteInfo("=====================================STARP=================================================");
- IntPtr handle = GetStdHandle(-11);
- SetConsoleTitle("MediaTool 1.0.1");
-
- ThreadStart THMqttClinetchildref = new ThreadStart(THMqttClinetThread);
- Thread THMqttClinetChildThread = new Thread(THMqttClinetchildref);
- THMqttClinetChildThread.Start();
-
- ThreadStart THDownloadFilechildref = new ThreadStart(THDownloadFileThread);
- Thread THDownloadFileChildThread = new Thread(THDownloadFilechildref);
- THDownloadFileChildThread.Start();
-
- ThreadStart THUploadFilechildref = new ThreadStart(THUploadFileThread);
- Thread THUploadFileChildThread = new Thread(THUploadFilechildref);
- THUploadFileChildThread.Start();
- }
- }
- }
|