internal ResultSet(EntitySchema entity, JObject results) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } if (results == null) { throw new ArgumentNullException(nameof(results)); } Entity = entity; Reset(); HasMore = (bool)results["has_more"]; NextResult = (string)results["next_result"]; var resultArray = (JArray)results["result"]; var headers = (JArray)resultArray[0]; _fields = headers.Select(p => (EntityTypedField)entity.Members[(string)p]).ToList(); _fieldsByName = _fields.ToDictionary(p => p.Name, p => _fields.IndexOf(p)); _fieldsByField = _fields.ToDictionary(p => p, p => _fields.IndexOf(p)); _rows = new List <object[]>(resultArray.Count - 1); for (int i = 1; i < resultArray.Count; i++) { var resultRow = (JArray)resultArray[i]; var row = new object[resultRow.Count]; _rows.Add(row); for (int j = 0; j < resultRow.Count; j++) { var value = ((JValue)resultRow[j]).Value; switch (_fields[j].DataType) { case EntityDataType.Date: value = ApiUtils.ParseDate((string)value); break; case EntityDataType.DateTime: value = ApiUtils.ParseDateTime((string)value); break; case EntityDataType.DateTimeTz: value = ApiUtils.ParseDateTimeOffset((string)value); break; } row[j] = value; } } }
internal ApiUpdate(Api api, EntitySchema entity, RecordSet records, ApiUpdateMode mode) { if (api == null) { throw new ArgumentNullException(nameof(api)); } if (entity == null) { throw new ArgumentNullException(nameof(entity)); } _api = api; Entity = entity; Mode = mode; Records = records ?? new RecordSet(); }
public EntitySchema GetEntitySchema(string name) { if (name == null) { throw new ArgumentNullException(nameof(name)); } EntitySchema schema; if (!_entities.TryGetValue(name, out schema)) { schema = new EntitySchema(name, (JObject)ExecuteJson(name, "$meta", "GET", null)); _entities.Add(name, schema); } return(schema); }
public async Task <EntitySchema> GetEntitySchemaAsync(string name) { if (name == null) { throw new ArgumentNullException(nameof(name)); } EntitySchema schema; if (!_entities.TryGetValue(name, out schema)) { schema = new EntitySchema(name, (JObject)await ExecuteJsonAsync(name, "$meta", "GET", null)); _entities[name] = schema; } return(schema); }
internal ApiQuery(Api api, EntitySchema entity) { if (api == null) { throw new ArgumentNullException(nameof(api)); } if (entity == null) { throw new ArgumentNullException(nameof(entity)); } _api = api; Entity = entity; Filters = new FilterCollection(); Expand = new StringCollection(); Order = new QueryOrderCollection(); Output = OutputFormat.Compact; }
internal ApiDelete(Api api, EntitySchema entity, IEnumerable <string> ids) { if (api == null) { throw new ArgumentNullException(nameof(api)); } if (entity == null) { throw new ArgumentNullException(nameof(entity)); } _api = api; Entity = entity; Ids = new StringCollection(); if (ids != null) { foreach (string id in ids) { Ids.Add(id); } } }
public ApiDelete CreateDelete(EntitySchema entity, IEnumerable <string> ids) { return(new ApiDelete(this, entity, ids)); }
public ApiDelete CreateDelete(EntitySchema entity) { return(new ApiDelete(this, entity, null)); }
public ApiUpdate CreateUpdate(EntitySchema entity, RecordSet records) { return(new ApiUpdate(this, entity, records, ApiUpdateMode.Update)); }
public ApiUpdate CreateUpdate(EntitySchema entity) { return(new ApiUpdate(this, entity, null, ApiUpdateMode.Update)); }
public ApiQuery CreateQuery(EntitySchema entity) { return(new ApiQuery(this, entity)); }