예제 #1
0
 public object deserialize(string jsonString, Type apexType) =>
 JsonConvert.DeserializeObject(jsonString, apexType);
예제 #2
0
 public static string Serialize(object obj) => JsonConvert.SerializeObject(obj);
예제 #3
0
파일: HistoryPage.cs 프로젝트: TabNoc/PiWeb
        private Task <int> FetchAmount()
        {
            string url = PageStorage <BackendData> .Instance.StorageData.GetUrl("History");

            if (url != "")
            {
                return(new HttpClient().GetAsync($"{url}/amount").ContinueWith(task => JsonConvert.DeserializeObject <int>(task.EnsureResultSuccessStatusCode().Result.Content.ReadAsStringAsync().Result)));
            }
            else
            {
                return(Task.Run(() => PageStorage <HistoryData> .Instance.StorageData.HistoryElements.Count));
            }
        }
예제 #4
0
 public void InsertOne <T>(T obj)
 {
     InsertOne(JsonConvert.SerializeObject(obj));
 }
예제 #5
0
 public string Serialize_Newtonsoft_Complex_ToString()
 {
     return(JsonNet.SerializeObject(TestData.ComplexJsonObject));
 }
예제 #6
0
 public string serializePretty(object objectToSerialize) =>
 JsonConvert.SerializeObject(objectToSerialize, Formatting.Indented);
예제 #7
0
 [Fact] public void Char() => Run(() => _writer.Write('c')).ShouldBeEquivalentTo(Newton.SerializeObject('c'));
예제 #8
0
 public static object GetObject(string text)
 {
     return(JC.DeserializeObject(text));
 }
예제 #9
0
 public static T GetObject <T>(string text)
 {
     return(JC.DeserializeObject <T>(text));
 }
예제 #10
0
        private static List <string> SerializeWithJsonNet <T>(List <T> objects)
        {
            var jsonStrings = objects.Select(o => JsonNetJsonConvert.SerializeObject(o)).ToList();

            return(jsonStrings);
        }
예제 #11
0
 public static string GetString(object value)
 {
     return(JC.SerializeObject(value));
 }
예제 #12
0
        public void ProcessExcelData()
        {
            try
            {
                List <Dictionary <string, object> > result = new List <Dictionary <string, object> >();


                var is2007 = false;
                if (filepath.ToLower().IndexOf("xlsx") != -1)
                {
                    is2007 = true;
                }
                var      stream = File.OpenRead(filepath);
                NPOIData svr    = new NPOIData();
                if (string.IsNullOrEmpty(CurrentRule.StartLine))
                {
                    CurrentRule.StartLine = "1";
                }
                var list = svr.getSheetInfo(stream, is2007, CurrentRule.StartLine, "");

                if (list.Count > 0)
                {
                    Dictionary <string, object> dictMap = new Dictionary <string, object>();

                    DataRow row = list[0].dt.Rows[0];
                    foreach (DataColumn col in list[0].dt.Columns)
                    {
                        var label = row[col.ColumnName].ToString();
                        var res   = CurrentRule.Cols.Where(p => p.FName == label).ToList();
                        if (res.Count > 0)
                        {
                            dictMap.Add(res[0].FCode, col.ColumnName);
                            continue;
                        }
                    }
                    for (var i = 1; i < list[0].dt.Rows.Count; i++)
                    {
                        Dictionary <string, object> obj = new Dictionary <string, object>();
                        var dataRow = list[0].dt.Rows[i];
                        foreach (var item in CurrentRule.Cols)
                        {
                            var key = item.FCode;
                            if (dictMap.ContainsKey(key))
                            {
                                obj.Add(key, dataRow[dictMap[key].ToString()]);
                            }
                            else
                            {
                                obj.Add(key, item.DeafultValue == null ? "" : item.DeafultValue);
                            }
                        }
                        result.Add(obj);
                    }
                }



                ExecScript("ImportController.setData('" + JSON.SerializeObject(result) + "')");
            }
            catch (Exception ex)
            {
                ExecScript("ImportController.showError('" + ex.Message + "')");
            }
        }
