object IList.this[int index] { get { return(this[index]); } set { this[index] = new WFJson(new JValue(value)); } }
protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { return(Task.Run(() => { IHttpRouteData routeData = request.GetRouteData(); Contract.Assert(routeData != null); if (!routeData.Values.TryGetValue(RouteConstants.SysWFPath, out object obj)) { return request.CreateErrorResponse(HttpStatusCode.BadRequest, "workflow Id not set in request"); } string id = obj.ToString(); var invoker = GetWorkflowInvoker(id); if (invoker == null) { return request.CreateErrorResponse(HttpStatusCode.BadRequest, "workflow Id not set in request"); } var content = request.Content; string jsonContent = content.ReadAsStringAsync().Result; dynamic b = WFJson.Parse(jsonContent); var rtv = invoker.Invoke(new Dictionary <string, object>() { { "context", _Setting.GetContext(request) }, { "data", b } }); return request.CreateResponse(HttpStatusCode.OK, (rtv["output"] as WFJson)._JToken); })); WorkflowInvoker CreateWorkflowInvoker(string id) { WorkflowInvoker invoker = null; Activity activity = null; if (_Setting.GetStream != null) { activity = ActivityFactory.Create(id, _Setting.GetStream); } else if (_Setting.GetFile != null) { activity = ActivityFactory.Create(id, _Setting.GetFile); } if (activity == null) { return(null); } invoker = new WorkflowInvoker(activity); return(invoker); } WorkflowInvoker GetWorkflowInvoker(string id) { if (_Setting.SafeMode) { return(CreateWorkflowInvoker(id)); } if (_InvokerCache.TryGetValue(id, out WorkflowInvoker invoker)) { return(invoker); } lock (_LockObj) { if (!_InvokerCache.TryGetValue(id, out invoker)) { invoker = CreateWorkflowInvoker(id); _InvokerCache.TryAdd(id, invoker); } } return(invoker); } }