protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); var requestQueue = Volley.NewRequestQueue(this); requestQueue.Start(); FindViewById<Button>(Resource.Id.btnString).Click += (e, s) => { var stringRequest = new StringRequest("http://www.baidu.com", (x) => { Log.Debug("Test", "String Request is Finished"); Log.Debug("Test", x.ToString()); }, (x) => { Log.Debug("tt", x.ToString()); }); requestQueue.Add(stringRequest); }; FindViewById<Button>(Resource.Id.btnJson).Click += (sender, e) => { //该测试需要开发人员搭建一个简单的web端 var jsonRequest = new JsonRequest<Test, Test>("http://172.16.101.77/Volley.ashx", new Test { UName="s",UPass="******"}, (x) => { Log.Debug("Test", x.UName); }, (x) => { Log.Debug("Test", x.ToString()); }); requestQueue.Add(jsonRequest); }; }
public object Get(JsonRequest request) { var response = new { message = "Hello, World!" }; return response; }
/// <summary> /// Intecepts incoming jsonRequests, checks to see if already answered and if so will reply with the previous response /// </summary> /// <param name="jsonRequest">The JSON request sent</param> /// <returns>A null if we need to run the function, or the previous response if we've already handled it</returns> public JsonResponse interceptRequest(JsonRequest jsonRequest) { // print intercepted request on the console String request = JsonConvert.SerializeObject(jsonRequest); Console.WriteLine("intercepted request: " + request); JsonResponse response = null; //The request ID is made up of bookie name and the unique number for that message if (jsonRequest.Id != null) { var data = _listOfResponsesAndRequest.Where(t=> t.Request.Id.ToString().Equals(jsonRequest.Id.ToString())); if (data.Count() > 0 && data.First().Response != null) { response = data.First().Response; Console.WriteLine("Duplicate request recieved, sending original response back"); } } return response; }
/// <summary> /// An interceptor for the responses to be sent to the requesting client /// </summary> /// <param name="jsonRequest">The request for data</param> /// <param name="jsonResponse">The response of data</param> public void interceptResponse(JsonRequest jsonRequest, JsonResponse jsonResponse) { String request = JsonConvert.SerializeObject(jsonRequest); String response = JsonConvert.SerializeObject(jsonResponse); //Check if we haven't had the message before from the request, and if so let's add it to the list of processed messages if (_listOfResponsesAndRequest.Where(t => t.Request.Id.ToString().Equals(jsonRequest.Id.ToString())).Count() == 0) _listOfResponsesAndRequest.Add(new RequestResponse(jsonRequest, jsonResponse)); Console.WriteLine("intercepted response: " + response + " for request: " + request); }
public void WhenTheSubmissionEntryIsSubmitted() { var restRequest = new JsonRequest <Submission, string>("api/Submit", _submission); _submitFormResponse = _restClient.Post(restRequest); }
/// <summary> /// Any requests processed by the Gambler will be stored as a request response pair. Helps preventing duplicate messages sent to the gambler /// </summary> /// <param name="request">The JSÒN request message</param> /// <param name="response">The JSON response message</param> public RequestResponse(JsonRequest request, JsonResponse response) { this.Request = request; this.Response = response; }
public IObservable <JsonResponse <T> > InvokeRequest <T>(JsonRequest jsonRpc) { return(InvokeRequestWithScheduler <T>(jsonRpc, ImmediateScheduler.Instance)); }
/// <summary> /// 检查是否已登录 /// </summary> /// <returns></returns> static public Object Test() { string result = string.Empty; try { string sEcho = JsonRequest.GetJsonKeyVal(jsonText, "sEcho"); int displayStart = ComPage.SafeToInt(JsonRequest.GetJsonKeyVal(jsonText, "iDisplayStart")); int displayLength = ComPage.SafeToInt(JsonRequest.GetJsonKeyVal(jsonText, "iDisplayLength")); string sSearch = JsonRequest.GetJsonKeyVal(jsonText, "sSearch"); string iSortCol_0 = JsonRequest.GetJsonKeyVal(jsonText, "iSortCol_0"); string sSortDir_0 = JsonRequest.GetJsonKeyVal(jsonText, "sSortDir_0"); int iSortingCols = ComPage.SafeToInt(JsonRequest.GetJsonKeyVal(jsonText, "iSortingCols")); string timeStamp = JsonRequest.GetJsonKeyVal(jsonText, "timeStamp"); int pageIndex = (displayStart / displayLength) + 1; int pageSize = displayLength; string orderBy = string.Empty; if (!string.IsNullOrEmpty(iSortCol_0)) { string orderField = JsonRequest.GetJsonKeyVal(jsonText, string.Format("mDataProp_{0}", iSortCol_0)); orderBy = string.Format(" order by {0} {1}", orderField, sSortDir_0); } List <object> list = new List <object>(); //list.Sort(); int totalCount = 1000; for (int i = 1; i <= totalCount; i++) { if (i > displayStart && i <= (displayStart + displayLength)) { object data = new { Id = i, Name = "hfm" + i.ToString().PadLeft(4, '0'), Sex = new Random().Next(0, 2).ToString(), CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), }; list.Add(data); } } object obj = new { result = true, code = "", msg = "", recordsTotal = totalCount, recordsFiltered = totalCount, data = list, sEcho = sEcho, #region 注释 //iColumns = 6, //sColumns = "", //mDataProp_0 = "Id", //sSearch_0 = "", //bRegex_0 = false, //bSearchable_0 = true, //bSortable_0 = false, //mDataProp_1 = "Id", //sSearch_1 = "", //bRegex_1 = false, //bSearchable_1 = true, //bSortable_1 = true, //mDataProp_2 = "Name", //sSearch_2 = "", //bRegex_2 = false, //bSearchable_2 = true, //bSortable_2 = true, //mDataProp_3 = "Sex", //sSearch_3 = "", //bRegex_3 = false, //bSearchable_3 = true, //bSortable_3 = true, //mDataProp_4 = "CreateDate", //sSearch_4 = "", //bRegex_4 = false, //bSearchable_4 = true, //bSortable_4 = true, //mDataProp_5 = "", //sSearch_5 = "", //bRegex_5 = false, //bSearchable_5 = true, //bSortable_5 = true, //sSearch = "", //bRegex = false, //iSortCol_0 = 0, //sSortDir_0 = "asc", //iSortingCols = 1, #endregion }; result = Newtonsoft.Json.JsonConvert.SerializeObject(obj); } catch (Exception ex) { result = DNTRequest.GetResultJson(false, "操作异常,请稍候再试", null); Log.WriteLog(" " + ex); } return(result); }
private async Task ExecuteOperation(ExecutionContext context) { var operation = context.Operation; if (operation.values != null) { context.AddValuesIn(ProcessValues(operation.values, context.Values)); } var patternOkay = context.PatternMatcher.IsMatch(context.Path); var message = ConvertToString(ProcessValues(operation.message, context.Values)); var conditionOkay = true; if (!string.IsNullOrEmpty(operation.condition)) { var conditionResult = _jmesPathQuery.Search(operation.condition, context.Values); conditionOkay = ConditionBoolean(conditionResult); } for (var shouldExecute = patternOkay && conditionOkay; shouldExecute; shouldExecute = await EvaluateRepeat(context)) { if (!string.IsNullOrEmpty(message)) { _console.WriteLine(); _console.WriteLine($"{new string(' ', context.Indent * 2)}- {message.Color(ConsoleColor.Cyan).Bold()}"); } var debugPath = Path.Combine(OutputDirectory.Required(), "logs", $"{++_operationCount:000}-{new string('-', context.Indent * 2)}{new string((message ?? operation.write ?? operation.request ?? operation.template ?? string.Empty).Select(ch => char.IsLetterOrDigit(ch) ? ch : '-').ToArray())}.yaml"); Directory.CreateDirectory(Path.GetDirectoryName(debugPath)); using (var writer = _secretTracker.FilterTextWriter(File.CreateText(debugPath))) { var logentry = new Dictionary <object, object> { { "operation", new Dictionary <object, object> { { "message", message }, { "target", operation.target }, { "condition", operation.condition }, { "repeat", operation.repeat }, { "request", operation.request }, { "template", operation.template }, { "write", operation.write }, } }, { "valuesIn", context.ValuesIn }, { "valuesOut", context.ValuesOut }, { "request", null }, { "response", null }, { "cumulativeValues", context.Values }, }; try { WorkflowModel.Request request = null; object response = null; object resultOut = null; // First special type of operation - executing a request if (!string.IsNullOrWhiteSpace(operation.request)) { request = context.TemplateEngine.Render <WorkflowModel.Request>( operation.request, context.Values); logentry["request"] = request; HttpAuthentication auth = null; if (request.auth != null) { // TODO: remove these defaults auth = new HttpAuthentication { tenant = request?.auth?.tenant ?? "common", resourceId = request?.auth?.resource ?? "499b84ac-1321-427f-aa17-267ca6975798", clientId = request?.auth?.client ?? "e8f3cc86-b3b2-4ebb-867c-9c314925b384", interactive = IsInteractive }; } var client = _clientFactory.Create(auth); var method = new HttpMethod(request.method ?? "GET"); if (IsDryRun && method.Method != "GET") { _console.WriteLine($"Skipping {method.Method.ToString().Color(ConsoleColor.Yellow)} {request.url}"); } else { try { var jsonRequest = new JsonRequest { method = method, url = request.url, headers = request.headers, body = request.body, secret = request.secret, }; var jsonResponse = await client.SendAsync(jsonRequest); logentry["response"] = jsonResponse; if ((int)jsonResponse.status >= 400) { throw new ApplicationException($"Request failed with status code {jsonResponse.status}"); } response = jsonResponse.body; } catch { // TODO - retry logic here? throw; } resultOut = response; } } // Second special type of operation - rendering a template if (!string.IsNullOrWhiteSpace(operation.template)) { if (!string.IsNullOrEmpty(operation.write)) { var targetPath = Path.Combine(OutputDirectory.Required(), operation.write); Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); using (var targetWriter = File.CreateText(targetPath)) { if (!string.IsNullOrWhiteSpace(operation.template)) { context.TemplateEngine.Render(operation.template, context.Values, targetWriter); } } } else { resultOut = context.TemplateEngine.Render <object>(operation.template, context.Values); } } // Third special type of operation - nested operations if (operation.operations != null) { resultOut = await ExecuteOperations(context, operation.operations); } // If output is specifically stated - use it to query if (operation.output != null) { if (operation.operations != null) { // for nested operations, output expressions can pull in the current operation's cumulative values as well context.AddValuesOut(ProcessValues(operation.output, MergeUtils.Merge(resultOut, context.Values) ?? context.Values)); } else if (resultOut != null) { // for request and template operations, output expressions are based only on the current operation to avoid collisions context.AddValuesOut(ProcessValues(operation.output, resultOut)); } else { // there are no values coming out of this operation - output queries are based only on cumulative values context.AddValuesOut(ProcessValues(operation.output, context.Values)); } } if (operation.@throw != null) { var throwMessage = ConvertToString(ProcessValues([email protected], context.Values)); throwMessage = string.IsNullOrEmpty(throwMessage) ? message : throwMessage; var throwDetails = ProcessValues([email protected], context.Values); _console.WriteLine(throwMessage.Color(ConsoleColor.Red)); if (throwDetails != null) { _console.WriteLine(_serializers.YamlSerializer.Serialize(throwDetails).Color(ConsoleColor.Red)); } throw new OperationException(string.IsNullOrEmpty(throwMessage) ? message : throwMessage) { Details = throwDetails }; } // otherwise if output is unstated, and there are nested operations with output - those flows back as effective output if (operation.output == null && operation.operations != null && resultOut != null) { context.AddValuesOut(resultOut); } } catch (Exception ex) { logentry["error"] = new Dictionary <object, object> { { "type", ex.GetType().FullName }, { "message", ex.Message }, { "stack", ex.StackTrace }, }; throw; } finally { logentry["valuesIn"] = context?.ValuesIn; logentry["valuesOut"] = context?.ValuesOut; logentry["cumulativeValues"] = context?.Values; _serializers.YamlSerializer.Serialize(writer, logentry); } } } }
public void fetchOffer() { string req = WSRequest.getRequest("account_offers", "", JsonRequest.getAccountOffersJsonRequest(RConfig.rippleAddress)); wsClient.Send(req); }
public object Get(JsonRequest request) { var response = new { message = "Hello, World!" }; return(response); }