Exemple #1
0
        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;
                }
            }
        }
Exemple #2
0
        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();
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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;
        }
Exemple #6
0
        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);
                }
            }
        }
Exemple #7
0
 public ApiDelete CreateDelete(EntitySchema entity, IEnumerable <string> ids)
 {
     return(new ApiDelete(this, entity, ids));
 }
Exemple #8
0
 public ApiDelete CreateDelete(EntitySchema entity)
 {
     return(new ApiDelete(this, entity, null));
 }
Exemple #9
0
 public ApiUpdate CreateUpdate(EntitySchema entity, RecordSet records)
 {
     return(new ApiUpdate(this, entity, records, ApiUpdateMode.Update));
 }
Exemple #10
0
 public ApiUpdate CreateUpdate(EntitySchema entity)
 {
     return(new ApiUpdate(this, entity, null, ApiUpdateMode.Update));
 }
Exemple #11
0
 public ApiQuery CreateQuery(EntitySchema entity)
 {
     return(new ApiQuery(this, entity));
 }