private static logData GetLogStrong(string url, Action errorAct, out long b) { var hc = new HttpClient(); hc.BaseAddress = new Uri("http://rest.logging.sh.ctriptravel.com"); hc.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); long secondS = 60; long timeS = secondS * 1000 * 10000; hc.Timeout = new TimeSpan(timeS); var res = hc.GetAsync(url); //Console.WriteLine(hc.BaseAddress + url); var a = DateTime.Now.Ticks; string rs = string.Empty; logData rsObj = null; var errorInfoTmp = new ErrorInfo { HasMore = false, ErrorMoreInfo = new MoreInfo(), IsError = false, ErrorRetryInfo = new RetryInfo() }; b = DateTime.Now.Ticks; try { rs = res.Result.Content.ReadAsStringAsync().Result; //Console.WriteLine(rs); b = DateTime.Now.Ticks; Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(url + System.Environment.NewLine + ":" + (b - a) / 10000); JsConfig.ConvertObjectTypesIntoStringDictionary = true; rsObj = rs.FromJson <logData>(); //var dyn = DynamicJson.Deserialize(rs); } catch (Exception) { errorAct(); //errorInfoTmp.IsError = true; //errorInfoTmp.ErrorRetryInfo.url = url; //return new List<LogInfo>(); } //errorAct(errorInfoTmp); return(rsObj); }
private static List <LogInfo> dataProcessorStrong(LogCondition logCondition, DateTime head, long b, logData rsObj, Action act) { var infoTmpList = new List <LogInfo>(); if (rsObj != null && rsObj.size > 0) { #region db //using (var db = new clogEntity()) //{ Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("size=" + rsObj.size); var logs = rsObj.logs; foreach (var log in logs) { var appIdTmp = log.appId; // logTmp["appId"] as string; var logLevelTmp = log.logLevel; // logTmp["logLevel"] as string; var hostTmp = log.hostName; // logTmp["hostName"] as string; //var logTyptTmp = logTmp["logType"] as string; var logTimeTmp = log.timestamp; // logTmp["timestamp"] as string; var logTitleTmp = log.title; // logTmp["title"] as string; var logMessageTmp = log.message; // logTmp["message"] as string; if (logCondition.appidLs.Contains(appIdTmp) && logCondition.LogLevelLs.Contains(logLevelTmp)) { if (rsObj.size == 100) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(rsObj.size); act(); } var attrArrTmp = log.attributes;// logTmp["attributes"] as List<object>; //attrArrTmp.AsEnumerable().Aggregate(infoTmpList, (r, n) => // { // takeValueWhenMatch(logCondition,infoTmpList , infoTmp, n.key, n.value); // return r; // }); Dictionary <string, string> attrDic = attrArrTmp.AsEnumerable(). Aggregate(new Dictionary <string, string>(), (r, n) => { r.Add(n.key.ToLower(), n.value); return(r); }); //Func<string, string> helpTmp = (str) => attrDic.Keys.Contains(str) ? attrDic[str] : string.Empty; Func <string, string> helpExTmp = (str) => { string res = string.Empty; try { res = attrDic[str]; } catch (Exception) { res = string.Empty; } return(res); }; var typeTmp = helpExTmp("logtype"); if (logCondition.TagValueArr.Contains(typeTmp)) { var infoTmp = new LogInfo(); //var infoTmp = new LogInfo(); infoTmp.AppId = appIdTmp; infoTmp.HostIp = (hostIp)Enum.Parse(typeof(hostIp), hostTmp); infoTmp.TimeStamp = ulong.Parse(logTimeTmp); infoTmp.Title = logTitleTmp; infoTmp.message = logMessageTmp; infoTmp.head = head; infoTmp.Level = (logLevel)Enum.Parse(typeof(logLevel), logLevelTmp); infoTmp.Logtype = helpExTmp("logtype"); // attrDic.Keys.Contains("logtype") ? attrDic["logtype"] : string.Empty; infoTmp.Uid = helpExTmp("uid"); // attrDic.Keys.Contains("uid") ? attrDic["uid"] : string.Empty; infoTmp.Platform = helpExTmp("platform"); // attrDic.Keys.Contains("platform") ? attrDic["platform"] : string.Empty; infoTmp.Servicecode = helpExTmp("servicecode"); // attrDic.Keys.Contains("servicecode") ? attrDic["servicecode"] : string.Empty; infoTmp.Servicetype = helpExTmp("servicetype"); // attrDic.Keys.Contains("servicetype") ? attrDic["servicetype"] : string.Empty; infoTmp.Serviceversion = helpExTmp("serviceversion"); // attrDic.Keys.Contains("serviceversion") ? attrDic["serviceversion"] : string.Empty; infoTmp.Guid = helpExTmp("guid"); // attrDic.Keys.Contains("guid") ? attrDic["Guid"] : string.Empty; infoTmp.Bustype = helpExTmp("bustype"); // attrDic.Keys.Contains("bustype") ? attrDic["bustype"] : string.Empty; infoTmp.Orderid = helpExTmp("orderid"); // attrDic.Keys.Contains("orderid") ? attrDic["orderid"] : string.Empty; infoTmpList.Add(infoTmp); } } } #endregion } var c = DateTime.Now.Ticks; Console.WriteLine("self:" + (c - b) / 10000); return(infoTmpList); }