more extension methods
This commit is contained in:
@@ -41,38 +41,38 @@ public class DefaultDataManager : IDataManager
|
|||||||
|
|
||||||
protected virtual bool HandleGet(OnActionEventArgs e)
|
protected virtual bool HandleGet(OnActionEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Action != DataManagerActions.Get)
|
if (!e.Is(DataManagerActions.Get))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Character
|
// Character
|
||||||
if (e.Action == DataManagerActions.Getter.Character)
|
if (e.Is(DataManagerActions.Getter.Character))
|
||||||
{
|
{
|
||||||
// Get
|
// Get
|
||||||
if (e.ActionType == DataManagerActionType.Set)
|
if (e.Is(DataManagerActionType.Set))
|
||||||
{
|
{
|
||||||
if (e.Object is Group group && e.Parameters.GetAt(0, out string? name))
|
if (e.Object is Group group && e.GetParam(0, out string? name))
|
||||||
return e.SetResult(CreateCharacter(e.CurrentUser, name, group));
|
return e.SetResult(CreateCharacter(e.CurrentUser, name, group));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Group
|
// Group
|
||||||
if (e.Action == DataManagerActions.Getter.Group)
|
if (e.Is(DataManagerActions.Getter.Group))
|
||||||
{
|
{
|
||||||
// Get
|
// Get
|
||||||
if (e.ActionType == DataManagerActionType.Get)
|
if (e.Is(DataManagerActionType.Get))
|
||||||
{
|
{
|
||||||
if (e.Parameters.GetAt(0, out string? name))
|
if (e.GetParam(0, out string? name))
|
||||||
return e.SetResult(CreateGroup(e.CurrentUser, name));
|
return e.SetResult(CreateGroup(e.CurrentUser, name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// User
|
// User
|
||||||
if (e.Action == DataManagerActions.Getter.UserAccount)
|
if (e.Is(DataManagerActions.Getter.UserAccount))
|
||||||
{
|
{
|
||||||
// Get
|
// Get
|
||||||
if (e.ActionType == DataManagerActionType.Get)
|
if (e.Is(DataManagerActionType.Get))
|
||||||
{
|
{
|
||||||
if (e.Parameters.GetAt(0, out string? username) && e.Parameters.GetAt(1, out string? password))
|
if (e.GetParam(0, out string? username) && e.GetParam(1, out string? password))
|
||||||
return e.SetResult(CreateUserAccount(username, password));
|
return e.SetResult(CreateUserAccount(username, password));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ public class DefaultDataManager : IDataManager
|
|||||||
|
|
||||||
protected virtual bool HandleSave(OnActionEventArgs e)
|
protected virtual bool HandleSave(OnActionEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Action != DataManagerActions.Save)
|
if (!e.Is(DataManagerActions.Save))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
@@ -96,7 +96,7 @@ public class DefaultDataManager : IDataManager
|
|||||||
|
|
||||||
protected virtual bool HandleDelete(OnActionEventArgs e)
|
protected virtual bool HandleDelete(OnActionEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Action != DataManagerActions.Delete)
|
if (!e.Is(DataManagerActions.Delete))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Character
|
// Character
|
||||||
@@ -116,10 +116,10 @@ public class DefaultDataManager : IDataManager
|
|||||||
|
|
||||||
protected virtual bool HandleAssociation(OnActionEventArgs e)
|
protected virtual bool HandleAssociation(OnActionEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Action != DataManagerActions.Associate)
|
if (!e.Is(DataManagerActions.Associate))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (e.Action == DataManagerActions.Association.Owner)
|
if (e.Is(DataManagerActions.Association.Owner))
|
||||||
{
|
{
|
||||||
if (e.Object is Group group)
|
if (e.Object is Group group)
|
||||||
{
|
{
|
||||||
@@ -128,7 +128,7 @@ public class DefaultDataManager : IDataManager
|
|||||||
case DataManagerActionType.Get:
|
case DataManagerActionType.Get:
|
||||||
return e.SetResultT(DataProvider.GetOwner(group));
|
return e.SetResultT(DataProvider.GetOwner(group));
|
||||||
case DataManagerActionType.Set:
|
case DataManagerActionType.Set:
|
||||||
if (e.Parameters.Length >= 1 && e.Parameters[0] is UserProfile profile)
|
if (e.GetParam(0, out UserProfile? profile))
|
||||||
return DataProvider.SetOwner(group, profile);
|
return DataProvider.SetOwner(group, profile);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ public class DefaultDataManager : IDataManager
|
|||||||
case DataManagerActionType.Get:
|
case DataManagerActionType.Get:
|
||||||
return e.SetResultT(DataProvider.GetOwner(character));
|
return e.SetResultT(DataProvider.GetOwner(character));
|
||||||
case DataManagerActionType.Set:
|
case DataManagerActionType.Set:
|
||||||
if (e.Parameters.Length >= 1 && e.Parameters[0] is UserProfile profile)
|
if (e.GetParam(0, out UserProfile? profile))
|
||||||
return DataProvider.SetOwner(character, profile);
|
return DataProvider.SetOwner(character, profile);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ public static class Extensions
|
|||||||
return account.Type >= permissions;
|
return account.Type >= permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region OnActionEventArgs
|
||||||
|
|
||||||
public static bool SetResult(this OnActionEventArgs @this, object? data)
|
public static bool SetResult(this OnActionEventArgs @this, object? data)
|
||||||
{
|
{
|
||||||
@this.Result = data;
|
@this.Result = data;
|
||||||
@@ -33,4 +35,26 @@ public static class Extensions
|
|||||||
@this.Result = data;
|
@this.Result = data;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool GetParam<T>(this OnActionEventArgs @this, int index, [NotNullWhen(true)] out T? result)
|
||||||
|
{
|
||||||
|
return @this.Parameters.GetAt(index, out result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool Is(this OnActionEventArgs @this, UserType minLevel)
|
||||||
|
{
|
||||||
|
return @this.CurrentUser.HasPermission(minLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool Is(this OnActionEventArgs @this, DataManagerActionType actionType)
|
||||||
|
{
|
||||||
|
return @this.ActionType == actionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool Is(this OnActionEventArgs @this, DataManagerAction action)
|
||||||
|
{
|
||||||
|
return @this.Action == action;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user