コード例 #1
0
ファイル: Server.cs プロジェクト: trithien264/NService
        public Dictionary <string, object> CallToDic(ServiceCaller.CallType callType, string service, params object[] args)
        {
            Dictionary <string, object> ret = new Dictionary <string, object>();

            try
            {
                object result = Call(callType, service, args);
                ret["AjaxError"] = 0;
                ret["Result"]    = result;
                ret["Params"]    = args;
            }
            catch (NSNeedLoginException lex)
            {
                ret["AjaxError"] = 1;
                ret["Message"]   = "Need Login(" + lex.Message + ")";

                if (LogHelper.Instance.GetLogLevel() == LogHelper.LogLevel.High)
                {
                    Tool.Warn("Service call (login required)", "Info", lex.Message);
                }
            }
            catch (NSNoPermissionException pex)
            {
                ret["AjaxError"] = 2;
                ret["Message"]   = "No Pemission:" + pex.Message;
                if (LogHelper.Instance.GetLogLevel() == LogHelper.LogLevel.High)
                {
                    Tool.Warn("Service Invocation (No Privileges)", "Info", pex.Message);
                }
            }
            catch (NSInfoException pex)
            {
                ret["AjaxError"] = 3;
                ret["Message"]   = pex.Message;
            }
            catch (ApplicationException aex)
            {
                ret["AjaxError"] = 4;
                ret["Message"]   = aex.Message;
                Tool.Error("Application Exception", "Message", aex.Message, "ApplicationException", aex.InnerException);
            }
            catch (Exception ex)
            {
                ret["AjaxError"] = 5;
                ret["Message"]   = "[Unrecognized exception]: " + ex.Message;
                Tool.Error("Service call error (uncaught)", "ex", ex);
            }

            ret["Service"] = service;
            return(ret);
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: nickel264/GitProject
        public Dictionary <string, object> CallToDic(ServiceCaller.CallType callType, Dictionary <string, object> dic)
        {
            Dictionary <string, object> ret = new Dictionary <string, object>();

            if (dic != null)
            {
                string   service = null;
                object[] args    = null;
                //合在一起是因為,對外提供服務不一定是這樣的形式,還可能是直接一個服務名稱(如PCIUserList)
                //所以留下接口在這里
                if (dic.ContainsKey("service"))
                {
                    service = dic["service"].ToString();
                    if (dic.ContainsKey("params"))
                    {
                        ArrayList tmp = dic["params"] as ArrayList;
                        if (tmp != null)
                        {
                            args = new object[tmp.Count];
                            tmp.CopyTo(args);
                        }
                    }
                    //開發測試用,可以指定延遲,以測試網路,database繁忙情況
                    if (dic.ContainsKey("callDelay"))
                    {
                        System.Threading.Thread.Sleep(int.Parse(dic["callDelay"].ToString()));
                    }

                    ret = CallToDic(callType, service, args);
                }
                else
                {
                    ret["AjaxError"] = 4;
                    ret["Message"]   = "service call description invalid(must provide service!)";
                }
            }
            else
            {
                ret["AjaxError"] = 4;
                ret["Message"]   = "service call description is null(not a json object)";
            }
            return(ret);
        }
コード例 #3
0
ファイル: Server.cs プロジェクト: trithien264/NService
        public Dictionary <string, object> CallToDic(ServiceCaller.CallType callType, Dictionary <string, object> dic)
        {
            Dictionary <string, object> ret = new Dictionary <string, object>();

            if (dic != null)
            {
                string   service = null;
                object[] args    = null;
                // Together because the external service is not necessarily such a form, it may be a direct service name (such as PCIUserList)
                // So leave the interface here
                if (dic.ContainsKey("service"))
                {
                    service = dic["service"].ToString();
                    if (dic.ContainsKey("params"))
                    {
                        ArrayList tmp = dic["params"] as ArrayList;
                        if (tmp != null)
                        {
                            args = new object[tmp.Count];
                            tmp.CopyTo(args);
                        }
                    }
                    //Development test, you can specify the delay to test the network, database busy
                    if (dic.ContainsKey("callDelay"))
                    {
                        System.Threading.Thread.Sleep(int.Parse(dic["callDelay"].ToString()));
                    }

                    ret = CallToDic(callType, service, args);
                }
                else
                {
                    ret["AjaxError"] = 4;
                    ret["Message"]   = "service call description invalid(must provide service!)";
                }
            }
            else
            {
                ret["AjaxError"] = 4;
                ret["Message"]   = "service call description is null(not a json object)";
            }
            return(ret);
        }
コード例 #4
0
ファイル: Server.cs プロジェクト: nickel264/GitProject
        public Dictionary <string, object> CallToDic(ServiceCaller.CallType callType, string service, params object[] args)
        {
            Dictionary <string, object> ret = new Dictionary <string, object>();

            try
            {
                object result = Call(callType, service, args);
                ret["AjaxError"] = 0;
                ret["Result"]    = result;
                ret["Params"]    = args;
            }
            catch (Exception ex)
            {
                ret["AjaxError"] = 5;
                ret["Message"]   = ex.Message;
                Tool.Error("服務調用出錯(未捕獲)", "ex", ex);
            }
            ret["Service"] = service;
            return(ret);
        }
コード例 #5
0
ファイル: Server.cs プロジェクト: nickel264/GitProject
        public Dictionary <string, object> CallToDic(ServiceCaller.CallType callType, string jsonCall)
        {
            Dictionary <string, object> ret = new Dictionary <string, object>();

            object jsonObject = null;

            try
            {
                jsonObject = Tool.ToObject(jsonCall);
            }
            catch (Exception ex)
            {
                ret["AjaxError"] = "4";
                ret["Message"]   = "Tool.ToObject failure,json format invalid(" + jsonCall + " message:" + ex.Message + ")";
                return(ret);
            }

            bool      isMultiple = false; //是不是多個調用
            ArrayList items      = null;

            if (jsonObject is ArrayList)
            {
                isMultiple = true;
                items      = jsonObject as ArrayList;
            }
            else if (jsonObject is Dictionary <string, object> )
            {
                items = new ArrayList(new object[] { jsonObject });
            }

            List <Dictionary <string, object> > multipleRet = new List <Dictionary <string, object> >();

            if (items != null && items.Count > 0)
            {
                foreach (Dictionary <string, object> dic in items)
                {
                    multipleRet.Add(CallToDic(callType, dic));
                }
            }
            else
            {
                ret["AjaxError"] = "4";
                ret["Message"]   = "service format(json) invalid(" + jsonCall + ")";
            }


            if (isMultiple)
            {
                ret["AjaxError"]  = 0;
                ret["Result"]     = multipleRet;
                ret["IsMultiple"] = true;
            }
            else
            {
                ret = multipleRet[0];
                ret["IsMultiple"] = false;
            }

            return(ret);
            //return Tool.ToJson(ret);
        }