123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983 |
- using SAGA.DotNetUtils.Extend;
- namespace SAGA.DotNetUtils
- {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Management;
- using System.Net;
- using System.Net.NetworkInformation;
- using System.Net.Sockets;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
- public class PubMethod : StringOperate
- {
- public static string Combine(string strSavePath, string strFileName)
- {
- if (strSavePath.IsNullOrEmptyExt())
- {
- throw new ArgumentNullException("strSavePath");
- }
- if (strFileName.IsNullOrEmptyExt())
- {
- throw new ArgumentNullException("strFileName");
- }
- if (!strSavePath.EndsWith(@"\"))
- {
- strSavePath = strSavePath + @"\";
- }
- if (strFileName.StartsWith(@"\"))
- {
- strFileName = strFileName.TrimStart(new char[] { '\\' });
- }
- return (strSavePath + strFileName);
- }
- public static bool CompareBytes(byte[] buffer1, byte[] buffer2)
- {
- if ((buffer1 != null) || (buffer2 != null))
- {
- if ((buffer1 == null) || (buffer2 == null))
- {
- return false;
- }
- if (buffer1.Length != buffer2.Length)
- {
- return false;
- }
- for (int i = 0; i < buffer1.Length; i++)
- {
- if (buffer1[i] != buffer2[i])
- {
- return false;
- }
- }
- }
- return true;
- }
- public static int CompareDate(DateTime beginDt, DateTime endDt)
- {
- if (beginDt.Year > endDt.Year)
- {
- return 1;
- }
- if (beginDt.Year < endDt.Year)
- {
- return -1;
- }
- if (beginDt.Month > endDt.Month)
- {
- return 1;
- }
- if (beginDt.Month < endDt.Month)
- {
- return -1;
- }
- if (beginDt.Day > endDt.Day)
- {
- return 1;
- }
- if (beginDt.Day < endDt.Day)
- {
- return -1;
- }
- return 0;
- }
- public static bool CompareFile(string strFile1, string strFile2)
- {
- FileInfo info = new FileInfo(strFile1);
- FileInfo info2 = new FileInfo(strFile2);
- if (!info.Exists || !info2.Exists)
- {
- return false;
- }
- if (info.Length != info2.Length)
- {
- return false;
- }
- try
- {
- info.OpenRead();
- info2.OpenRead();
- }
- catch (Exception)
- {
- return false;
- }
- using (FileStream stream = info.OpenRead())
- {
- using (FileStream stream2 = info2.OpenRead())
- {
- for (int i = 0; i < stream.Length; i++)
- {
- int num2 = stream.ReadByte();
- int num3 = stream2.ReadByte();
- if (num2 != num3)
- {
- return false;
- }
- }
- }
- }
- return true;
- }
- public static int CompareTime(DateTime beginDt, DateTime endDt)
- {
- int num = CompareDate(beginDt, endDt);
- if (num != 0)
- {
- return num;
- }
- if (beginDt.Hour > endDt.Hour)
- {
- return 1;
- }
- if (beginDt.Hour < endDt.Hour)
- {
- return -1;
- }
- if (beginDt.Minute > endDt.Minute)
- {
- return 1;
- }
- if (beginDt.Minute < endDt.Minute)
- {
- return -1;
- }
- if (beginDt.Second > endDt.Second)
- {
- return 1;
- }
- if (beginDt.Second < endDt.Second)
- {
- return -1;
- }
- return 0;
- }
- public static string CreateGuidKey()
- {
- DateTime now = DateTime.Now;
- string str = now.Year.ToString().PadLeft(4, '0') + now.Month.ToString().PadLeft(2, '0') + now.Day.ToString().PadLeft(2, '0') + now.Hour.ToString().PadLeft(2, '0') + now.Minute.ToString().PadLeft(2, '0') + now.Second.ToString().PadLeft(2, '0') + now.Millisecond.ToString().PadLeft(3, '0');
- string str2 = Guid.NewGuid().ToString().Replace("-", string.Empty).ToUpper();
- System.Random random = new System.Random(Guid.NewGuid().GetHashCode());
- string str3 = random.Next(1, 0x270f).ToString().PadLeft(4, '0');
- return (str + "_" + str2 + "_" + str3);
- }
- public static string CreateNowTimeString()
- {
- DateTime now = DateTime.Now;
- return (now.Year.ToString().PadLeft(4, '0') + now.Month.ToString().PadLeft(2, '0') + now.Day.ToString().PadLeft(2, '0') + now.Hour.ToString().PadLeft(2, '0') + now.Minute.ToString().PadLeft(2, '0') + now.Second.ToString().PadLeft(2, '0') + now.Millisecond.ToString().PadLeft(3, '0'));
- }
- public static string CreateUniqueName()
- {
- DateTime now = DateTime.Now;
- string str = now.Year.ToString().PadLeft(4, '0') + now.Month.ToString().PadLeft(2, '0') + now.Day.ToString().PadLeft(2, '0') + now.Hour.ToString().PadLeft(2, '0') + now.Minute.ToString().PadLeft(2, '0') + now.Second.ToString().PadLeft(2, '0') + now.Millisecond.ToString().PadLeft(3, '0');
- System.Random random = new System.Random(Guid.NewGuid().GetHashCode());
- string str2 = random.Next(1, 0x270f).ToString().PadLeft(4, '0');
- return (str + "_" + str2);
- }
- public static bool DeleteFile(string strFileName)
- {
- try
- {
- if (System.IO.File.Exists(strFileName))
- {
- FileAttribute attribute = new FileAttribute(strFileName) {
- IsReadOnly = false
- };
- System.IO.File.Delete(strFileName);
- return true;
- }
- return false;
- }
- catch
- {
- return false;
- }
- }
- public static void DeleteFolder(string folderName)
- {
- if (Directory.Exists(folderName))
- {
- DirectoryInfo info = new DirectoryInfo(folderName);
- foreach (FileInfo info2 in info.GetFiles())
- {
- try
- {
- FileAttribute attribute = new FileAttribute(info2.FullName);
- if (attribute.IsReadOnly)
- {
- attribute.IsReadOnly = false;
- }
- System.IO.File.Delete(info2.FullName);
- }
- catch
- {
- }
- }
- if (Directory.Exists(folderName))
- {
- foreach (DirectoryInfo info3 in info.GetDirectories())
- {
- DeleteFolder(info3.FullName);
- }
- try
- {
- Directory.Delete(info.FullName, true);
- }
- catch
- {
- }
- }
- }
- }
- public static bool EnumExistsValue(System.Enum source, System.Enum value)
- {
- string[] strArray = source.ToString().Trim().Split(new char[] { ',' });
- string str2 = value.ToString().Trim();
- for (int i = 0; i < strArray.Length; i++)
- {
- if (str2 == strArray[i].Trim())
- {
- return true;
- }
- }
- return false;
- }
- public static void ExtendLastCol(DataGridView grid)
- {
- if (grid.Columns.Count != 0)
- {
- int num = 0;
- foreach (DataGridViewColumn column in grid.Columns)
- {
- num += column.Width;
- }
- if (grid.Width > num)
- {
- DataGridViewColumn column2 = grid.Columns[grid.Columns.Count - 1];
- column2.Width = ((grid.Width - num) + column2.Width) - grid.RowHeadersWidth;
- }
- }
- }
- public static bool FileCopyNew(string strSourceFile, string strDestFile)
- {
- bool flag = true;
- if (!System.IO.File.Exists(strDestFile))
- {
- System.IO.File.Copy(strSourceFile, strDestFile, true);
- return flag;
- }
- FileInfo info = new FileInfo(strSourceFile);
- FileInfo info2 = new FileInfo(strDestFile);
- if (info.LastWriteTime > info2.LastWriteTime)
- {
- try
- {
- FileAttribute attribute = new FileAttribute(strDestFile) {
- IsReadOnly = false
- };
- System.IO.File.Delete(strDestFile);
- }
- catch
- {
- flag = false;
- }
- try
- {
- System.IO.File.Copy(strSourceFile, strDestFile, true);
- }
- catch
- {
- flag = false;
- }
- }
- return flag;
- }
- public static string GetAcadVersion(string strDwgFileName)
- {
- if (!System.IO.File.Exists(strDwgFileName))
- {
- return "";
- }
- FileInfo info = new FileInfo(strDwgFileName);
- if (info.Extension.ToLower() != ".dwg")
- {
- return "";
- }
- FileStream stream = new FileStream(strDwgFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
- byte[] buffer = new byte[6];
- stream.Read(buffer, 0, buffer.Length);
- string str = new UTF8Encoding(true).GetString(buffer);
- stream.Close();
- return str.Substring(4, 2);
- }
- public static string GetCnWeek(string strValue)
- {
- string str = string.Empty;
- switch (strValue.Trim().ToLower())
- {
- case "monday":
- return "星期一";
- case "tuesday":
- return "星期二";
- case "wednesday":
- return "星期三";
- case "thursday":
- return "星期四";
- case "friday":
- return "星期五";
- case "saturday":
- return "星期六";
- case "sunday":
- return "星期日";
- }
- return str;
- }
- public static string GetCpuID()
- {
- try
- {
- ManagementObjectCollection instances = new ManagementClass("Win32_Processor").GetInstances();
- string str = null;
- foreach (ManagementObject obj2 in instances)
- {
- str = obj2.Properties["ProcessorId"].Value.ToString().Trim();
- if (str.Length > 0)
- {
- break;
- }
- }
- return str;
- }
- catch
- {
- return string.Empty;
- }
- }
- public static DateTime? GetDateTime(object value)
- {
- if (value != null)
- {
- DateTime time;
- if (value == DBNull.Value)
- {
- return null;
- }
- string s = value.ToString().Trim();
- if (s.Length <= 0)
- {
- return null;
- }
- if (DateTime.TryParse(s, out time))
- {
- return new DateTime?(time);
- }
- }
- return null;
- }
- public static long GetDriveFreeSpace(string strDrive)
- {
- long lpFreeBytesAvalibe = 0L;
- long lpTotalNumberOfBytes = 0L;
- long lpTotalNumberOfFreeBytes = 0L;
- Win32APIMethod.GetDiskFreeSpaceEx(strDrive, out lpFreeBytesAvalibe, out lpTotalNumberOfBytes, out lpTotalNumberOfFreeBytes);
- return lpFreeBytesAvalibe;
- }
- public static string GetDriveFreeSpaceFormat(string strDrive)
- {
- double num2 = (((double) GetDriveFreeSpace(strDrive)) / 1024.0) / 1024.0;
- if (num2 < 1024.0)
- {
- return (Math.Round(num2, 2) + " MB");
- }
- return (Math.Round((double) (num2 / 1024.0), 3) + " GB");
- }
- public static int GetDriveType(string driveName)
- {
- return Win32APIMethod.GetDriveType(driveName);
- }
- public static Icon GetFileIcon(string strFileName, bool blnSmallIcon)
- {
- strFileName = Path.GetExtension(strFileName);
- int num = 0;
- Icon icon = null;
- Win32APIMethod.SHFILEINFO psfi = new Win32APIMethod.SHFILEINFO();
- if (blnSmallIcon)
- {
- num = (int) Win32APIMethod.SHGetFileInfo(strFileName, 0, ref psfi, (uint) Marshal.SizeOf(psfi), 0x111);
- }
- else
- {
- num = (int) Win32APIMethod.SHGetFileInfo(strFileName, 0, ref psfi, (uint) Marshal.SizeOf(psfi), 0x110);
- }
- if ((num > 0) && (((int) psfi.hIcon) != 0))
- {
- icon = Icon.FromHandle(psfi.hIcon);
- }
- return icon;
- }
- public static bool GetFileThumbnailImage(string strInFile, out string strOutFile)
- {
- strOutFile = string.Empty;
- try
- {
- Path.GetExtension(strInFile).ToLower().TrimStart(new char[] { '.' });
- if (!true)
- {
- return false;
- }
- strOutFile = Path.GetDirectoryName(strInFile) + @"\" + Guid.NewGuid().ToString();
- int width = 0;
- int height = 0;
- int num3 = 800;
- Image image = null;
- image = new Bitmap(strInFile);
- if ((image.Width <= num3) && (image.Height <= num3))
- {
- image.Save(strOutFile, ImageFormat.Jpeg);
- image.Dispose();
- return true;
- }
- if (image.Width > image.Height)
- {
- if (image.Width > (num3 - 2))
- {
- width = num3 - 2;
- height = (image.Height * (num3 - 2)) / image.Width;
- }
- else
- {
- width = image.Width;
- height = image.Height;
- }
- }
- else if (image.Height > (num3 - 2))
- {
- width = (image.Width * (num3 - 2)) / image.Height;
- height = num3 - 2;
- }
- else
- {
- width = image.Width;
- height = image.Height;
- }
- if (width == 0)
- {
- width = image.Width;
- }
- if (height == 0)
- {
- height = image.Height;
- }
- Bitmap bitmap = new Bitmap(width, height);
- try
- {
- Graphics graphics = Graphics.FromImage(bitmap);
- graphics.Clear(Color.White);
- graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
- graphics.DrawImage(image, new Rectangle(0, 0, width, height), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
- graphics.Dispose();
- }
- catch
- {
- bitmap = new Bitmap(image.GetThumbnailImage(width, height, null, IntPtr.Zero));
- }
- image.Dispose();
- bitmap.Save(strOutFile, ImageFormat.Jpeg);
- }
- catch
- {
- return false;
- }
- return true;
- }
- public static string[] GetFontFamilyNames()
- {
- FontFamily[] fontFamilys = GetFontFamilys();
- string[] strArray = new string[fontFamilys.Length];
- for (int i = 0; i < fontFamilys.Length; i++)
- {
- strArray[i] = fontFamilys[i].Name;
- }
- return strArray;
- }
- public static FontFamily[] GetFontFamilys()
- {
- return FontFamily.Families;
- }
- public static string GetHostAndIp(string IPorHostName, out string HostName)
- {
- string str = string.Empty;
- string str2 = string.Empty;
- try
- {
- IPHostEntry hostEntry = Dns.GetHostEntry(IPorHostName);
- if (!StringOperate.CheckIP(IPorHostName))
- {
- str2 = IPorHostName;
- foreach (IPAddress address in hostEntry.AddressList)
- {
- if (StringOperate.CheckIP(address.ToString().Trim()))
- {
- str = address.ToString().Trim();
- goto Label_00C1;
- }
- }
- }
- else
- {
- str = IPorHostName;
- str2 = hostEntry.HostName.ToLower();
- if (str2.IndexOf(".") >= 0)
- {
- str2 = str2.Substring(0, str2.IndexOf("."));
- }
- }
- }
- catch (SocketException exception)
- {
- if (exception.ToString().IndexOf("不知道这样的主机") >= 0)
- {
- str = string.Empty;
- str2 = string.Empty;
- }
- }
- Label_00C1:
- HostName = str2;
- return str;
- }
- public static int? GetInteger(object value)
- {
- if (value != null)
- {
- int num;
- if (value == DBNull.Value)
- {
- return null;
- }
- string s = value.ToString().Trim();
- if (s.Length <= 0)
- {
- return null;
- }
- if (int.TryParse(s, out num))
- {
- return new int?(num);
- }
- }
- return null;
- }
- public static string GetMachineIP()
- {
- return GetMachineIP(Environment.MachineName);
- }
- public static string GetMachineIP(string MachineName)
- {
- string str = string.Empty;
- if (MachineName != string.Empty)
- {
- try
- {
- foreach (IPAddress address in Dns.GetHostEntry(MachineName).AddressList)
- {
- if (StringOperate.CheckIP(address.ToString().Trim()))
- {
- return address.ToString().Trim();
- }
- }
- }
- catch
- {
- }
- }
- return str;
- }
- public static string GetNetCardMAC()
- {
- try
- {
- string str = string.Empty;
- ManagementClass class2 = new ManagementClass("Win32_NetworkAdapterConfiguration");
- foreach (ManagementObject obj2 in class2.GetInstances())
- {
- if ((bool) obj2["IPEnabled"])
- {
- str = obj2["MACAddress"].ToString().Trim();
- if (str.Length > 0)
- {
- return str;
- }
- }
- }
- return str;
- }
- catch
- {
- return string.Empty;
- }
- }
- public static double? GetNumber(object value)
- {
- if (value != null)
- {
- double num;
- if (value == DBNull.Value)
- {
- return null;
- }
- string s = value.ToString().Trim();
- if (s.Length <= 0)
- {
- return null;
- }
- if (double.TryParse(s, out num))
- {
- return new double?(num);
- }
- }
- return null;
- }
- public static Image GetThubmnailImage(Image image, int intImageSize)
- {
- if (intImageSize == 0)
- {
- intImageSize = 200;
- }
- int width = 0;
- int height = 0;
- if (image.Width > image.Height)
- {
- if (image.Width > (intImageSize - 2))
- {
- width = intImageSize - 2;
- height = (image.Height * (intImageSize - 2)) / image.Width;
- }
- else
- {
- width = image.Width;
- height = image.Height;
- }
- }
- else if (image.Height > (intImageSize - 2))
- {
- width = (image.Width * (intImageSize - 2)) / image.Height;
- height = intImageSize - 2;
- }
- else
- {
- width = image.Width;
- height = image.Height;
- }
- if (width == 0)
- {
- width = image.Width;
- }
- if (height == 0)
- {
- height = image.Height;
- }
- Bitmap bitmap = new Bitmap(intImageSize, intImageSize);
- Graphics graphics = Graphics.FromImage(bitmap);
- graphics.Clear(Color.White);
- Pen pen = new Pen(Color.Black, 1f);
- graphics.DrawRectangle(pen, 0, 0, intImageSize - 1, intImageSize - 1);
- graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
- graphics.DrawImage(image, new Rectangle((intImageSize - width) / 2, (intImageSize - height) / 2, width, height), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
- graphics.Dispose();
- image.Dispose();
- return bitmap;
- }
- public static List<T[]> GroupArray<T>(T[] source, int intGroups)
- {
- List<T[]> list = new List<T[]>();
- if (source.Length < intGroups)
- {
- list.Add(source);
- return list;
- }
- int num = source.Length / intGroups;
- for (int i = 0; i < intGroups; i++)
- {
- List<T> list2 = new List<T>();
- int num3 = num;
- if (i == (intGroups - 1))
- {
- num3 += source.Length % intGroups;
- }
- for (int j = 0; j < num3; j++)
- {
- list2.Add(source[(i * num) + j]);
- }
- list.Add(list2.ToArray());
- }
- return list;
- }
- public static void KillProcess(string ProName)
- {
- try
- {
- Process[] processesByName = Process.GetProcessesByName(ProName);
- if (processesByName.Length > 0)
- {
- for (int i = 0; i < processesByName.Length; i++)
- {
- processesByName[i].Kill();
- Thread.Sleep(0x3e8);
- }
- }
- }
- catch
- {
- }
- }
- public static bool KillProcess(string ProName, int intCpuMinutes)
- {
- bool flag = false;
- try
- {
- Process[] processesByName = Process.GetProcessesByName(ProName);
- if (processesByName.Length <= 0)
- {
- return flag;
- }
- for (int i = 0; i < processesByName.Length; i++)
- {
- Process process = processesByName[i];
- if (process.TotalProcessorTime.Minutes == intCpuMinutes)
- {
- process.Kill();
- flag = true;
- }
- }
- }
- catch
- {
- }
- return flag;
- }
- public static bool KillProcess(string ProName, long Memory)
- {
- bool flag = false;
- try
- {
- Process[] processesByName = Process.GetProcessesByName(ProName);
- if (processesByName.Length <= 0)
- {
- return flag;
- }
- for (int i = 0; i < processesByName.Length; i++)
- {
- Process process = processesByName[i];
- if (process.WorkingSet64 > Memory)
- {
- SystemLogger.Default.Write(" Cur Memory Size : " + process.WorkingSet64.ToString());
- process.Kill();
- flag = true;
- }
- }
- }
- catch
- {
- }
- return flag;
- }
- public static void NavigateFile(string strFileName)
- {
- Process.Start("explorer.exe", "/select," + strFileName);
- }
- public static int Random(int intMaxValue)
- {
- return new System.Random(Guid.NewGuid().GetHashCode()).Next(-2147483648, intMaxValue);
- }
- public static int Random(int intMinValue, int intMaxValue)
- {
- return new System.Random(Guid.NewGuid().GetHashCode()).Next(intMinValue, intMaxValue);
- }
- public static string RemoveEmptyZero(string s)
- {
- if (s == null)
- {
- return s;
- }
- int index = s.IndexOf(".");
- if (index <= -1)
- {
- return s;
- }
- List<char> list = new List<char>();
- string str = s.Substring(index);
- for (int i = 0; i < str.Length; i++)
- {
- char c = str[i];
- if (char.IsNumber(c))
- {
- string str2 = str.Substring(i);
- bool flag = false;
- for (int j = 1; j <= 9; j++)
- {
- if (str2.IndexOf(j.ToString()) > -1)
- {
- flag = true;
- break;
- }
- }
- if (flag)
- {
- list.Add(c);
- }
- continue;
- }
- if (c == '.')
- {
- string str3 = str.Substring(i);
- bool flag2 = false;
- for (int k = 1; k <= 9; k++)
- {
- if (str3.IndexOf(k.ToString()) > -1)
- {
- flag2 = true;
- break;
- }
- }
- if (flag2)
- {
- list.Add(c);
- }
- continue;
- }
- list.Add(c);
- }
- if (list.Count > 0)
- {
- return (s.Substring(0, index) + new string(list.ToArray()));
- }
- return s.Substring(0, index);
- }
- public static string ReplaceErrChar(object objValue)
- {
- return objValue.ToString().Replace(@"\", string.Empty).Replace("'", string.Empty);
- }
- public static string ReplaceErrChar(string strValue)
- {
- return strValue.Replace(@"\", string.Empty).Replace("'", string.Empty);
- }
- public static List<T[]> SplitArray<T>(T[] source, int intFixLength)
- {
- List<T[]> list = new List<T[]>();
- List<T> list2 = new List<T>();
- for (int i = 0; i < source.Length; i++)
- {
- list2.Add(source[i]);
- if ((list2.Count >= intFixLength) || (i == (source.Length - 1)))
- {
- list.Add(list2.ToArray());
- list2.Clear();
- }
- }
- return list;
- }
- public static void SwapValue<T>(ref T a, ref T b)
- {
- T local = a;
- a = b;
- b = local;
- }
- public static bool TestMachineOnline(string MachineIP)
- {
- try
- {
- string hostNameOrAddress = MachineIP;
- if (hostNameOrAddress.IndexOf('\\') > 0)
- {
- hostNameOrAddress = hostNameOrAddress.Substring(0, hostNameOrAddress.IndexOf('\\'));
- }
- Ping ping = new Ping();
- if (ping.Send(hostNameOrAddress, 0x7d0).Status == IPStatus.Success)
- {
- return true;
- }
- }
- catch (Exception exception)
- {
- SystemLogger.Default.Write("Ping " + MachineIP + exception.ToString());
- return true;
- }
- SystemLogger.Default.Write("现在不能ping通机器:" + MachineIP);
- return false;
- }
- public static string[] ToStringArray<T>(T[] items)
- {
- string[] strArray = new string[items.Length];
- for (int i = 0; i < items.Length; i++)
- {
- if (items[i] == null)
- {
- strArray[i] = string.Empty;
- }
- else
- {
- strArray[i] = items[i].ToString();
- }
- }
- return strArray;
- }
- }
- }
|