/// <summary> /// 创建节点 /// </summary> /// <param name="action"></param> /// <returns></returns> public IRestHttpClient UseNode(Action <RestNode> action) { RestNode node = new RestNode(); action.Invoke(node); node.SetNode(node); return(this); }
public async System.Threading.Tasks.Task RestGetTestAsync() { var node = new RestNode(); node.EndPoint = "http://httpbin.org/get"; node.Method = "get"; await node.Init(new PadExecutionContext() { Pad = new Pad(ExecutionMode.Normal) { Nodes = new List <INode>() } }); await node.Execute(node.Context); Assert.Equal(ExecutionStatus.Success, node.Context.Status); }
public async System.Threading.Tasks.Task RestPostTestAsync() { var node = new RestNode(); node.EndPoint = "http://httpbin.org/post"; node.Method = "post"; node.Body = "Hello World"; await node.Init(new PadExecutionContext() { Pad = new Pad(ExecutionMode.Normal) { Nodes = new List <INode>() } }); await node.Execute(node.Context); Debug.WriteLine(node.Context.Result); Assert.Equal(ExecutionStatus.Success, node.Context.Status); }
private async Task <byte[]> ConfigRequest(RestClient client, RestNode Node, Action <RestResponse> action = null) { switch (Node.Provider) { case RestProviderMethod.GET: this.Request.RequestFormat = DataFormat.None; this.Request.Resource = Node.Route; this.Request.Method = Method.Get; break; case RestProviderMethod.POST: this.Request.Resource = Node.Route; this.Request.Method = Method.Post; if (Node.ProviderType == RestProviderType.JSON) { this.Request.AddJsonBody(Node.Param); } if (Node.ProviderType == RestProviderType.XML) { this.Request.AddXmlBody(Node.Param); } if (Node.ProviderType == RestProviderType.FORM) { Node.PropertyNames.ForEnumerEach(item => { var value = Node.Param.GetType().GetProperty(item, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance).GetValue(Node.Param).ToString(); this.Request.AddParameter(item, value); }); } break; case RestProviderMethod.PUT: this.Request.Resource = Node.Route; this.Request.Method = Method.Put; if (Node.ProviderType == RestProviderType.JSON) { this.Request.AddJsonBody(Node.Param); } if (Node.ProviderType == RestProviderType.XML) { this.Request.AddXmlBody(Node.Param); } if (Node.ProviderType == RestProviderType.FORM) { Node.PropertyNames.ForEnumerEach(item => { var value = Node.Param.GetType().GetProperty(item, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance).GetValue(Node.Param).ToString(); this.Request.AddParameter(item, value); }); } break; case RestProviderMethod.DELETE: this.Request.RequestFormat = DataFormat.None; this.Request.Resource = Node.Route; this.Request.Method = Method.Delete; break; default: break; } var waitRes = client.ExecuteAsync(this.Request); Wait(waitRes, Node.TaskWait); var response = await waitRes; action?.Invoke(response); return(response.RawBytes); }
internal RestChain(RestNode rest, ChainIdModel chainId) : base(rest, chainId) => _jsonStore = new JsonStoreImplementation(this);