public void ProcessRequest(HttpContext context) { string action = context.Request.Form["Action"]; context.Response.Clear(); context.Response.ContentType = "application/json"; try { switch (action) { #region 本月账单 case "currentMon": TradeLsit(context, action); break; #endregion #region 全部账单 case "allMon": TradeLsit(context, action); break; #endregion default: break; } } catch (Exception ex) { JsonObject json = new JsonObject(); json.Put(TAO_KEY_STATUS, TAO_STATUS_ERROR); json.Put(TAO_KEY_DATA, ex); context.Response.Write(json.ToString()); } }
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; }
public static JsonObject FromRequest(HttpRequest request) { //String methodName = request.getPathInfo().replaceAll("/", ""); JsonObject root = new JsonObject(); NameValueCollection parameters = request.Params; root.Put("method", parameters["method"]); if (!string.IsNullOrEmpty(parameters.Get("id"))) { root.Put("id", parameters["id"]); } JsonObject paramsRoot = new JsonObject(); for (int i = 0; i < parameters.Count; i++) { if (!RESERVED_PARAMS.Contains(parameters.GetKey(i).ToLower())) { String[] path = parameters.GetKey(i).Split('\\'); JsonObject holder = BuildHolder(paramsRoot, path, 0); holder.Put(path[path.Length - 1], ConvertToJsonValue(parameters.GetValues(i)[0])); } } if (paramsRoot.Count > 0) { root.Put("params", paramsRoot); } return root; }
public override string ToString() { JsonObject serialized = new JsonObject(); serialized.Put(KEY_MMSI, this.Mmsi); serialized.Put(KEY_NAME, this.Name); return serialized.ToString(); }
public void WriteObjectArray() { var o = new JsonObject(); o.Put("one", 1); o.Put("two", 2); o.Put("three", 3); Assert.AreEqual("[{\"one\":1,\"two\":2,\"three\":3},{\"one\":1,\"two\":2,\"three\":3},{\"one\":1,\"two\":2,\"three\":3}]", WriteValue(new object[] { o, o, o })); }
public void Names() { JsonObject o = new JsonObject(); o.Put("one", 1); o.Put("two", 2); ICollection names = o.Names; IEnumerator e = names.GetEnumerator(); e.MoveNext(); Assert.AreEqual("one", e.Current); e.MoveNext(); Assert.AreEqual("two", e.Current); }
private static JsonObject ToLocalError(Exception e) { Debug.Assert(e != null); JsonObject error = new JsonObject(); error.Put("name", e.GetType().Name); error.Put("message", e.Message); return error; }
public void Names() { var o = new JsonObject(); o.Put("one", 1); o.Put("two", 2); var names = o.Names; var e = names.GetEnumerator(); e.MoveNext(); Assert.AreEqual("one", e.Current); e.MoveNext(); Assert.AreEqual("two", e.Current); }
public void Names() { JsonObject o = new JsonObject(); o.Put("one", 1); o.Put("two", 2); ICollection names = o.Names; IEnumerator e = names.GetEnumerator(); e.MoveNext(); Assert.AreEqual("one", e.Current); e.MoveNext(); Assert.AreEqual("two", e.Current); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; HttpRequest Request = context.Request; HttpResponse Response = context.Response; JsonObject json = new JsonObject(); if (!string.IsNullOrEmpty(Request.Form["cid"]) && !string.IsNullOrEmpty(Request.Form["mids"]) && !string.IsNullOrEmpty(Request.Form["uid"]) && !string.IsNullOrEmpty(Request.Form["uEmail"]) && !string.IsNullOrEmpty(Request.Form["uName"]) && !string.IsNullOrEmpty(Request.Form["SellerId"]) && !string.IsNullOrEmpty(Request.Form["tprice"])) { int cid = int.Parse(Request.Form["cid"]); string mids = Request.Form["mids"]; int type = -1; if(mids.Contains(',')) { mids = mids.TrimEnd(','); type = 1; } else { type = 0; } int uid = int.Parse(Request.Form["uid"]); string email = Request.Form["uEmail"]; int sellerId = int.Parse(Request.Form["SellerId"]); decimal totalPrice = decimal.Parse(Request.Form["tprice"]); string uName = Request.Form["uName"]; Model.Tao.Orders orderList = new Model.Tao.Orders(); orderList.BuyerID = uid; orderList.Email = email; orderList.Amount = totalPrice; orderList.UserName = uName; orderList.SellerID = sellerId; BLL.Tao.Orders orderBll = new BLL.Tao.Orders(); int OId = orderBll.CreateNewOrderInfo(orderList, cid, mids, type); if (OId > 0) { json.Put(TAO_KEY_STATUS, TAO_STATUS_SUCCESS); json.Put(TAO_KEY_DATA, OId); } else { json.Put(TAO_KEY_STATUS, TAO_STATUS_FAILED); } } else { json.Put(TAO_KEY_STATUS, TAO_STATUS_FAILED); } context.Response.Write(json.ToString()); }
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); return error; }
/** * Convert a response to a JSON object. static so it can be used by HttpPreloaders as well. * * The returned JSON object contains the following values: * rc: integer response code * body: string response body * headers: object, keys are header names, values are lists of header values * * @param response the response body * @param body string to use as the body of the response. * @return a JSONObject representation of the response body. */ public static JsonObject getResponseAsJson(sResponse response, String body) { JsonObject resp = new JsonObject(); resp.Put("rc", response.getHttpStatusCode()); resp.Put("body", body); JsonObject headers = new JsonObject(); addHeaders(headers, response, "set-cookie"); addHeaders(headers, response, "location"); resp.Put("headers", headers); // Merge in additional response data foreach (var entry in response.getMetadata()) { resp.Put(entry.Key, entry.Value); } return resp; }
private static void addHeaders(JsonObject headers, sResponse response, String headerName) { string[] values = response.getHeaders(headerName); if (values != null) { headers.Put(headerName.ToLower(), new JsonArray(values)); } }
public void HasMemberWhenNotEmpty() { JsonObject o = new JsonObject(); Assert.IsFalse(o.HasMembers); o.Put("foo", "bar"); Assert.IsTrue(o.HasMembers); }
public void ContentsClearedBeforeImporting() { JsonObject o = new JsonObject(); o.Put("foo", "bar"); Assert.AreEqual(1, o.Count); o.Import(new JsonTextReader(new StringReader("{}"))); Assert.AreEqual(0, o.Count); }
public void ContentsClearedBeforeImporting() { var o = new JsonObject(); o.Put("foo", "bar"); Assert.AreEqual(1, o.Count); o.Import(new JsonTextReader(new StringReader("{}"))); Assert.AreEqual(0, o.Count); }
private JsonObject Load(RegistryKey root) { JsonObject jo = new JsonObject(); using (RegistryKey key = root != null ? root : GetRootKey(false)) { if (!this.GetType().ToString().Equals(key.GetValue(""))) throw new Exception("Not for this class"); // TODO: find a better Exception foreach (string valueName in key.GetValueNames()) { if (!valueName.Equals("")) jo.Put(valueName, key.GetValue(valueName)); } foreach (string subKeyName in key.GetSubKeyNames()) { jo.Put(subKeyName, Load(key.OpenSubKey(subKeyName))); } } return jo; }
public void Export() { JsonObject o = new JsonObject(); o.Put("Number", 123); o.Put("String", "Hello World"); o.Put("Boolean", true); JsonRecorder writer = new JsonRecorder(); o.Export(writer); JsonReader reader = writer.CreatePlayer(); reader.ReadToken(JsonTokenClass.Object); string[] members = (string[]) o.GetNamesArray().ToArray(typeof(string)); Assert.AreEqual(members[0], reader.ReadMember()); Assert.AreEqual(o[members[0]], reader.ReadNumber().ToInt32()); Assert.AreEqual(members[1], reader.ReadMember()); Assert.AreEqual(o[members[1]], reader.ReadString()); Assert.AreEqual(members[2], reader.ReadMember()); Assert.AreEqual(o[members[2]], reader.ReadBoolean()); Assert.AreEqual(JsonTokenClass.EndObject, reader.TokenClass); }
public void Export() { JsonObject o = new JsonObject(); o.Put("Number", 123); o.Put("String", "Hello World"); o.Put("Boolean", true); JsonRecorder writer = new JsonRecorder(); o.Export(writer); JsonReader reader = writer.CreatePlayer(); reader.ReadToken(JsonTokenClass.Object); string[] members = (string[])o.GetNamesArray().ToArray(typeof(string)); Assert.AreEqual(members[0], reader.ReadMember()); Assert.AreEqual(o[members[0]], reader.ReadNumber().ToInt32()); Assert.AreEqual(members[1], reader.ReadMember()); Assert.AreEqual(o[members[1]], reader.ReadString()); Assert.AreEqual(members[2], reader.ReadMember()); Assert.AreEqual(o[members[2]], reader.ReadBoolean()); Assert.AreEqual(JsonTokenClass.EndObject, reader.TokenClass); }
/// <summary> /// Makes an API call given a method name and JSON argument object /// </summary> /// <param name="method">Method name (eg. earth911.searchLocations)</param> /// <param name="args">JSON object containing method arguments</param> /// <returns>JSON result (typically a JsonObject or JsonArray)</returns> /// <exception cref="ApiError">Raised if an API error occurred</exception> public object Call(string method, JsonObject args) { args.Put("api_key", this.apiKey); string url = this.apiUrl + method + '?' + BuildQuery(args); string text = GetURL(url); JsonObject result = (JsonObject)JsonConvert.Import(text); if (result["error"] != null) { throw new ApiError((string)result["error"]); } else { return result["result"]; } }
public override JsonObject SaveToJson() { JsonObject jo = base.SaveToJson(); Toolbox.JsonPut(jo, SettingsKey.REGKEY_USESSL, UseSSL); Toolbox.JsonPut(jo, SettingsKey.REGKEY_REFRESHRATE, RefreshRate); Toolbox.JsonPut(jo, SettingsKey.REGKEY_REFRESHRATETRAY, RefreshRateTray); Toolbox.JsonPut(jo, SettingsKey.REGKEY_CUSTOMPATH, CustomPath); Toolbox.JsonPut(jo, SettingsKey.REGKEY_RETRYLIMIT, RetryLimit); Toolbox.JsonPut(jo, SettingsKey.REGKEY_DOWNLIMIT, DownLimit); Toolbox.JsonPut(jo, SettingsKey.REGKEY_UPLIMIT, UpLimit); Toolbox.JsonPut(jo, SettingsKey.REGKEY_STARTPAUSED, StartPaused); Toolbox.JsonPut(jo, SettingsKey.REGKEY_PLINKENABLE, PlinkEnable); Toolbox.JsonPut(jo, SettingsKey.REGKEY_PLINKCMD, PlinkCmd); Toolbox.JsonPut(jo, SettingsKey.REGKEY_PROXY, Proxy.SaveToJson()); Toolbox.JsonPut(jo, SettingsKey.REGKEY_DESTINATION_PATH_HISTORY, new JsonArray(destpathhistory)); JsonObject ja = new JsonObject(); foreach (KeyValuePair<string, string> s in SambaShareMappings) { ja.Put(s.Key, s.Value); } Toolbox.JsonPut(jo, SettingsKey.REGKEY_SAMBASHAREMAPPINGS, ja); return jo; }
/// <summary> /// 检查邮箱唯一性 /// </summary> private void ValidateEmail(HttpRequest Request, HttpResponse Response) { JsonObject json = new JsonObject(); if (!string.IsNullOrEmpty(Request.Params["Email"]) && !string.IsNullOrEmpty(Request.Params["Uid"])) { string Email = Request.Params["Email"]; string strId = Request.Params["Uid"]; int uid = Common.Globals.SafeInt(strId, -1); Maticsoft.Model.SysManage.Users model = new BLL.SysManage.Users().GetModel(uid); if (new BLL.SysManage.Users().ExistsByEmail(Email) && model.Email == Email) { json.Put(TAO_KEY_STATUS, TAO_STATUS_SUCCESS); } else if (new BLL.SysManage.Users().ExistsByEmail(Email) && model.Email != Email) { json.Put(TAO_KEY_STATUS, "WARNING"); } else { json.Put(TAO_KEY_STATUS, TAO_STATUS_FAILED); } } else { json.Put(TAO_KEY_STATUS, TAO_STATUS_FAILED); } Response.Write(json.ToString()); }
private void RegionName(HttpContext context) { BLL.Tao.Regions regionbll = new BLL.Tao.Regions(); JsonObject json = new JsonObject(); if (!string.IsNullOrEmpty(context.Request.Params["regionId"])) { int rid = Common.Globals.SafeInt(context.Request.Params["regionId"], 0); json.Put(TAO_KEY_STATUS, TAO_STATUS_SUCCESS); json.Put(TAO_KEY_DATA, regionbll.GetRegionAllName(rid)); } else { json.Put(TAO_KEY_STATUS, TAO_STATUS_FAILED); } context.Response.Write(json.ToString()); }
private void TradeLsit(HttpContext context,string action) { int RowCount = 0; int PageCount = 0; decimal Balance = 0.0M; JsonObject json = new JsonObject(); string strID = context.Request.Params["UserId"]; int uid = Common.Globals.SafeInt(strID, 0); string strIndex = context.Request.Params["PageIndex"]; int PageIndex = Common.Globals.SafeInt(strIndex, 1); int PageSize = 10; List<Model.Tao.TradeDetails> list = null; if (action == "currentMon") { list = bll.GetListByUId(out RowCount, out PageCount, out Balance, uid, PageIndex, PageSize, true); } else { list = bll.GetListByUId(out RowCount, out PageCount, out Balance, uid, PageIndex, PageSize, false); } if (list.Count > 0) { JsonArray data = new JsonArray(); list.ForEach(info => data.Add(new JsonObject( new string[] { "ID", "DataTime", "InCome", "Pay", "Balance", "Remark" }, new object[] { info.ID, info.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"), info.TradeAmount, info.Pay, info.Balance, info.Remark } ))); json.Put(TAO_KEY_STATUS, TAO_STATUS_SUCCESS); json.Put(TAO_KEY_DATA, data); json.Put("ROWCOUNT", RowCount); json.Put("PAGECOUNT", PageCount); json.Put("BALANCE", Balance); } else { json.Put(TAO_KEY_STATUS, TAO_STATUS_FAILED); } context.Response.Write(json.ToString()); }
public static JsonObject CreateBasicObject(string method, ResponseTag tag) { JsonObject obj = new JsonObject(); obj.Put(ProtocolConstants.KEY_TAG, (int)tag); obj.Put(ProtocolConstants.KEY_METHOD, method); obj.Put(ProtocolConstants.KEY_ARGUMENTS, new JsonObject()); return obj; }
private void InsertComment(HttpContext context) { JsonObject json = new JsonObject(); string strMid = context.Request.Params["Mid"]; string strCid = context.Request.Params["Cid"]; string strUid = context.Request.Params["Uid"]; string strPid = context.Request.Params["Pid"];// string strCtype = context.Request.Params["Ctype"]; string strContent = context.Request.Params["Con"]; if (!string.IsNullOrEmpty(strMid) && !string.IsNullOrEmpty(strCid) && !string.IsNullOrEmpty(strUid) && !string.IsNullOrEmpty(strPid)) { Model.Tao.Comment model = new Model.Tao.Comment(); model.CourseID = int.Parse(strCid); if (strMid != "null") { model.ModuleID = int.Parse(strMid); } model.UserID = int.Parse(strUid); model.ParentID = int.Parse(strPid); model.Comments = strContent; model.Status = 1; model.CommentDate = DateTime.Now; model.Type = Common.Globals.SafeInt(strCtype, 0); int comId = bll.Add(model); if (comId > 0) { List<Maticsoft.Model.Tao.Comment> list = bll.GetModelList(comId); if (list.Count > 0) { JsonArray data = new JsonArray(); list.ForEach(info => data.Add(new JsonObject( new string[] { "CommentID", "OrderID", "CourseID", "ModuleID", "UserID", "CommentInfo", "CommentDate", "ParentID", "Score", "Status" }, new object[] { info.CommentID, info.OrderID, info.CourseID, info.ModuleID, info.UserID, info.Comments, info.CommentDate.ToString("yyyy-MM-dd HH:mm:ss"), info.ParentID, info.Score, info.Status } ))); json.Put(TAO_KEY_STATUS, TAO_STATUS_SUCCESS); json.Put(TAO_KEY_DATA, data); } else { json.Put(TAO_KEY_STATUS, TAO_STATUS_FAILED); } } else { json.Put(TAO_KEY_STATUS, TAO_STATUS_ERROR); } } else { json.Put(TAO_KEY_STATUS, TAO_STATUS_ERROR); } context.Response.Write(json.ToString()); }
private void JoinComment(HttpContext context) { string strPid = context.Request.Params["ParentID"]; JsonObject json = new JsonObject(); List<Maticsoft.Model.Tao.Comment> list = bll.GetChildComment(int.Parse(strPid)); if (list != null) { JsonArray data = new JsonArray(); list.ForEach(info => data.Add(new JsonObject( new string[] { "CommentID", "OrderID", "CourseID", "ModuleID", "UserID", "CommentInfo", "CommentDate", "ParentID", "Score", "Status" }, new object[] { info.CommentID, info.OrderID, info.CourseID, info.ModuleID, info.UserID, info.Comments, info.CommentDate.ToString("yyyy-MM-dd HH:mm:ss"), info.ParentID, info.Score, info.Status } ))); json.Put(TAO_KEY_STATUS, TAO_STATUS_SUCCESS); json.Put(TAO_KEY_DATA, data); } else { json.Put(TAO_KEY_STATUS, TAO_STATUS_FAILED); } context.Response.Write(json.ToString()); }
private void OffLineCourse(HttpContext context) { List<Maticsoft.Model.Tao.OffLineCourse> list = OffLinebll.GetModelList(); JsonObject json = new JsonObject(); if (list.Count > 0) { JsonArray data = new JsonArray(); list.ForEach(info => data.Add( new JsonObject( new string[] { "CourseID", "CourseName", "TimeDuration", "Price", "PV", "CreatedUserID", "ImageUrl", "CategoryId", "RegionID" }, new object[] { info.CourseID, info.CourseName, info.StartTime.ToString("yyyy-MM-dd"), info.CoursePrice, info.PV, info.CreatedUserID, info.ImageURL, info.CategoryId, info.RegionID } ))); json.Put(TAO_KEY_STATUS, TAO_STATUS_SUCCESS); json.Put(TAO_KEY_DATA, data); } else { json.Put(TAO_KEY_STATUS, TAO_STATUS_FAILED); } context.Response.Write(json.ToString()); }
private void RelateTeacherCourse(HttpContext context) { int RowCount = 0; int PageCount = 0; string strId = context.Request.Params["CateId"]; string strPi = context.Request.Params["pageIndex"]; int intPi = 0; if (!int.TryParse(strPi, out intPi))//将字符串页码 转成 整型页码,如果失败,设置页码为1 { intPi = 1; } int intPz = Maticsoft.Common.Globals.SafeInt(context.Request.Params["pageSize"], 1); JsonObject json = new JsonObject(); if (!string.IsNullOrEmpty(strId)) { List<Maticsoft.Model.Tao.SearchCourse> list = coursesBLL.GetListByTeacherID(out RowCount, out PageCount, int.Parse(strId), intPi, intPz); if (list.Count > 0) { JsonArray data = new JsonArray(); list.ForEach(info => data.Add( new JsonObject( new string[] { "CourseID", "CourseName", "TimeDuration", "Price", "PV", "CreatedUserID", "ImageUrl", "TrueName", "DepartmentID", "NAME", "CategoryId" }, new object[] { info.Courseid, info.Coursename, info.Timeduration, info.Price, info.Pv, info.Createduserid, info.Imageurl, info.TrueName, info.DepartmentId, info.EnterName, info.CategoryId } ))); json.Put(TAO_KEY_STATUS, TAO_STATUS_SUCCESS); json.Put(TAO_KEY_DATA, data); } json.Put("ROWCOUNT", RowCount); json.Put("PAGECOUNT", PageCount); } else { json.Put(TAO_KEY_STATUS, TAO_STATUS_FAILED); } context.Response.Write(json.ToString()); }
public JsonObject SaveToJson() { JsonObject jo = new JsonObject(); Toolbox.JsonPut(jo, SettingsKey.REGKEY_COMPLETEDBALLOON, CompletedBaloon); Toolbox.JsonPut(jo, SettingsKey.REGKEY_MINONCLOSE, MinOnClose); Toolbox.JsonPut(jo, SettingsKey.REGKEY_MINTOTRAY, MinToTray); Toolbox.JsonPut(jo, SettingsKey.REGKEY_COLORTRAY, ColorTray); Toolbox.JsonPut(jo, SettingsKey.REGKEY_STARTEDBALLOON, StartedBalloon); Toolbox.JsonPut(jo, SettingsKey.REGKEY_USELOCALCOOKIES, UseLocalCookies); Toolbox.JsonPut(jo, SettingsKey.REGKEY_DONTSAVEPASSWORDS, DontSavePasswords); Toolbox.JsonPut(jo, SettingsKey.REGKEY_AUTOCHECKUPDATE, AutoCheckupdate); Toolbox.JsonPut(jo, SettingsKey.REGKEY_UPDATETOBETA, UpdateToBeta); Toolbox.JsonPut(jo, SettingsKey.REGKEY_AUTOUPDATEGEOIP, AutoUpdateGeoip); Toolbox.JsonPut(jo, SettingsKey.REGKEY_DELETETORRENT, DeleteTorrentWhenAdding); Toolbox.JsonPut(jo, SettingsKey.REGKEY_NOGRADIENTTORRENTLIST, NoGradientTorrentList); Toolbox.JsonPut(jo, SettingsKey.REGKEY_DEFAULTACTION, DefaultDoubleClickAction); Toolbox.JsonPut(jo, SettingsKey.REGKEY_LOCALE, Locale); Toolbox.JsonPut(jo, SettingsKey.REGKEY_PLINKPATH, PlinkPath); Toolbox.JsonPut(jo, SettingsKey.REGKEY_UPLOADPROMPT, UploadPrompt); Toolbox.JsonPut(jo, SettingsKey.REGKEY_TABIMAGE, InfopanelImagePath); Toolbox.JsonPut(jo, SettingsKey.REGKEY_STATEIMAGE, StateImagePath); Toolbox.JsonPut(jo, SettingsKey.REGKEY_TOOLBARIMAGE, ToolbarImagePath); Toolbox.JsonPut(jo, SettingsKey.REGKEY_TRAYIMAGE, TrayImagePath); Toolbox.JsonPut(jo, SettingsKey.REGKEY_AUTOCONNECT, AutoConnect); Toolbox.JsonPut(jo, SettingsKey.REGKEY_CURRENTPROFILE, CurrentProfile); JsonObject ja = new JsonObject(); foreach (KeyValuePair<string, TransmissionServer> s in Servers) { ja.Put(s.Key, s.Value.SaveToJson()); } Toolbox.JsonPut(jo, SettingsKey.REGKEY_PROFILES, ja); ja = new JsonObject(); foreach (KeyValuePair<string, string> s in RssFeeds) { ja.Put(s.Key, s.Value); } Toolbox.JsonPut(jo, SettingsKey.REGKEY_RSSFEEDS, ja); ja = new JsonObject(); foreach (KeyValuePair<string, object> s in Misc) { ja.Put(s.Key, s.Value); } Toolbox.JsonPut(jo, SettingsKey.REGKEY_MISC, ja); return jo; }
private static object ReadParameters(Method method, JsonReader reader, ImportContext importContext) { Debug.Assert(method != null); Debug.Assert(reader != null); Debug.Assert(importContext != null); reader.MoveToContent(); Parameter[] parameters = method.GetParameters(); if (reader.TokenClass == JsonTokenClass.Array) { reader.Read(); ArrayList argList = new ArrayList(parameters.Length); // TODO: This loop could bomb when more args are supplied that parameters available. for (int i = 0; i < parameters.Length && reader.TokenClass != JsonTokenClass.EndArray; i++) argList.Add(importContext.Import(parameters[i].ParameterType, reader)); reader.StepOut(); return argList.ToArray(); } else if (reader.TokenClass == JsonTokenClass.Object) { reader.Read(); JsonObject argByName = new JsonObject(); while (reader.TokenClass != JsonTokenClass.EndObject) { // TODO: Imporve this lookup. // FIXME: Does not work when argument is positional. Type parameterType = AnyType.Value; string name = reader.ReadMember(); foreach (Parameter parameter in parameters) { if (parameter.Name.Equals(name)) { parameterType = parameter.ParameterType; break; } } argByName.Put(name, importContext.Import(parameterType, reader)); } reader.Read(); return argByName; } else { return importContext.Import(reader); } }
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))); }; }
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; }
public void WriteObjectArray() { JsonObject o = new JsonObject(); o.Put("one", 1); o.Put("two", 2); o.Put("three", 3); Assert.AreEqual("[{\"one\":1,\"two\":2,\"three\":3},{\"one\":1,\"two\":2,\"three\":3},{\"one\":1,\"two\":2,\"three\":3}]", WriteValue(new object[] { o, o, o })); }
public void HasMemberWhenNotEmpty() { JsonObject o = new JsonObject(); Assert.IsFalse(o.HasMembers); o.Put("foo", "bar"); Assert.IsTrue(o.HasMembers); }
private void RecommendedCourse(HttpContext context) { List<Maticsoft.Model.Tao.SearchCourse> list = coursesBLL.GetRecommendedCourseList(4); JsonObject json = new JsonObject(); if (list.Count > 0) { JsonArray data = new JsonArray(); list.ForEach(info => data.Add( new JsonObject( new string[] { "CourseID", "CourseName", "TimeDuration", "Price", "PV", "CreatedUserID", "ImageUrl", "TrueName", "DepartmentID", "NAME", "CategoryId" }, new object[] { info.Courseid, info.Coursename, info.Timeduration, info.Price, info.Pv, info.Createduserid, info.Imageurl, info.TrueName, info.DepartmentId, info.EnterName, info.CategoryId } ))); json.Put(TAO_KEY_STATUS, TAO_STATUS_SUCCESS); json.Put(TAO_KEY_DATA, data); } else { json.Put(TAO_KEY_STATUS, TAO_STATUS_FAILED); } context.Response.Write(json.ToString()); }