private void BuildAction(string actionId, int step, WbapAction action, WbapRequest request) { ActionFlowSchema actionSchema = WbdlSchema.Actions.FindItem(actionId); if (actionSchema == null) { throw (new E_CanNotFindActionSchema(actionId)); } bool hasBuildedRequest = false; for (int i = step; i < actionSchema.Actions.Count; i++) { ActionSchema methodSchema = actionSchema.Actions[i]; if (methodSchema.IsRunAtClient()) { if (hasBuildedRequest) { break; } ClientAction clientAction = new ClientAction(); action.ClientActions.Add(clientAction); BuildClientAction(methodSchema, clientAction, request); } else { BuildServerRequest(action.Request, actionSchema, i); hasBuildedRequest = true; break; } } }
private void InitEventBinds() { Page.Events.Clear(); // Wbap.Wbap wbap = new Wbap.Wbap(this); foreach (EventSchema eventBindSchema in Schame.EventBinds) { PageEvent elementEvent = Page.Events.NewObject(eventBindSchema.Id); elementEvent.EventName = eventBindSchema.EventName; ActionFlowSchema actionSchema = null; if (eventBindSchema.ActionFlow == null || eventBindSchema.ActionFlow == "") { throw (new E_WbdlPageActionIdNotAssignedForEvent(eventBindSchema.Id)); } try { actionSchema = Schame.Actions.GetItem(eventBindSchema.ActionFlow); } catch (EPeresisListNoItemOfId) { throw new E_WbdlPageEventActionNotDefine(eventBindSchema.ActionFlow); } // elementEvent.RequestEnv = wbap.GetRequestEnv(actionSchema); } }
/// <summary> /// 取得环境变量 /// </summary> /// <param name="action"></param> /// <returns></returns> public RequestEnv GetRequestEnv(ActionFlowSchema action) { RequestEnv requestEnv = new RequestEnv(); requestEnv.FormId = pageCtr.Schame.Id; requestEnv.ActionId = action.Id; foreach (ActionSchema method in action.Actions) { MethodRef methodBody = new MethodRef(); methodBody.MethodName = method.MethodName; // methodBody.RunAt = method.RunAt; methodBody.ReturnValue = method.ReturnValue; requestEnv.Body.Add(method.Id, methodBody); foreach (ParameterSchema parameter in method.Parameters) { Object parameterValue = EncloseClientRequestParam(parameter.Value); methodBody.Parameters.Add(parameter.Id, parameterValue); } } return(requestEnv); }
//private WbapResponse InvokeFarAction(WbapRequest wbapRequest) //{ // WbapResponse response = new WbapResponse(); // response.PageName = schema.Id; // Dictionary<string, Object> namedParams = new Dictionary<string, object>(); // foreach (KeyValuePair<string, Object> elementItem in wbapRequest.ElementBinds) // { // string retElement = null; // if (elementItem.Key.Equals("ReturnValue")) // { // retElement = elementItem.Value.ToString(); // } // else // { // namedParams.Add(elementItem.Key, GetParamVarValue(elementItem.Value.ToString())); // } // } // Umc.Umc.InvokeFunction("sid", "msid", wbapRequest.ActionId, namedParams); // return response; //} private void BuildServerRequest(WbapRequest request, ActionFlowSchema action, int Step) { request.Step = Step; request.PageName = WbdlSchema.Id; request.ActionId = action.Id; for (int i = Step; i < action.Actions.Count; i++) { ActionSchema methodSchema = action.Actions[i]; if (methodSchema.IsRunAtClient()) { break; } for (int j = 0; j < methodSchema.Parameters.Count; j++) { ParameterSchema paramSchema = methodSchema.Parameters[j]; if (string.IsNullOrEmpty(paramSchema.Value)) { continue; } string[] realParamValues = paramSchema.Value.Split(PARAM_SPLITOR); foreach (string realParamValue in realParamValues) { if (Array.IndexOf(VAR_TYPES, realParamValue[0]) == (int)VarFlagType.Element) { string key = realParamValue.Remove(0, 1); if (!request.ElementBinds.ContainsKey(key)) { request.ElementBinds.Add(key, ""); } } else if (Array.IndexOf(VAR_TYPES, realParamValue[0]) == (int)VarFlagType.Table) { request.ElementBinds.ImportTableSchema(realParamValue.Remove(0, 1), WbdlSchema); } else if (realParamValue[0].Equals('$')) { request.ElementBinds.Add(realParamValue, ""); } else if (pageCtr.ContainsDataTable(realParamValue)) { pageCtr.BuildRequestDataBodyWithTable(request.ElementBinds, realParamValue, null); } else if (methodSchema.MethodName.Equals("UpdateDataSet", StringComparison.OrdinalIgnoreCase)) { pageCtr.BuildRequestDataBodyWithDataSet(request.ElementBinds); } } } } }
/// <summary> /// 构造函数 /// </summary> public ActionBroker(WbapRequest wbapRequest, ActionFlowSchema actionSchema, PageController pageController, string sessionId, WbdlSchema schema, ISecurity secHandler) { request = wbapRequest; _ActionSchema = actionSchema; this.pageController = pageController; this.sessionId = sessionId; this.schema = schema; // this.Logger = new XLogging.XLoggingService(); _ISec = secHandler; actionId = wbapRequest.ActionId; //在开始已经update // UpdatePage(wbapRequest); }
/// <summary> /// 取得动作 /// </summary> /// <param name="wbapRequest"></param> /// <param name="response"></param> /// <param name="pageName"></param> /// <param name="sessionId"></param> /// <returns></returns> public ActionBroker GetAction(WbapRequest wbapRequest, ref WbapResponse response, string pageName, string sessionId, ISecurity secHandler) { SetSessionInfo(wbapRequest); ActionBroker action = null; SaveRequestData(wbapRequest); if (response == null) { response = new WbapResponse(); } response.PageName = pageName; //if (pageCtr == null || pageCtr.BuzObject.Id != pageName) // pageCtr = new PageController(pageName,sessionId); this.sessionId = sessionId; ActionFlowSchema actionSchema = null; if (pageCtr.Schame.Actions.FindItem(wbapRequest.ActionId) == null) { if (wbapRequest.ActionId.Equals("onLoad", StringComparison.OrdinalIgnoreCase)) { return(null); } else { action = new ActionBroker(wbapRequest, actionSchema, pageCtr, sessionId, WbdlSchema, secHandler); response = action.ExecuteFar(); return(null); } } try { actionSchema = pageCtr.Schame.Actions.GetItem(wbapRequest.ActionId); } catch (Exception) { throw (new E_CanNotFindActionSchema(wbapRequest.ActionId)); } if (actionSchema == null) { throw (new E_CanNotFindActionSchema(wbapRequest.ActionId)); } action = new ActionBroker(wbapRequest, actionSchema, pageCtr, sessionId, WbdlSchema, _ISec); return(action); }
private int CreateBackAction(int step, ActionFlowSchema flowSchema) { this.clientScript = ""; //int ret = 0; for (int i = step; i < flowSchema.Actions.Count; i++) { ActionSchema ss = flowSchema.Actions[i]; if (ss.RunAt != RunAtType.Client) { return(i); } this.clientScript += ss.ClientScript + ";"; } return(0); }
private bool FlowNeedValid(ActionFlowSchema fs) { foreach (ActionSchema act in fs.Actions) { if (act.IsRunAtClient()) { continue; } if (string.IsNullOrEmpty(act.MethodName)) { continue; } WbdlDataSchema dss = pageSchema.DataSources.GetItem(act.DataSourceId); if (umc.Umc.GetObjectPermissionTypes(dss.DataType, act.MethodName) == PermissionTypes.Write) { return(true); } } return(false); }
/// <summary> /// 执行任务流程 /// </summary> /// <param name="flowId"></param> /// <param name="flowVars"></param> /// <returns>流程结束返回真</returns> public bool InvokeFlow(ActionFlowSchema fs, Dictionary <string, string> flowVars) { changedElementsIds.Clear(); this.needDatas.Clear(); for (int step = this.nextStep; step < fs.Actions.Count; step++) { ActionSchema ss = fs.Actions[step]; if (ss.RunAt == RunAtType.Client) { this.nextStep = CreateBackAction(step, fs); return(nextStep == 0); } if (!InvokeAction(ss, flowVars)) { this.nextStep = step; return(false); } } nextStep = 0; return(true); }
private Dictionary <string, string[]> getFlowNeedElementDatas(string actionFlowId) { Dictionary <string, string[]> ret = new Dictionary <string, string[]>(); ActionFlowSchema afs = pageSchema.ActionFlows.GetItem(actionFlowId); foreach (ActionSchema acs in afs.Actions) { //流程对象属性所需的元素 if (acs.Props != null) { foreach (DataPropertySchema prop in acs.Props) { string s = prop.Value; //元素标记的标量 Regex regex_ElementMark = new Regex(@"\" + Element_Var_Mark + @"[A-Za-z]\w+");//匹配$aaaa,@bbb=@ccc;@za23sdzz@z123@123 MatchCollection ms_ElementMark = regex_ElementMark.Matches(s); foreach (Match match in ms_ElementMark) { foreach (Capture c in match.Captures) { string elName = c.Value; string elKey = elName.Trim(new char[] { Element_Var_Mark }); if (!ret.ContainsKey(elKey)) { ret.Add(elKey, new string[] { }); } } } } } //流程对象捆绑的元素数据 if (pageSchema.ElementDatas != null) { foreach (ElementDataSchema eds in pageSchema.ElementDatas) { if (eds.ReadOnly) { continue; } if (eds.Id.EndsWith("_attr_options")) { continue; } if (eds.DataSourceId.Equals(acs.DataSourceId, StringComparison.OrdinalIgnoreCase)) { if (!ret.ContainsKey(eds.Id)) { ret.Add(eds.Id, new string[] { }); } } } } //流程对象函数参数捆绑的元素 if (acs.Parameters != null) { foreach (ParameterSchema ps in acs.Parameters) { List <string> keys = GetElementVarsFromString(ps.Value); foreach (string key in keys) { if (!ret.ContainsKey(key)) { ret.Add(key, new string[] { }); } } } } } return(ret); }
/// <summary> /// 执行一个Wbps请求 /// </summary> /// <param name="request"></param> /// <returns></returns> public WbpsResponse InvokeRequest(WbpsResquest request) { WbpsResponse ret = new WbpsResponse(); if (pageSchema == null) { return(ret); } string flowId = request.FlowId; ActionFlowSchema fs = null; if (!string.IsNullOrEmpty(flowId)) { fs = pageSchema.ActionFlows.FindItem(flowId); if (fs == null) { throw new XException("不能发现流程配置" + flowId); } } if (request.Step > 0) { this.nextStep = request.Step; request.Sender = this.request.Sender; } this.request = request; bool isEnd = true; if (!security.CheckObjectPermission("ListData", request.PageId, PermissionTypes.Read)) { ret.Err = JsonExceptionUtils.ThrowErr(SecErrs.NotPemission, security.LoginPageUrl).Err; return(ret); } if (request.ElementDatas != null) { if (fs != null && FlowNeedValid(fs)) { ValidateRequestData(request.ElementDatas); } ReceiveRequestData(request.ElementDatas); } if (fs != null) { isEnd = InvokeFlow(fs, request.FlowVars); } ret.ElementDatas = GetChangedElements(); if (!isEnd) { ret.BackRequest = new WbpsResquest(); ret.BackRequest.PageId = request.PageId; ret.BackRequest.FlowId = request.FlowId; ret.BackRequest.Step = this.nextStep; ret.BackRequest.SessionId = this.sessionId; for (int i = 0; i < NeedDatas.Count; i++) { ret.BackRequest.ElementDatas.Add(NeedDatas[i], null); } this.executingFlow = request.FlowId; } else { this.executingFlow = null; } if (!string.IsNullOrEmpty(this.clientScript)) { ret.ClientScript = CheckValueVar(this.clientScript).ToString(); } this.clientScript = ""; if (fs == null) { ret.Events = getWbapEvents(); } return(ret); }