| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using Quartz; |
| | | using Quartz.Impl.Matchers; |
| | | using System.Diagnostics; |
| | | using WIDESEA_Comm.LogInfo; |
| | | using WIDESEA_Core.Extensions; |
| | | using WIDESEA_Core.Extensions.AutofacManager; |
| | | using WIDESEA_Core.FreeDB; |
| | | using WIDESEA_Core.ManageUser; |
| | | using WIDESEA_Core.Services; |
| | | using WIDESEA_Core.Utilities; |
| | | using WIDESEA_Entity.DomainModels; |
| | | using WIDESEA_WCS.IRepositories; |
| | |
| | | { |
| | | if (!scheduler.IsRun()) |
| | | { |
| | | WIDESEA.Helper.GetToken(); |
| | | |
| | | var cooRes = CoonPLC(); |
| | | var startRes = SrartScheduler(); |
| | | if (startRes.Status) |
| | | { |
| | | if (cooRes.Status) |
| | | { |
| | | WriteDBLog.Success($"å¼å¯æå¡", new { æ°æ® = "æå¡å¯å¨æåï¼" }, "PCS", UserContext.Current.UserName); |
| | | return webResponse.OK("æå¡å¯å¨æåï¼"); |
| | | } |
| | | else |
| | | { |
| | | //è¿åPLCå¼å¸¸ |
| | | WriteDBLog.Error($"å¼å¯æå¡", new { æ°æ® = cooRes }, "PCS", UserContext.Current.UserName); |
| | | return cooRes; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //è°åº¦å¯å¨å¤±è´¥ï¼å
³éå
¨é¨ |
| | | WriteLog.Write_Log("æå¡", "æå¡", "å¯å¨æå¡\n[è°åº¦å¼å¸¸]" + startRes.Message); |
| | | //WriteLog.Write_Log("æå¡", "æå¡", "å¯å¨æå¡\n[è°åº¦å¼å¸¸]" + startRes.Message); |
| | | WriteDBLog.Error($"å¼å¯æå¡", new { æ°æ® = startRes.Message }, "PCS", UserContext.Current.UserName); |
| | | return startRes; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | WriteLog.Write_Log("æå¡", "æå¡", "å¯å¨æå¡\n[å¼å¸¸]" + ex.Message); |
| | | //WriteLog.Write_Log("æå¡", "æå¡", "å¯å¨æå¡\n[å¼å¸¸]" + ex.Message); |
| | | WriteDBLog.Error($"å¼å¯æå¡", new { æ°æ® = ex.Message }, "PCS", UserContext.Current.UserTrueName); |
| | | return webResponse.Error($"å¼å¸¸ï¼{ex.Message}"); |
| | | } |
| | | } |
| | |
| | | var plcList = freeDB.Select<dt_plcinfohead>().Where("EXISTS (select * from dt_equipmentinfo where equipment_state='Enable' and equipment_name=a.plcinfo_name)").ToList(); |
| | | if (plcList.Count == 0) |
| | | { |
| | | throw new Exception("æªé
置任ä½PLCè¿æ¥å¯¹è±¡ï¼"); |
| | | return content.OK(); |
| | | //throw new Exception("æªé
置任ä½PLCè¿æ¥å¯¹è±¡ï¼"); |
| | | } |
| | | |
| | | var detialList = freeDB.Select<dt_plcinfodetail>().ToList(); |
| | |
| | | PLCClient client = null; |
| | | if (plc.plcinfo_type == "Simene") |
| | | { |
| | | client = new SiemensPLCClient() |
| | | client = new SiemensPLCClient(plc.plcinfo_model) |
| | | { |
| | | PLCName = plc.plcinfo_name, |
| | | Ip = plc.plcinfo_ip, |
| | |
| | | { |
| | | order.dbAddress = item.plcdetail_db + "." + item.plcdetail_value; |
| | | } |
| | | order.opratortype = item.plcdetail_opratortype; |
| | | order.dataLen = item.plcdetail_len; |
| | | order.Methods = item.plcdetail_number;// |
| | | itmes.Add(order); |
| | | } |
| | | return itmes; |
| | |
| | | scheduler.Shutdown(); |
| | | Console.WriteLine("æå¡å
³éæåï¼"); |
| | | WriteLog.Write_Log("æå¡", "æå¡", "æå¡å
³éæå!"); |
| | | WriteDBLog.Success($"å
³éæå¡", new { æ°æ® = "æå¡å
³éæåï¼" }, "PCS", UserContext.Current.UserTrueName); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | WriteLog.Write_Log("æå¡", "æå¡", "å
³éæå¡\n[å¼å¸¸]" + ex.Message); |
| | | WriteDBLog.Error($"å
³éæå¡", new { æ°æ® = ex.Message }, "PCS", UserContext.Current.UserTrueName); |
| | | return webResponse.Error(ex.Message); |
| | | } |
| | | return webResponse.OK("æå¡å
³éæåï¼"); |
| | | } |
| | |
| | | public WebResponseContent StartJob(string jobName) |
| | | { |
| | | WebResponseContent webResponse = new WebResponseContent(); |
| | | if (!scheduler.IsRun()) |
| | | try |
| | | { |
| | | return webResponse.Error("请å
å¯å¨æå¡ï¼"); |
| | | } |
| | | var jobData = freeDB.Select<VV_Dispatch>().Where(t => t.JobName == jobName).First(); |
| | | if (jobData == null) |
| | | { |
| | | webResponse.Error($"è°åº¦{jobName}ä¸åå¨ï¼"); |
| | | } |
| | | else |
| | | { |
| | | var job = scheduler.GetJobByJobName(jobName); |
| | | if (job != null) |
| | | if (!scheduler.IsRun()) |
| | | { |
| | | webResponse.Error($"è°åº¦{jobName}å·²æ¯æ§è¡ç¶æï¼"); |
| | | throw new Exception("请å
å¯å¨æå¡ï¼"); |
| | | //return webResponse.Error("请å
å¯å¨æå¡ï¼"); |
| | | } |
| | | var jobData = freeDB.Select<VV_Dispatch>().Where(t => t.JobName == jobName).First(); |
| | | if (jobData == null) |
| | | { |
| | | throw new Exception($"è°åº¦{jobName}ä¸åå¨ï¼"); |
| | | //webResponse.Error($"è°åº¦{jobName}ä¸åå¨ï¼"); |
| | | } |
| | | else |
| | | { |
| | | scheduler.AddJob(jobData); |
| | | webResponse.OK("è°åº¦æ·»å æå"); |
| | | var job = scheduler.GetJobByJobName(jobName); |
| | | if (job != null) |
| | | { |
| | | throw new Exception($"è°åº¦{jobName}å·²æ¯æ§è¡ç¶æï¼"); |
| | | //webResponse.Error($"è°åº¦{jobName}å·²æ¯æ§è¡ç¶æï¼"); |
| | | } |
| | | else |
| | | { |
| | | scheduler.AddJob(jobData); |
| | | webResponse.OK($"è°åº¦{jobName}æ§è¡æåï¼"); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | WriteDBLog.Error($"æ§è¡{jobName}è°åº¦", new { æ°æ® = ex.Message }, "PCS", UserContext.Current.UserTrueName); |
| | | return webResponse.Error(ex.Message); |
| | | } |
| | | WriteDBLog.Success($"æ§è¡{jobName}è°åº¦", new { æ°æ® = jobName + "æ§è¡æåï¼" }, "PCS", UserContext.Current.UserTrueName); |
| | | return webResponse; |
| | | } |
| | | |
| | |
| | | public WebResponseContent CloseJob(string jobName) |
| | | { |
| | | WebResponseContent webResponse = new WebResponseContent(); |
| | | if (!scheduler.IsRun()) |
| | | try |
| | | { |
| | | return webResponse.Error("请å
å¯å¨æå¡ï¼"); |
| | | } |
| | | if (!scheduler.IsRun()) |
| | | { |
| | | throw new Exception("请å
å¯å¨æå¡ï¼"); |
| | | //return webResponse.Error("请å
å¯å¨æå¡ï¼"); |
| | | } |
| | | |
| | | var job = scheduler.GetJobByJobName(jobName); |
| | | if (job == null) |
| | | { |
| | | return webResponse.Error($"ä»»å¡{jobName},ä¸åå¨ï¼"); |
| | | var job = scheduler.GetJobByJobName(jobName); |
| | | if (job == null) |
| | | { |
| | | throw new Exception($"ä»»å¡{jobName},ä¸åå¨ï¼"); |
| | | //return webResponse.Error($"ä»»å¡{jobName},ä¸åå¨ï¼"); |
| | | } |
| | | var res = scheduler.RemoveJob(job); |
| | | if (res) |
| | | { |
| | | webResponse.OK($"è°åº¦{jobName}æåæåï¼"); |
| | | } |
| | | else |
| | | { |
| | | throw new Exception($"è°åº¦{jobName}æå失败ï¼"); |
| | | //webResponse.Error($"è°åº¦{jobName}å
³é失败ï¼"); |
| | | } |
| | | } |
| | | var res = scheduler.RemoveJob(job); |
| | | if (res) |
| | | catch (Exception ex) |
| | | { |
| | | webResponse.OK($"è°åº¦{jobName}å
³éæåï¼"); |
| | | WriteDBLog.Error($"æå{jobName}è°åº¦", new { æ°æ® = ex.Message }, "PCS", UserContext.Current.UserTrueName); |
| | | return webResponse.Error(ex.Message); |
| | | } |
| | | else |
| | | { |
| | | webResponse.Error($"è°åº¦{jobName}å
³é失败ï¼"); |
| | | } |
| | | WriteDBLog.Success($"æå{jobName}è°åº¦", new { æ°æ® = jobName + "æåæåï¼" }, "PCS", UserContext.Current.UserTrueName); |
| | | return webResponse; |
| | | } |
| | | |
| | |
| | | } |
| | | return data; |
| | | } |
| | | |
| | | public override WebResponseContent Upload(List<IFormFile> files) |
| | | { |
| | | #region |
| | | WebResponseContent Response = new WebResponseContent(); |
| | | if (files == null || files.Count == 0) return Response.Error("请ä¸ä¼ æä»¶"); |
| | | |
| | | string msg = ""; |
| | | string IP = "\\\\" + "192.168.1.35" + "\\ipc$"; |
| | | string password = "971204"; |
| | | string User = "dell"; |
| | | |
| | | int i = 0; |
| | | string filePath = $"\\\\192.168.1.35\\TextTest"; |
| | | string fullPath = filePath.MapPath(true); |
| | | Process process = new Process(); |
| | | try |
| | | { |
| | | process.StartInfo.FileName = "cmd.exe"; |
| | | process.StartInfo.UseShellExecute = false; |
| | | process.StartInfo.RedirectStandardInput = true; |
| | | process.StartInfo.RedirectStandardOutput = true; |
| | | process.StartInfo.RedirectStandardError = true; |
| | | process.StartInfo.CreateNoWindow = true; |
| | | process.Start(); |
| | | string dosLine = "net use " + IP + " " + password + " /user:" + User; |
| | | process.StandardInput.WriteLine(dosLine); |
| | | process.StandardInput.WriteLine("exit"); |
| | | while (!process.HasExited) |
| | | { |
| | | process.WaitForExit(1000); |
| | | } |
| | | msg = process.StandardError.ReadToEnd(); |
| | | process.StandardError.Close(); |
| | | if (msg != "") |
| | | throw new Exception(msg); |
| | | if (!Directory.Exists(fullPath)) Directory.CreateDirectory(fullPath); |
| | | for (i = 0; i < files.Count; i++) |
| | | { |
| | | string fileName = files[i].FileName; |
| | | fullPath = fullPath + "/" + fileName; |
| | | using (var stream = new FileStream(fullPath, FileMode.Create)) |
| | | { |
| | | files[i].CopyTo(stream); |
| | | } |
| | | //FileStream outFileStream = new FileStream(fullPath, FileMode.Create); |
| | | //files[i].CopyTo(outFileStream); |
| | | } |
| | | return Response.OK("æä»¶ä¸ä¼ æå", filePath); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //return Response.Error(ex.Message); |
| | | Logger.Error($"ä¸ä¼ æä»¶å¤±è´¥ï¼{typeof(T).GetEntityTableCnName()},è·¯å¾ï¼{filePath},失败æä»¶:{files[i]},{ex.Message + ex.StackTrace}"); |
| | | return Response.Error("æä»¶ä¸ä¼ 失败"); |
| | | } |
| | | finally |
| | | { |
| | | process.Close(); |
| | | process.Dispose(); |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |
| | | } |