private string GetValue(FlightNode flt) { if (type == "intRange") { if (digits == -1) { return(ProcessValue(rand.Next(lowerLimit, upperLimit).ToString())); } string digitsStr = rand.Next(lowerLimit, upperLimit).ToString().ToString(); while (digitsStr.Length < digits) { digitsStr = "0" + digitsStr; } return(ProcessValue(digitsStr)); } if (type == "sequence") { if (digits == -1) { seqNum++; return(ProcessValue(seqNum.ToString())); } string digitsStr = seqNum.ToString(); while (digitsStr.Length < digits) { digitsStr = "0" + digitsStr; } seqNum++; return(ProcessValue(digitsStr)); } if (type == "intgaussian") { double u1 = 1.0 - rand.NextDouble(); //uniform(0,1] random doubles double u2 = 1.0 - rand.NextDouble(); double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2); //random normal(0,1) double randNormal = normalInt + stdDev * randStdNormal; //random normal(mean,stdDev^2) string rtn = Convert.ToInt32(randNormal).ToString(); if (digits == -1) { return(ProcessValue(rtn)); } while (rtn.Length < digits) { rtn = "0" + rtn; } return(ProcessValue(rtn)); } if (type == "doublegaussian") { double u1 = 1.0 - rand.NextDouble(); //uniform(0,1] random doubles double u2 = 1.0 - rand.NextDouble(); double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2); //random normal(0,1) double randNormal = normalDouble + stdDev * randStdNormal; //random normal(mean,stdDev^2) return(ProcessValue(randNormal.ToString(CultureInfo.CurrentCulture))); } if (type == "uuid") { return(ProcessValue(Guid.NewGuid().ToString())); } if (type == "datetime") { int offset = rand.Next(lowerOffset, upperOffset); if (dtRelative && flt != null) { return(ProcessValue(flt.dateTime.AddMinutes(offset).AddMinutes(delta).ToString(format))); } else { return(ProcessValue(DateTime.Now.AddMinutes(offset).AddMinutes(delta).ToString(format))); } } if (type == "fixed") { return(ProcessValue(fixedValue)); } if (type == "timestamp") { return(ProcessValue(DateTime.Now.ToString(format))); } if (type == "value") { return(ProcessValue(values[rand.Next(0, values.Count)])); } if (type == "file") { if (seq >= listLength && abortOnListEnd) { throw new ArgumentException("Ran out of iteration data"); } return(ProcessValue(File.ReadAllText(fileEntries[seq++ % listLength]))); } if (type == "flightInfo") { if (flt == null) { return(""); } switch (sub) { case "airlineCode": return(ProcessValue(flt.airlineCode)); case "airlineCodeICAO": return(ProcessValue(flt.airlineCodeICAO)); case "fltNumber": return(ProcessValue(flt.fltNumber)); case "arrivalAirport": return(ProcessValue(flt.arrivalAirport)); case "departureAirport": return(ProcessValue(flt.departureAirport)); case "arrivalAirportICAO": return(ProcessValue(flt.arrivalAirportICAO)); case "departureAirportICAO": return(ProcessValue(flt.departureAirportICAO)); case "schedDate": return(ProcessValue(flt.schedDate)); case "schedTime": return(ProcessValue(flt.schedTime)); case "kind": return(ProcessValue(flt.nature)); case "xpath": return(ProcessValue(flt.GetXPath(xpath))); case "property": string v; try { v = flt.externals[externalName]; } catch (Exception) { v = null; } return(ProcessValue(v)); default: return(null); } } return(null); }
private string GetValue(FlightNode fl, List <Variable> vars = null) { if (vars == null) { return(GetValue(fl)); } subDict.TryGetValue("lowerLimit", out string ll); subDict.TryGetValue("upperLimit", out string ul); subDict.TryGetValue("normalInt", out string ni); subDict.TryGetValue("normalDouble", out string nd); if (ll != null) { string toke = ll.Substring(2); foreach (Variable v in vars) { if (v.token == toke) { try { lowerLimit = int.Parse(v.value); } catch (Exception) { lowerLimit = Int32.MinValue; } break; } } } if (ul != null) { string toke = ul.Substring(2); foreach (Variable v in vars) { if (v.token == toke) { try { upperLimit = int.Parse(v.value); } catch (Exception) { upperLimit = Int32.MaxValue; } break; } } } if (ni != null) { string toke = ni.Substring(2); foreach (Variable v in vars) { if (v.token == toke) { try { normalInt = int.Parse(v.value); } catch (Exception) { normalInt = 0; } break; } } } if (nd != null) { string toke = nd.Substring(2); foreach (Variable v in vars) { if (v.token == toke) { try { normalDouble = int.Parse(v.value); } catch (Exception) { normalDouble = 0.0; } break; } } } if (type == "intRange") { return(ProcessValue(rand.Next(lowerLimit, upperLimit).ToString())); } if (type == "intgaussian") { double u1 = 1.0 - rand.NextDouble(); //uniform(0,1] random doubles double u2 = 1.0 - rand.NextDouble(); double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2); //random normal(0,1) double randNormal = normalInt + stdDev * randStdNormal; //random normal(mean,stdDev^2) return(ProcessValue(Convert.ToInt32(randNormal).ToString())); } if (type == "doublegaussian") { double u1 = 1.0 - rand.NextDouble(); //uniform(0,1] random doubles double u2 = 1.0 - rand.NextDouble(); double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2); //random normal(0,1) double randNormal = normalDouble + stdDev * randStdNormal; //random normal(mean,stdDev^2) return(ProcessValue(randNormal.ToString(CultureInfo.CurrentCulture))); } return(null); }