Beispiel #1
0
        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;
                }
            }
        }
Beispiel #2
0
        private ClientAction BuildClientAction(ActionSchema methodSchema, WbapRequest request)
        {
            ClientAction clientRequest = new ClientAction();

            BuildClientAction(methodSchema, clientRequest, request);
            return(clientRequest);
        }
Beispiel #3
0
        /// <summary>
        /// 反序列化输入流
        /// </summary>
        /// <param name="requestText"></param>
        /// <returns></returns>
        public static WbapRequest DeserializeRequest(string requestText)
        {
            WbapRequest wbapRequest = new WbapRequest();
            JObject     jObj        = JObject.Parse(requestText);

            wbapRequest.PageName = jObj.Value <string>("PageName");
            wbapRequest.ActionId = jObj.Value <string>("ActionId");
            wbapRequest.Url      = jObj.Value <string>("Url");

            JObject elementBinds = (JObject)jObj.Value <JObject>("ElementBinds");

            if (elementBinds == null)
            {
                return(wbapRequest);
            }
            wbapRequest.Step = jObj.Value <int>("Step");
            foreach (JProperty elementBind in elementBinds.Properties())
            {
                string elementName = elementBind.Name;
                if (WbapDataBody.ElementIsDataType(elementName, WbapDataType._List))
                {
                    string   s        = elementBind.Value.ToString();
                    WbapList dataList = JsonConvert.DeserializeObject <WbapList>(s);
                    wbapRequest.ElementBinds.Add(elementBind.Name, dataList);
                }
                else if (WbapDataBody.ElementIsDataType(elementName, WbapDataType._String))
                {
                    string value = elementBind.Value.Value <string>();
                    wbapRequest.ElementBinds.Add(elementName, value);
                }
            }


            return(wbapRequest);
        }
Beispiel #4
0
        //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);
                        }
                    }
                }
            }
        }
Beispiel #5
0
        private void SetSessionInfo(WbapRequest wbapRequest)
        {
            string sessionKey      = "$SessionID";
            string userIdKey       = "$UserID";
            string userIdStringKey = "$UserIDString";
            string userNameKey     = "$UserName";

            #region set session info
            UserContext uc = UserContextContainer.GetUserContextBySessionId(this.sessionId);
            if (uc != null)
            {
                //wbapRequest.ElementBinds.Add("$CurrentYear", DateTime.Now.Year.ToString());
                //wbapRequest.ElementBinds.Add("$CurrentMonth", DateTime.Now.Month.ToString());
                //wbapRequest.ElementBinds.Add("$CurrentDay", DateTime.Now.Day.ToString());
                //wbapRequest.ElementBinds.Add("$CurrentWeek", System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek));
                if (!wbapRequest.ElementBinds.ContainsKey(sessionKey))
                {
                    wbapRequest.ElementBinds.Add(sessionKey, this.sessionId);
                }
                else
                {
                    wbapRequest.ElementBinds[sessionKey] = this.sessionId;
                }
                if (!wbapRequest.ElementBinds.ContainsKey(userIdKey))
                {
                    wbapRequest.ElementBinds.Add(userIdKey, uc.UserId);
                }
                else
                {
                    wbapRequest.ElementBinds[userIdKey] = uc.UserId;
                }
                if (!wbapRequest.ElementBinds.ContainsKey(userIdStringKey))
                {
                    wbapRequest.ElementBinds.Add(userIdStringKey, "'" + uc.UserId + "'");
                }
                else
                {
                    wbapRequest.ElementBinds[userIdStringKey] = "'" + uc.UserId + "'";
                }
                if (!wbapRequest.ElementBinds.ContainsKey(userNameKey))
                {
                    wbapRequest.ElementBinds.Add(userNameKey, uc.UserName);
                }
                else
                {
                    wbapRequest.ElementBinds[userNameKey] = uc.UserName;
                }
            }
            #endregion
        }
Beispiel #6
0
        /// <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);
        }
