C/S架构软件开发平台旗舰版V6.0-WebApi新增接口
目录
1、客户端调用WebApi报错: BouncyCastle.Crypto
解决方案
客户端 CSFrameworkV6.WebApiClient 模块,添加nuget包:Portable.BouncyCastle 1.9.0
2、SystemCommonController.cs 添加接口
C# 全选
[AllowAnonymous]
[HttpPost]
public res_systemSettings4Program GetSystemSettings4Program(req_Permission_Account input)
{//OK
var list = _business.GetSystemSettings4Program(input);
return new res_systemSettings4Program { list = list };
}
3个cs文件需要添加 GetSystemSettings4Program 方法:
SystemCommonController.cs
SystemCommonBusiness.cs
ISystemCommonBusiness.cs
3、主窗体切换 WebApi / Ado-Direct 模式
ADO-Direct模式登录 --> 切换 --> WebApi模式
思路:WebApi需要JWT token, 因此要退回到登录界面,重新登录。
WebApi模式登录 --> 切换 --> ADO-Direct模式
思路:直连模式是直接连接数据,初始化CSFramework.EF数据库组件即可。
BridgeFactory.cs 文件修改
C# 全选
public static bool InitializeBridge(bool loadType = true)
{
//联系作者获取代码
}
frmMain.cs 代码修改
修改 2个按钮事件
C# 全选
private void btnBridgeADO_ItemClick(object sender, ItemClickEventArgs e)
{
this.SetBridgeType(BridgeType.ADODirect, btnBridgeADO);
}
private void btnBridgeWebApi_ItemClick(object sender, ItemClickEventArgs e)
{
this.SetBridgeType(BridgeType.WebApi, btnBridgeWebApi);
}
修改 SetBridgeType 方法
C# 全选
/// <summary>
/// 切换连接模式
/// </summary>
/// <param name="bridgeType">切换后的连接策略类型</param>
/// <param name="sender">按钮组件</param>
private void SetBridgeType(BridgeType bridgeType, BarCheckItem sender)
{
bool isChanged = false;
BridgeType old = BridgeFactory.BridgeType;
//用户切换连接方式
if (BridgeFactory.BridgeType != bridgeType)
{
BridgeFactory.BridgeType = bridgeType;
isChanged = BridgeFactory.InitializeBridge(false);
//直连模式,直接切换,不需要重新登录
if (bridgeType == BridgeType.ADODirect)
{
//修改失败还原状态
if (false == isChanged) BridgeFactory.BridgeType = old;
if (isChanged && old != BridgeFactory.BridgeType)
{
btnBridgeType.Caption = sender.Caption;
Msg.ShowInformation(LanLib.Get("操作成功!"));
}
}
//WebApi模式,需要重新登录(生成jwt token)
else if (bridgeType == BridgeType.WebApi)
{
btnLogOut.PerformClick();
}
}
if (isChanged || sender == null)//设置勾选状态
{
btnBridgeADO.Checked = BridgeType.ADODirect == BridgeFactory.BridgeType;
btnBridgeWebApi.Checked = BridgeType.WebApi == BridgeFactory.BridgeType;
}
}
切换到Ado-Direct模式报错
发现 WebApi_Demo_INV类定义了Table特性,删除这行代码,重新编译即可。
4、操作日志 (Operation Log) 扩展4个WebApi接口
温馨提示:本文作为扩展WebApi接口的标准操作步骤。
客户端:WebApi_OperateLog.cs
C# 全选
public void ClearAll()
{
APIProvider.Sign.RequestObjectByPost<int>(APIList.CommonData_OperateLog_ClearAll, null);
}
public void ClearLog(DateTime beginDate, DateTime endDate)
{
var input = new req_data_log { date_from = beginDate, date_to = endDate };
APIProvider.Sign.RequestObjectByPost<int>(APIList.CommonData_OperateLog_ClearLog, input);
}
public void ClearLog(string user, DateTime beginDate, DateTime endDate)
{
var input = new req_data_log { date_from = beginDate, date_to = endDate, user_id = user };
APIProvider.Sign.RequestObjectByPost<int>(APIList.CommonData_OperateLog_ClearLog, input);
}
public void WriteLog(object content)
{
APIProvider.Sign.RequestObjectByPost<int>(APIList.CommonData_OperateLog_WriteLog, content);
}
客户端:APIList.cs
C# 全选
public const string CommonData_OperateLog_ClearAll = "/api/CommonData/OperateLog_ClearAll";
public const string CommonData_OperateLog_ClearLog = "/api/CommonData/OperateLog_ClearLog";
public const string CommonData_OperateLog_WriteLog = "/api/CommonData/OperateLog_WriteLog";
服务端:CommonDataController.cs
C# 全选
[HttpPost]
public int OperateLog_ClearAll()
{
return _business.OperateLog_ClearAll();
}
[HttpPost]
public int OperateLog_ClearLog(req_data_log input)
{
return _business.OperateLog_ClearLog(input);
}
[HttpPost]
public int OperateLog_WriteLog(object content)
{
return _business.OperateLog_WriteLog(content);
}
服务端:ICommonDataBusiness.cs
C# 全选
int OperateLog_ClearAll();
int OperateLog_ClearLog(req_data_log input);
int OperateLog_WriteLog(object content);
服务端:CommonDataBusiness.cs
C# 全选
public int OperateLog_ClearAll()
{
new dalLogOperation(_Loginer).ClearAll();
return 0;
}
public int OperateLog_ClearLog(req_data_log input)
{
if (input.user_id.IsEmpty())
new dalLogOperation(_Loginer).ClearLog(input.date_from.Value, input.date_to.Value);
else
new dalLogOperation(_Loginer).ClearLog(input.user_id, input.date_from.Value, input.date_to.Value);
return 0;
}
public int OperateLog_WriteLog(object content)
{
new dalLogOperation(_Loginer).WriteLog(content);
return 0;
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
CSFrameworkV6 C/S框架网