Skip to content

Commit

Permalink
添理不需要的类和代码
Browse files Browse the repository at this point in the history
  • Loading branch information
chatop committed Nov 28, 2020
1 parent 64cd8db commit c1020a6
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 2,641 deletions.
104 changes: 7 additions & 97 deletions CommonFunctions/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

namespace CommonFunctions
{
/// <summary>
/// 通用类
/// </summary>
public static class Common
{
public static bool IsDebug = true;
Expand All @@ -24,7 +27,6 @@ public static class Common
public static string FFmpegBinPath = "./ffmpeg";
public static SystemConfig MySystemConfig = new SystemConfig();
public static SipCoreHelper SipProcess;
public static SessionManager SessionManager = new SessionManager();
public static List<MediaServerInstance> MediaServerList = new List<MediaServerInstance>();
public static List<CameraInstance> CameraInstanceList = new List<CameraInstance>();

Expand All @@ -41,14 +43,12 @@ public static class Common
public static object CameraInstanceListLock = new object();
public static object PlayerSessionListLock = new object();

public static ResGetSystemInfo SystemInfo = new ResGetSystemInfo();


static Common()
{
if (!MySystemConfig.LoadConfig(SystemConfigPath))
{
KillSelf();
Environment.Exit(0); //退出程序
}

//清理ffmpeg进程
Expand All @@ -70,7 +70,6 @@ static Common()
}

ErrorMessage.Init();

SipProcess = new SipCoreHelper(false); //启动sip服务
SipProcess.Start();
}
Expand Down Expand Up @@ -257,7 +256,9 @@ public static bool CheckFFmpegBin(string ffpath = "")
ffpath = "ffmpeg";
}

ProcessShell.Run(ffpath, 1000, out string std, out string err);
ProcessHelper tmpProcessHelper = new ProcessHelper(null, null, null);
tmpProcessHelper.RunProcess(ffpath, "", 1000, out string std, out string err);

if (!string.IsNullOrEmpty(std))
{
if (std.ToLower().Contains("ffmpeg version"))
Expand Down Expand Up @@ -342,20 +343,6 @@ public static bool IsUuidByError(string strSrc)
}


/// <summary>
/// 检测session和allow
/// </summary>
/// <param name="ipAddr"></param>
/// <param name="allowKey"></param>
/// <param name="sessionCode"></param>
/// <returns></returns>
public static bool CheckAuth(string ipAddr, string allowKey, string sessionCode)
{
if (!CheckSession(sessionCode)) return false;
if (!CheckAllow(ipAddr, allowKey)) return false;
return true;
}

/// <summary>
/// 检查密码
/// </summary>
Expand All @@ -366,24 +353,6 @@ public static bool CheckPassword(string password)
return MySystemConfig.Password.Trim().Equals(password.Trim());
}

/// <summary>
/// 检查Session是否正常
/// </summary>
/// <param name="sessionCode"></param>
/// <returns></returns>
public static bool CheckSession(string sessionCode)
{
Session s = SessionManager.SessionList.FindLast(x =>
x.SessionCode.Trim().ToLower().Equals(sessionCode.Trim().ToLower()))!;
long a = GetTimeStampMilliseconds();

if (s != null && s.Expires > a)
{
return true;
}

return false;
}

/// <summary>
/// 检查appkey
Expand Down Expand Up @@ -441,64 +410,5 @@ public static bool CheckAllow(string ipAddr, string allowKey)

return false;
}


/// <summary>
/// 结束自己
/// </summary>
public static void KillSelf()
{
// LogWriter.WriteLog("因异常结束进程...");
Logger.Logger.Fatal("因异常结束进程...");
string fileName = Path.GetFileName(Environment.GetCommandLineArgs()[0]);
var ret = GetProcessPid(fileName);
if (ret > 0)
{
KillProcess(ret);
}
}

public static void KillProcess(int pid)
{
string cmd = "kill -9 " + pid.ToString();
ProcessShell.Run(cmd, 1000);
}

/// <summary>
/// 获取pid
/// </summary>
/// <param name="processName"></param>
/// <returns></returns>
public static int GetProcessPid(string processName)
{
string cmd = "";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
cmd = "ps -aux |grep " + processName + "|grep -v grep|awk \'{print $2}\'";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
cmd = "ps -A |grep " + processName + "|grep -v grep|awk \'{print $1}\'";
}

ProcessShell.Run(cmd, 1000, out string std, out string err);
if (string.IsNullOrEmpty(std) && string.IsNullOrEmpty(err))
{
return -1;
}

int pid = -1;
if (!string.IsNullOrEmpty(std))
{
int.TryParse(std, out pid);
}

if (!string.IsNullOrEmpty(err))
{
int.TryParse(err, out pid);
}

return pid;
}
}
}
Loading

0 comments on commit c1020a6

Please sign in to comment.