2014-07-08 12:58:53 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
2015-03-21 18:14:00 +00:00
|
|
|
|
using System.Text;
|
2015-02-24 20:58:20 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2014-07-08 12:58:53 +00:00
|
|
|
|
using System.Windows.Forms;
|
2015-05-21 16:27:43 +00:00
|
|
|
|
using System.Drawing.Imaging;
|
2014-07-08 12:58:53 +00:00
|
|
|
|
|
2015-01-13 18:29:11 +00:00
|
|
|
|
namespace xClient.Core.Helper
|
2014-07-08 12:58:53 +00:00
|
|
|
|
{
|
2015-01-13 18:43:55 +00:00
|
|
|
|
public static class Helper
|
2014-07-08 12:58:53 +00:00
|
|
|
|
{
|
|
|
|
|
private const string CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
2015-01-14 12:15:31 +00:00
|
|
|
|
private static readonly Random _rnd = new Random(Environment.TickCount);
|
2014-07-08 12:58:53 +00:00
|
|
|
|
|
|
|
|
|
public static string GetRandomFilename(int length, string extension)
|
|
|
|
|
{
|
2015-03-21 18:14:00 +00:00
|
|
|
|
StringBuilder randomName = new StringBuilder(length);
|
2014-07-08 12:58:53 +00:00
|
|
|
|
for (int i = 0; i < length; i++)
|
2015-03-21 18:14:00 +00:00
|
|
|
|
randomName.Append(CHARS[_rnd.Next(CHARS.Length)]);
|
2014-07-08 12:58:53 +00:00
|
|
|
|
|
2015-03-21 18:14:00 +00:00
|
|
|
|
return string.Concat(randomName.ToString(), extension);
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetRandomName(int length)
|
|
|
|
|
{
|
2015-03-21 18:14:00 +00:00
|
|
|
|
StringBuilder randomName = new StringBuilder(length);
|
2014-07-08 12:58:53 +00:00
|
|
|
|
for (int i = 0; i < length; i++)
|
2015-03-21 18:14:00 +00:00
|
|
|
|
randomName.Append(CHARS[_rnd.Next(CHARS.Length)]);
|
2014-07-08 12:58:53 +00:00
|
|
|
|
|
2015-03-21 18:14:00 +00:00
|
|
|
|
return randomName.ToString();
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-02 08:26:57 +00:00
|
|
|
|
public static Bitmap GetDesktop(int screenNumber)
|
2014-07-08 12:58:53 +00:00
|
|
|
|
{
|
2015-04-02 08:26:57 +00:00
|
|
|
|
var bounds = Screen.AllScreens[screenNumber].Bounds;
|
2015-05-21 18:35:57 +00:00
|
|
|
|
var screenshot = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
|
2015-03-31 18:38:16 +00:00
|
|
|
|
using (Graphics graph = Graphics.FromImage(screenshot))
|
2015-01-14 12:15:31 +00:00
|
|
|
|
{
|
2015-03-31 18:38:16 +00:00
|
|
|
|
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy);
|
|
|
|
|
return screenshot;
|
2015-01-14 12:15:31 +00:00
|
|
|
|
}
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-18 16:23:04 +00:00
|
|
|
|
public static bool IsWindowsXP()
|
|
|
|
|
{
|
2015-01-14 12:15:31 +00:00
|
|
|
|
var osVersion = Environment.OSVersion.Version;
|
|
|
|
|
return osVersion.Major == 5 && osVersion.Minor >= 1;
|
2014-07-18 16:23:04 +00:00
|
|
|
|
}
|
2015-02-24 20:58:20 +00:00
|
|
|
|
|
|
|
|
|
public static string FormatMacAddress(string macAddress)
|
|
|
|
|
{
|
2015-04-21 18:27:52 +00:00
|
|
|
|
return (macAddress.Length != 12)
|
|
|
|
|
? "00:00:00:00:00:00"
|
|
|
|
|
: Regex.Replace(macAddress, "(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})", "$1:$2:$3:$4:$5:$6");
|
2015-02-24 20:58:20 +00:00
|
|
|
|
}
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
2015-04-21 18:27:52 +00:00
|
|
|
|
}
|