public static JsonObject FromException(Exception e, bool includeStackTrace) { if (e == null) throw new ArgumentNullException("e"); JsonObject error = new JsonObject(); error.Put("name", "JSONRPCError"); error.Put("message", e.GetBaseException().Message); if (includeStackTrace) error.Put("stackTrace", e.StackTrace); JsonArray errors = new JsonArray(); do { errors.Put(ToLocalError(e)); e = e.InnerException; } while (e != null); error.Put("errors", errors); return error; }
private static JsonObject Files(int id, bool includePriorities) { JsonObject request = CreateBasicObject(ProtocolConstants.METHOD_TORRENTGET, ResponseTag.UpdateFiles); JsonObject arguments = GetArgObject(request); JsonArray ids = new JsonArray(); ids.Push(id); arguments.Put(ProtocolConstants.KEY_IDS, ids); JsonArray fields = new JsonArray(); fields.Put(ProtocolConstants.FIELD_FILES); fields.Put(ProtocolConstants.FIELD_ID); if (includePriorities) { fields.Put(ProtocolConstants.FIELD_PRIORITIES); fields.Put(ProtocolConstants.FIELD_WANTED); } arguments.Put(ProtocolConstants.KEY_FIELDS, fields); return request; }
public JsonObject process(String feedUrl, String feedXml, bool getSummaries, int numEntries) { JsonObject json = new JsonObject(); XmlReader reader = XmlReader.Create(feedUrl); SyndicationFeed feed = SyndicationFeed.Load(reader); if (feed == null) { throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, "Unable to retrieve feed xml."); } json.Put("Title", feed.Title); json.Put("URL", feedUrl); json.Put("Description", feed.Description); json.Put("Link", feed.Links); var authors = feed.Authors; String jsonAuthor = null; if (authors.Count != 0) { SyndicationPerson author = authors[0]; if (!String.IsNullOrEmpty(author.Name)) { jsonAuthor = author.Name; } else if (!String.IsNullOrEmpty(author.Email)) { jsonAuthor = author.Email; } } JsonArray entries = new JsonArray(); json.Put("Entry", entries); int entryCnt = 0; foreach(var obj in feed.Items) { SyndicationItem e = obj; if (entryCnt >= numEntries) { break; } entryCnt++; JsonObject entry = new JsonObject(); entry.Put("Title", e.Title); entry.Put("Link", e.Links); if (getSummaries) { entry.Put("Summary", e.Summary); } if (e.LastUpdatedTime == e.PublishDate) { entry.Put("Date", e.PublishDate.LocalDateTime.ToShortDateString()); } else { entry.Put("Date", e.LastUpdatedTime.LocalDateTime.ToShortDateString()); } // if no author at feed level, use the first entry author if (jsonAuthor == null && e.Authors.Count != 0) { jsonAuthor = e.Authors[0].Name; } entries.Put(entry); } json.Put("Author", jsonAuthor ?? ""); reader.Close(); return json; }
private void DispatchFilesUpdate(string datatype, JsonArray FileList) { Torrent t; lock (torrentListView) { if (torrentListView.SelectedItems.Count != 1) return; t = (Torrent)torrentListView.SelectedItems[0]; } JsonObject request = new JsonObject(); request.Put(ProtocolConstants.KEY_METHOD, ProtocolConstants.METHOD_TORRENTSET); JsonObject arguments = new JsonObject(); JsonArray ids = new JsonArray(); ids.Put(t.Id); arguments.Put(ProtocolConstants.KEY_IDS, ids); if (FileList.Count == t.Files.Count) arguments.Put(datatype, new JsonArray()); else if (FileList.Count > 0) arguments.Put(datatype, FileList); request.Put(ProtocolConstants.KEY_ARGUMENTS, arguments); request.Put(ProtocolConstants.KEY_TAG, (int)ResponseTag.DoNothing); Program.Form.SetupAction(CommandFactory.RequestAsync(request)).Completed += delegate (object sender, ResultEventArgs e) { if (e.Result.GetType() != typeof(ErrorCommand)) Program.Form.SetupAction(CommandFactory.RequestAsync(Requests.FilesAndPriorities(t.Id))); }; }
private JsonArray BuildIdArray() { JsonArray ids = new JsonArray(); lock (torrentListView) { foreach (Torrent t in torrentListView.SelectedItems) { ids.Put(t.Id); } } return ids; }
/** * Creates a proxy request by fetching pipelined data and adding it to an existing request. * */ private sRequest createPipelinedProxyRequest(Gadget gadget, sRequest original) { sRequest request = new sRequest(original); request.setIgnoreCache(true); GadgetSpec spec = gadget.getSpec(); GadgetContext context = gadget.getContext(); IPreloads proxyPreloads = preloader.preload(context, spec, PreloaderService.PreloadPhase.PROXY_FETCH); // TODO: Add current url to GadgetContext to support transitive proxying. // POST any preloaded content if ((proxyPreloads != null) && proxyPreloads.getData().Count != 0) { JsonArray array = new JsonArray(); foreach(PreloadedData preload in proxyPreloads.getData()) { Dictionary<String, Object> dataMap = preload.toJson(); foreach(var entry in dataMap) { // TODO: the existing, supported content is JSONObjects that contain the // key already. Discarding the key is odd. array.Put(entry.Value); } } String postContent = array.ToString(); // POST the preloaded content, with a method override of GET // to enable caching request.setMethod("POST") .setPostBody(Encoding.UTF8.GetBytes(postContent)) .setHeader("Content-Type", "text/json;charset=utf-8"); } return request; }
public static JsonArray ListViewSelectionToIdArray(ListView.SelectedListViewItemCollection selections) { JsonArray ids = new JsonArray(); foreach (Torrent item in selections) { ids.Put(item.Id); } return ids; }
/** * Collects all of the queued requests and encodes them into a single JSON * string before creating a new HTTP request, attaching this string to the * request body, signing it, and sending it to the container. * * @param client OpenSocialClient object with RPC_ENDPOINT property set * @return Object encapsulating the data requested from the container * @throws OpenSocialRequestException * @throws JSONException * @throws OAuthException * @throws IOException * @throws URISyntaxException */ private OpenSocialResponse submitRpc(OpenSocialClient client) { String rpcEndpoint = client.getProperty(OpenSocialClient.Properties.RPC_ENDPOINT); JsonArray requestArray = new JsonArray(); foreach(OpenSocialRequest r in this.requests) { requestArray.Put(JsonConvert.Import(r.getJsonEncoding())); } OpenSocialUrl requestUrl = new OpenSocialUrl(rpcEndpoint); OpenSocialHttpRequest request = new OpenSocialHttpRequest(requestUrl); request.setPostBody(requestArray.ToString()); OpenSocialRequestSigner.signRequest(request, client); String responseString = getHttpResponse(request); return OpenSocialJsonParser.getResponse(responseString); }