Commit 437aefa4 张东亮

添加互斥锁,以确保配置文件保存的完整性

1 个父辈 05a1d4dc
......@@ -15,7 +15,7 @@ namespace OnlineStore.Common
//public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static int seq = 1;
static object lockobj = new object();
public static int nextSeq()
{
if (seq.Equals(Int32.MaxValue))
......@@ -126,28 +126,36 @@ namespace OnlineStore.Common
}
public static void SaveValue(string key, string value)
{
try
if (Monitor.TryEnter(lockobj, 300))
{
if (key.Equals(""))
//if (key.Equals("") || value.Equals(""))
try
{
return;
if (key.Equals(""))
//if (key.Equals("") || value.Equals(""))
{
return;
}
//增加的内容写在appSettings段下 <add key="RegCode" value="0"/>
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
SetValue(key, value);
}
else
{
UpdateConfig(key, value);
}
}
//增加的内容写在appSettings段下 <add key="RegCode" value="0"/>
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
catch (Exception ex)
{
SetValue(key, value);
LogUtil.error("SaveValue保存配置出错:AppKey=" + key + ",AppValue=" + value + ",", ex);
}
else
{
UpdateConfig(key, value);
finally
{
Monitor.Exit(lockobj);
}
}
catch (Exception ex)
{
LogUtil.error( "SaveValue保存配置出错:AppKey=" + key + ",AppValue=" + value + ",",ex);
}
}
public static string GetValue(object debugDeviceId)
......
......@@ -351,10 +351,11 @@ namespace OnlineStore.DeviceLibrary
}
return false;
}
static string codeParampath = ConfigAppSettings.GetValue(Setting_Init.CodeParamPath);
public static string GetCodeParamFilePath(string codePath)
{
string appPath = Application.StartupPath;
string path = appPath + ConfigAppSettings.GetValue(Setting_Init.CodeParamPath);
string path = appPath + codeParampath;
string filePath = path + codePath + ".dcm";
if (File.Exists(filePath))
{
......
......@@ -202,11 +202,11 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 开始记录
/// </summary>
public void StartRecord(bool isTest=false)
public void StartRecord(bool isTest = false)
{
if(isTest)
if (isTest)
{
inOutPosInfo = new InOutPosInfo("code"+DateTime.Now.ToString("mmssfff"), DateTime.Now.ToString("yyyyMMddhh"));
inOutPosInfo = new InOutPosInfo("code" + DateTime.Now.ToString("mmssfff"), DateTime.Now.ToString("yyyyMMddhh"));
}
else
{
......@@ -217,7 +217,7 @@ namespace OnlineStore.DeviceLibrary
string inputfolderB = Application.StartupPath + imgPath + "box_B\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + inOutPosInfo.PosId;
string outputfolderA = Application.StartupPath + "\\Videos\\box_A\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + inOutPosInfo.PosId;
string outputfolderB = Application.StartupPath + "\\Videos\\box_B\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + inOutPosInfo.PosId;
ffmpegA.SetParam(inputfolderA, outputfolderA,$"{DateTime.Now.ToString("hhmmss")}_{inOutPosInfo.barcode}.mp4");
ffmpegA.SetParam(inputfolderA, outputfolderA, $"{DateTime.Now.ToString("hhmmss")}_{inOutPosInfo.barcode}.mp4");
ffmpegB.SetParam(inputfolderB, outputfolderB, $"{DateTime.Now.ToString("hhmmss")}_{inOutPosInfo.barcode}.mp4");
IsRecord = true;
}
......@@ -227,8 +227,29 @@ namespace OnlineStore.DeviceLibrary
public void StopRecord()
{
IsRecord = false;
ffmpegA.ConvertImgsToMp4();
ffmpegB.ConvertImgsToMp4();
Task task1 = ffmpegA.ConvertImgsToMp4();
Task task2 = ffmpegB.ConvertImgsToMp4();
Task.WaitAll(new Task[] { task1, task2 }, TimeSpan.FromMinutes(1));
Task.Factory.StartNew(delegate {
try
{
System.IO.Directory.Delete(ffmpegA.InputFolder, true);
}
catch (Exception ex)
{
LogUtil.error($"删除文件夹失败:{ffmpegA.InputFolder}", ex);
}
});
Task.Factory.StartNew(delegate {
try
{
System.IO.Directory.Delete(ffmpegB.InputFolder, true);
}
catch (Exception ex)
{
LogUtil.error($"删除文件夹失败:{ffmpegB.InputFolder}", ex);
}
});
}
#endregion
}
......@@ -250,7 +271,7 @@ namespace OnlineStore.DeviceLibrary
}
public class FFMPEG
{
public static string appFolderPath = Application.StartupPath;
public static string appFolderPath = Application.StartupPath;
static string imgPath = ConfigAppSettings.GetValue(Setting_Init.ImagePath);
/// <summary>
/// 帧频
......@@ -272,7 +293,7 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 输出文件夹
/// </summary>
public string OutputFolder { get; set; } = appFolderPath + "Videos\\";
public string OutputFolder { get; set; } = appFolderPath + "Videos\\";
/// <summary>
/// 输出文件名带后缀
/// </summary>
......@@ -294,7 +315,7 @@ namespace OnlineStore.DeviceLibrary
sb.Append(OutputFolder + "\\" + OutputFileName);
return sb.ToString();
}
public void ConvertImgsToMp4()
public Task ConvertImgsToMp4()
{
Task task = Task.Factory.StartNew(delegate
{
......@@ -319,17 +340,10 @@ namespace OnlineStore.DeviceLibrary
p.StandardInput.Close();
p.StandardError.ReadToEnd();
p.WaitForExit();
try
{
System.IO.Directory.Delete(InputFolder, true);
}
catch { }
}
});
task.Wait(120000);
return task;
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!