Skip to content

Commit

Permalink
几个好玩的函数
Browse files Browse the repository at this point in the history
  • Loading branch information
zsh2401 committed Feb 8, 2019
1 parent 3383fb4 commit ba8908c
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*.dll
*.psd
*.txt
fast
#fast
gfast.exe
makezip
##dirs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
<Compile Include="$(MSBuildThisFileDirectory)LeafExtension\Kit\Impl\LeafLogger.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LeafExtension\LeafConstants.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LeafExtension\LeafTerminatedException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LeafExtension\LeafUIHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LeafExtension\Fast\LeafUIHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LeafExtension\Attributes\LFromDataAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LeafExtension\Kit\ILeafUI.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LeafExtension\Kit\LeafCloseBtnClickedEventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LeafExtension\Internal\LeafEntryExecutor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LeafExtension\Internal\LeafContext.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LeafExtension\LeafExtensionHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LeafExtension\Fast\LeafExtensionHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LeafExtension\Internal\LeafPropertyInjector.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LeafExtension\Attributes\LMainAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LeafExtension\LeafExtensionBase.cs" />
Expand Down Expand Up @@ -140,5 +140,6 @@
<Folder Include="$(MSBuildThisFileDirectory)LeafExtension\Attributes\" />
<Folder Include="$(MSBuildThisFileDirectory)LeafExtension\Internal\" />
<Folder Include="$(MSBuildThisFileDirectory)LeafExtension\Kit\Impl\" />
<Folder Include="$(MSBuildThisFileDirectory)LeafExtension\Fast\" />
</ItemGroup>
</Project>
37 changes: 37 additions & 0 deletions AutumnBox.OpenFramework.Shared/Fast/Lib.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using AutumnBox.OpenFramework.ExtLibrary;
using AutumnBox.OpenFramework.Management;
using AutumnBox.OpenFramework.Wrapper;
using System;
using System.Collections.Generic;

