127 lines
2.9 KiB
C#
127 lines
2.9 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace HxBusiness
|
|
{
|
|
// Token: 0x02000003 RID: 3
|
|
public class ConfigBiz
|
|
{
|
|
// Token: 0x06000007 RID: 7 RVA: 0x0000235C File Offset: 0x0000055C
|
|
public ConfigBiz()
|
|
{
|
|
this.xmlPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "/Config/";
|
|
this.objlock = new ReaderWriterLockSlim();
|
|
}
|
|
|
|
// Token: 0x06000008 RID: 8 RVA: 0x000023AC File Offset: 0x000005AC
|
|
public bool WriteDb<T>(object parm)
|
|
{
|
|
this.objlock.EnterWriteLock();
|
|
bool result;
|
|
try
|
|
{
|
|
string str = typeof(T).Name.ToString() + ".json";
|
|
bool flag = !Directory.Exists(this.xmlPath);
|
|
if (flag)
|
|
{
|
|
Directory.CreateDirectory(this.xmlPath);
|
|
}
|
|
bool flag2 = !File.Exists(this.xmlPath + str);
|
|
if (flag2)
|
|
{
|
|
FileStream fileStream = new FileStream(this.xmlPath + str, FileMode.Create, FileAccess.ReadWrite);
|
|
fileStream.Close();
|
|
}
|
|
else
|
|
{
|
|
FileInfo fileInfo = new FileInfo(this.xmlPath + str);
|
|
fileInfo.Delete();
|
|
FileStream fileStream2 = new FileStream(this.xmlPath + str, FileMode.Create, FileAccess.ReadWrite);
|
|
fileStream2.Close();
|
|
}
|
|
File.WriteAllText(this.xmlPath + str, JsonConvert.SerializeObject(parm, Formatting.Indented));
|
|
result = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("write error!" + ex.ToString());
|
|
bool flag3 = this.writecount < 10;
|
|
if (flag3)
|
|
{
|
|
Thread.Sleep(1);
|
|
this.writecount++;
|
|
this.WriteDb<T>(parm);
|
|
}
|
|
result = false;
|
|
}
|
|
finally
|
|
{
|
|
this.objlock.ExitWriteLock();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Token: 0x06000009 RID: 9 RVA: 0x00002528 File Offset: 0x00000728
|
|
public string ReadDb<T>()
|
|
{
|
|
this.objlock.EnterReadLock();
|
|
string result;
|
|
try
|
|
{
|
|
string str = typeof(T).Name.ToString() + ".json";
|
|
bool flag = !Directory.Exists(this.xmlPath);
|
|
if (flag)
|
|
{
|
|
Directory.CreateDirectory(this.xmlPath);
|
|
}
|
|
bool flag2 = !File.Exists(this.xmlPath + str);
|
|
if (flag2)
|
|
{
|
|
FileStream fileStream = new FileStream(this.xmlPath + str, FileMode.Create, FileAccess.ReadWrite);
|
|
fileStream.Close();
|
|
result = null;
|
|
}
|
|
else
|
|
{
|
|
string text = File.ReadAllText(this.xmlPath + str);
|
|
result = text;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("read error!" + ex.ToString());
|
|
bool flag3 = this.readcount < 10;
|
|
if (flag3)
|
|
{
|
|
Thread.Sleep(1);
|
|
this.readcount++;
|
|
this.ReadDb<T>();
|
|
}
|
|
result = null;
|
|
}
|
|
finally
|
|
{
|
|
this.objlock.ExitReadLock();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Token: 0x04000001 RID: 1
|
|
private const int TryReadWriteCount = 10;
|
|
|
|
// Token: 0x04000002 RID: 2
|
|
private int readcount = 0;
|
|
|
|
// Token: 0x04000003 RID: 3
|
|
private int writecount = 0;
|
|
|
|
// Token: 0x04000004 RID: 4
|
|
private string xmlPath;
|
|
|
|
// Token: 0x04000005 RID: 5
|
|
private ReaderWriterLockSlim objlock;
|
|
}
|
|
}
|