本文整理汇总了C#中Newtonsoft.Json.Linq.JObject.SelectTokens方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.SelectTokens方法的具体用法?C# JObject.SelectTokens怎么用?C# JObject.SelectTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Linq.JObject
的用法示例。
在下文中一共展示了JObject.SelectTokens方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EvaluateWildcardProperty
public void EvaluateWildcardProperty()
{
JObject o = new JObject(
new JProperty("Blah", 1),
new JProperty("Blah2", 2));
IList<JToken> t = o.SelectTokens("$.*").ToList();
Assert.IsNotNull(t);
Assert.AreEqual(2, t.Count);
Assert.AreEqual(1, (int)t[0]);
Assert.AreEqual(2, (int)t[1]);
}
示例2: System
/// <summary>
/// Default constructor
/// </summary>
/// <param name="locale"></param>
public System(string locale = "en")
: base(locale)
{
mimes = this.GetObject("mimeTypes");
mimeKeys = mimes.Properties()
.Select(p => p.Name)
.Distinct()
.ToArray();
exts = mimes.SelectTokens("*.extensions.[*]")
.Select(x => x.ToString()).ToArray();
types = mimeKeys.Select(k => k.Substring(0, k.IndexOf('/')))
.Distinct()
.ToArray();
}
示例3: QueryAgainstNonStringValues
public void QueryAgainstNonStringValues()
{
IList<object> values = new List<object>
{
"ff2dc672-6e15-4aa2-afb0-18f4f69596ad",
new Guid("ff2dc672-6e15-4aa2-afb0-18f4f69596ad"),
"http://localhost",
new Uri("http://localhost"),
"2000-12-05T05:07:59Z",
new DateTime(2000, 12, 5, 5, 7, 59, DateTimeKind.Utc),
#if !NET20
"2000-12-05T05:07:59-10:00",
new DateTimeOffset(2000, 12, 5, 5, 7, 59, -TimeSpan.FromHours(10)),
#endif
"SGVsbG8gd29ybGQ=",
Encoding.UTF8.GetBytes("Hello world"),
"365.23:59:59",
new TimeSpan(365, 23, 59, 59)
};
JObject o = new JObject(
new JProperty("prop",
new JArray(
values.Select(v => new JObject(new JProperty("childProp", v)))
)
)
);
IList<JToken> t = o.SelectTokens("$.prop[?(@.childProp =='ff2dc672-6e15-4aa2-afb0-18f4f69596ad')]").ToList();
Assert.AreEqual(2, t.Count);
t = o.SelectTokens("$.prop[?(@.childProp =='http://localhost')]").ToList();
Assert.AreEqual(2, t.Count);
t = o.SelectTokens("$.prop[?(@.childProp =='2000-12-05T05:07:59Z')]").ToList();
Assert.AreEqual(2, t.Count);
#if !NET20
t = o.SelectTokens("$.prop[?(@.childProp =='2000-12-05T05:07:59-10:00')]").ToList();
Assert.AreEqual(2, t.Count);
#endif
t = o.SelectTokens("$.prop[?(@.childProp =='SGVsbG8gd29ybGQ=')]").ToList();
Assert.AreEqual(2, t.Count);
t = o.SelectTokens("$.prop[?(@.childProp =='365.23:59:59')]").ToList();
Assert.AreEqual(2, t.Count);
}
示例4: BetRequest
public static int BetRequest(JObject gameState)
{
//TODO: Use this method to return the value You want to bet
int currentBuyIn = (int)gameState.SelectToken("current_buy_in");
List<Card> resultCards = new List<Card>();
List<Card> communityCards = new List<Card>();
try
{
// Fetch player cards
IEnumerable<JToken> players = gameState.SelectTokens("players");
foreach(JToken playerToken in players)
{
IEnumerable<JToken> childrenTokens = playerToken.Children();
foreach(JToken child in childrenTokens)
{
string playerName = (string)child.SelectToken("name");
if (playerName == "Shoe People")
{
JToken holeCards = child.SelectToken("hole_cards");
foreach(JToken card in holeCards.Children())
{
string rank = (string)card.SelectToken("rank");
string suit = (string)card.SelectToken("suit");
Card resultCard = new Card();
resultCard.RankString = rank;
resultCard.SuitString = suit;
resultCard.Rank = resultCard.ToCardRank(resultCard.RankString);
resultCard.Suit = resultCard.ToCardSuit(resultCard.SuitString);
resultCard.getCardValue(resultCard);
resultCards.Add(resultCard);
}
}
}
}
// Fetch community cards
//JToken communityCards = gameState.SelectToken("community_cards");
//foreach(JToken card in communityCards.Children())
//{
// string rank = (string)card.SelectToken("rank");
// string suit = (string)card.SelectToken("suit");
// Card resultCard = new Card();
// resultCard.RankString = rank;
// resultCard.SuitString = suit;
// resultCard.Rank = resultCard.ToCardRank(resultCard.RankString);
// resultCard.Suit = resultCard.ToCardSuit(resultCard.SuitString);
// resultCard.getCardValue(resultCard);
// resultCards.Add(resultCard);
//}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
//Random r = new Random();
//return r.Next(300, 500);
int bet = currentBuyIn + currentBuyIn;
if (resultCards.Count == 2)
{
Card c1 = resultCards.First();
Card c2 = resultCards.Last();
int handIndex = getHandIndex(c1, c2);
Console.WriteLine(c1);
Console.WriteLine(c2);
Console.WriteLine("Hand index: " + handIndex);
if (handIndex >= 15) {
bet = currentBuyIn + currentBuyIn;
}else if (handIndex >= 8) {
bet = currentBuyIn + currentBuyIn / 2;
}else if (handIndex >= 6) {
bet = currentBuyIn;
}else{
bet = 0;
}
}
else
{
bet = currentBuyIn + currentBuyIn / 2;
}
Console.WriteLine("Bet: " + bet);
return bet;
}
示例5: SelectTokens
public override IEnumerable<JToken> SelectTokens(JObject entity)
{
return entity.SelectTokens(Path);
}
示例6: SendShipyardData
/// <summary>
/// send the shipyard data of this station
/// </summary>
/// <param name="stationData">json object with companion data</param>
public void SendShipyardData(JObject dataObject)
{
Int32 objectCount = 0;
Boolean writeToFile = false;
StreamWriter writer = null;
String debugFile = @"C:\temp\shipyard_ibe.csv";
SQL.Datasets.dsEliteDB.tbshipyardbaseDataTable baseData;
try
{
if(m_SenderIsActivated && m_lDBCon.getIniValue<Boolean>(IBE.EDDN.EDDNView.DB_GROUPNAME, "EDDNPostShipyardData", true.ToString(), false))
{
IBECompanion.CompanionConverter cmpConverter = new IBECompanion.CompanionConverter();
String systemName = dataObject.SelectToken("lastSystem.name").ToString();
String stationName = dataObject.SelectToken("lastStarport.name").ToString();
if((m_ID_of_Shipyard_Station.Item1 != systemName + "|" + stationName) || ((DateTime.Now - m_ID_of_Shipyard_Station.Item2).TotalMinutes >= 60))
{
StringBuilder shipyardStringEDDN = new StringBuilder();
shipyardStringEDDN.Append(String.Format("\"message\": {{"));
shipyardStringEDDN.Append(String.Format("\"systemName\":\"{0}\", ",dataObject.SelectToken("lastSystem.name").ToString()));
shipyardStringEDDN.Append(String.Format("\"stationName\":\"{0}\", ",dataObject.SelectToken("lastStarport.name").ToString()));
shipyardStringEDDN.Append(String.Format("\"timestamp\":\"{0}\", ", DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture)));
shipyardStringEDDN.Append(String.Format("\"ships\": ["));
if(writeToFile)
{
if(File.Exists(debugFile))
File.Delete(debugFile);
writer = new StreamWriter(File.OpenWrite(debugFile));
}
if(dataObject.SelectToken("lastStarport.ships", false) != null)
{
baseData = new SQL.Datasets.dsEliteDB.tbshipyardbaseDataTable();
m_lDBCon.Execute("select * from tbShipyardBase;", (System.Data.DataTable)baseData);
List<JToken> allShips = dataObject.SelectTokens("lastStarport.ships.shipyard_list.*").ToList();
allShips.AddRange(dataObject.SelectTokens("lastStarport.ships.unavailable_list.[*]").ToList());
foreach (JToken outfittingItem in allShips)
{
if(!String.IsNullOrWhiteSpace(outfittingItem.Value<String>("name")))
{
ShipyardObject shipyardItem = cmpConverter.GetShipFromFDevIDs(baseData, outfittingItem, false);
//ShipyardObject shipyardItem = cmpConverter.GetShipFromCompanion(outfittingItem, false);
if(writeToFile)
{
writer.WriteLine(String.Format("{0},{1},{2},{3}",
systemName, stationName, shipyardItem.Name,
DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture)));
}
shipyardStringEDDN.Append(String.Format("\"{0}\", ", outfittingItem.Value<String>("name")));
objectCount++;
}
}
shipyardStringEDDN.Remove(shipyardStringEDDN.Length-2, 2);
shipyardStringEDDN.Append("]}");
if(objectCount > 0)
{
_Send_Shipyard.Enqueue(shipyardStringEDDN);
_SendDelayTimer_Shipyard.Start();
m_ID_of_Shipyard_Station = new Tuple<String, DateTime>(systemName +"|" + stationName, DateTime.Now);
}
if(writeToFile)
{
writer.Close();
writer.Dispose();
}
}
}
}
}
catch (Exception ex)
{
throw new Exception("Error while extracting shipyard data for eddn", ex);
}
}
示例7: CreateOrderFromJObject
/// <summary>
/// Create an order from a simple JObject
/// </summary>
/// <param name="jObject"></param>
/// <returns>Order Object</returns>
public static Order CreateOrderFromJObject(JObject jObject)
{
// create order instance based on order type field
var orderType = (OrderType) jObject["Type"].Value<int>();
var order = CreateOrder(orderType, jObject);
// populate common order properties
order.Id = jObject["Id"].Value<int>();
order.Quantity = jObject["Quantity"].Value<int>();
order.Status = (OrderStatus) jObject["Status"].Value<int>();
order.Time = jObject["Time"].Value<DateTime>();
order.Tag = jObject["Tag"].Value<string>();
order.Quantity = jObject["Quantity"].Value<int>();
order.Price = jObject["Price"].Value<decimal>();
var securityType = (SecurityType) jObject["SecurityType"].Value<int>();
order.BrokerId = jObject["BrokerId"].Select(x => x.Value<string>()).ToList();
order.ContingentId = jObject["ContingentId"].Value<int>();
var market = Market.USA;
if (securityType == SecurityType.Forex) market = Market.FXCM;
if (jObject.SelectTokens("Symbol.ID").Any())
{
var sid = SecurityIdentifier.Parse(jObject.SelectTokens("Symbol.ID").Single().Value<string>());
var ticker = jObject.SelectTokens("Symbol.Value").Single().Value<string>();
order.Symbol = new Symbol(sid, ticker);
}
else if (jObject.SelectTokens("Symbol.Value").Any())
{
// provide for backwards compatibility
var ticker = jObject.SelectTokens("Symbol.Value").Single().Value<string>();
order.Symbol = Symbol.Create(ticker, securityType, market);
}
else
{
var tickerstring = jObject["Symbol"].Value<string>();
order.Symbol = Symbol.Create(tickerstring, securityType, market);
}
return order;
}
示例8: SendOutfittingData
/// <summary>
/// send the outfitting data of this station
/// </summary>
/// <param name="stationData">json object with companion data</param>
public void SendOutfittingData(JObject dataObject)
{
Int32 objectCount = 0;
Boolean writeToFile = false;
StreamWriter writer = null;
String debugFile = @"C:\temp\outfitting_ibe.csv";
SQL.Datasets.dsEliteDB.tboutfittingbaseDataTable baseData;
System.Text.RegularExpressions.Regex allowedPattern = new System.Text.RegularExpressions.Regex("(^Hpt_|^Int_|_Armour_)");
try
{
if(m_SenderIsActivated && m_lDBCon.getIniValue<Boolean>(IBE.EDDN.EDDNView.DB_GROUPNAME, "EDDNPostOutfittingData", true.ToString(), false))
{
IBECompanion.CompanionConverter cmpConverter = new IBECompanion.CompanionConverter();
String systemName = dataObject.SelectToken("lastSystem.name").ToString();
String stationName = dataObject.SelectToken("lastStarport.name").ToString();
if((m_ID_of_Outfitting_Station.Item1 != systemName + "|" + stationName) || ((DateTime.Now - m_ID_of_Outfitting_Station.Item2).TotalMinutes >= 60))
{
m_ID_of_Outfitting_Station = new Tuple<String, DateTime>(systemName +"|" + stationName, DateTime.Now);
StringBuilder outfittingStringEDDN = new StringBuilder();
outfittingStringEDDN.Append(String.Format("\"message\": {{"));
outfittingStringEDDN.Append(String.Format("\"systemName\":\"{0}\", " , dataObject.SelectToken("lastSystem.name").ToString()));
//outfittingStringEDDN.Append(String.Format("\"systemId\":\"{0}\", " , dataObject.SelectToken("lastSystem.id").ToString()));
//outfittingStringEDDN.Append(String.Format("\"systemAddress\":\"{0}\", " , dataObject.SelectToken("lastSystem.address").ToString()));
outfittingStringEDDN.Append(String.Format("\"stationName\":\"{0}\", " , dataObject.SelectToken("lastStarport.name").ToString()));
//outfittingStringEDDN.Append(String.Format("\"stationId\":\"{0}\", " , dataObject.SelectToken("lastStarport.id").ToString()));
outfittingStringEDDN.Append(String.Format("\"timestamp\":\"{0}\", ", DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture)));
outfittingStringEDDN.Append(String.Format("\"modules\": ["));
if(writeToFile)
{
if(File.Exists(debugFile))
File.Delete(debugFile);
writer = new StreamWriter(File.OpenWrite(debugFile));
}
baseData = new SQL.Datasets.dsEliteDB.tboutfittingbaseDataTable();
m_lDBCon.Execute("select * from tbOutfittingBase;", (System.Data.DataTable)baseData);
foreach (JToken outfittingItem in dataObject.SelectTokens("lastStarport.modules.*"))
{
if(allowedPattern.IsMatch(outfittingItem.Value<String>("name")) &&
((outfittingItem.Value<String>("sku") == null) || (outfittingItem.Value<String>("sku").Equals("ELITE_HORIZONS_V_PLANETARY_LANDINGS"))) &&
(!outfittingItem.Value<String>("name").Equals("Int_PlanetApproachSuite")))
{
OutfittingObject outfitting = cmpConverter.GetOutfittingFromFDevIDs(baseData, outfittingItem, false);
if(objectCount > 0)
outfittingStringEDDN.Append(", ");
if(writeToFile)
{
writer.WriteLine(String.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}",
systemName, stationName, outfitting.Category, outfitting.Name, outfitting.Mount,
outfitting.Guidance, outfitting.Ship, outfitting.Class, outfitting.Rating,
DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture)));
}
outfittingStringEDDN.Append(String.Format("\"{0}\", ", outfittingItem.Value<String>("name")));
outfittingStringEDDN.Remove(outfittingStringEDDN.Length-1, 1);
outfittingStringEDDN.Replace(",", "", outfittingStringEDDN.Length-1, 1);
objectCount++;
}
}
outfittingStringEDDN.Append("]}");
if(objectCount > 0)
{
_Send_Outfitting.Enqueue(outfittingStringEDDN);
_SendDelayTimer_Outfitting.Start();
m_ID_of_Outfitting_Station = new Tuple<String, DateTime>(systemName +"|" + stationName, DateTime.Now);
}
if(writeToFile)
{
writer.Close();
writer.Dispose();
}
}
}
}
catch (Exception ex)
//.........这里部分代码省略.........
示例9: SendCommodityData
/// <summary>
/// send the commodity data of this station
/// </summary>
/// <param name="stationData">json object with companion data</param>
public void SendCommodityData(JObject dataObject)
{
Int32 objectCount = 0;
Boolean writeToFile = false;
StreamWriter writer = null;
String debugFile = @"C:\temp\commodity_ibe.csv";
SQL.Datasets.dsEliteDB.tbcommoditybaseDataTable baseData;
try
{
if(m_SenderIsActivated &&
m_lDBCon.getIniValue<Boolean>(IBE.EDDN.EDDNView.DB_GROUPNAME, "EDDNPostCompanionData", true.ToString(), false))
{
IBECompanion.CompanionConverter cmpConverter = new IBECompanion.CompanionConverter();
String systemName = dataObject.SelectToken("lastSystem.name").ToString();
String stationName = dataObject.SelectToken("lastStarport.name").ToString();
if((m_ID_of_Commodity_Station.Item1 != systemName + "|" + stationName) || ((DateTime.Now - m_ID_of_Commodity_Station.Item2).TotalMinutes >= 60))
{
m_ID_of_Commodity_Station = new Tuple<String, DateTime>(systemName +"|" + stationName, DateTime.Now);
StringBuilder commodityStringEDDN = new StringBuilder();
commodityStringEDDN.Append(String.Format("\"message\": {{"));
commodityStringEDDN.Append(String.Format("\"systemName\":\"{0}\", " , dataObject.SelectToken("lastSystem.name").ToString()));
//commodityStringEDDN.Append(String.Format("\"systemId\":\"{0}\", " , dataObject.SelectToken("lastSystem.id").ToString()));
//commodityStringEDDN.Append(String.Format("\"systemAddress\":\"{0}\", " , dataObject.SelectToken("lastSystem.address").ToString()));
commodityStringEDDN.Append(String.Format("\"stationName\":\"{0}\", " , dataObject.SelectToken("lastStarport.name").ToString()));
//commodityStringEDDN.Append(String.Format("\"stationId\":\"{0}\", " , dataObject.SelectToken("lastStarport.id").ToString()));
commodityStringEDDN.Append(String.Format("\"timestamp\":\"{0}\", ", DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture)));
commodityStringEDDN.Append(String.Format("\"commodities\": ["));
if(writeToFile)
{
if(File.Exists(debugFile))
File.Delete(debugFile);
writer = new StreamWriter(File.OpenWrite(debugFile));
}
baseData = new SQL.Datasets.dsEliteDB.tbcommoditybaseDataTable();
m_lDBCon.Execute("select * from tbcommodityBase;", (System.Data.DataTable)baseData);
foreach (JToken commodityItem in dataObject.SelectTokens("lastStarport.commodities[*]"))
{
if(!commodityItem.Value<String>("categoryname").Equals("NonMarketable", StringComparison.InvariantCultureIgnoreCase))
{
CommodityObject commodity = cmpConverter.GetCommodityFromFDevIDs(baseData, commodityItem, false);
//commodityObject commodity = cmpConverter.GetcommodityFromCompanion(commodityItem, false);
int? dbValue = String.IsNullOrWhiteSpace(commodityItem.Value<String>("demandBracket")) ? null : commodityItem.Value<int?>("demandBracket");
if((commodity != null) && (dbValue.HasValue))
{
if (objectCount > 0)
commodityStringEDDN.Append(", {");
else
commodityStringEDDN.Append("{");
if(writeToFile)
{
writer.WriteLine(String.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}",
systemName, stationName, commodity.Id, commodity.Name, commodity.Category, commodity.Average,
DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture)));
}
commodityStringEDDN.Append(String.Format("\"name\":\"{0}\", ", commodityItem.Value<String>("name")));
//commodityStringEDDN.Append(String.Format("\"id\":\"{0}\", ", commodity.Id));
commodityStringEDDN.Append(String.Format("\"meanPrice\":{0}, ", commodityItem.Value<Int32>("meanPrice")));
commodityStringEDDN.Append(String.Format("\"buyPrice\":{0}, ", commodityItem.Value<Int32>("buyPrice")));
commodityStringEDDN.Append(String.Format("\"sellPrice\":{0}, ", commodityItem.Value<Int32>("sellPrice")));
commodityStringEDDN.Append(String.Format("\"demandBracket\":{0}, ", commodityItem.Value<int?>("demandBracket")));
if (commodityItem.Value<int?>("demandBracket") == 0)
commodityStringEDDN.Append(String.Format("\"demand\":{0}, ", 0));
else
commodityStringEDDN.Append(String.Format("\"demand\":{0}, ", commodityItem.Value<Int32>("demand")));
commodityStringEDDN.Append(String.Format("\"stockBracket\":{0}, ", commodityItem.Value<int?>("stockBracket")));
if (commodityItem.Value<int?>("stockBracket") == 0)
commodityStringEDDN.Append(String.Format("\"stock\":{0}, ", 0));
else
commodityStringEDDN.Append(String.Format("\"stock\":{0}, ", commodityItem.Value<Int32>("demand")));
//.........这里部分代码省略.........
示例10: ConvertCommodityV3_To_CSVRows
private String[] ConvertCommodityV3_To_CSVRows(JObject commodityV3Data)
{
String system;
String starPort;
Int32 commodityCount = 0;
List<String> csvStrings = new List<string>();
try
{
system = commodityV3Data["message"]["systemName"].ToString();
starPort = commodityV3Data["message"]["stationName"].ToString();
foreach (Newtonsoft.Json.Linq.JToken commodity in commodityV3Data.SelectTokens("message.commodities[*]"))
{
CsvRow csvData = new CsvRow();
csvData.SystemName = system;
csvData.StationName = starPort;
csvData.StationID = String.Format("{0} [{1}]", starPort, system);
csvData.CommodityName = commodity.Value<String>("name");
csvData.SellPrice = commodity.Value<Int32>("sellPrice");
csvData.BuyPrice = commodity.Value<Int32>("buyPrice");
csvData.Demand = commodity.Value<Int32>("demand");
csvData.Supply = commodity.Value<Int32>("stock");
csvData.SampleDate = DateTime.Now;
if((!String.IsNullOrEmpty(commodity.Value<String>("demandBracket"))) && (commodity.Value<Int32>("demandBracket") > 0))
csvData.DemandLevel = (String)Program.Data.BaseTableIDToName("economylevel", commodity.Value<Int32>("demandBracket") - 1, "level");
else
csvData.DemandLevel = null;
if((!String.IsNullOrEmpty(commodity.Value<String>("stockBracket"))) && (commodity.Value<Int32>("stockBracket") > 0))
csvData.SupplyLevel = (String)Program.Data.BaseTableIDToName("economylevel", commodity.Value<Int32>("stockBracket") - 1, "level");
else
csvData.SupplyLevel = null;
csvData.SourceFileName = "";
csvData.DataSource = "";
csvStrings.Add(csvData.ToString());
commodityCount++;
}
return csvStrings.ToArray();
}
catch (Exception ex)
{
throw new Exception("Error while converting commodity v3 data to csv rows", ex);
}
}
示例11: SendJournalData
/// <summary>
/// send the journal data
/// </summary>
/// <param name="stationData">json object with journal data</param>
public void SendJournalData(JObject dataObject)
{
try
{
if(m_SenderIsActivated && m_lDBCon.getIniValue<Boolean>(IBE.EDDN.EDDNView.DB_GROUPNAME, "EDDNPostJournalData", true.ToString(), false))
{
StringBuilder journalStringEDDN = new StringBuilder();
journalStringEDDN.Append(String.Format("\"message\": {{"));
journalStringEDDN.Append(String.Format("\"timestamp\":\"{0}Z\", ", DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture)));
journalStringEDDN.Append(String.Format("\"event\":\"{0}\", ", dataObject.SelectToken("event").ToString()));
if(dataObject.SelectToken("StarSystem") == null)
journalStringEDDN.Append(String.Format("\"StarSystem\":\"{0}\", ", Program.actualCondition.System));
else
journalStringEDDN.Append(String.Format("\"StarSystem\":\"{0}\", ", dataObject.SelectToken("StarSystem").ToString()));
if(dataObject.SelectToken("StarPos") == null)
journalStringEDDN.Append(String.Format("\"StarPos\":[{0},{1},{2}], ", SQL.DBConnector.SQLDecimal(Program.actualCondition.Coordinates.X.Value), SQL.DBConnector.SQLDecimal(Program.actualCondition.Coordinates.Y.Value), SQL.DBConnector.SQLDecimal(Program.actualCondition.Coordinates.Z.Value)));
else
journalStringEDDN.Append(String.Format("\"StarPos\":{0}, ", dataObject.SelectToken("StarPos")));
System.Text.RegularExpressions.Regex forbiddenPattern = new System.Text.RegularExpressions.Regex("(CockpitBreach|BoostUsed|FuelLevel|FuelUsed|JumpDist|_Localised$|timestamp|event|StarSystem|StarPos)");
List<String> typeList = new List<String>() { "array", "boolean", "integer", "float", "double", "object", "string" };
foreach (JToken dataItem in dataObject.SelectTokens("*"))
{
if(!forbiddenPattern.IsMatch(dataItem.Path))
{
if(typeList.Contains(dataItem.Type.ToString().ToLower()))
{
Debug.Print("allowed : " + dataItem.Path + "(" + dataItem.Type.ToString() + ")");
switch (dataItem.Type.ToString().ToLower())
{
case "string":
journalStringEDDN.Append(String.Format("\"{0}\":\"{1}\", ", dataItem.Path, dataItem));
break;
case "float":
case "double":
journalStringEDDN.Append(String.Format("\"{0}\":{1}, ", dataItem.Path, SQL.DBConnector.SQLDecimal((double)dataItem)));
break;
case "boolean":
journalStringEDDN.Append(String.Format("\"{0}\":{1}, ", dataItem.Path, dataItem.ToString().ToLower()));
break;
default:
journalStringEDDN.Append(String.Format("\"{0}\":{1}, ", dataItem.Path, dataItem));
break;
}
}
else
Debug.Print("disallowed : " + dataItem.Path + "(" + dataItem.Type.ToString() + ")");
}
else
Debug.Print("disallowed : " + dataItem.Path);
}
journalStringEDDN.Remove(journalStringEDDN.Length-2, 2);
journalStringEDDN.Append("}");
_Send_Journal.Enqueue(journalStringEDDN);
_SendDelayTimer_Journal.Start();
}
}
catch (Exception ex)
{
throw new Exception("Error while extracting journal data for eddn", ex);
}
}
示例12: ApplyTo
internal IEnumerable<JToken> ApplyTo(JObject result)
{
return result.SelectTokens(RawValue);
}