コード例 #1
0
ファイル: ServiceHandler.cs プロジェクト: mind0n/hive
		private InvokeResult InvokeMethod(JsRequest r, MethodInfo mi)
		{
			InvokeResult rlt = new InvokeResult();
			try
			{
				if (mi != null)
				{
					mi.ValidateServiceMethod(rlt);
					r.AddMethod(mi.Name);
					if (mi.ReturnType == typeof (void))
					{
						if (Params != null && Params.Length > 0)
						{
							object[] args = Params.ConvertType(0, mi.GetParameters());
							mi.Invoke(this, args);
							r.Methods[0].MethodReturnValue = null;
						}
						else
						{
							mi.Invoke(this, null);
							r.Methods[0].MethodReturnValue = null;
						}
					}
					else
					{
					    object rv = null;
						if (Params != null && Params.Length > 0)
						{
							object[] args = Params.ConvertType(0, mi.GetParameters());
							rv = mi.Invoke(this, args);
						}
						else
						{
                            rv = mi.Invoke(this, null);
						}
                        r.Methods[0].MethodReturnValue = rv;
					    if (rv is ResultBase)
					    {
					        ResultBase result = (ResultBase)rv;
					        if (!result.IsNoException)
					        {
					            r.SetException(result.LastError, mi.Name);
					        }
					    }
					}
				}
				else
				{
					throw new ArgumentNullException(ServerErrorCode.MethodNull);
				}
			}
			catch (Exception ex)
			{
				rlt.LastError = ex;
				if (mi != null)
				{
					r.SetException(ex, mi.Name);
				}
				else
				{
					r.SetException(ex);
				}
			}
			return rlt;
		}
コード例 #2
0
ファイル: ServiceHandler.cs プロジェクト: mind0n/hive
		private void HandleNormalRequest()
		{
			JsRequest r = new JsRequest();
			MethodInfo mi = Intent;
			InvokeResult ir = null;
			if (mi != null)
			{
				ir = InvokeMethod(r, mi);
			}
			else
			{
				r.SetException(new ArgumentException(ServerErrorCode.InvalidNormalRequestMethod));
			}
			if (ir == null || !ir.IsPageResponse)
			{
				OutputResponse(r);
			}
		}
コード例 #3
0
ファイル: ServiceHandler.cs プロジェクト: mind0n/hive
		private void HandleRestfulRequest(HttpContext context)
		{
			string method = context.Request.HttpMethod;
			JsRequest r = new JsRequest();
			Method m = r.AddMethod(method);
			if (method.IndexOf("get", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				m.MethodReturnValue = Get(context);
			}
			else if (method.IndexOf("post", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				m.MethodReturnValue = Post(context);
			}
			else if (method.IndexOf("put", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				m.MethodReturnValue = Put(context);
			}
			else if (method.IndexOf("delete", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				m.MethodReturnValue = Delete(context);
			}
			else
			{
				r.SetException(new ArgumentException(ServerErrorCode.InvalidHttpMethod));
			}
			OutputResponse(r);
		}