protected ILGenerator CreateMethodDefinition(ExtractInfo extractInfo, bool createNamespace, out TypeBuilder typeBuilder) { string prefix = "DataPropertySetter."; if (extractInfo.TargetType.FullName.StartsWith(prefix)) { prefix = String.Empty; } string className = prefix + extractInfo.TargetType.FullName + (createNamespace ? "." : "_") + "Link" + extractInfo.SchemeId; typeBuilder = _ModuleBuilder.DefineType(className, TypeAttributes.Class | TypeAttributes.Public); MethodBuilder methodBuilder = typeBuilder.DefineMethod("LinkChild_" + extractInfo.TargetType, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, null, new Type[] { typeof(ExtractInfo), typeof(Dictionary <ExtractInfo, DataMapper.KeyObjectIndex>), typeof(Dictionary <ExtractInfo, DataMapper.KeyObjectIndex>), typeof(Dictionary <ExtractInfo, object>) }); extractInfo.LinkMethod = methodBuilder; return(methodBuilder.GetILGenerator()); }
protected void WriteDebugCreate(ExtractInfo extractInfo, int extractLevel, Type generatorSourceType) { Debug.WriteLine(string.Format( new String('\t', extractLevel) + "Creating method for {0}, source {1}", extractInfo, generatorSourceType.Name)); }
/// <summary> /// Generates setter method using xml config or type metadata (attributes). /// </summary> /// <param name="targetClassType"></param> /// <param name="schemeId"></param> /// <param name="dtSource"></param> /// <returns></returns> public ExtractInfo GenerateSetterMethod( ExtractInfo extractInfo, DataTable dtSource, Type generatorSourceType, bool createNamespace) { return(GenerateSetterMethod(extractInfo, dtSource, generatorSourceType, 0, createNamespace)); }
protected override bool AddMappingInfo(MemberInfo member, ExtractInfo extractInfo) { bool result = false; object[] attrs = member.GetCustomAttributes(typeof(DataMapAttribute), true); if (attrs == null || attrs.Length <= 0) { return(result); } foreach (object att in attrs) { DataColumnMapAttribute columnMap = att as DataColumnMapAttribute; if (columnMap != null && columnMap.SchemeId == extractInfo.SchemeId && att.GetType() == typeof(DataColumnMapAttribute)) { result = true; extractInfo.MemberColumns.Add( new MemberExtractInfo(string.IsNullOrEmpty(columnMap.MappingName) ? member.Name : columnMap.MappingName, member)); } ComplexDataMapAttribute complexMap = att as ComplexDataMapAttribute; if (complexMap != null && complexMap.SchemeId == extractInfo.SchemeId && att.GetType() == typeof(ComplexDataMapAttribute)) { result = true; extractInfo.SubTypes.Add( new RelationExtractInfo( complexMap.MappingName, member, new ExtractInfo(complexMap.ItemType, complexMap.NestedSchemeId), null ) ); } DataRelationMapAttribute relationMap = att as DataRelationMapAttribute; if (relationMap != null && relationMap.SchemeId == extractInfo.SchemeId && att.GetType() == typeof(DataRelationMapAttribute)) { result = true; extractInfo.ChildTypes.Add( new RelationExtractInfo( relationMap.MappingName, member, new ExtractInfo(relationMap.ItemType, relationMap.NestedSchemeId), GetParentKey(extractInfo.TargetType, relationMap, extractInfo.SchemeId, attrs) ) ); } } //end of foreach return(result); }
/// <summary> /// Generates setter method using xml config or type metadata (attributes). /// </summary> /// <param name="targetClassType"></param> /// <param name="schemeId"></param> /// <param name="dtSource"></param> /// <returns></returns> protected ExtractInfo GenerateSetterMethod( ExtractInfo extractInfo, DataTable dtSource, Type generatorSourceType, int extractLevel, bool createNamespace) { //Method alredy exists if (extractInfo.FillMethodInfo.ContainsKey(generatorSourceType)) { return(extractInfo); } WriteDebugCreate(extractInfo, extractLevel, generatorSourceType); IPropertySetterGenerator methodGenerator = _SetterGenerators[generatorSourceType]; //Generating Type and method declaration TypeBuilder typeBuilder = CreateAssemblyType(extractInfo.TargetType, extractInfo.SchemeId, generatorSourceType, createNamespace); MethodBuilder methodBuilder = GenerateSetterMethodDefinition( extractInfo.TargetType, typeBuilder, methodGenerator.DataSourceType); extractInfo.FillMethodInfo[methodGenerator.DataSourceType] = methodBuilder; extractInfo.MethodIndex[methodGenerator.DataSourceType] = _MethodIndex++; ILGenerator ilGen = methodBuilder.GetILGenerator(); //First process complex types foreach (RelationExtractInfo item in extractInfo.SubTypes) { GenerateSetterMethod( item.RelatedExtractInfo, dtSource, generatorSourceType, extractLevel + 1, true ); } //Generate method body GenerateSetterMethod(ilGen, methodGenerator, extractInfo, dtSource, extractLevel); Type type = typeBuilder.CreateType(); var fillMethodInfo = type.GetMethod("SetProps_" + extractInfo.TargetType); extractInfo.FillMethodInfo[methodGenerator.DataSourceType] = fillMethodInfo; extractInfo.FillMethod[methodGenerator.DataSourceType] = (FillMethodDef)Delegate.CreateDelegate(typeof(FillMethodDef), null, fillMethodInfo); WriteDebugDone(extractInfo, extractLevel); return(extractInfo); }
protected override RefInfo GetRefInfo(ExtractInfo extractInfo) { object[] attrs = extractInfo.TargetType.GetCustomAttributes(typeof(TableMapAttribute), true); if (attrs == null || attrs.Length <= 0) { return(null); } TableMapAttribute tm = attrs[0] as TableMapAttribute; return(new RefInfo(tm.TableIx, tm.TableName)); }
public ExtractInfo Extract(string result) { foreach (var item in chainList) { ExtractInfo info = item.Extract(result); if (ExtractInfo.ZeroInfo != info) { return(info); } } return(ExtractInfo.ZeroInfo); }
public bool GetExtractInfo(ExtractInfo extractInfo) { bool result = false; foreach (var item in _Providers) { result = item.GetExtractInfo(extractInfo); if (result) { break; } } return(result); }
public bool GetExtractInfo(ExtractInfo extractInfo) { bool result = false; ForEachMember(extractInfo.TargetType, m => result |= AddMappingInfo(m, extractInfo) ); RefInfo refTable = GetRefInfo(extractInfo); if (refTable != null) { extractInfo.RefTable = refTable; result = true; } return(result); }
protected override RefInfo GetRefInfo(ExtractInfo extractInfo) { if (_XmlDocument == null) { return(null); } XmlNode typeMapping = FindTypeMapping(extractInfo.TargetType, extractInfo.SchemeId); if (typeMapping == null) { return(null); } int[] tableIx; string tableName; GetTableID(typeMapping, out tableIx, out tableName); return(new RefInfo(tableIx, tableName)); }
public abstract CheckReesultInfo Convert(ExtractInfo extractInfo);
public ExtractInfo Extract(string result) { ExtractInfo extInfo = new ExtractInfo(); #region 情况一 // 正在 Ping 127.0.0.1 具有 32 字节的数据: // 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128 // 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128 // 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128 // 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128 // 127.0.0.1 的 Ping 统计信息: // 数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失), // 往返行程的估计时间(以毫秒为单位): // 最短 = 0ms,最长 = 0ms,平均 = 0ms #endregion #region 情况二 //Ping 请求找不到主机 928.929.1.1。请检查该名称,然后重试。 #endregion #region 情况三 //选项 -d 不正确。 //选项 -n 的值有错误,有效范围从 1 到 4294967295。 #endregion #region 情况四 // 正在 Ping 233.233.233.233 具有 32 字节的数据: // 请求超时。 // 请求超时。 // 请求超时。 // 请求超时。 // 233.233.233.233 的 Ping 统计信息: // 数据包: 已发送 = 4,已接收 = 0,丢失 = 4 (100% 丢失), #endregion #region 情况五 //'ping' 不是内部或外部命令 #endregion //0:ip //2~?:过程回显数据 //?:数据包统计信息 //?:时间消耗统计 string[] lines = result.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (0 == lines.Length) { return(ExtractInfo.ZeroInfo); } #region 处理情况三,情况五 //情况三,情况五莫得ip,先判断 if (Regex.IsMatch(lines[0], "选项(\\s)+([\\w\\W])+不正确")) { extInfo.InfoType = PingResultStatus.ExecuteError; return(extInfo); } else if (Regex.IsMatch(lines[0], "选项(\\s)+([\\w\\W])+错误")) { extInfo.InfoType = PingResultStatus.ExecuteError; return(extInfo); } else if (lines[0].Contains("不是内部或外部命令")) { extInfo.InfoType = PingResultStatus.PingNotfound; return(extInfo); } #endregion #region 找不到主机 if (Regex.IsMatch(lines[0], $"找不到主机(\\s+){extInfo.IpV4}")) { //访问不到ip地址 extInfo.InfoType = PingResultStatus.HostNotfound; return(extInfo); } #endregion #region 匹配第一行的ip或域名 //匹配第一行的ip Match ipMatch = Regex.Match(lines[0], UsualRegularExp.IPADRESS); //匹配第一行域名 Match domainMatch = Regex.Match(lines[0], $"({UsualRegularExp.NET_DOMAIN})"); //ip或域名都不匹配,只能推出解析 if (!(ipMatch.Success || domainMatch.Success)) { return(ExtractInfo.ZeroInfo); } extInfo.IpV4 = ipMatch.Success?ipMatch.Value:domainMatch.Groups[1].Value; extInfo.Port = "80"; #endregion #region 剩下的参数循环解析 for (int i = 1; i < lines.Length; i++) { string currentLine = lines[i]; //行信息里含有ip证明还不是我们想要的数据 if (currentLine.Contains(extInfo.IpV4)) { continue; } //情况四简单,先处理 if ("请求超时。" == currentLine) { //超时只能初步判定为丢包,最后丢包率100%才是超时,无法访问 extInfo.InfoType = PingResultStatus.PacketLoss; continue; } else if (currentLine.Contains("数据包")) { //数据包: 已发送 = 4,已接收 = 0,丢失 = 4 (100% 丢失), Match lossRateMatch = Regex.Match(currentLine, "[\\s\\w\\W]+\\(([\\d.]+)%[\\s\\w\\W]+\\)"); if (lossRateMatch.Success) { string lossRate = lossRateMatch.Groups[1].Value; //丢包100%,全部超时 if ("100" == lossRate) { extInfo.InfoType = PingResultStatus.CanNotAccess; } extInfo.LossRate = "100" == lossRate ? 100 : Convert.ToInt32(lossRate); //如果是最后一行,需要再这里返回,否则出了循环,就会变成了return ExtractInfo.ZeroInfo; if (i == (lines.Length - 1)) { return(extInfo); } } } else if (currentLine.Contains("最短 = ")) { // 最短 = 0ms,最长 = 0ms,平均 = 0ms Match responseTimeMatch = Regex.Match(currentLine, @"[^\d]+=[^\d]+(\d+)ms[,,][^\d]+=[^\d]+(\d+)ms[,,][^\d]+=[^\d]+(\d+)ms"); if (!responseTimeMatch.Success) { //又有ip响应,又没超时,却没有响应时间统计信息,这个数据有问题,所以标记成无结果 //todao:需要加日志记录一下这个特殊情况 return(ExtractInfo.ZeroInfo); } extInfo.MinTime = Convert.ToInt32(responseTimeMatch.Groups[1].Value); extInfo.Maxtime = Convert.ToInt32(responseTimeMatch.Groups[2].Value); extInfo.AvgTime = Convert.ToInt32(responseTimeMatch.Groups[3].Value); //如果之前没有丢过包,才将他设置为通过 if (PingResultStatus.PacketLoss != extInfo.InfoType) { extInfo.InfoType = PingResultStatus.Pass; } //todo:获取系统设置的预设超时时间 int presetTime = 1000; extInfo.InfoType = extInfo.AvgTime <= presetTime ? extInfo.InfoType : PingResultStatus.Timeout; return(extInfo); } } #endregion //出了循环还没又返回,证明前面都么有合适的值可以填,给结果类型重置成为none //todo:日志记录这个特殊情况 return(ExtractInfo.ZeroInfo); }
private static CheckReesultInfo CreateFromExtractInfo(string ipV4, string port, string remarks, DateTime receiveTime, ExtractInfo extractInfo) { Assembly convertAssembly = Assembly.GetAssembly(typeof(CheckReesultInfo)); ConstructorInfo contInfo = convertAssembly.GetType($"ManjuuDomain.ExtractInfos.{extractInfo.InfoType.ToString()}ResultConverter") .GetConstructor(new Type[] { typeof(string), typeof(string), typeof(string), typeof(DateTime) }); if (null == contInfo) { throw new EntryPointNotFoundException($"状态{extractInfo.InfoType.ToString()}没有对应的处理程序"); } IResultConverter resultConverter = contInfo.Invoke(new object[] { ipV4, port, remarks, receiveTime }) as IResultConverter; if (null == resultConverter) { throw new NotSupportedException($"状态{extractInfo.InfoType.ToString()}无法使用IResultConverter处理"); } return(resultConverter.Convert(extractInfo)); }
private List <ExtractInfo> getFile() { //declare list of objects List <ExtractInfo> anotherList = new List <ExtractInfo>(); ExtractInfo item1 = new ExtractInfo(); //declare the lists that will be used List <String> ivDates = new List <String>(); List <String> ivNums = new List <String>(); List <Double> tAmounts = new List <Double>(); List <String> dDates = new List <String>(); List <String> jAccountCodes = new List <String>(); List <Double> jGrossAmounts = new List <Double>(); List <String> lineItemDescrs = new List <String>(); List <String> reqCustoms03 = new List <String>(); List <String> reqCustoms07 = new List <String>(); List <String> vNames = new List <String>(); OpenFileDialog openTxtFile = new OpenFileDialog(); //open the file if (openTxtFile.ShowDialog() == DialogResult.OK) { string fileName = openTxtFile.FileName; List <List <string> > lines = new List <List <string> >(); foreach (string line in File.ReadAllLines(fileName)) { var list2 = new List <string>(); foreach (string s in line.Split(new[] { '|' })) { list2.Add(s); } lines.Add(list2); } //Grab all data from the txt file into a 2d list var count = lines.Count; string[][] newList = new string[lines.Count][]; for (int i = 0; i > count; i++) { List <string> sublists = lines.ElementAt(i); newList[i] = new string[sublists.Count]; for (int j = 0; j < sublists.Count; j++) { newList[i][j] = sublists.ElementAt(j); } } //Populate single Lists from data in txt file from the 2d list for (var i = 1; i < lines.Count; i++) { var vName = lines[i][163]; vNames.Add(vName); var iDate = lines[i][6]; ivDates.Add(iDate); var iNum = lines[i][5]; ivNums.Add(iNum); double tAmount = Convert.ToDouble(lines[i][9]); tAmounts.Add(tAmount); var dDate = lines[i][7]; dDates.Add(dDate); var jCode = lines[i][60]; jAccountCodes.Add(jCode); double jAmount = Convert.ToDouble(lines[i][62]); jGrossAmounts.Add(jAmount); var lItemDescr = lines[i][132]; lineItemDescrs.Add(lItemDescr); var req03 = lines[i][15]; string actualInput; switch (req03) { case "111": actualInput = "New Iberia"; reqCustoms03.Add(actualInput); break; case "112": actualInput = "Liberty"; reqCustoms03.Add(actualInput); break; case "113": actualInput = "Laurel"; reqCustoms03.Add(actualInput); break; case "114": actualInput = "Houma"; reqCustoms03.Add(actualInput); break; case "115": actualInput = "Thru Tubing - LA"; reqCustoms03.Add(actualInput); break; case "221": actualInput = "Midland"; reqCustoms03.Add(actualInput); break; case "222": actualInput = "Thru Tubing - TX"; reqCustoms03.Add(actualInput); break; case "331": actualInput = "Fort Collins"; reqCustoms03.Add(actualInput); break; case "332": actualInput = "Vernal"; reqCustoms03.Add(actualInput); break; case "333": actualInput = "Watford City"; reqCustoms03.Add(actualInput); break; case "334": actualInput = "Machine Shop"; reqCustoms03.Add(actualInput); break; case "335": actualInput = "Machine Shop"; reqCustoms03.Add(actualInput); break; case "910": actualInput = "Corp Ops"; reqCustoms03.Add(actualInput); break; case "920": actualInput = "Corp Admin"; reqCustoms03.Add(actualInput); break; case "930": actualInput = "Corp Acct"; reqCustoms03.Add(actualInput); break; case "940": actualInput = "Corp Sales"; reqCustoms03.Add(actualInput); break; } var req07 = lines[i][19]; reqCustoms07.Add(req07); } //put data from lists into object and then put object into list for (int i = 0; i < vNames.Count; i++) { item1.vendorName = vNames[i]; item1.invoiceDate = ivDates[i]; item1.invoiceNumber = ivNums[i]; item1.reqCuston03 = reqCustoms03[i]; item1.lineItemDescr = lineItemDescrs[i]; item1.jGrossAmount = jGrossAmounts[i]; item1.jAccCode = jAccountCodes[i]; item1.dueDate = dDates[i]; item1.reqCustom07 = reqCustoms07[i]; anotherList.Add(item1); } List <ExtractInfo> List1 = anotherList.OrderBy(o => o.invoiceNumber).ToList(); textBox1.Text = Path.GetFileName(fileName); } return(anotherList); }
protected void WriteDebugDone(ExtractInfo extractInfo, int extractLevel) { Debug.WriteLine(string.Format( new String('\t', extractLevel) + "Done with creating method for {0}", extractInfo)); }
/// <summary> /// Generates setter method using xml config or type metadata (attributes). /// </summary> /// <param name="targetClassType"></param> /// <param name="schemeId"></param> /// <param name="dtSource"></param> /// <returns></returns> protected void GenerateSetterMethod( ILGenerator ilGen, IPropertySetterGenerator methodGenerator, ExtractInfo extractInfo, DataTable dtSource, int extractLevel) { methodGenerator.GenerateMethodHeader( ilGen, extractInfo.MethodIndex[methodGenerator.DataSourceType]); int propIx = 0; foreach (MemberExtractInfo mei in extractInfo.MemberColumns) { int columnIx = dtSource.Columns.IndexOf(mei.MapName); if (columnIx < 0) { //Debug.WriteLine(string.Format( // "Warning! Column {0} that was defined in mapping does not exists. No mapping code will be generated for member {1}", // mei.MapName, // mei.Member.Name)); //propIx++; //continue; throw new DataMapperException( string.Format( "Column {0} that was defined in mapping does not exists. Try to use another mapping schema.", mei.MapName)); } WriteDebugGenerateSetter(extractLevel, mei, propIx, dtSource, columnIx); methodGenerator.CreateExtractScalar( ilGen, mei.Member as PropertyInfo, mei.Member as FieldInfo, dtSource.Columns[columnIx].DataType, propIx++ ); } foreach (RelationExtractInfo rei in extractInfo.ChildTypes) { WriteDebugGenerateFillChildren(extractLevel, rei); methodGenerator.CreateExtractNested( ilGen, rei.Member as PropertyInfo, rei.RelatedExtractInfo.TargetType, rei.MapName, rei.RelatedExtractInfo.SchemeId ); } foreach (RelationExtractInfo rei in extractInfo.SubTypes) { WriteDebugGenerateFillChildren(extractLevel, rei); methodGenerator.GenerateExtractComplex( ilGen, rei.Member as PropertyInfo, rei.RelatedExtractInfo.TargetType, rei.RelatedExtractInfo.FillMethodInfo[methodGenerator.DataSourceType], rei.RelatedExtractInfo.MethodIndex[methodGenerator.DataSourceType] ); } ilGen.Emit(OpCodes.Ldloc_2); ilGen.Emit(OpCodes.Ret); }
public ExtractInfo Extract(string result) { ExtractInfo extInfo = new ExtractInfo(); #region 情况一 // Pinging www.a.shifen.com [14.215.177.38] with 32 bytes of data: // Reply from 14.215.177.38: bytes=32 time=9ms TTL=128 // Reply from 14.215.177.38: bytes=32 time=11ms TTL=128 // Reply from 14.215.177.38: bytes=32 time=9ms TTL=128 // Reply from 14.215.177.38: bytes=32 time=9ms TTL=128 // Ping statistics for 14.215.177.38: // Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), // Approximate round trip times in milli-seconds: // Minimum = 9ms, Maximum = 11ms, Average = 9ms #endregion #region 情况二 //Ping request could not find host www.abc.bili. Please check the name and try again. #endregion #region 情况三 //Bad option -c. //Bad value for option -n, valid range is from 1 to 4294967295. #endregion #region 情况四 // Pinging 233.233.233.233 with 32 bytes of data: // Request timed out. // Request timed out. // Request timed out. // Request timed out. // Ping statistics for 233.233.233.233: // Packets: Sent = 4, Received = 0, Lost = 4 (100% loss), #endregion #region 情况五 //'pingg' is not recognized as an internal or external command, // operable program or batch file. #endregion //0:ip //2~?:过程回显数据 //?:数据包统计信息 //?:时间消耗统计 string[] lines = result.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (0 == lines.Length) { return(ExtractInfo.ZeroInfo); } #region 处理情况三,情况五 //情况三,情况五莫得ip,先判断 if (Regex.IsMatch(lines[0], "Bad(\\s)+option")) { extInfo.InfoType = PingResultStatus.ExecuteError; return(extInfo); } else if (Regex.IsMatch(lines[0], "Bad(\\s)+([\\w\\W])+option")) { extInfo.InfoType = PingResultStatus.PingNotfound; return(extInfo); } else if (lines[0].Contains("is not recognized as an internal or external command")) { extInfo.InfoType = PingResultStatus.PingNotfound; return(extInfo); } #endregion #region 找不到主机 if (Regex.IsMatch(lines[0], $"could not find host(\\s+){extInfo.IpV4}")) { //访问不到ip地址 extInfo.InfoType = PingResultStatus.HostNotfound; return(extInfo); } #endregion #region 匹配第一行的ip或域名 //匹配第一行的ip Match ipMatch = Regex.Match(lines[0], UsualRegularExp.IPADRESS); //匹配第一行域名 Match domainMatch = Regex.Match(lines[0], $"({UsualRegularExp.NET_DOMAIN})"); //ip或域名都不匹配,只能推出解析 if (!(ipMatch.Success || domainMatch.Success)) { return(ExtractInfo.ZeroInfo); } extInfo.IpV4 = ipMatch.Success?ipMatch.Value:domainMatch.Groups[1].Value; extInfo.Port = "80"; #endregion #region 剩下的参数循环解析 for (int i = 1; i < lines.Length; i++) { string currentLine = lines[i]; //行信息里含有ip证明还不是我们想要的数据 if (currentLine.Contains(extInfo.IpV4)) { continue; } //情况四简单,先处理 if ("Request timed out." == currentLine) { //超时只能初步判定为丢包,最后丢包率100%才是超时,无法访问 extInfo.InfoType = PingResultStatus.PacketLoss; continue; } else if (currentLine.Contains("Packets")) { //数据包: 已发送 = 4,已接收 = 0,丢失 = 4 (100% 丢失), Match lossRateMatch = Regex.Match(currentLine, "[\\s\\w\\W]+\\(([\\d.]+)%[\\s\\w\\W]+\\)"); if (lossRateMatch.Success) { string lossRate = lossRateMatch.Groups[1].Value; //丢包100%,全部超时 if ("100" == lossRate) { extInfo.InfoType = PingResultStatus.CanNotAccess; } extInfo.LossRate = "100" == lossRate ? 100 : Convert.ToInt32(lossRate); //如果是最后一行,需要再这里返回,否则出了循环,就会变成了return ExtractInfo.ZeroInfo; if (i == (lines.Length - 1)) { return(extInfo); } } } else if (currentLine.Contains("Minimum = ")) { // Minimum = 9ms, Maximum = 11ms, Average = 9ms Match responseTimeMatch = Regex.Match(currentLine, @"[^\d]+=[^\d]+(\d+)ms[,,][^\d]+=[^\d]+(\d+)ms[,,][^\d]+=[^\d]+(\d+)ms"); if (!responseTimeMatch.Success) { //又有ip响应,又没超时,却没有响应时间统计信息,这个数据有问题,所以标记成无结果 //todao:需要加日志记录一下这个特殊情况 return(ExtractInfo.ZeroInfo); } extInfo.MinTime = Convert.ToInt32(responseTimeMatch.Groups[1].Value); extInfo.Maxtime = Convert.ToInt32(responseTimeMatch.Groups[2].Value); extInfo.AvgTime = Convert.ToInt32(responseTimeMatch.Groups[3].Value); //如果之前没有丢过包,才将他设置为通过 if (PingResultStatus.PacketLoss != extInfo.InfoType) { extInfo.InfoType = PingResultStatus.Pass; } //todo:获取系统设置的预设超时时间 int presetTime = 1000; extInfo.InfoType = extInfo.AvgTime <= presetTime ? extInfo.InfoType : PingResultStatus.Timeout; return(extInfo); } } #endregion //出了循环还没又返回,证明前面都么有合适的值可以填,给结果类型重置成为none //todo:日志记录这个特殊情况 return(ExtractInfo.ZeroInfo); }
protected abstract bool AddMappingInfo(MemberInfo member, ExtractInfo extractInfo);
public void GenerateLinkMethod(ExtractInfo extractInfo, bool createNamespace) { if (extractInfo.LinkMethod != null) { return; } TypeBuilder typeBuilder; ILGenerator ilOut = CreateMethodDefinition(extractInfo, createNamespace, out typeBuilder); foreach (var item in extractInfo.ChildTypes) { if (item.RelatedExtractInfo.ChildTypes.Count > 0) { GenerateLinkMethod(item.RelatedExtractInfo, createNamespace); } } LocalBuilder pkObjects = ilOut.DeclareLocal(typeof(DataMapper.KeyObjectIndex)); //pkObjects.SetLocalSymInfo("pkObjects"); //Label needLink = ilOut.DefineLabel(); Label lblRet = ilOut.DefineLabel(); //if (filled.ContainsKey(extractInfo)) // return; ilOut.Emit(OpCodes.Ldarg_3); ilOut.Emit(OpCodes.Ldarg_0); ilOut.Emit(OpCodes.Callvirt, _DicContainsKey); ilOut.Emit(OpCodes.Brtrue, lblRet); //ilOut.Emit(OpCodes.Ret); //ilOut.MarkLabel(needLink); //filled.Add(extractInfo) ilOut.Emit(OpCodes.Ldarg_3); ilOut.Emit(OpCodes.Ldarg_0); ilOut.Emit(OpCodes.Ldnull); ilOut.Emit(OpCodes.Callvirt, _DicAdd); //KeyObjectIndex pkObjects = tempPrimary[extractInfo]; ilOut.Emit(OpCodes.Ldarg_1); ilOut.Emit(OpCodes.Ldarg_0); ilOut.Emit(OpCodes.Ldloca, pkObjects); ilOut.Emit(OpCodes.Callvirt, _DicTryGet); ilOut.Emit(OpCodes.Brfalse, lblRet); //ilOut.Emit(OpCodes.Callvirt, _DicGetItem); //ilOut.Emit(OpCodes.Stloc, pkObjects); Type parentListType = typeof(List <>).MakeGenericType(extractInfo.TargetType); Type parentEnumeratorListType = typeof(List <> .Enumerator).MakeGenericType(extractInfo.TargetType); LocalBuilder childEI = ilOut.DeclareLocal(typeof(ExtractInfo)); //childEI.SetLocalSymInfo("childEI"); LocalBuilder fkObjects = ilOut.DeclareLocal(typeof(DataMapper.KeyObjectIndex)); //fkObjects.SetLocalSymInfo("fkObjects"); LocalBuilder parentList = ilOut.DeclareLocal(parentListType); //parentList.SetLocalSymInfo("parentList"); for (int i = 0; i < extractInfo.ChildTypes.Count; i++) { Type childType = extractInfo.ChildTypes[i].RelatedExtractInfo.TargetType; Type childListType = typeof(List <>).MakeGenericType(childType); Type childEnumeratorListType = typeof(List <> .Enumerator).MakeGenericType(childType); Type enumerableChildType = typeof(IEnumerable <>).MakeGenericType(childType); LocalBuilder children = ilOut.DeclareLocal(childListType); //children.SetLocalSymInfo("children" + i); Label afterListNull = ilOut.DefineLabel(); Label lblNoFk = ilOut.DefineLabel(); Type listType = ReflectionHelper.GetReturnType(extractInfo.ChildTypes[i].Member); LocalBuilder targetList = ilOut.DeclareLocal(listType); //targetList.SetLocalSymInfo("targetList" + i); //ExtractInfo childEI = extractInfo.ChildTypes[0].RelatedExtractInfo; ilOut.Emit(OpCodes.Ldarg_0); ilOut.Emit(OpCodes.Callvirt, _EiGetChildTypes); ilOut.Emit(OpCodes.Ldc_I4, i); ilOut.Emit(OpCodes.Callvirt, _ListREIGet); ilOut.Emit(OpCodes.Callvirt, _ReiGetEI); ilOut.Emit(OpCodes.Stloc, childEI); //DataMapper.KeyObjectIndex fkObjects = tempForeign[childEI]; ilOut.Emit(OpCodes.Ldarg_2); ilOut.Emit(OpCodes.Ldloc, childEI); ilOut.Emit(OpCodes.Ldloca, fkObjects); ilOut.Emit(OpCodes.Callvirt, _DicTryGet); ilOut.Emit(OpCodes.Brfalse, lblNoFk); //ilOut.Emit(OpCodes.Callvirt, _DicGetItem); //ilOut.Emit(OpCodes.Stloc, fkObjects); //LinkObjects(childEI, tempPrimary, tempForeign, filled); if (extractInfo.ChildTypes[i].RelatedExtractInfo.LinkMethod != null) { ilOut.Emit(OpCodes.Ldloc, childEI); ilOut.Emit(OpCodes.Ldarg_1); ilOut.Emit(OpCodes.Ldarg_2); ilOut.Emit(OpCodes.Ldarg_3); ilOut.Emit(OpCodes.Call, extractInfo.ChildTypes[i].RelatedExtractInfo.LinkMethod); } //foreach (var item in pkObjects) GenForEach <KeyValuePair <object, IList> >(ilOut, pkObjects, pkItem => { //List<object> parentList = item.Value ilOut.Emit(OpCodes.Ldloca, pkItem); ilOut.Emit(OpCodes.Call, _KvObjListGetValue); ilOut.Emit(OpCodes.Stloc, parentList); //List<object> children; //fkObjects.TryGetValue(item.Key, out children); ilOut.Emit(OpCodes.Ldloc, fkObjects); ilOut.Emit(OpCodes.Ldloca, pkItem); ilOut.Emit(OpCodes.Call, _KvObjListGetKey); ilOut.Emit(OpCodes.Ldloca, children); ilOut.Emit(OpCodes.Callvirt, _DicObjListTryGet); ilOut.Emit(OpCodes.Pop); //foreach (var parent in parentList) GenForEach(ilOut, parentList, extractInfo.TargetType, parent => { ilOut.Emit(OpCodes.Ldloc, parent); if (extractInfo.ChildTypes[i].Member is PropertyInfo) { ilOut.Emit(OpCodes.Callvirt, ((PropertyInfo)extractInfo.ChildTypes[i].Member).GetGetMethod()); } else { ilOut.Emit(OpCodes.Ldfld, (FieldInfo)extractInfo.ChildTypes[i].Member); } ilOut.Emit(OpCodes.Stloc, targetList); ilOut.Emit(OpCodes.Ldloc, targetList); ilOut.Emit(OpCodes.Brtrue, afterListNull); ilOut.Emit(OpCodes.Newobj, listType.GetConstructor(new Type[] { })); ilOut.Emit(OpCodes.Stloc, targetList); ilOut.Emit(OpCodes.Ldloc, parent); ilOut.Emit(OpCodes.Ldloc, targetList); if (extractInfo.ChildTypes[i].Member is PropertyInfo) { ilOut.Emit(OpCodes.Callvirt, ((PropertyInfo)extractInfo.ChildTypes[i].Member).GetSetMethod()); } else { ilOut.Emit(OpCodes.Stfld, (FieldInfo)extractInfo.ChildTypes[i].Member); } ilOut.MarkLabel(afterListNull); MethodInfo addRange = listType.GetMethod("AddRange", new Type[] { enumerableChildType }); ilOut.Emit(OpCodes.Ldloc, children); Label noChildren = ilOut.DefineLabel(); ilOut.Emit(OpCodes.Brfalse, noChildren); if (listType.IsAssignableFrom(typeof(Collection <>).MakeGenericType(childType))) { GenTryIncreaseCollectionCapacity( ilOut, childType, listType, targetList, childListType, children); } ilOut.Emit(OpCodes.Ldloc, targetList); ilOut.Emit(OpCodes.Ldloc, children); if (addRange != null) { ilOut.Emit(OpCodes.Callvirt, addRange); } else { ilOut.Emit(OpCodes.Call, typeof(LinkObjectsMethodGenerator).GetMethod("ListHelperAddRange")); } ilOut.MarkLabel(noChildren); }); }); ilOut.MarkLabel(lblNoFk); } ilOut.MarkLabel(lblRet); ilOut.Emit(OpCodes.Ret); extractInfo.LinkMethod = typeBuilder.CreateType().GetMethod("LinkChild_" + extractInfo.TargetType); }
protected abstract RefInfo GetRefInfo(ExtractInfo extractInfo);
public IActionResult Extract() { var selectModel = JsonConvert.DeserializeObject <DatasetInfo>(HttpContext.Session.GetString("SelectedModel")); ExtractInfo info = new ExtractInfo(); info.parameters = (string)Request.Form["parameter"]; selectModel.isPostback = true; if (info.parameters == null || info.parameters == "") { ModelState.AddModelError("parameter", "Parameter is required."); } else { selectModel.parameterField = (string)Request.Form["parameter"]; } //Statistics info.stat = (string)Request.Form["stat"]; if (info.stat == null || info.stat == "") { ModelState.AddModelError("stat", "Statistics is required."); } else { selectModel.statField = (string)Request.Form["stat"]; } //StartDate try { info.startDate = DateTime.Parse(Request.Form["startDate"]); selectModel.startDateField = Convert.ToDateTime(Request.Form["startDate"]); } catch (FormatException e) { if (info.startDate == null) { ModelState.AddModelError("startDate", "Start Date is required."); } else { ModelState.AddModelError("startDate", e.Message + "-Start Date"); } } //End Date try { info.endDate = DateTime.Parse(Request.Form["endDate"]); selectModel.endDateField = Convert.ToDateTime(Request.Form["endDate"]); } catch (FormatException e) { if (info.endDate == null) { ModelState.AddModelError("lastDate", "End Date is required."); } else { ModelState.AddModelError("lastDate", e.Message + "-End Date"); } } if (!(info.startDate == null && info.endDate == null)) { int result = DateTime.Compare(info.startDate, info.endDate); if (result > 0) { ModelState.AddModelError("Date", "Start Date is later than End Date"); } } //Latitude try { info.latmin = double.Parse(Request.Form["latmin"]); } catch (FormatException e) { if (Request.Form["latmin"] == "") { ModelState.AddModelError("latmin", "latmin is required."); } else { ModelState.AddModelError("latmin", e.Message + "-latmin"); } } //Longitude try { info.lonmin = double.Parse(Request.Form["lonmin"]); } catch (FormatException e) { if (Request.Form["lonmin"] != "") { ModelState.AddModelError("lonmin", e.Message + "-lonmin"); } else { ModelState.AddModelError("lonmin", "lonmin is required."); } } //Redirect page for the desired output var decision = Request.Form["decision"]; if (Request.Form["outFormat"] == "") { if (decision == "Download") { ModelState.AddModelError("outFormat", "Output Format is required."); } } else //outFormat { info.outFormat = (string)Request.Form["outFormat"]; if (Request.Form["save"].Equals("on")) { info.saveDownload = true; } else { info.saveDownload = false; } selectModel.saveDownload = info.saveDownload; selectModel.outFormatField = info.outFormat; } info.format = (string)Request.Form["format"]; info.path = (string)Request.Form["path"]; if (!ModelState.IsValid) { return(View(selectModel)); } else { //check if it is the same request.Dont call WebApi if it is same if (string.IsNullOrEmpty(HttpContext.Session.GetString("info"))) { HttpContext.Session.SetString("info", JsonConvert.SerializeObject(info)); String Status = GetDatafromWebApi(selectModel); } else { string oldrequest = HttpContext.Session.GetString("info"); string newrequest = JsonConvert.SerializeObject(info); if (!(oldrequest.Equals(newrequest))) { HttpContext.Session.SetString("info", JsonConvert.SerializeObject(info)); String Status = GetDatafromWebApi(selectModel); } } HttpContext.Session.SetString("parameters", info.parameters.ToString()); HttpContext.Session.SetString("period", selectModel.startDateField.Year.ToString() + "," + selectModel.endDateField.Year.ToString()); if (decision == "Visualize") { return(RedirectToAction("Visualize", "Visualize")); } else if (decision == "View") { return(RedirectToAction("ViewData")); } else { return(RedirectToAction("Download", new { @type = info.outFormat })); } } }
protected override bool AddMappingInfo(MemberInfo member, ExtractInfo extractInfo) { bool result = false; if (_XmlDocument == null) { return(result); } //Looking for node in reflected type Type targetType = member.ReflectedType; XmlNode xmlMapping = FindPropMapping(targetType, extractInfo.SchemeId, member); if (xmlMapping == null) { targetType = member.DeclaringType; xmlMapping = FindPropMapping(targetType, extractInfo.SchemeId, member); if (xmlMapping == null) { return(result); } } result = true; XmlAttribute att = xmlMapping.Attributes["dataColumnName"]; if (att == null) { att = xmlMapping.Attributes["dataRelationName"]; Type itemType = null; int nestedSchemaId = extractInfo.SchemeId; if (att != null) { GetNestedProps(xmlMapping, ref nestedSchemaId, ref itemType); extractInfo.ChildTypes.Add(new RelationExtractInfo( att.Value, member, new ExtractInfo(itemType, nestedSchemaId), GetParentKey(targetType, itemType, att.Value, extractInfo.SchemeId))); //return new DataRelationMapAttribute(att.Value, schemeId, nestedSchemaId, itemType); } else { att = xmlMapping.Attributes["complex"]; if (att != null || ReflectionHelper.IsComplexType(ReflectionHelper.GetReturnType(member))) { GetNestedProps(xmlMapping, ref nestedSchemaId, ref itemType); extractInfo.SubTypes.Add(new RelationExtractInfo( null, member, new ExtractInfo(itemType, nestedSchemaId), null)); } else { extractInfo.MemberColumns.Add(new MemberExtractInfo( member.Name, member)); } } } else { extractInfo.MemberColumns.Add(new MemberExtractInfo( String.IsNullOrEmpty(att.Value) ? member.Name : att.Value, member)); } return(result); }