| | |
| | | using System.Linq.Expressions; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_ISystemRepository; |
| | | using WIDESEAWCS_ISystemServices; |
| | |
| | | |
| | | private const string DbName = "WIDESEA_HF"; |
| | | private const string ConnectionString = "Data Source=11.2.30.112;Initial Catalog=WIDESEA_HF;User ID=kuka;Password=kuka;Integrated Security=False;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; |
| | | private const long MaxMdfSizeBytes = 8L * 1024 * 1024 * 1024; // 8GB |
| | | private const long MaxMdfSizeBytes = 7L * 1024 * 1024 * 1024; // 7GB |
| | | private const int TargetShrinkSizeMB = 4500; // 4.5GB |
| | | private const double FragmentationThreshold = 30.0; // 30%ç¢ççéå¼ |
| | | private const int MaintenanceIntervalDays = 15; // 15天æ§è¡ä¸æ¬¡ |
| | |
| | | public Sys_LogService(ISys_LogRepository BaseDal) : base(BaseDal) |
| | | { |
| | | // ç¡®ä¿å¤ä»½ç®å½åå¨ |
| | | EnsureBackupDirectory(); |
| | | //EnsureBackupDirectory(); |
| | | } |
| | | |
| | | private void EnsureBackupDirectory() |
| | |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// éå½è·åæä»¶ä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="dirPath"></param> |
| | | /// <returns></returns> |
| | | private DirInfo GetDirInfo(string dirPath) |
| | | { |
| | | //å½åæä»¶å¤¹ |
| | | var dirInfo = new DirInfo(); |
| | | dirInfo.dirName = Path.GetFileName(dirPath); |
| | | |
| | | //åæä»¶ |
| | | List<FileDataInfo> files = new List<FileDataInfo>(); |
| | | foreach (var file in Directory.GetFiles(dirPath)) |
| | | { |
| | | files.Add(new FileDataInfo() |
| | | { |
| | | filePath = file, |
| | | fileName = Path.GetFileName(file) |
| | | }); |
| | | } |
| | | |
| | | //åæä»¶å¤¹ |
| | | var dirs = Directory.GetDirectories(dirPath); |
| | | dirInfo.dirs = new List<DirInfo>(); |
| | | foreach (var dir in dirs) |
| | | { |
| | | dirInfo.dirs.Add(GetDirInfo(dir)); |
| | | } |
| | | |
| | | //åæä»¶å¤¹ï¼ä¸åç®å½åå¹¶ |
| | | foreach (var file in files) |
| | | { |
| | | dirInfo.dirs.Add(new DirInfo() { dirPath = file.filePath, dirName = file.fileName }); |
| | | } |
| | | return dirInfo; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åæ¥å¿æä»¶å表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent GetLogList() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | string path = Path.Combine(AppContext.BaseDirectory, "log"); |
| | | if (!Directory.Exists(path)) |
| | | { |
| | | return content.Error("ææ æ¥å¿æä»¶"); |
| | | } |
| | | |
| | | content.Data = GetDirInfo(path); |
| | | content.OK(); |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åæä»¶å
容 |
| | | /// </summary> |
| | | /// <param name="parm"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent GetLogData(GetLogParm parm) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | string res = ""; |
| | | //æ¯å¦è¯»åå°æå |
| | | bool isEnd = false; |
| | | long startIndex = 0; |
| | | //æä»¶å¤§å° |
| | | long len = 0; |
| | | try |
| | | { |
| | | if (!File.Exists(parm.path)) |
| | | { |
| | | throw new Exception($"æä»¶{parm.path}ä¸åå¨ï¼"); |
| | | } |
| | | using (FileStream fs = new FileStream(parm.path, FileMode.Open, FileAccess.Read, FileShare.Read)) |
| | | { |
| | | //æå¤§è¯»åå¤§å° |
| | | int maxsize = (int)(1024 * parm.maxsize_KB); |
| | | len = fs.Length; |
| | | long startPos = (long)(len * (parm.percent / 100));//èµ·å§ä½ç½® |
| | | long readLen = len - startPos;//读åé¿åº¦ |
| | | |
| | | //ååå è½½ |
| | | if (parm.topStartPos != 0) |
| | | { |
| | | startPos = parm.topStartPos - maxsize; |
| | | if (startPos < 0) |
| | | { |
| | | //已读å°èµ·å§ä½ |
| | | startPos = 0; |
| | | readLen = parm.topStartPos; |
| | | } |
| | | else |
| | | { |
| | | readLen = maxsize; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //读å大尿¯å¦è¶
åºæå¤§é¿åº¦ |
| | | if (readLen > maxsize) |
| | | { |
| | | readLen = maxsize; |
| | | } |
| | | else |
| | | { |
| | | isEnd = true; |
| | | } |
| | | } |
| | | |
| | | //å è½½100%ï¼ææå¤§å
容读å |
| | | if (parm.percent == 100) |
| | | { |
| | | if (len < maxsize) |
| | | { |
| | | startPos = 0; |
| | | readLen = len; |
| | | } |
| | | else |
| | | { |
| | | startPos = len - maxsize; |
| | | readLen = maxsize; |
| | | } |
| | | } |
| | | |
| | | fs.Seek(startPos, SeekOrigin.Begin); |
| | | var buffer = new byte[readLen]; |
| | | fs.Read(buffer, 0, (int)readLen); |
| | | |
| | | startIndex = startPos; |
| | | if (startPos != 0 && (parm.percent != 0 || parm.topStartPos != 0)) |
| | | { |
| | | //䏿¯ä»å¤´å è½½ï¼å é¤å¯è½ä¸å®æ´ç第ä¸è¡ |
| | | int skipCount = 0; |
| | | for (int i = 0; i < buffer.Length; i++) |
| | | { |
| | | if (buffer[i] == 10) |
| | | { |
| | | skipCount = i; |
| | | break; |
| | | } |
| | | } |
| | | if (skipCount != 0) |
| | | { |
| | | //廿æ¢è¡ |
| | | skipCount++; |
| | | //䏿¬¡è¯»ååå»¶ |
| | | startIndex += skipCount; |
| | | } |
| | | res = Encoding.UTF8.GetString(buffer.Skip(skipCount).ToArray()); |
| | | } |
| | | else |
| | | { |
| | | res = Encoding.UTF8.GetString(buffer); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | return content.OK(data: new { content = res, isEnd, startIndex, len }); |
| | | } |
| | | } |
| | | |
| | | } |