Skip to content

Commit

Permalink
一系列细节优化与问题修复
Browse files Browse the repository at this point in the history
  • Loading branch information
zsh2401 committed Aug 19, 2020
1 parent d05fa3c commit 2408a31
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 106 deletions.
34 changes: 23 additions & 11 deletions src/AutumnBox.Extensions.Essentials.Shared/Extensions/ETest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* ==============================================================================
*/
using AutumnBox.Basic.Device;
using AutumnBox.Leafx.Container;
using AutumnBox.OpenFramework.Extension;
using AutumnBox.OpenFramework.Extension.Leaf;
using AutumnBox.OpenFramework.Open;
Expand All @@ -24,19 +25,30 @@

namespace AutumnBox.Essentials.Extensions
{
[ExtName("test")]
[ExtRequiredDeviceStates(AutumnBoxExtension.NoMatter)]
[ExtDeveloperMode]
class ETest : LeafExtensionBase
//[ExtName("test")]
//[ExtRequiredDeviceStates(AutumnBoxExtension.NoMatter)]
//[ExtDeveloperMode]
class ETest : IClassExtension
{
[LMain]
public void EntryPoint(ILeafUI ui)
public void Dispose()
{
ui.Show();
ui.StatusInfo = "少女祈祷中...";
ui.ShowMessage("你好!秋之盒");
ui.Println("测试信息");
ui.Finish();
throw new NotImplementedException();
}

//[LMain]
//public void EntryPoint(ILeafUI ui)
//{
// ui.Show();
// ui.StatusInfo = "少女祈祷中...";
// ui.ShowMessage("你好!秋之盒");
// ui.Println("测试信息");
// ui.Finish();
//}

public object Main(Dictionary<string, object> args)
{
LakeProvider.Lake.Get<IUx>().Agree("Hello World!");
throw new NotImplementedException();
}
}
}
55 changes: 26 additions & 29 deletions src/AutumnBox.GUI/Models/ExtensionDock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using AutumnBox.OpenFramework.Exceptions;
using AutumnBox.OpenFramework.Management.ExtInfo;
using AutumnBox.Logging;
using AutumnBox.Leafx.Container;

namespace AutumnBox.GUI.Models
{
Expand All @@ -29,7 +30,7 @@ public string ToolTip
{
get
{
return $"{ExtensionInfo.Name()}{Environment.NewLine}{ExtensionInfo.Author()}";
return $"{ExtensionInfo.Name()}{Environment.NewLine}v{ExtensionInfo.Version()} by {ExtensionInfo.Author()}";
}
}

Expand All @@ -40,14 +41,14 @@ public ImageSource Icon
{
get
{
if (icon == null)
if (iconCache == null)
{
icon = ExtensionInfo.Icon().ToExtensionIcon();
iconCache = ExtensionInfo.Icon().ToExtensionIcon();
}
return icon;
return iconCache;
}
}
private ImageSource icon;
private ImageSource? iconCache;

public Color RemarksColor
{
Expand All @@ -63,15 +64,12 @@ public Color RemarksColor
}
private Color _remarksColor;

private string _remarks;

public string Remarks
{
get { return _remarks; }
set { _remarks = value; RaisePropertyChanged(); }
}


private string _remarks;

public FlexiableCommand Execute
{
Expand All @@ -81,32 +79,31 @@ public FlexiableCommand Execute
RaisePropertyChanged();
}
}


private FlexiableCommand _execute;

[AutoInject]
private readonly IAdbDevicesManager devicesManager;
readonly IAdbDevicesManager devicesManager = App.Current.Lake.Get<IAdbDevicesManager>();

readonly INotificationManager notificationManager = App.Current.Lake.Get<INotificationManager>();

[AutoInject]
private readonly INotificationManager notificationManager;
private const string MARK_NEED_ROOT = "ROOT";
private const string MARK_NO_ROOT = "";

