コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: RestNodeTest.cs プロジェクト: pandalogix/pandalogix
        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);
        }
コード例 #3
0
ファイル: RestNodeTest.cs プロジェクト: pandalogix/pandalogix
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 internal RestChain(RestNode rest, ChainIdModel chainId) : base(rest, chainId) => _jsonStore = new JsonStoreImplementation(this);