private ConditionConfig extractTerminalConditions(string conditionTypeStr, JsonAccessor terminalConditonNode) { string conditionFeild = ""; List <Pair> arguments = new List <Pair>(); foreach (var field in terminalConditonNode) // NOTE: only one element exist { conditionFeild = field.Get <string>(); var fieldArguments = terminalConditonNode[conditionFeild].Get <System.Object>(); if (fieldArguments is IDictionary) // "range": {"status": {"lte": 1} { IDictionary argumentMap = (IDictionary)fieldArguments; foreach (var argumentKey in argumentMap.Keys) { string keyString = (string)argumentKey; System.Object argValue = argumentMap[keyString]; arguments.Add(new Pair(keyString, argValue)); } } else if (fieldArguments is string) // {"term": {"status": "happy"}} { arguments.Add(new Pair((string)fieldArguments, null)); } } return(new ConditionConfig(conditionTypeStr, conditionFeild, arguments)); }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { var jsonProperty = base.CreateProperty(member, memberSerialization); var accessor = JsonAccessor.Create(member); var jsonIgnoreAttribute = member.GetCustomAttribute <JsonIgnoreAttribute>(); if (jsonIgnoreAttribute != null) { jsonProperty.Ignored = true; return(jsonProperty); } var jsonPropertyAttribute = member.GetCustomAttribute <JsonPropertyAttribute>(); if (jsonPropertyAttribute == null) { jsonProperty.Ignored = true; return(jsonProperty); } jsonProperty.PropertyName = jsonPropertyAttribute.Name; jsonProperty.NullValueHandling = (Newtonsoft.Json.NullValueHandling?)jsonPropertyAttribute.NullValueHandling; if (jsonProperty.PropertyType.IsGenericType && typeof(IOptional).IsAssignableFrom(jsonProperty.PropertyType)) { jsonProperty.ShouldSerialize = instance => ((IOptional)accessor.GetValue(instance)).HasValue; jsonProperty.Converter = GetOptionalConverter(accessor); } else { jsonProperty.Converter = GetConverter(accessor.Type) ?? jsonProperty.Converter; } return(jsonProperty); }
private void extractResponders(ConfigurationBuilder builder, JsonAccessor json) { foreach (var responderName in json["responders"]) { var targetName = responderName.Get <string>(); var targetResponders = json["responders"][targetName]; foreach (var responder in targetResponders) { var values = new List <string>(); foreach (var respond in responder["responds"]) { values.Add(respond.Get <string>()); } if (responder.Contains <string>("condition")) { ConditionConfig condition = this.extractCondtion(responder["condition"]); builder.AddResponds(targetName, values, new List <ConditionConfig>() { condition }); } else { builder.AddResponds(targetName, values, new List <ConditionConfig>()); } } } }
public void GetRecordsByArea(string name) { JsonAccessor accessor = new JsonAccessor(new ConnectionString()); foreach (var record in accessor.GetRecordsByArea(name)) { Console.WriteLine(record); } }
public async Task <string> GetGeoJsonByName(string name) { NameValueCollection query = new NameValueCollection(); query.Add("q", name); query.Add("format", "json"); query.Add("polygon_geojson", "1"); Uri uri = new Uri(this.GeoCoderURL); UriBuilder builder = new UriBuilder(this.GeoCoderURL); builder.Query = String.Join("&", query.AllKeys.Select(a => a + "=" + HttpUtility.UrlEncode(query[a], Encoding.UTF8))); return(await JsonAccessor.Download(builder.ToString())); }
private static void extractIntents(ConfigurationBuilder builder, JsonAccessor json) { foreach (var intent in json["intents"]) { var name = intent["name"].Get <string>(); var type = intent["match"]["type"].Get <string>(); var expressions = new List <string>(); IDictionary <string, string> slots = new Dictionary <string, string>(); foreach (var expression in intent["match"]["expressions"]) { expressions.Add(expression.Get <string>()); } if (intent["match"].Contains <string>("slots")) { foreach (var slot in intent["match"]["slots"]) { slots.Add(slot["name"].Get <string>(), slot["type"].Get <string>()); } } builder.AddIntent(name, type, expressions, slots); // handle optional effects if (intent.Contains <string>("effects")) { foreach (var effect in intent["effects"]) { var targetField = effect["field"].Get <string>(); var effectType = effect["type"].Get <string>(); object defaultValue = null; if (effect.Contains <string>("default")) { defaultValue = effect["default"].Get <object>(); } object setValue = null; if (effect.Contains <string>("value")) { setValue = effect["value"].Get <object>(); } string referField = null; { referField = effect["refer"].Get <string>(); } builder.AddEffect(targetField, effectType, defaultValue, setValue, referField); } } } }
private void DispatchDriver(SettingsDriver driver) { if (driver == SettingsDriver.Ini) { Accessor = new IniAccessor(); } else if (driver == SettingsDriver.Json) { Accessor = new JsonAccessor(); } else { Accessor = new BaseAcessor(); } }
public Configuration loadFromString(string jsonText) { var builder = new ConfigurationBuilder(); Debug.Log("loading configuration string" + jsonText); JsonAccessor json = JsonAccessor.Parse(jsonText); Debug.Log("Succeeded to parse given json"); Debug.Log(json); extractIntents(builder, json); extractTypes(builder, json); extractResponders(builder, json); return(builder.Build()); }
private ConditionConfig extractCondtion(JsonAccessor conditionNode) { foreach (var conditionType in conditionNode) { string conditionTypeStr = conditionType.Get <string>(); if (conditionTypeStr == "must" || conditionTypeStr == "should") // intermidiate node { return(new ConditionConfig(conditionTypeStr, this.extractChildCondtions(conditionNode[conditionType.Get <string>()]))); } else // terminal node { return(this.extractTerminalConditions(conditionTypeStr, conditionNode[conditionTypeStr])); } } throw new InvalidOperationException("No conditon is specified..."); }
private static void extractTypes(ConfigurationBuilder builder, JsonAccessor json) { if (!json.Contains <string>("types")) { return; } // extract types foreach (var type in json["types"]) { Debug.Log("come to types block"); var name = type["name"].Get <string>(); var values = new List <string>(); foreach (var value in type["values"]) { values.Add(value.Get <string>()); } builder.AddType(name, values); } }
private List <ConditionConfig> extractChildCondtions(JsonAccessor childConditionListNodes) { List <ConditionConfig> childConditions = new List <ConditionConfig>(); foreach (var conditionNode in childConditionListNodes) { foreach (var conditionType in conditionNode) { string conditionTypeStr = conditionType.Get <string>(); if (conditionTypeStr == "must" || conditionTypeStr == "should") // intermidiate node { childConditions.Add(new ConditionConfig(conditionTypeStr, this.extractChildCondtions(conditionNode[conditionTypeStr]))); } else // terminal node { childConditions.Add(this.extractTerminalConditions(conditionTypeStr, conditionNode[conditionTypeStr])); } } } return(childConditions); }
void onMaintenanceMessage(object message) { if (encoding_ == FunEncoding.kJson) { JsonAccessor json_helper = FunapiMessage.JsonHelper; FunDebug.Log("Maintenance message\nstart: {0}\nend: {1}\nmessage: {2}", json_helper.GetStringField(message, "date_start"), json_helper.GetStringField(message, "date_end"), json_helper.GetStringField(message, "messages")); } else if (encoding_ == FunEncoding.kProtobuf) { FunMessage msg = message as FunMessage; object obj = FunapiMessage.GetMessage(msg, MessageType.pbuf_maintenance); if (obj == null) { return; } MaintenanceMessage maintenance = obj as MaintenanceMessage; FunDebug.Log("Maintenance message\nstart: {0}\nend: {1}\nmessage: {2}", maintenance.date_start, maintenance.date_end, maintenance.messages); } }
//HTMLでいじれるようにする #if UNITY_EDITOR public void Save() { JsonAccessor.SaveFile("Master/mst_quest.json", Quest); }
public void Init() { Quest = JsonAccessor.ReadFile <MstQuestData>("Master/mst_quest.json"); }
public static T Load <T>(string path) where T : new() { return(JsonAccessor.ReadFile <T>(path)); }
private OptionalConverter GetOptionalConverter(JsonAccessor accessor) { var optionalType = accessor.Type.GenericTypeArguments[0]; return(_optionalConverters.GetOrAdd(optionalType, (x, @this) => OptionalConverter.Create(@this.GetConverter(x)), this)); }