namespace AutumnBox.OpenFramework.Fast
{
/// <summary>
/// 关于ILibsManager的拓展函数
/// </summary>
public static class Lib
{
/// <summary>
/// 获取加载的Wrappers
/// </summary>
/// <param name="libsManager"></param>
/// <returns></returns>
public static IEnumerable<IExtensionWrapper> Wrappers(this ILibsManager libsManager)
{
List<IExtensionWrapper> result = new List<IExtensionWrapper>();
IEnumerable<ILibrarian> libs = libsManager.Librarians;
foreach (var lib in libs)
{
try
{
result.AddRange(lib.GetWrappers());
}
catch (Exception ex)
{
OpenFx.BaseApi.Log("LibExtension", "Warn", $"获取拓展模块封装类失败({lib.Name}){ex}");
}
}
return result;
}
}
}
109 changes: 109 additions & 0 deletions AutumnBox.OpenFramework.Shared/Fast/WrapperFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using AutumnBox.Basic.Device;
using AutumnBox.OpenFramework.Extension;
using AutumnBox.OpenFramework.Wrapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AutumnBox.OpenFramework.Fast
{
/// <summary>
/// 一些过滤器
/// </summary>
public static class WrapperFilter
{
/// <summary>
/// 根据所需状态过滤
/// </summary>
/// <param name="wrappers"></param>
/// <param name="state"></param>
/// <returns></returns>
public static IEnumerable<IExtensionWrapper> State(this IEnumerable<IExtensionWrapper> wrappers, DeviceState state)
{
return from wrapper in wrappers
where wrapper.Info.RequiredDeviceStates.HasFlag(state) || wrapper.Info.RequiredDeviceStates == state
select wrapper;
}

/// <summary>
/// 根据当前地区进行过滤
/// </summary>
/// <param name="wrappers"></param>
/// <param name="region"></param>
/// <returns></returns>
public static IEnumerable<IExtensionWrapper> Region(this IEnumerable<IExtensionWrapper> wrappers, string region)
{
return from wrapper in wrappers
where wrapper.RegionOK(region)
select wrapper;
}
private static bool RegionOK(this IExtensionWrapper wrapper, string region)
{
if (wrapper.Info.Regions == null)
{
return true;
}
return wrapper.Info.Regions.Where((str) =>
{
return str.ToLower() == region;
}).Count() > 0;
}

/// <summary>
/// 根据开发者状态进行过滤
/// </summary>
/// <param name="wrappers"></param>
/// <param name="nowIsDevMode"></param>
/// <param name="region"></param>
/// <returns></returns>
public static IEnumerable<IExtensionWrapper> Dev(this IEnumerable<IExtensionWrapper> wrappers, bool nowIsDevMode)
{
return from wrapper in wrappers
where wrapper.IsPassedDevCheck(nowIsDevMode)
select wrapper;
}
private static bool IsPassedDevCheck(this IExtensionWrapper wrapper, bool nowIsDevMode)
{
if (wrapper.Info.TryGetValueType(ExtensionInformationKeys.IS_DEVELOPING, out bool isDevExt))
{
if (isDevExt)
{
return nowIsDevMode;
}
else
{
return true;
}
}
else
{
return true;
}
}

/// <summary>
/// 过滤掉隐藏的
/// </summary>
/// <param name="wrappers"></param>
/// <returns></returns>
public static IEnumerable<IExtensionWrapper> Hide(this IEnumerable<IExtensionWrapper> wrappers)
{
return from wrapper in wrappers
where wrapper.IsHide()
select wrapper;
}
private static bool IsHide(this IExtensionWrapper wrapper)
{
if (wrapper.Info.TryGetValueType(ExtensionInformationKeys.IS_HIDE, out bool result))
{

return !result;
}
else
{
return true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using AutumnBox.OpenFramework.Wrapper;
using System.Linq;

namespace AutumnBox.OpenFramework.LeafExtension
namespace AutumnBox.OpenFramework.LeafExtension.Fast
{
/// <summary>
/// LeafExtension的帮助类
Expand Down Expand Up @@ -54,7 +54,7 @@ public static string GetName(this LeafExtensionBase leaf)
/// <exception cref="LeafTerminatedException"></exception>
/// <param name="leaf"></param>
/// <param name="exitCode"></param>
public static void End(this LeafExtensionBase leaf,int exitCode=0)
public static void EndCurrentLeafThread(this LeafExtensionBase leaf,int exitCode=0)
{
throw new LeafTerminatedException(exitCode);
}
Expand Down
100 changes: 100 additions & 0 deletions AutumnBox.OpenFramework.Shared/LeafExtension/Fast/LeafUIHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using AutumnBox.Basic.Device;
using AutumnBox.OpenFramework.LeafExtension.Kit;

namespace AutumnBox.OpenFramework.LeafExtension.Fast
{
/// <summary>
/// LeafUI相关拓展函数
/// </summary>
public static class LeafUIHelper
{
/// <summary>
///
/// </summary>
/// <exception cref="LeafTerminatedException"></exception>
/// <param name="ui"></param>
/// <param name="exitCode"></param>
public static void EFinish(this ILeafUI ui, int exitCode = 0)
{
ui.Finish(exitCode);
LeafExtensionHelper.EndCurrentLeafThread(null, exitCode);
}
/// <summary>
///
/// </summary>
/// <exception cref="LeafTerminatedException"></exception>
/// <param name="ui"></param>
/// <param name="tip"></param>
public static void EFinish(this ILeafUI ui, string tip)
{
ui.Finish(tip);
LeafExtensionHelper.EndCurrentLeafThread(null);
}
/// <summary>
/// Shutdown
/// </summary>
/// <param name="ui"></param>
public static void EShutdown(this ILeafUI ui)
{
ui.Shutdown();
LeafExtensionHelper.EndCurrentLeafThread(null);
}
/// <summary>
/// 检查是否安装APP并询问用户,如果处于不恰当情况,将停止LeafExtension执行流程
/// </summary>
/// <param name="ui"></param>
/// <param name="device"></param>
/// <param name="packageName"></param>
public static void ECheckApp(this ILeafUI ui, IDevice device, string packageName)
{
throw new System.NotImplementedException();
}
/// <summary>
/// 检查设备安卓版本
/// </summary>
/// <param name="ui"></param>
/// <param name="device"></param>
/// <param name="minAndroidVersion"></param>
/// <param name="maxAndroidVersion"></param>
/// <param name="targetAndroidVersion"></param>
public static void ECheckAndroidVersion(this ILeafUI ui, IDevice device,
string minAndroidVersion = null, string maxAndroidVersion = null, string targetAndroidVersion = null)
{
throw new System.NotImplementedException();
}
/// <summary>
/// 进行警告
/// </summary>
/// <param name="ui"></param>
/// <param name="warn"></param>
public static void EWarn(this ILeafUI ui, string warn)
{
throw new System.NotImplementedException();
}
/// <summary>
/// 进行是否抉择
/// </summary>
/// <param name="ui"></param>
/// <param name="msg"></param>
/// <param name="btnYes"></param>
/// <param name="btnNo"></param>
/// <returns></returns>
public static bool EYN(this ILeafUI ui, string msg, string btnYes = null, string btnNo = null)
{
throw new System.NotImplementedException();
}
/// <summary>
/// 进行可取消的是否抉择
/// </summary>
/// <param name="ui"></param>
/// <param name="msg"></param>
/// <param name="btnYes"></param>
/// <param name="btnNo"></param>
/// <param name="btnCancel"></param>
/// <returns></returns>
public static bool? EChoice(this ILeafUI ui, string msg, string btnYes = null, string btnNo = null, string btnCancel = null)
{
throw new System.NotImplementedException();
}
}
}
42 changes: 0 additions & 42 deletions AutumnBox.OpenFramework.Shared/LeafExtension/LeafUIHelper.cs

This file was deleted.

4 changes: 2 additions & 2 deletions AutumnBox.OpenFramework/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("8.26")]
[assembly: AssemblyFileVersion("8.26")]
[assembly: AssemblyVersion("8.27")]
[assembly: AssemblyFileVersion("8.27")]
3 changes: 2 additions & 1 deletion AutumnBox.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutumnBox.GUI", "AutumnBox.
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9C12A545-FC99-4185-86D1-22D029637239}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
AutumnBox.OpenFramework\AutumnBox.OpenFramework.nuspec = AutumnBox.OpenFramework\AutumnBox.OpenFramework.nuspec
LICENSE = LICENSE
README.md = README.md
Expand Down Expand Up @@ -223,7 +224,7 @@ Global
{60988B1A-74B7-470A-AEBA-6D7FE474614D} = {FA99B881-45A3-4D66-8ECE-9D65DFC57C48}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EnterpriseLibraryConfigurationToolBinariesPathV6 = packages\EnterpriseLibrary.Common.6.0.1304.0\lib\NET45;packages\EnterpriseLibrary.PolicyInjection.6.0.1304.0\lib\NET45
SolutionGuid = {E8E55705-AE5C-4952-B4C7-9D7F81C38731}
EnterpriseLibraryConfigurationToolBinariesPathV6 = packages\EnterpriseLibrary.Common.6.0.1304.0\lib\NET45;packages\EnterpriseLibrary.PolicyInjection.6.0.1304.0\lib\NET45
EndGlobalSection
EndGlobal

0 comments on commit ba8908c

Please sign in to comment.