814 lines
22 KiB
C#
814 lines
22 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Management;
|
|
using System.Net;
|
|
using System.Net.NetworkInformation;
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace SIDConvInfoEditorII
|
|
{
|
|
|
|
public static partial class UTIL
|
|
{
|
|
|
|
public static bool ImportSIDInfo(DataSet1.Component_Reel_SID_InformationDataTable Component_Reel_SID_Information,
|
|
String InputFileName,
|
|
System.Windows.Forms.ProgressBar progressBar1 = null)
|
|
{
|
|
//엑셀을 읽어와서 처리한다.
|
|
var fi = new System.IO.FileInfo(InputFileName);
|
|
var ext = fi.Extension.ToLower();
|
|
libxl.Book book;
|
|
if (ext == ".xlsx") book = new libxl.XmlBook();
|
|
else if (ext == ".xls") book = new libxl.BinBook();
|
|
else return false;
|
|
|
|
var keyinfo = Properties.Settings.Default.libxl.Split('/');
|
|
book.setKey(keyinfo[0], keyinfo[1]);
|
|
book.load(fi.FullName);
|
|
var sheet = book.getSheet(0);
|
|
|
|
var cs = sheet.firstCol();
|
|
var ce = sheet.lastCol();
|
|
var rs = sheet.firstRow();
|
|
var re = sheet.lastRow();
|
|
|
|
if (progressBar1 != null)
|
|
{
|
|
progressBar1.Minimum = 0;
|
|
progressBar1.Maximum = re;
|
|
progressBar1.Value = 0;
|
|
}
|
|
|
|
if (rs == 0) rs += 1;
|
|
|
|
int cntA = 0;
|
|
//int cntU = 0;
|
|
for (int row = rs; row <= re; row++)
|
|
{
|
|
//update progress bar
|
|
if (progressBar1 != null)
|
|
{
|
|
if (progressBar1.Value < progressBar1.Maximum) progressBar1.Value += 1;
|
|
}
|
|
|
|
|
|
var cCustCode = sheet.readStr(row, 0);
|
|
var cSID = sheet.readStr(row, 1);
|
|
var cPartNo = sheet.readStr(row, 2);
|
|
|
|
if (cCustCode.isEmpty() == false && cCustCode.Length != 4)
|
|
cCustCode = cCustCode.PadLeft(4, '0');
|
|
|
|
if (cSID.isEmpty() && cCustCode.isEmpty()) break; //
|
|
|
|
//if (cSID.StartsWith("10"))
|
|
//{
|
|
EnumerableRowCollection<DataSet1.Component_Reel_SID_InformationRow> plist = null;
|
|
plist = Component_Reel_SID_Information.Where(t => t.MC == PUB.setting.McName && t.SID == cSID && t.CustCode == cCustCode && t.PartNo == cPartNo);
|
|
|
|
if (plist == null || plist.Any() == false)
|
|
{
|
|
//존재하지않으면 추가한다.
|
|
var newdr = Component_Reel_SID_Information.NewComponent_Reel_SID_InformationRow();
|
|
newdr.CustCode = cCustCode;
|
|
newdr.SID = cSID;
|
|
newdr.PartNo = cPartNo;
|
|
newdr.MC = PUB.setting.McName;
|
|
newdr.wdate = DateTime.Now;
|
|
Component_Reel_SID_Information.AddComponent_Reel_SID_InformationRow(newdr);
|
|
cntA += 1;
|
|
}
|
|
else
|
|
{
|
|
//있다면 업데이트 해준다.
|
|
//foreach (var item in plist)
|
|
//{
|
|
// if (cSID.isEmpty() == false)
|
|
// {
|
|
// item.SID = cSID; ;
|
|
// item.EndEdit();
|
|
// cntU += 1;
|
|
// }
|
|
|
|
//}
|
|
}
|
|
//}
|
|
|
|
}
|
|
PUB.log.Add($"Import SID Information : {cntA}");
|
|
return true;
|
|
}
|
|
|
|
public static bool GetBitState(UInt16 val, int idx)
|
|
{
|
|
UInt16 offset = 1;
|
|
offset = (UInt16)(offset << idx);
|
|
return (val & offset) > 0;
|
|
}
|
|
public static UInt16 SetBitState(UInt16 val, int idx, bool state)
|
|
{
|
|
UInt16 offset = 0x01;
|
|
offset = (UInt16)(offset << idx);
|
|
if (state == false) offset = (UInt16)~offset;
|
|
|
|
if (state)
|
|
{
|
|
return (UInt16)(val | offset);
|
|
}
|
|
else
|
|
{
|
|
return (UInt16)(val & offset);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static Control GetContextOwnerControl(object sender)
|
|
{
|
|
if (sender is ToolStripMenuItem menuitem)
|
|
{
|
|
if (menuitem.Owner is ContextMenuStrip menu)
|
|
{
|
|
return menu.SourceControl;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static double GetFreeSpace(string driveletter)
|
|
{
|
|
try
|
|
{
|
|
var di = new System.IO.DriveInfo(driveletter);
|
|
var freespace = di.TotalFreeSpace;
|
|
var totalspace = di.TotalSize;
|
|
var freeSpaceRate = (freespace * 1.0 / totalspace) * 100.0;
|
|
return freeSpaceRate;
|
|
}
|
|
catch
|
|
{
|
|
return 100.0;
|
|
}
|
|
}
|
|
|
|
|
|
#region "MessageBox"
|
|
public static void MsgI(string m, Boolean legacy = false)
|
|
{
|
|
|
|
|
|
MessageBox.Show(m, "확인", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
}
|
|
public static void MsgE(string m, Boolean legacy = false)
|
|
{
|
|
MessageBox.Show(m, "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
}
|
|
public static DialogResult MsgQ(string m, string btOK = "확인", string btCancel = "아니오")
|
|
{
|
|
var dlg = MessageBox.Show(m, "확인", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
return dlg;
|
|
}
|
|
|
|
#endregion
|
|
|
|
// <summary>
|
|
/// 현재위치를 기준으로 폴더명을 구성합니다.
|
|
/// </summary>
|
|
/// <param name="subname"></param>
|
|
/// <returns></returns>
|
|
public static string MakePath(params string[] subname)
|
|
{
|
|
List<string> pathlist = new List<string>();
|
|
pathlist.Add(CurrentPath);
|
|
if (subname.Length > 0) pathlist.AddRange(subname);
|
|
return System.IO.Path.Combine(pathlist.ToArray());
|
|
}
|
|
|
|
public static Boolean SendMail(string title, string body, string from, string[] tolist, string file = "")
|
|
{
|
|
//메일을 전송하고 나간다
|
|
Chilkat.MailMan mailman = new Chilkat.MailMan();
|
|
bool success = mailman.UnlockComponent("BLUPRT.CBX012020_rzDFf7pQAsCS");
|
|
if (success != true)
|
|
{
|
|
UTIL.MsgE("메일 전송이 실패되었습니다\n잠시 후 다시 시도하세요", true);
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
mailman.SmtpHost = "10.101.10.6";
|
|
mailman.SmtpPort = 25;
|
|
Chilkat.Email email = new Chilkat.Email();
|
|
email.Subject = title;
|
|
//email.Body = this.textBox1.Text;
|
|
email.SetHtmlBody(body.Replace("\r", "").Replace("\n", "<br/>"));
|
|
email.From = from;
|
|
|
|
foreach (var to in tolist)
|
|
email.AddTo(to.Substring(0, to.IndexOf('@')), to);
|
|
|
|
if (System.IO.File.Exists(file))
|
|
email.AddFileAttachment(file);
|
|
|
|
success = mailman.SendEmail(email);
|
|
if (success != true)
|
|
{
|
|
UTIL.MsgE("발송 실패", true);
|
|
return false;
|
|
}
|
|
|
|
success = mailman.CloseSmtpConnection();
|
|
if (success != true)
|
|
{
|
|
UTIL.MsgE("Connection to SMTP server not closed cleanly.", true);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
public static Dictionary<string, string> ComputerInfo()
|
|
{
|
|
string ip = "";
|
|
string mac = "";
|
|
// string prgmName = Application.ProductName;
|
|
|
|
var nif = NetworkInterface.GetAllNetworkInterfaces();
|
|
var host = Dns.GetHostEntry(Dns.GetHostName());
|
|
string fullname = System.Net.Dns.GetHostEntry("").HostName;
|
|
foreach (IPAddress r in host.AddressList)
|
|
{
|
|
string str = r.ToString();
|
|
|
|
if (str != "" && str.Substring(0, 3) == "10.")
|
|
{
|
|
ip = str;
|
|
break;
|
|
}
|
|
}
|
|
|
|
string rtn = string.Empty;
|
|
ObjectQuery oq = new System.Management.ObjectQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled='TRUE'");
|
|
ManagementObjectSearcher query1 = new ManagementObjectSearcher(oq);
|
|
foreach (ManagementObject mo in query1.Get())
|
|
{
|
|
string[] address = (string[])mo["IPAddress"];
|
|
if (address[0] == ip && mo["MACAddress"] != null)
|
|
{
|
|
mac = mo["MACAddress"].ToString();
|
|
break;
|
|
}
|
|
}
|
|
|
|
var username = System.Environment.UserName;
|
|
var retval = new Dictionary<string, string>();
|
|
retval.Add("IP", ip);
|
|
retval.Add("MAC", mac);
|
|
retval.Add("USER", username);
|
|
retval.Add("HOST", fullname);
|
|
return retval;
|
|
|
|
|
|
|
|
}
|
|
public static string ScreenCaptrue(int _BitmapWidth, int _BitmapHeight, Point ptSouce, Boolean prompt)
|
|
{
|
|
try
|
|
{
|
|
Bitmap bitmap = new Bitmap(_BitmapWidth, _BitmapHeight);
|
|
Graphics _graphic = Graphics.FromImage(bitmap);
|
|
|
|
_graphic.CopyFromScreen(ptSouce, new Point(0, 0), new Size(_BitmapWidth, _BitmapHeight));
|
|
|
|
string savefile = System.IO.Path.Combine(UTIL.CurrentPath, "ScreenShot", DateTime.Now.ToString("yyyyMMddHHmmss") + ".png");
|
|
System.IO.FileInfo grpath = new FileInfo(savefile);
|
|
if (!grpath.Directory.Exists) grpath.Directory.Create();
|
|
|
|
bitmap.Save(grpath.FullName, System.Drawing.Imaging.ImageFormat.Png);
|
|
if (prompt)
|
|
UTIL.MsgI("화면 캡쳐 성공\n" +
|
|
"위치:" + grpath.Directory.FullName + "\n" +
|
|
"파일명: " + grpath.Name);
|
|
|
|
return grpath.FullName;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (prompt)
|
|
UTIL.MsgE("화면 캡쳐 실패\n" + ex.Message);
|
|
return string.Empty;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//public static bool SendMail(string seqdate, string seqno)
|
|
//{
|
|
// Chilkat.MailMan mailman = new Chilkat.MailMan();
|
|
// bool success = mailman.UnlockComponent("BLUPRT.CBX012020_rzDFf7pQAsCS");
|
|
// if (success != true)
|
|
// {
|
|
// Debug.WriteLine(mailman.LastErrorText);
|
|
// return false;
|
|
// }
|
|
|
|
// mailman.SmtpHost = "10.101.10.6";
|
|
|
|
// mailman.SmtpPort = 25;
|
|
|
|
// Create a new email object
|
|
// Chilkat.Email email = new Chilkat.Email();
|
|
|
|
// var mailform = PUB.mailForm.FirstOrDefault();
|
|
// if (mailform == null)
|
|
// return false;
|
|
|
|
|
|
|
|
// var subject = mailform.subject.Trim();
|
|
// subject = subject.Replace("{seqdate}", seqdate);
|
|
// subject = subject.Replace("{seqno}", seqno);
|
|
|
|
|
|
// var buffer = System.IO.File.ReadAllText(Util.CurrentPath + "\\Mailform.html");
|
|
|
|
// 시드별집계데이터생성
|
|
// System.Text.StringBuilder sbFileSID = new StringBuilder();
|
|
// System.Text.StringBuilder sbFileREEL = new StringBuilder();
|
|
// sbFileSID.AppendLine(string.Format("NO,SID,작업수량,예정수량,UNIT"));
|
|
// sbFileREEL.AppendLine(string.Format("NO,SID,REEL,QTY,TIME"));
|
|
|
|
// int cntrid = 1;
|
|
|
|
// System.IO.File.WriteAllText(Util.CurrentPath + "\\result_sidsummary.csv", sbFileSID.ToString(), System.Text.Encoding.Default);
|
|
// System.IO.File.WriteAllText(Util.CurrentPath + "\\result_reelist.csv", sbFileREEL.ToString(), System.Text.Encoding.Default);
|
|
|
|
// 메일본문의 내용 치환
|
|
// var contents = buffer.Trim();
|
|
// contents = contents.Replace("{seqdate}", seqdate);
|
|
// contents = contents.Replace("{seqno}", seqno);
|
|
|
|
// email.Subject = subject;
|
|
// email.SetHtmlBody(contents);
|
|
// email.From = "ReelSorter";
|
|
// email.AddFileAttachment(Util.CurrentPath + "\\result_sidsummary.csv");
|
|
// email.AddFileAttachment(Util.CurrentPath + "\\result_reelist.csv");
|
|
|
|
|
|
// System.Text.StringBuilder maillist = new StringBuilder();
|
|
// foreach (DataSet1.MailRecipientRow r in PUB.mailList.Rows)
|
|
// {
|
|
// success = email.AddTo(r.Name, r.Address);
|
|
// maillist.Append(string.Format("{0}({1})", r.Name, r.Address));
|
|
// }
|
|
|
|
|
|
// success = mailman.SendEmail(email);
|
|
// if (success != true)
|
|
// {
|
|
// Debug.WriteLine(mailman.LastErrorText);
|
|
// return false;
|
|
// }
|
|
|
|
// success = mailman.CloseSmtpConnection();
|
|
// if (success != true)
|
|
// {
|
|
// Debug.WriteLine("Connection to SMTP server not closed cleanly.");
|
|
// PUB.log.AddE("메일 발송 실패(" + maillist.ToString() + ")");
|
|
// }
|
|
|
|
// PUB.log.AddI("메일 발송 완료(" + maillist.ToString() + ")");
|
|
// return true;
|
|
//}
|
|
|
|
public static T FileDeSerialize<T>(string file)
|
|
{
|
|
T Retval = default(T);
|
|
if (System.IO.File.Exists(file) == false) return Retval;
|
|
var xmlSerializer = new BinaryFormatter();
|
|
using (FileStream fs = new FileStream(file, FileMode.Open))
|
|
{
|
|
try
|
|
{
|
|
var value = xmlSerializer.Deserialize(fs);
|
|
Retval = (T)Convert.ChangeType(value, typeof(T));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
PUB.log.AddE("File DeSerialized Error : " + ex.Message);
|
|
}
|
|
//Retval = (T)xmlSerializer.Deserialize(fs);
|
|
}
|
|
return Retval;
|
|
}
|
|
|
|
|
|
public static void FileSerialize(object data, string file)
|
|
{
|
|
if (data == null) return;
|
|
var xmlSerializer = new BinaryFormatter();
|
|
using (FileStream fs = new FileStream(file, FileMode.Create))
|
|
{
|
|
xmlSerializer.Serialize(fs, data);
|
|
}
|
|
}
|
|
|
|
|
|
public static void splitID(string ID, out string ww, out string seq)
|
|
{
|
|
if (ID.Length < 3)
|
|
{
|
|
ww = "";
|
|
seq = "";
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
ww = ID.Substring(0, 2);// int.Parse(ID.Substring(0, 2));
|
|
seq = ID.Substring(2);// int.Parse(ID.Substring(2));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
PUB.log.AddE("slit id eerr" + ex.Message);
|
|
ww = "";
|
|
seq = "-1";
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public static void ScreenCaptrue(int _BitmapWidth, int _BitmapHeight, Point ptSouce)
|
|
{
|
|
try
|
|
{
|
|
Bitmap bitmap = new Bitmap(_BitmapWidth, _BitmapHeight);
|
|
Graphics _graphic = Graphics.FromImage(bitmap);
|
|
|
|
_graphic.CopyFromScreen(ptSouce, new Point(0, 0), new Size(_BitmapWidth, _BitmapHeight));
|
|
|
|
string savefile = System.IO.Path.Combine(UTIL.CurrentPath, "ScreenShot", DateTime.Now.ToString("yyyyMMddHHmmss") + ".png");
|
|
System.IO.FileInfo grpath = new FileInfo(savefile);
|
|
if (!grpath.Directory.Exists) grpath.Directory.Create();
|
|
|
|
bitmap.Save(grpath.FullName, System.Drawing.Imaging.ImageFormat.Png);
|
|
UTIL.MsgI("화면 캡쳐 성공\n" +
|
|
"위치:" + grpath.Directory.FullName + "\n" +
|
|
"파일명: " + grpath.Name);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
UTIL.MsgE("화면 캡쳐 실패\n" + ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
public static void SaveBugReport(string content, string subdirName = "BugReport")
|
|
{
|
|
try
|
|
{
|
|
var path = CurrentPath + subdirName;
|
|
if (!System.IO.Directory.Exists(path)) System.IO.Directory.CreateDirectory(path);
|
|
var file = path + "\\" + DateTime.Now.ToString("yyyyMMdd_HHmmss_fff") + ".txt";
|
|
System.IO.File.WriteAllText(file, content, System.Text.Encoding.UTF8);
|
|
}
|
|
catch
|
|
{
|
|
//nothing
|
|
}
|
|
}
|
|
|
|
public static void CopyData(System.Data.DataRow drSrc, System.Data.DataRow drDes)
|
|
{
|
|
if (drDes == null || drSrc == null) return;
|
|
foreach (System.Data.DataColumn col in drSrc.Table.Columns)
|
|
{
|
|
if (col.ColumnName.ToUpper() == "IDX") continue;
|
|
drDes[col.ColumnName] = drSrc[col.ColumnName];
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 현재실행중인폴더를 반환합니다.
|
|
/// </summary>
|
|
public static string CurrentPath
|
|
{
|
|
get
|
|
{
|
|
return AppDomain.CurrentDomain.BaseDirectory;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 콤마와 줄바꿈등을 제거합니다.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string ToCSVString(string src)
|
|
{
|
|
string retval = src.Replace("\r", "").Replace("\n", "").Replace(",", "");
|
|
return retval;
|
|
}
|
|
|
|
public static Boolean RunProcess(string file, string arg = "")
|
|
{
|
|
var fi = new System.IO.FileInfo(file);
|
|
if (!fi.Exists)
|
|
{
|
|
PUB.log.AddE("Run Error : " + file);
|
|
return false;
|
|
}
|
|
System.Diagnostics.Process prc = new System.Diagnostics.Process();
|
|
System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo(file);
|
|
si.Arguments = arg;
|
|
prc.StartInfo = si;
|
|
prc.Start();
|
|
return true;
|
|
}
|
|
|
|
#region "convert"
|
|
public static string RectToStr(Rectangle rect)
|
|
{
|
|
return string.Format("{0};{1};{2};{3}", rect.X, rect.Y, rect.Width, rect.Height);
|
|
}
|
|
public static string RectToStr(RectangleF rect)
|
|
{
|
|
return string.Format("{0};{1};{2};{3}", rect.X, rect.Y, rect.Width, rect.Height);
|
|
}
|
|
public static string PointToStr(Point pt)
|
|
{
|
|
return string.Format("{0};{1}", pt.X, pt.Y);
|
|
}
|
|
public static string PointToStr(PointF pt)
|
|
{
|
|
return string.Format("{0};{1}", pt.X, pt.Y);
|
|
}
|
|
public static Rectangle StrToRect(string str)
|
|
{
|
|
if (str.isEmpty() || str.Split(';').Length != 4) str = "0;0;0;0";
|
|
var roibuf1 = str.Split(';');
|
|
return new System.Drawing.Rectangle(
|
|
int.Parse(roibuf1[0]),
|
|
int.Parse(roibuf1[1]),
|
|
int.Parse(roibuf1[2]),
|
|
int.Parse(roibuf1[3]));
|
|
}
|
|
public static RectangleF StrToRectF(string str)
|
|
{
|
|
if (str.isEmpty() || str.Split(';').Length != 4) str = "0;0;0;0";
|
|
var roibuf1 = str.Split(';');
|
|
return new System.Drawing.RectangleF(
|
|
float.Parse(roibuf1[0]),
|
|
float.Parse(roibuf1[1]),
|
|
float.Parse(roibuf1[2]),
|
|
float.Parse(roibuf1[3]));
|
|
}
|
|
public static Point StrToPoint(string str)
|
|
{
|
|
if (str.isEmpty() || str.Split(';').Length != 2) str = "0;0";
|
|
var roibuf1 = str.Split(';');
|
|
return new System.Drawing.Point(
|
|
int.Parse(roibuf1[0]),
|
|
int.Parse(roibuf1[1]));
|
|
}
|
|
public static PointF StrToPointF(string str)
|
|
{
|
|
if (str.isEmpty() || str.Split(';').Length != 2) str = "0;0";
|
|
var roibuf1 = str.Split(';');
|
|
return new System.Drawing.PointF(
|
|
float.Parse(roibuf1[0]),
|
|
float.Parse(roibuf1[1]));
|
|
}
|
|
#endregion
|
|
|
|
#region "NIC"
|
|
|
|
/// <summary>
|
|
/// 지정된 nic카드가 현재 목록에 존재하는지 확인한다.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static Boolean ExistNIC(string NICName)
|
|
{
|
|
if (string.IsNullOrEmpty(NICName)) return false;
|
|
foreach (string NetName in NICCardList())
|
|
{
|
|
if (NetName.ToLower() == NICName.ToLower())
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ehternet Card 를 사용안함으로 설정합니다.(관리자권한필요)
|
|
/// </summary>
|
|
/// <param name="NicName"></param>
|
|
public static Boolean NICDisable(string NICName)
|
|
{
|
|
//해당 nic 가 현재 목록에 존재하는지 확인한다.
|
|
|
|
string cmd = "interface set interface " + NICName + " disable";
|
|
Process prc = new Process();
|
|
ProcessStartInfo si = new ProcessStartInfo("netsh", cmd);
|
|
si.WindowStyle = ProcessWindowStyle.Hidden;
|
|
prc.StartInfo = si;
|
|
prc.Start();
|
|
|
|
////목록에서 사라질때까지 기다린다.
|
|
DateTime SD = DateTime.Now;
|
|
Boolean timeout = false;
|
|
while ((true))
|
|
{
|
|
|
|
bool FindNetwork = false;
|
|
foreach (string NetName in NICCardList())
|
|
{
|
|
if (NetName == NICName.ToLower())
|
|
{
|
|
FindNetwork = true;
|
|
break; // TODO: might not be correct. Was : Exit For
|
|
}
|
|
}
|
|
|
|
if (!FindNetwork)
|
|
break; // TODO: might not be correct. Was : Exit While
|
|
|
|
System.Threading.Thread.Sleep(1000);
|
|
TimeSpan ts = DateTime.Now - SD;
|
|
if (ts.TotalSeconds > 10)
|
|
{
|
|
timeout = true;
|
|
break; // TODO: might not be correct. Was : Exit While
|
|
}
|
|
}
|
|
return !timeout;
|
|
}
|
|
|
|
public static List<String> NICCardList()
|
|
{
|
|
List<String> Retval = new List<string>();
|
|
foreach (System.Net.NetworkInformation.NetworkInterface Net in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
|
|
{
|
|
if (Net.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Ethernet)
|
|
{
|
|
Retval.Add(Net.Name.ToUpper());
|
|
}
|
|
}
|
|
return Retval;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 이더넷카드를 사용함으로 설정합니다.
|
|
/// </summary>
|
|
/// <param name="NicName"></param>
|
|
public static Boolean NICEnable(string NICName)
|
|
{
|
|
string cmd = "interface set interface " + NICName + " enable";
|
|
System.Diagnostics.Process prc = new System.Diagnostics.Process();
|
|
System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo("netsh", cmd);
|
|
si.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
|
|
prc.StartInfo = si;
|
|
prc.Start();
|
|
|
|
|
|
////목록에생길떄까지 대기
|
|
DateTime SD = DateTime.Now;
|
|
while ((true))
|
|
{
|
|
|
|
bool FindNetwork = false;
|
|
foreach (string NetName in NICCardList())
|
|
{
|
|
if (NetName.ToLower() == NICName.ToLower())
|
|
{
|
|
FindNetwork = true;
|
|
break; // TODO: might not be correct. Was : Exit For
|
|
}
|
|
}
|
|
|
|
if (FindNetwork)
|
|
break; // TODO: might not be correct. Was : Exit While
|
|
|
|
System.Threading.Thread.Sleep(1000);
|
|
TimeSpan ts = DateTime.Now - SD;
|
|
if (ts.TotalSeconds > 10)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
////결이 완료될떄까지 기다린다.
|
|
SD = DateTime.Now;
|
|
while ((true))
|
|
{
|
|
|
|
bool FindNetwork = false;
|
|
foreach (System.Net.NetworkInformation.NetworkInterface Net in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
|
|
{
|
|
if (Net.NetworkInterfaceType != System.Net.NetworkInformation.NetworkInterfaceType.GigabitEthernet &&
|
|
Net.NetworkInterfaceType != System.Net.NetworkInformation.NetworkInterfaceType.Ethernet) continue;
|
|
if (Net.Name.ToLower() == NICName.ToLower())
|
|
{
|
|
//string data = Net.GetIPProperties().GatewayAddresses[0].ToString();
|
|
|
|
if (Net.OperationalStatus == System.Net.NetworkInformation.OperationalStatus.Up)
|
|
{
|
|
|
|
FindNetwork = true;
|
|
break; // TODO: might not be correct. Was : Exit For
|
|
}
|
|
}
|
|
}
|
|
if (FindNetwork)
|
|
return true;
|
|
|
|
System.Threading.Thread.Sleep(1000);
|
|
TimeSpan ts = DateTime.Now - SD;
|
|
if (ts.TotalSeconds > 10)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
public static void RunExplorer(string arg)
|
|
{
|
|
System.Diagnostics.ProcessStartInfo si = new ProcessStartInfo("explorer");
|
|
si.Arguments = arg;
|
|
System.Diagnostics.Process.Start(si);
|
|
}
|
|
|
|
#region "watchdog"
|
|
public static void WatchDog_Run()
|
|
{
|
|
System.IO.FileInfo fi = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "WatchCat.exe");
|
|
if (!fi.Exists) return;
|
|
var Exist = CheckExistProcess("watchcat");
|
|
if (Exist != null) return;
|
|
RunProcess(fi.FullName);
|
|
}
|
|
|
|
public static System.Diagnostics.Process CheckExistProcess(string ProcessName)
|
|
{
|
|
foreach (var prc in System.Diagnostics.Process.GetProcesses())
|
|
{
|
|
if (prc.ProcessName.StartsWith("svchost")) continue;
|
|
if (prc.ProcessName.ToUpper() == ProcessName.ToUpper()) return prc;
|
|
}
|
|
return null;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region "web function"
|
|
/// <summary>
|
|
/// URL로부터 문자열을 수신합니다.
|
|
/// </summary>
|
|
/// <param name="url"></param>
|
|
/// <param name="isError"></param>
|
|
/// <returns></returns>
|
|
public static string GetStrfromurl(string url, out Boolean isError)
|
|
{
|
|
isError = false;
|
|
string result = "";
|
|
try
|
|
{
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url));
|
|
request.Timeout = 60000;
|
|
request.ReadWriteTimeout = 60000;
|
|
|
|
request.MaximumAutomaticRedirections = 4;
|
|
request.MaximumResponseHeadersLength = 4;
|
|
request.Credentials = CredentialCache.DefaultCredentials;
|
|
var response = request.GetResponse() as HttpWebResponse;
|
|
var txtReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
|
|
result = txtReader.ReadToEnd();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
isError = true;
|
|
result = ex.Message.ToString();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|