Skip to content

Commit

Permalink
remove watch file
Browse files Browse the repository at this point in the history
  • Loading branch information
nhathoang989 committed Dec 30, 2023
1 parent 0aa9f96 commit fb6e57b
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions src/mix.heart/Services/ConfigurationServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@ public class ConfigurationServiceBase<T>
public T AppSettings { get; set; }
protected string FilePath { get => filePath; set => filePath = value; }

protected readonly FileSystemWatcher watcher = new();

public ConfigurationServiceBase(string filePath, string sectionName = null)
{
FilePath = filePath;
SectionName = sectionName;
LoadAppSettings();
WatchFile();
}
public ConfigurationServiceBase(string filePath, bool isEncrypt)
{
FilePath = filePath;
_isEncrypt = isEncrypt;
LoadAppSettings();
WatchFile();
}

public TValue GetConfig<TValue>(string name, TValue defaultValue = default)
Expand Down Expand Up @@ -80,7 +76,7 @@ public virtual bool SaveSettings()
? ReflectionHelper.ParseObject(AppSettings).ToString(Formatting.None)
: ReflectionHelper.ParseObject(
new JObject(
new JProperty(SectionName, ReflectionHelper.ParseObject (AppSettings))))
new JProperty(SectionName, ReflectionHelper.ParseObject(AppSettings))))
.ToString(Formatting.None);
if (_isEncrypt)
{
Expand All @@ -95,20 +91,6 @@ public virtual bool SaveSettings()
}
}

protected void WatchFile()
{
watcher.Path = FilePath[..FilePath.LastIndexOf('/')];
watcher.Filter = "";
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
}

private void OnChanged(object sender, FileSystemEventArgs e)
{
Thread.Sleep(500);
LoadAppSettings();
}

protected virtual void LoadAppSettings()
{
var settings = MixFileHelper.GetFileByFullName($"{FilePath}{MixFileExtensions.Json}", true, "{}");
Expand Down

0 comments on commit fb6e57b

Please sign in to comment.