Пример #1
0
        private IApiRequest DeleteRequest(Datastore datastore)
        {
            IApiRequest request = ApiRequestFactory.Current.CreateRequest("POST", "delete_datastore", ApiToken);

            request.AddParam("handle", datastore.Handle);
            return(request);
        }
Пример #2
0
        private void ListDatastores(JObject response)
        {
            _token = response["token"].Value <string>();
            var dataStores = response["datastores"] as JArray;

            foreach (var datastore in dataStores)
            {
                Datastore store;
                string    dsid   = datastore["dsid"].Value <string>();
                string    handle = datastore["handle"].Value <string>();
                if (!_datastores.TryGetValue(dsid, out store))
                {
                    store = new Datastore(this, dsid, handle);
                    _datastores.Add(dsid, store);
                }
                if (datastore["info"] != null)
                {
                    var title = datastore["info"]["title"].Value <string>();
                    if (!string.IsNullOrEmpty(title))
                    {
                        store.Title = title;
                    }
                    var mtime = datastore["info"]["mtime"];
                    if (mtime != null)
                    {
                        store.Modified = (new DateTime(1970, 1, 1)).AddMilliseconds(mtime["T"].Value <Int64>());
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Delete a datastore and all its tables and data
        /// </summary>
        /// <param name="datastore">The datastore to delete</param>
        /// <returns>True if the deletion succeeds</returns>
        public bool Delete(Datastore datastore)
        {
            IApiRequest request  = DeleteRequest(datastore);
            ApiResponse response = request.GetResponse();

            return(DeleteResponse(datastore, response));
        }
Пример #4
0
        /// <summary>
        /// Delete a datastore and all its tables and data asynchronously
        /// </summary>
        /// <param name="datastore">The datastore to delete</param>
        /// <returns>True if the deletion succeeds</returns>
        public async Task <bool> DeleteAsync(Datastore datastore)
        {
            IApiRequest request  = DeleteRequest(datastore);
            ApiResponse response = await request.GetResponseAsync();

            return(DeleteResponse(datastore, response));
        }
Пример #5
0
        private Datastore GetResponse(string id, Datastore store, ApiResponse response)
        {
            if (response.StatusCode != 200)
            {
                throw new DatastoreException("Api call list_datastores returned status code " + response.StatusCode);
            }

            if (response.Body["notfound"] != null)
            {
                if (store != null)
                {
                    _datastores.Remove(id);
                }
                return(null);
            }

            if (store == null)
            {
                store = new Datastore(this, id, response.Body["handle"].Value <string>());
                _datastores.Add(id, store);
            }
            else
            {
                store           = new Datastore(this, id, response.Body["handle"].Value <string>());
                _datastores[id] = store;
            }
            return(store);
        }
Пример #6
0
 internal Table(DatastoreManager manager, Datastore store, string id)
 {
     Datastore       = store;
     Id              = id;
     _manager        = manager;
     _rows           = new Dictionary <string, Row>();
     _pendingChanges = new List <JArray>();
 }
Пример #7
0
        /// <summary>
        /// Loads a datastore from a previous snapshot. If this datastore manager already has a datastore with
        /// the same Id, loading a snapshot will replace the existing datastore state
        /// </summary>
        /// <param name="reader">A reader containing the snapshot data</param>
        /// <returns>The loaded datastore</returns>
        public Datastore Load(TextReader reader)
        {
            Datastore store = new Datastore(this, reader);

            if (_datastores.ContainsKey(store.Id))
            {
                _datastores[store.Id] = store;
            }
            else
            {
                _datastores.Add(store.Id, store);
            }
            return(store);
        }
Пример #8
0
        private bool DeleteResponse(Datastore datastore, ApiResponse response)
        {
            if (response.StatusCode != 200)
            {
                throw new DatastoreException("Api call create_datastore returned status code " + response.StatusCode);
            }

            if (response.Body["notfound"] != null)
            {
                throw new DatastoreException("Datastore with id " + datastore.Id + " not found");
            }

            _datastores.Remove(datastore.Id);
            return(response.Body["ok"] != null);
        }
Пример #9
0
        /// <summary>
        /// Delete a datastore and all its tables and data asynchronously
        /// </summary>
        /// <param name="datastore">The datastore to delete</param>
        /// <param name="success">Callback if the method is successful</param>
        /// <param name="failure">Callback if the method fails</param>
        public void DeleteAsync(Datastore datastore, Action <bool> success, Action <Exception> failure)
        {
            IApiRequest request = DeleteRequest(datastore);

            request.GetResponseAsync(response =>
            {
                try
                {
                    success(DeleteResponse(datastore, response));
                }
                catch (Exception ex)
                {
                    failure(ex);
                }
            });
        }
Пример #10
0
        private Datastore CreateResponse(string key, string id, ApiResponse response)
        {
            if (response.StatusCode != 200)
            {
                throw new DatastoreException("Api call create_datastore returned status code " + response.StatusCode);
            }

            if (response.Body["notfound"] != null)
            {
                throw new DatastoreException("Datastore with key " + key + " (id " + id + ") not found");
            }

            Datastore store = new Datastore(this, id, response.Body["handle"].Value <string>());

            _datastores.Add(id, store);
            return(store);
        }
Пример #11
0
        private Datastore GetOrCreateResponse(string id, Datastore store, ApiResponse response)
        {
            if (response.StatusCode != 200)
            {
                throw new DatastoreException("Api call get_or_create_datastore returned status code " + response.StatusCode);
            }

            if (store == null)
            {
                store = new Datastore(this, id, response.Body["handle"].Value <string>());
                _datastores.Add(id, store);
            }
            else
            {
                store           = new Datastore(this, id, response.Body["handle"].Value <string>());
                _datastores[id] = store;
            }
            return(store);
        }
Пример #12
0
 internal Transaction(Datastore store, TransactionDelegate actions)
 {
     _store   = store;
     _actions = actions;
 }