Beispiel #7
0
        private void SaveRequestData(WbapRequest wbapRequest)
        {
            if (wbapRequest == null)
            {
                return;
            }

            foreach (KeyValuePair <string, object> data in wbapRequest.ElementBinds)
            {
                if (!requestDataMap.ContainsKey(data.Key))
                {
                    requestDataMap.Add(data.Key, data.Value);
                }
                else
                {
                    requestDataMap[data.Key] = data.Value;
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <returns></returns>
        public WbapResponse Initialize(string pageName, string sessionId)
        {
            WbapResponse resp = null;

            //CheckPermissionRetrun ret = _ISec.CheckObjectPermission(sessionId, pageName, 1);
            //if (ret != CheckPermissionRetrun.Yes)
            //{
            //    resp = new WbapResponse();
            //    resp.ErrorNo = (int)(ret);
            //    // Convert.ToInt32
            //    resp.Message = "Access denied: " + ret.ToString();
            //    resp.PageName = pageName;
            //    return resp;
            //}

            //pageCtr = new PageController(pageName,sessionId);

            this.sessionId = sessionId;
            // this.schema = pageCtr.Schame;
            pageCtr.Initialize();

            WbapRequest request = new WbapRequest();

            request.ActionId = "OnLoad";
            request.Step     = 0;
            request.PageName = pageName;

            #region 权限管理
            //ret =_ISec.CheckObjectPermission(sessionId, streamRequest.ActionId, 2);
            //if (ret != CheckPermissionRetrun.Yes)
            //{
            //    resp = new WbapResponse();
            //    resp.ErrorNo = Convert.ToInt32(ret);
            //    resp.Message = "Access denied:" + ret.ToString();
            //    resp.PageName = pageName;
            //    return resp;
            //}
            #endregion

            ActionBroker action = GetAction(request, ref resp, pageName, sessionId, _ISec);

            if (action != null)
            {
                resp = action.Execute();
            }



            //元素捆绑
            foreach (FieldBindSchema fieldBindSchema in WbdlSchema.FieldBinds)
            {
                //ret = _ISec.CheckObjectPermission(sessionId, fieldBindSchema.Id, 2);
                //if (ret == CheckPermissionRetrun.Yes)
                this.InitualElement(resp, fieldBindSchema);
            }

            //捆绑列表列属性
            foreach (DataListBindSchema listBindSchema in WbdlSchema.DataListBinds)
            {
                //ret = _ISec.CheckObjectPermission(sessionId, listBindSchema.Id, 2);
                //if (ret == CheckPermissionRetrun.Yes)
                //{
                foreach (FieldBindSchema fieldBindSchema in listBindSchema.Columns)
                {
                    //ret = _ISec.CheckObjectPermission(sessionId, fieldBindSchema.Id, 2);
                    //if (ret == CheckPermissionRetrun.Yes)
                    this.InitualElement(resp, fieldBindSchema);
                }
                //}
            }

            //控件捆绑
            foreach (WbdlControl wbdlControl in WbdlSchema.Controls)
            {
                ActionSchema ms = wbdlControl.DataFunction;
                MethodBroker mb = new MethodBroker(ms);

                object invokeRet = mb.Invoke(sessionId, WbdlSchema, request);

                WbapControl wbapControl = new WbapControl();
                wbapControl.Data         = invokeRet;
                wbapControl.VenderObject = wbdlControl.VenderObject;
                wbapControl.VenderUrl    = wbdlControl.VerderUrl;
                resp.Controls.Add(wbdlControl.Id, wbapControl);
            }



            //捆绑数据;
            pageCtr.FillDataBodyWithDataSet(resp.ElementBinds);
            //捆绑列表

            //foreach (PageDataList pageList in pageCtr.Page.PageLists.Values)
            //{
            //    string listId = pageList.ElementId;
            //    if (!resp.ElementBinds.ContainsKey(listId + WbapList.TypeMarker))
            //    {
            //        WbapList wbapList = pageCtr.GetWbapList(listId);
            //        resp.ElementBinds.Add(listId + WbapList.TypeMarker, wbapList);
            //    }

            //}



            //捆绑事件
            foreach (EventSchema eventBindSchema in WbdlSchema.EventBinds)
            {
                string    actionId  = eventBindSchema.ActionFlow;
                WbapEvent wbapEvent = new WbapEvent();
                wbapEvent.EventName = eventBindSchema.EventName;
                BuildAction(actionId, 0, wbapEvent.Action, request);
                resp.ElementBinds.AddEvent(eventBindSchema.Id, wbapEvent);
            }

            //替换全局变量

            foreach (string elementKey in resp.ElementBinds.Keys)
            {
                if (elementKey.Length > 0 && elementKey[0] == '$')
                {
                    resp.ElementBinds[elementKey] = request.ElementBinds[elementKey];
                }
            }

            return(resp);
        }
Beispiel #9
0
 private void BuildClientAction(ActionSchema methodSchema, ClientAction clientRequest, WbapRequest request)
 {
     clientRequest.FuncName    = methodSchema.MethodName;
     clientRequest.ReturnValue = methodSchema.ReturnValue;
     foreach (ParameterSchema paramSchema in methodSchema.Parameters)
     {
         if (paramSchema.Value[0] == '$')
         {
             clientRequest.Parameters.Add(request.ElementBinds[paramSchema.Value]);
         }
         else
         {
             clientRequest.Parameters.Add(paramSchema.Value);
         }
     }
 }