예제 #13
0
        public CheCi_Out GetKehuoByCheCi(string input)
        {
            CheCi_Out json  = new CheCi_Out();
            CheCi_In  model = null;

            //List<TrainNoBelong> trainNoBelongs = null;
            //string strReg = String.Empty;
            //Regex regex = null;
            //int nBeginNumber, nEndNumber;
            //bool isMatch = false;
            try
            {
                #region 原来的代码
                //model = JsonConvert.DeserializeObject<CheCi_In>(input);
                //trainNoBelongs = GetTrainNoBelongArray();
                //if (trainNoBelongs != null)
                //{
                //    foreach (var trainNoBelong in trainNoBelongs)
                //    {
                //        nBeginNumber = trainNoBelong.nBeginNumber;
                //        nEndNumber = trainNoBelong.nEndNumber;
                //        int CheCi;
                //        json.result = "0";
                //        json.resultStr = "获取车次成功";
                //        //构造正则表达式
                //        if (String.IsNullOrEmpty(trainNoBelong.strTrainNoHead))
                //        {
                //            if (Int32.TryParse(model.TrainNo, out CheCi) && CheCi >= nBeginNumber && CheCi <= nEndNumber)
                //            {
                //                json.data.Kehuo = trainNoBelong.strKehuoName;
                //                isMatch = true;
                //                break;
                //            }
                //        }
                //        else
                //        {
                //            strReg = String.Format("^{0}", trainNoBelong.strTrainNoHead);
                //        }
                //        regex = new Regex(strReg);
                //        Match match = regex.Match(model.TrainNo);
                //        string strNum = String.Empty;
                //        if (match.Success)
                //        {
                //            int num;
                //            strNum = model.TrainNo.Substring(match.Length, model.TrainNo.Length - match.Length);
                //            if (strNum.Length > 0)
                //            {
                //                if ((Int32.TryParse(strNum, out num) && num >= nBeginNumber && num <= nEndNumber))
                //                {
                //                    json.data.Kehuo = trainNoBelong.strKehuoName;
                //                    isMatch = true;
                //                    break;
                //                }
                //            }
                //            else
                //            {
                //                if (trainNoBelong.nBeginNumber == 0 && trainNoBelong.nEndNumber == 0)
                //                {
                //                    json.data.Kehuo = trainNoBelong.strKehuoName;
                //                    isMatch = true;
                //                    break;
                //                }
                //            }

                //        }

                //    }
                //}
                //if (!isMatch)
                //{
                //    //json.result = "1";
                //    //json.resultStr = "根据车次获取客货类型失败,没有找到匹配的规则";
                //    json.data.Kehuo = "";
                //}
                #endregion
                string Remarks = "";
                model             = JsonConvert.DeserializeObject <CheCi_In>(input);
                json.data.Kehuo   = getKeHuoByTrainNo(model.TrainNo, ref Remarks);
                json.data.Remarks = Remarks;
                json.result       = "0";
                json.resultStr    = "获取客货成功";
            }
            catch (Exception ex)
            {
                LogClass.logex(ex, "");
                throw ex;
            }
            return(json);
        }
예제 #14
0
        public List <T> GetAllData <T>(string path)
        {
            var json = File.ReadAllText(path);

            return(JsonConvert.DeserializeObject <List <T> >(json));
        }
예제 #15
0
        public object deserializeUntyped(string jsonString)
        {
            var dictionary = JsonConvert.DeserializeObject <SysDictionary>(jsonString);

            return(new Map <string, object>(dictionary));
        }
예제 #16
0
        public async Task <Response> WorkflowApiProcessing(RequestContext ctx)
        {
            object data          = string.Empty;
            string error         = string.Empty;
            string detailedError = string.Empty;

            try
            {
                string operation = ctx.Request.HttpParams.QueryString["operation"];
                if (string.IsNullOrWhiteSpace(operation))
                {
                    throw new Exception("Parameter 'operation' is required!");
                }

                Guid processid;
                if (!Guid.TryParse(ctx.Request.HttpParams.QueryString["processid"], out processid))
                {
                    throw new Exception("Parameter 'processid' is required and must be is GUID!");
                }
                var identityid             = ctx.Request.HttpParams.QueryString["identityid"];
                var impersonatedIdentityId = ctx.Request.HttpParams.QueryString["impersonatedIdentityId"];
                var value = ctx.Request.HttpParams.QueryString["parameters"];

                var parameters = !string.IsNullOrWhiteSpace(value) ? JsonConvert.DeserializeObject <Dictionary <string, object> >(value) : null;

                CultureInfo culture = CultureInfo.CurrentUICulture;
                if (!string.IsNullOrWhiteSpace(ctx.Request.HttpParams.QueryString["culture"]))
                {
                    culture = new CultureInfo(ctx.Request.HttpParams.QueryString["culture"]);
                }

                switch (operation.ToLower())
                {
                case "createinstance":
                    var schemacode = ctx.Request.HttpParams.QueryString["schemacode"];
                    if (string.IsNullOrWhiteSpace(schemacode))
                    {
                        throw new Exception("Parameter 'schemacode' is required!");
                    }

                    if (parameters == null)
                    {
                        parameters = new Dictionary <string, object>();
                    }

                    var initialPrameters = await GetInitialProcessParameters(ctx, schemacode);

                    var createInstanceParams = new CreateInstanceParams(schemacode, processid)
                    {
                        IdentityId               = identityid,
                        ImpersonatedIdentityId   = impersonatedIdentityId,
                        InitialProcessParameters = initialPrameters,
                        SchemeCreationParameters = parameters
                    };

                    await _runtime.CreateInstanceAsync(createInstanceParams);

                    break;

                case "getavailablecommands":
                    var availableCommands = await _runtime.GetAvailableCommandsAsync(processid, new List <string>() { identityid }, null, impersonatedIdentityId);

                    data = JsonConvert.SerializeObject(availableCommands);
                    break;

                case "executecommand":
                    var command    = ctx.Request.HttpParams.QueryString["command"];
                    var wfcommands = await _runtime.GetAvailableCommandsAsync(processid, new List <string>() { identityid }, command, impersonatedIdentityId);

                    var wfcommand = wfcommands.FirstOrDefault();
                    if (wfcommand == null)
                    {
                        throw new Exception(string.Format("Command {0} is not found", command));
                    }

                    FillCommandParameters(ctx, wfcommand);
                    await _runtime.ExecuteCommandAsync(wfcommand, identityid, impersonatedIdentityId);

                    break;

                case "getavailablestatetoset":
                    var availableStateToSet = await _runtime.GetAvailableStateToSetAsync(processid, culture);

                    data = JsonConvert.SerializeObject(availableStateToSet);
                    break;

                case "setstate":
                    var state = ctx.Request.HttpParams.QueryString["state"];

                    if (parameters == null)
                    {
                        parameters = new Dictionary <string, object>();
                    }

                    await _runtime.SetStateAsync(processid, identityid, impersonatedIdentityId, state, parameters);

                    break;

                case "isexistprocess":
                    var isProcessExists = await _runtime.IsProcessExistsAsync(processid);

                    data = JsonConvert.SerializeObject(isProcessExists);
                    break;

                default:
                    throw new Exception(string.Format("operation={0} is not suported!", operation));
                }
            }
            catch (Exception ex)
            {
                detailedError = ex.ToDetailedString();
                error         = $"{ex.Message}{(ex.InnerException == null ? string.Empty : $". InnerException: {ex.InnerException.Message}")}";
                Parameters?.Log?.Invoke(detailedError, LogEntryType.Error);
            }

            var res = JsonConvert.SerializeObject(new
            {
                data,
                success = error.Length == 0,
                error,
                detailedError
            });

            return(new StringResponse(res));
        }
