Repository navigation
Expand file tree
/
Copy pathHelperClass.cs
More file actions
71 lines (66 loc) 路 2.26 KB
/
Copy pathHelperClass.cs
File metadata and controls
71 lines (66 loc) 路 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
锘縰sing System;
using System.Diagnostics;
using System.Text;
namespace ddb
{
/// <summary>
/// reference
/// https://loune.net/2017/06/running-shell-bash-commands-in-net-core/
/// </summary>
public static class HelperClass
{
public static bool Bash(this StringBuilder cmd)
{
try
{
using Process process = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "/bin/sh",
Arguments = $"-c \"{cmd.Replace("\"", "\\\"")}\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
}
};
process.Start();
string standardError = process.StandardError.ReadToEnd();
process.WaitForExit();
if (string.IsNullOrEmpty(standardError.Trim()))
{
return true;
}
else
{
throw new Exception(standardError);
}
}
catch (Exception)
{
throw;
}
}
public static String BytesToString(this long byteCount)
{
string[] suf = { "B", "KB", "MB", "GB", "TB", "PB", "EB" };
if (byteCount == 0)
return "0" + suf[0];
long bytes = Math.Abs(byteCount);
int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
double num = Math.Round(bytes / Math.Pow(1024, place), 1);
return (Math.Sign(byteCount) * num).ToString() + suf[place];
}
public static int GetMilisecund(int hour, int minute)
{
DateTime firstStart = DateTime.Today.AddHours(hour).AddMinutes(minute);
if (hour < DateTime.Now.Hour || hour == DateTime.Now.Hour && minute < DateTime.Now.Minute)
{
firstStart = firstStart.AddDays(1);
}
TimeSpan span = firstStart - DateTime.Now;
return (int)span.TotalMilliseconds;
}
}
}