public ExtensionDock(IExtensionInfo extInf)
{
this.ExtensionInfo = extInf;
RemarksColor = extInf.NeedRoot() ? Colors.Red : Colors.GreenYellow;
Remarks = extInf.NeedRoot() ? "ROOT" : "---";
Execute = new FlexiableCommand(p =>
_remarksColor = extInf.NeedRoot() ? Colors.Red : Colors.GreenYellow;
_remarks = extInf.NeedRoot() ? MARK_NEED_ROOT : MARK_NO_ROOT;
_execute = new FlexiableCommand(p =>
{
ExecuteImpl();
})
{
CanExecuteProp = ExtensionInfo.IsRunnableCheck(devicesManager.SelectedDevice)
CanExecuteProp = ExtensionInfo.IsRunnableCheck(devicesManager?.SelectedDevice)
};
devicesManager.DeviceSelectionChanged += DeviceSelectionChanged;
devicesManager!.DeviceSelectionChanged += DeviceSelectionChanged;
}

private void DeviceSelectionChanged(object sender, EventArgs e)
private void DeviceSelectionChanged(object? sender, EventArgs e)
{
Execute.CanExecuteProp = ExtensionInfo.IsRunnableCheck(devicesManager.SelectedDevice);
}
Expand All @@ -128,20 +125,20 @@ private string GetDeviceStateNotCorrectWarningMessage()
var reqState = ExtensionInfo.RequiredDeviceState();
List<string> statesString = new List<string>();
if (reqState.HasFlag(DeviceState.Poweron))
statesString.Add(App.Current.Resources[$"Dash.State.Poweron"].ToString());
statesString.Add(App.Current.Resources[$"Dash.State.Poweron"]?.ToString() ?? String.Empty);
if (reqState.HasFlag(DeviceState.Recovery))
statesString.Add(App.Current.Resources[$"Dash.State.Recovery"].ToString());
statesString.Add(App.Current.Resources[$"Dash.State.Recovery"]?.ToString() ?? String.Empty);
if (reqState.HasFlag(DeviceState.Fastboot))
statesString.Add(App.Current.Resources[$"Dash.State.Fastboot"].ToString());
statesString.Add(App.Current.Resources[$"Dash.State.Fastboot"]?.ToString() ?? String.Empty);
if (reqState.HasFlag(DeviceState.Sideload))
statesString.Add(App.Current.Resources[$"Dash.State.Sideload"].ToString());
statesString.Add(App.Current.Resources[$"Dash.State.Sideload"]?.ToString() ?? String.Empty);
if (reqState.HasFlag(DeviceState.Unauthorized))
statesString.Add(App.Current.Resources[$"Dash.State.Unauthorized"].ToString());
statesString.Add(App.Current.Resources[$"Dash.State.Unauthorized"]?.ToString() ?? String.Empty);
if (reqState.HasFlag(DeviceState.Offline))
statesString.Add(App.Current.Resources[$"Dash.State.Offline"].ToString());
statesString.Add(App.Current.Resources[$"Dash.State.Offline"]?.ToString() ?? String.Empty);
if (reqState.HasFlag(DeviceState.Unknown))
statesString.Add(App.Current.Resources[$"Dash.State.Unknown"].ToString());
string fmt = App.Current.Resources[$"StateNotRightTipFmt"].ToString();
statesString.Add(App.Current.Resources[$"Dash.State.Unknown"]?.ToString() ?? String.Empty);
string fmt = App.Current.Resources[$"StateNotRightTipFmt"]?.ToString() ?? String.Empty;
return string.Format(fmt, string.Join(",", statesString.ToArray()));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/AutumnBox.GUI/Models/LibDock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public ILibrarian Lib
private ILibrarian _lib;

public int Count => Lib.Extensions.Count();

public LibDock(ILibrarian lib)
{
Lib = lib ?? throw new ArgumentNullException(nameof(lib));
_lib = lib ?? throw new ArgumentNullException(nameof(lib));
}
public static IEnumerable<LibDock> From(IEnumerable<ILibrarian> libs)
{
Expand Down
2 changes: 1 addition & 1 deletion src/AutumnBox.GUI/Services/Impl/LoggingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public LoggingManager(IStorageManager storageManager)
public void Initialize()
{
var logger = new TraceLogger() + new AsyncFileLogger(OpenLogFileStream());
Logging.Management.LoggingManager.Use(logger);
Logging.Management.LoggingManager.CoreLogger = logger;
}
private FileStream OpenLogFileStream()
{
Expand Down
2 changes: 1 addition & 1 deletion src/AutumnBox.GUI/Views/Windows/LogEasyWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class LogEasyWindow : Window
public LogEasyWindow()
{
InitializeComponent();
logMg = this.GetComponent<ILoggingManager>();
logMg = this.GetComponent<ILoggingManager>();
logMg.Logs.All((log) =>
{
logBox.AppendText(log.ToFormatedString() + "\n");
Expand Down
4 changes: 4 additions & 0 deletions src/AutumnBox.Leafx.Shared/AutumnBox.Leafx.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)ObjectManagement\ObjectCache.General.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="$(MSBuildThisFileDirectory)Enhancement\Runtime\" />
<Folder Include="$(MSBuildThisFileDirectory)Enhancement\DependenciesManager\" />
</ItemGroup>
</Project>
7 changes: 5 additions & 2 deletions src/AutumnBox.Leafx.Shared/Container/LakeExtension.Getter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public static partial class LakeExtension
/// </summary>
/// <param name="lake"></param>
/// <param name="id"></param>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException"></exception>
/// <returns></returns>
public static IEnumerable<object> GetComponents(this ILake lake, string id)
{
Expand All @@ -46,12 +48,13 @@ public static IEnumerable<object> GetComponents(this ILake lake, string id)
throw new ArgumentException("message", nameof(id));
}
var method = lake.GetType().GetMethod(METHOD_NAME, BindingFlags.Public | BindingFlags.Instance);
if (method == null ||
if (method == null ||
method.ReturnType != typeof(IEnumerable<object>) ||
method.GetParameters().Length != 1 ||
method.GetParameters()[0].ParameterType != typeof(string))
{
throw new NotSupportedException($"This lake ({lake?.GetType()?.FullName}) does not support: IEnumerable<object> GetComponents(string)");
return new object[] { lake.GetComponent(id) };
//throw new NotSupportedException($"This lake ({lake?.GetType()?.FullName}) does not support: IEnumerable<object> GetComponents(string)");
}
return (IEnumerable<object>)method.Invoke(lake, new object[] { id });
}
Expand Down
9 changes: 5 additions & 4 deletions src/AutumnBox.Logging.Shared/Aogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@ namespace AutumnBox.Logging
/// </summary>
public static class Aogger
{
const int CALLER_POSITION = 1;
public static void WriteToLog(this Exception e, object? additionMessage = null)
{
SLogger.Warn(CallerQuerier.Get(2).TypeName, additionMessage ?? String.Empty, e);
SLogger.Warn(CallerQuerier.Get(CALLER_POSITION).TypeName, additionMessage ?? String.Empty, e);
}
public static void Info(object message)
{
SLogger.Info(CallerQuerier.Get(2).TypeName, message);
SLogger.Info(CallerQuerier.Get(CALLER_POSITION).TypeName, message);
}
public static void Warn(object message)
{
SLogger.Warn(CallerQuerier.Get(2).TypeName, message);
SLogger.Warn(CallerQuerier.Get(CALLER_POSITION).TypeName, message);
}
public static void Exception(Exception e)
{
SLogger.Exception(CallerQuerier.Get(2).TypeName, e);
SLogger.Exception(CallerQuerier.Get(CALLER_POSITION).TypeName, e);
}
}
}
3 changes: 2 additions & 1 deletion src/AutumnBox.Logging.Shared/CallerQuerier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ public static class CallerQuerier
public static Result Default { get; } = new Result("Unknow", String.Empty);
public static Result GetCurrent()
{
return Get(2);
return Get(1);
}
public static Result Get(int startAt)
{
if (startAt < 0) throw new ArgumentException("Start at should not smaller than zero.");
startAt += 1;
Result? result = null;
var frames = new StackTrace().GetFrames();
for (int i = startAt; i < frames.Length; i++)
Expand Down
30 changes: 16 additions & 14 deletions src/AutumnBox.Logging.Shared/Management/LoggingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,37 @@ public static class LoggingManager
/// <summary>
/// 日志站
/// </summary>
internal static ICoreLogger CoreLogger => proxy.InnerLogger;
public static ICoreLogger CoreLogger
{
get => proxy.InnerLogger; set
{
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
proxy.InnerLogger = value;
}
}

/// <summary>
/// 已记录的日志
/// </summary>
public static ILogsCollection Logs => proxy.Logs;

static readonly CoreLoggerProxy proxy = new CoreLoggerProxy();
static LoggingManager()
{
proxy.InnerLogger = new TraceLogger();
}

/// <summary>
/// 使用某个日志器
/// </summary>
/// <param name="coreLogger"></param>
[Obsolete("Use CoreLogger.Setter to instead of.")]
public static void Use(ICoreLogger coreLogger)
{
if (coreLogger is null)
{
throw new ArgumentNullException(nameof(coreLogger));
}

proxy.InnerLogger = coreLogger;
CoreLogger = coreLogger;
}

/// <summary>
/// 释放日志器
/// 释放所有日志资源,不可恢复
/// </summary>
public static void Free()
{
Expand All @@ -56,7 +58,7 @@ private class CoreLoggerProxy : ICoreLogger
{
public class LogsCollection : ObservableCollection<ILog>, ILogsCollection { }
public LogsCollection Logs { get; private set; }
public ICoreLogger InnerLogger { get; set; }
public ICoreLogger InnerLogger { get; set; } = new TraceLogger();
public CoreLoggerProxy()
{
//用这种奇葩方法初始化是为了防止线程问题
Expand All @@ -66,7 +68,6 @@ public CoreLoggerProxy()
}));
}


public void Log(ILog log)
{
lock (Logs)
Expand All @@ -83,6 +84,7 @@ public void Log(ILog log)
public void Dispose()
{
InnerLogger.Dispose();
InnerLogger = null;
}
}
}
Expand Down
Loading

0 comments on commit 2408a31

Please sign in to comment.