public static void WriteToFile(string log) { try { string date = DateTime.Now.ToString("yyyyMMdd"); string path = @"D:\\HEBScreenSearchWebApiLog-" + date + ".txt"; if (!File.Exists(path)) { File.Create(path); } using (StreamWriter sw = new StreamWriter(path, true)) { sw.WriteLine(log); sw.WriteLine('\n'); sw.Close(); sw.Dispose(); } } catch (Exception ex) { WriteLog.WriteToFile(string.Format("日志文件写入异常-异常信息:{0},{1}", ex.Message.ToString(), DateTime.Now.ToString("yyyy-MM-DD HH:mm:ss"))); throw; } }
/// <summary> /// 发送数据共5位。 /// 第一位8表示屏幕状态, /// 第二三位分别表示屏幕的行列, /// 第四五位表示屏幕具体状态。 /// 80000,屏幕正常。表示背光灯开,有信号,信号源是DVI. /// 80010,没有返回数据。 /// 80020,背光灯未开。 /// 80030,无信号源。 /// 80041,有信号,信号是VGA. /// 80042,有信号,信号是HDMI. /// 80043,有信号,信号是DVI. /// 80044,有信号,信号是VIDEO01. /// 80045,有信号,信号是VIDEO02. /// 80046,有信号,信号是VIDEO03. /// 80047,有信号,信号是VIDEO04. /// 80048,有信号,信号是SV. /// </summary> /// <param name="code"></param> /// <returns></returns> public static string GetErrorInfo(string pcname, string cityName, string lineName, string station, string position, string code, string time, out string flag) { try { string info = ""; string screenState = ""; string screenRow = ""; string screenColumn = ""; string screenDetailState = ""; string content = ""; if (code.Length == 5) { screenState = code[0].ToString(); screenRow = code[1].ToString(); screenColumn = code[2].ToString(); screenDetailState = code[3].ToString() + code[4].ToString(); //屏幕详细状态 switch (screenDetailState) { case "10": content = "没有返回数据"; break; case "20": content = "背光灯未开"; break; case "30": content = "无信号源"; break; case "41": content = "信号源错误,信号源应为DVI,实际为VGA"; break; case "42": content = "信号源错误,信号源应为DVI,实际为HDMI"; break; case "43": flag = "0"; break; case "44": content = "信号源错误,信号源应为DVI,实际为VIDEO01"; break; case "45": content = "信号源错误,信号源应为DVI,实际为VIDEO02"; break; case "46": content = "信号源错误,信号源应为DVI,实际为VIDEO03"; break; case "47": content = "信号源错误,信号源应为DVI,实际为VIDEO04"; break; case "48": content = "信号源错误,信号源应为DVI,实际为SV"; break; default: content = "未定义的状态码"; break; } } else { info = "屏幕状态码有误"; WriteLog.WriteToFile(string.Format("屏幕状态码解析错误,错误原因:【状态码有误(位数不够)】时间:【{0}】", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); flag = "0"; } if (code == "80000") { info = "屏幕正常"; flag = "0"; } else { flag = "1"; string tips = "--智元汇\n 【注意】本邮件为系统自动发送的邮件,请不要回复本邮件。"; info += string.Format(" 城市:【{0}】\n" + " 线路:【{1}】\n" + " 站点:【{2}】\n" + " 点位:【{3}】\n" + " 计算机名:【{4}】\n" + " 屏幕位置:【{5}行{6}列】\n" + " 故障信息:【{7}】\n" + " 发生时间:【{8}】\n \n \n {9}", cityName, lineName, station, position, pcname, screenRow, screenColumn, content, time, tips); } return(info); } catch (Exception ex) { WriteLog.WriteToFile(string.Format("解析错误码异常-异常信息:{0},{1}", ex.Message.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); throw; } }
public static void SendEmailToReportBroken(string contentStr) { try { var emailAcount = XmlParseHelper.GetSingNode("Sender", "Account").Trim();; var emailPassword = XmlParseHelper.GetSingNode("Sender", "Password").Trim(); MailMessage message = new MailMessage(); //设置发件人,发件人需要与设置的邮件发送服务器的邮箱一致 MailAddress fromAddr = new MailAddress(emailAcount); message.From = fromAddr; List <string> list = null; list = XmlParseHelper.GetNodeList("receiver", "Account"); //设置收件人,可添加多个,添加方法与下面的一样 if (list != null && list.Count > 0) { foreach (var item in list) { if (!string.IsNullOrWhiteSpace(item)) { message.To.Add(item.Trim()); } } } list = null; list = XmlParseHelper.GetNodeList("CCList", "Account"); //设置抄送人 if (list != null && list.Count > 0) { foreach (var item in list) { if (!string.IsNullOrWhiteSpace(item)) { message.CC.Add(item.Trim()); } } } //设置邮件标题 message.Subject = XmlParseHelper.GetSingNode("Title").Trim(); //设置邮件内容 message.Body = contentStr; //设置邮件发送服务器,服务器根据你使用的邮箱而不同,可以到相应的 邮箱管理后台查看,下面是QQ的 var smtp = XmlParseHelper.GetSingNode("SmtpClient", "Host").Trim(); var host = Convert.ToInt32(XmlParseHelper.GetSingNode("SmtpClient", "Port").Trim()); SmtpClient client = new SmtpClient(smtp, host); //设置发送人的邮箱账号和密码 client.Credentials = new NetworkCredential(emailAcount, emailPassword); //启用ssl,也就是安全发送 -服务器不支持安全 client.EnableSsl = false; //发送邮件 client.Send(message); } catch (Exception ex) { WriteLog.WriteToFile(string.Format("发送邮件异常-异常信息:{0},{1}", ex.Message.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); throw ex; } }