예제 #17
0
 public string serialize(object objectToSerialize) => JsonConvert.SerializeObject(objectToSerialize);
예제 #18
0
 public FilterDefinition <BsonDocument> crearFiltro(string strFiltroJson)
 {
     return(this.crearFiltro(JsonConvert.DeserializeObject <List <EntFiltroBlockStore> >(strFiltroJson)));
 }
예제 #19
0
 public void Strings(string input)
 {
     _writer.Write(input);
     _sw.ToString().ShouldBeEquivalentTo(Newton.SerializeObject(input));
 }
예제 #20
0
 public string Serialize_Newtonsoft_Simple_ToString()
 {
     return(JsonNet.SerializeObject(TestData.SimpleJsonObject));
 }
예제 #21
0
 [Fact] public void Byte() => Run(() => _writer.Write((byte)123)).ShouldBeEquivalentTo(Newton.SerializeObject((byte)123));
예제 #22
0
        public static TR Send <TR>(string url, object requestDto = null, string httpMethod = WebRequestMethods.Http.Get) where TR : class
        {
            try
            {
                if (string.IsNullOrEmpty(httpMethod))
                {
                    httpMethod = WebRequestMethods.Http.Get;
                }

                ApiKey = Statics.ApiKey;

                // TODO : specify this errors with codes and specify type of exception
                if (string.IsNullOrEmpty(ApiKey))
                {
                    throw new Exception("Please specify api key first");
                }

                if (string.IsNullOrEmpty(BaseUrl))
                {
                    throw new Exception("Please specify api address first");
                }

                if (httpMethod == "GET" && requestDto != null)
                {
                    url += "?" + requestDto.ToQueryString();
                }

                var serverUri   = new Uri(BaseUrl);
                var relativeUri = new Uri(url, UriKind.Relative);
                var fullUri     = new Uri(serverUri, relativeUri);

                var request = (HttpWebRequest)WebRequest.Create(fullUri);

                request.ContentType = "application/json; charset=utf-8";

                request.Accept = "application/json";
                request.Method = httpMethod;

                // ApiKey Auth
                request.Headers.Add("Authorization", "Bearer " + ApiKey);

                if ((request.Method == WebRequestMethods.Http.Post || request.Method == WebRequestMethods.Http.Put || request.Method == "DELETE") && requestDto != null)
                {
                    var requestDtoAsJson = JsonConvert.SerializeObject(requestDto);
                    using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                    {
                        streamWriter.Write(requestDtoAsJson);
                        streamWriter.Flush();
                    }
                }

                var response = (HttpWebResponse)request.GetResponse();

                using (var sr = new StreamReader(response.GetResponseStream()))
                {
                    var json = sr.ReadToEnd();
                    return(BsonSerializer.Deserialize <TR>(json));
                }
            }
            catch (Exception e)
            {
                var errorMessage = e.Message;
#if DEBUG
                errorMessage += " " + e.StackTrace;
#endif
                throw new CodeMashException(errorMessage, e);
            }
        }