调用带交互的服务的方法
9人赞赏了该文章
2,750次浏览
编辑于2014年10月28日 09:40:21
有些服务会抛出KDInteractionException用于前台交互,如保存或审核时做的负库存校验、序列号校验等。
在调用这类服务时,如果想要忽略交互,可以设置OperateOption:operateOption.SetIgnoreInteractionFlag(true);如果只是想跳过某个校验,则设置option.AddInteractionFlag(""):
[code]
OperateOption option = OperateOption.Create();
option.SetIgnoreWarning(false);
option.SetIgnoreInteractionFlag(true);
option.AddInteractionFlag(K3.Core.SCM.SCMConst.MinusCheckSensor);// 跳过负库存校验
option.AddInteractionFlag("BillSaveSNCountSpensor");// 跳过序列号校验
IOperationResult operationResult = AppServiceContext.SaveService.Save(ctx, formMetadata.BusinessInfo, objs, option);[/code]如果需要取得交互结果,那么IOperationResult是不够的,因为异常已经被处理,需要通过IInteractionResult来获取:
[code]IInteractionResult interresult = operationResult as IInteractionResult;
if (interresult != null && interresult.InteractionContext != null)
{
KDInteractionException ie = new KDInteractionException(interresult.Sponsor);
ie.InteractionContext.InteractionFormId = interresult .InteractionContext.InteractionFormId;
ie.InteractionContext.IsInteractive = interresult .InteractionContext.IsInteractive;
ie.InteractionContext.SimpleMessage = interresult .InteractionContext.SimpleMessage;
ie.InteractionContext.K3DisplayerModel = interresult .InteractionContext.K3DisplayerModel;
}[/code]
在调用这类服务时,如果想要忽略交互,可以设置OperateOption:operateOption.SetIgnoreInteractionFlag(true);如果只是想跳过某个校验,则设置option.AddInteractionFlag(""):
[code]
OperateOption option = OperateOption.Create();
option.SetIgnoreWarning(false);
option.SetIgnoreInteractionFlag(true);
option.AddInteractionFlag(K3.Core.SCM.SCMConst.MinusCheckSensor);// 跳过负库存校验
option.AddInteractionFlag("BillSaveSNCountSpensor");// 跳过序列号校验
IOperationResult operationResult = AppServiceContext.SaveService.Save(ctx, formMetadata.BusinessInfo, objs, option);[/code]如果需要取得交互结果,那么IOperationResult是不够的,因为异常已经被处理,需要通过IInteractionResult来获取:
[code]IInteractionResult interresult = operationResult as IInteractionResult;
if (interresult != null && interresult.InteractionContext != null)
{
KDInteractionException ie = new KDInteractionException(interresult.Sponsor);
ie.InteractionContext.InteractionFormId = interresult .InteractionContext.InteractionFormId;
ie.InteractionContext.IsInteractive = interresult .InteractionContext.IsInteractive;
ie.InteractionContext.SimpleMessage = interresult .InteractionContext.SimpleMessage;
ie.InteractionContext.K3DisplayerModel = interresult .InteractionContext.K3DisplayerModel;
}[/code]
推荐阅读