当前位置: 首页>>代码示例>>C#>>正文


C# JsonResponse.Add方法代码示例

本文整理汇总了C#中JsonResponse.Add方法的典型用法代码示例。如果您正苦于以下问题:C# JsonResponse.Add方法的具体用法?C# JsonResponse.Add怎么用?C# JsonResponse.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonResponse的用法示例。


在下文中一共展示了JsonResponse.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetUploadStatus

 public static JsonResponse GetUploadStatus(string qid)
 {
     var j = new JsonResponse();
     // try and turn the id into a guid
     Guid id;
     if (!Guid.TryParse(qid, out id)) {
         j.Message = "Id not a valid Guid.";
         j.Error = 1;
         return j;
     }
     if(!Core.UploadStatuses.ContainsKey(id)) {
         j.Message = "Upload does not exist or status has expired.";
         j.Error = 2;
         return j;
     }
     var u = Core.UploadStatuses[id];
     j.Add("BytesRead", u.BytesRead);
     j.Add("BytesTotal", u.BytesTotal);
     j.Add("Complete", u.Complete);
     j.Add("CurrentFile", u.CurrentFile);
     j.Add("Id", u.Id);
     j.Add("LastUpdated", u.LastUpdated);
     j.Add("Message", u.Message);
     j.Add("StartedOn", u.StartedOn);
     return j;
 }
开发者ID:CorbinDallas,项目名称:Oda,代码行数:26,代码来源:GetUploadStatusJson.cs

示例2: JsonReadOrDelete

 public static JsonResponse JsonReadOrDelete(string objectName, int rowFrom, int rowTo, SqlWhere whereClause, Guid accountId, SqlWhere searchClause,
                                     IDictionary<string, string> aggregates, ICollection<int> selectedRows, bool includeSchemaData, Int64 checksum, bool deleteSelection,
                                     string orderBy, OrderDirection orderByDirection, SqlConnection connection)
 {
     var s = new JsonResponse();
     var aggs = new StringBuilder();
     var sRows = new StringBuilder();
     s.MethodName = "JsonReadOrDelete";
     var rows = new List<object>();
     s.Add("rows", rows);
     // convert aggregate column dictionary to a string
     aggregates = aggregates ?? new Dictionary<string, string>();
     if(aggregates.Count>0){
         foreach(var k in aggregates){
             aggs.AppendFormat("{0}|{1},", k.Key, k.Value);
         }
         // remove trailing comma
         aggs.Remove(aggs.Length - 1, 1);
     }
     selectedRows = selectedRows ?? new Collection<int>();
     foreach(var i in selectedRows){
         sRows.AppendFormat("{0},",i);
         // remove trailing comma
         sRows.Remove(aggs.Length - 1, 1);
     }
     using (var cn = connection ?? CreateConnection()) {
         if (cn.State != ConnectionState.Open) { cn.Open(); }
         using (var cmd  = cn.CreateCommand()) {
             cmd.CommandText = _jsonReadOrDeleteQuery;
             cmd.CommandType = CommandType.StoredProcedure;
             SqlMetaData[] prameterList = {
                 new SqlMetaData("Name",SqlDbType.VarChar,100),
                 new SqlMetaData("Type",SqlDbType.VarChar,100),
                 new SqlMetaData("Length",SqlDbType.VarChar,10),
                 new SqlMetaData("Value",SqlDbType.Variant)
             };
             var whereParameterList = new List<SqlDataRecord>();
             var searchParameterList = new List<SqlDataRecord>();
             whereClause = whereClause ?? new SqlWhere();
             searchClause = searchClause ?? new SqlWhere();
             foreach(var p in whereClause.Parmeters){
                 var whereParameter = new SqlDataRecord(prameterList);
                 whereParameter.SetString(0, p.Name);
                 whereParameter.SetString(1, p.SqlDbType.ToString());
                 whereParameter.SetValue(2, p.Length);
                 whereParameter.SetValue(3, p.Value);
                 whereParameterList.Add(whereParameter);
             }
             foreach (var p in searchClause.Parmeters) {
                 var searchParameter = new SqlDataRecord(prameterList);
                 searchParameter.SetString(0, p.Name);
                 searchParameter.SetString(1, p.SqlDbType.ToString());
                 searchParameter.SetValue(2, p.Length);
                 searchParameter.SetValue(3, p.Value);
                 searchParameterList.Add(searchParameter);
             }
             cmd.Parameters.Add("@objName", SqlDbType.VarChar).Value = objectName;
             cmd.Parameters.Add("@record_from", SqlDbType.Int).Value = rowFrom;
             cmd.Parameters.Add("@record_to", SqlDbType.Int).Value = rowTo;
             cmd.Parameters.Add("@suffix", SqlDbType.VarChar).Value = whereClause.WhereClause;
             cmd.Parameters.Add("@accountId", SqlDbType.UniqueIdentifier).Value = accountId;
             cmd.Parameters.Add("@searchSuffix", SqlDbType.VarChar).Value = searchClause.WhereClause;
             cmd.Parameters.Add("@aggregateColumns", SqlDbType.VarChar).Value = aggs.ToString();
             cmd.Parameters.Add("@selectedRowsCSV", SqlDbType.VarChar).Value = sRows.ToString();
             cmd.Parameters.Add("@includeSchema", SqlDbType.Bit).Value = includeSchemaData;
             cmd.Parameters.Add("@checksum", SqlDbType.BigInt).Value = checksum;
             cmd.Parameters.Add("@delete", SqlDbType.Bit).Value = deleteSelection;
             cmd.Parameters.Add("@orderBy_override", SqlDbType.VarChar).Value = orderBy;
             cmd.Parameters.Add("@orderDirection_override", SqlDbType.VarChar).Value = orderByDirection == OrderDirection.Ascending ? "asc" : "desc";
             cmd.Parameters.Add("@whereParameterList", SqlDbType.Structured);
             cmd.Parameters["@whereParameterList"].Direction = ParameterDirection.Input;
             cmd.Parameters["@whereParameterList"].Value = (whereParameterList.Count == 0 ? null : whereParameterList);
             cmd.Parameters.Add("@searchParameterList", SqlDbType.Structured);
             cmd.Parameters["@searchParameterList"].Direction = ParameterDirection.Input;
             cmd.Parameters["@searchParameterList"].Value = (searchParameterList.Count == 0 ? null : searchParameterList);
             using (var r = cmd.ExecuteReader()) {
                 if(searchClause.WhereClause.Length == 0){
                     // add range data
                     var range = new Dictionary<string, object> { { "from", rowFrom }, { "to", rowTo } };
                     s.Add("range", range);
                     // first row contains error data
                     r.Read();
                     var header = JsonConvert.DeserializeObject<Dictionary<string, object>>(r.GetString(0));
                     s.Add("header", header);
                     // pull error and description info from SP result
                     s.Error = Convert.ToInt32((Int64)header["error"]);
                     s.Message = (string)header["description"];
                     // second row contains schema data
                     r.Read();
                     var schema = JsonConvert.DeserializeObject<List<object>>(r.GetString(0));
                     s.Add("columns", schema);
                     // the rest are row data
                     while (r.Read()) {
                         var row = JsonConvert.DeserializeObject<List<object>>(r.GetString(0));
                         rows.Add(row);
                     }
                 }else {
                     if(r.HasRows){
                         s["rows"] = JsonConvert.DeserializeObject<List<int>>(r.GetString(0));
                     }else {
//.........这里部分代码省略.........
开发者ID:CorbinDallas,项目名称:Oda,代码行数:101,代码来源:Sql.cs


注:本文中的JsonResponse.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。