add Logs, LoadJsonStorage, SaveJsonStorage to IPublicAPI

This commit is contained in:
弘韬 张 2021-02-14 18:08:30 +08:00
parent 6a318685a4
commit f8557da336
4 changed files with 57 additions and 1 deletions

View file

@ -12,7 +12,7 @@ namespace Flow.Launcher.Infrastructure.Storage
public class JsonStrorage<T> where T : new()
{
private readonly JsonSerializerOptions _serializerSettings;
private T _data;
protected T _data;
// need a new directory name
public const string DirectoryName = "Settings";
public const string FileSuffix = ".json";

View file

@ -15,5 +15,10 @@ namespace Flow.Launcher.Infrastructure.Storage
FilePath = Path.Combine(DirectoryPath, $"{dataType.Name}{FileSuffix}");
}
public PluginJsonStorage(T data) : this()
{
_data = data;
}
}
}

View file

@ -3,6 +3,7 @@ using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
@ -100,5 +101,16 @@ namespace Flow.Launcher.Plugin
void RemoveActionKeyword(string pluginId, string oldActionKeyword);
void LogDebug(string className, string message, [CallerMemberName] string methodName = "");
void LogInfo(string className, string message, [CallerMemberName] string methodName = "");
void LogWarn(string className, string message, [CallerMemberName] string methodName = "");
void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = "");
T LoadJsonStorage<T>(PluginMetadata metadata) where T : new();
void SaveJsonStorage<T>(PluginMetadata metadata, T setting) where T : new();
}
}

View file

@ -18,6 +18,9 @@ using System.Threading;
using System.IO;
using Flow.Launcher.Infrastructure.Http;
using JetBrains.Annotations;
using System.Runtime.CompilerServices;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.Storage;
namespace Flow.Launcher
{
@ -160,6 +163,41 @@ namespace Flow.Launcher
{
PluginManager.RemoveActionKeyword(pluginId, oldActionKeyword);
}
public void LogDebug(string className, string message, [CallerMemberName] string methodName = "")
{
Log.Debug(className, message, methodName);
}
public void LogInfo(string className, string message, [CallerMemberName] string methodName = "")
{
Log.Info(className, message, methodName);
}
public void LogWarn(string className, string message, [CallerMemberName] string methodName = "")
{
Log.Warn(className, message, methodName);
}
public void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = "")
{
Log.Exception(className, message, e, methodName);
}
public T LoadJsonStorage<T>(PluginMetadata metadata) where T : new()
{
var storage = new PluginJsonStorage<T>();
return storage.Load();
}
public void SaveJsonStorage<T>(PluginMetadata metadata, T setting) where T : new()
{
var storage = new PluginJsonStorage<T>(setting);
storage.Save();
}
#endregion
#region Private Methods
@ -173,6 +211,7 @@ namespace Flow.Launcher
return true;
}
#endregion
}
}