Example #1
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));
        }
Example #2
0
        /// <summary>
        /// Wait for up to a minute while checking for changes to the datastore list.
        /// </summary>
        /// <returns>If a change occurs during this time, returns True</returns>
        public bool AwaitListChanges()
        {
            IApiRequest request  = AwaitListChangesRequest();
            ApiResponse response = request.GetResponse();

            return(AwaitListChangesResponse(response));
        }
Example #3
0
        /// <summary>
        /// Push all pending changes to dropbox and apply them to the local datastore copy if the commit succeeds
        /// </summary>
        /// <returns>True if the changes are accepted without any errors or conflicts</returns>
        public bool Push()
        {
            IApiRequest request  = PushRequest();
            ApiResponse response = request.GetResponse();

            return(PushResponse(response));
        }
Example #4
0
        /// <summary>
        /// Wait for changes to this datastore from the server and apply them when(if) they arrive.
        /// This method will throw a DatastoreException if any local changes are pending
        /// </summary>
        /// <returns>True if changes were applied before the wait time elapsed</returns>
        public bool AwaitPull()
        {
            IApiRequest request  = AwaitPullRequest();
            ApiResponse response = request.GetResponse();

            return(AwaitPullResponse(response));
        }
Example #5
0
        /// <summary>
        /// Creates a new globally unique datastore
        /// </summary>
        /// <param name="key">Used to generate a hash that will comprise the created datastores dropbox id</param>
        /// <returns>A Tuple containing the id of the created datastore, and the datastore itself</returns>
        public KeyValuePair <string, Datastore> Create(string key)
        {
            string      id;
            IApiRequest request  = CreateRequest(key, out id);
            ApiResponse response = request.GetResponse();

            return(new KeyValuePair <string, Datastore>(id, CreateResponse(key, id, response)));
        }
Example #6
0
        /// <summary>
        /// Wait for up to a minute while checking for changes to any datastore. The list of datastores
        /// is defined by internally calling the <see cref="List" /> method
        /// </summary>
        /// <param name="changed">Adds every datastore which had a change during the waiting time</param>
        /// <returns>True if any changes were detected</returns>
        public bool AwaitDatastoreChanges(List <Datastore> changed)
        {
            var         datastores = List();
            IApiRequest request    = AwaitDatastoreChangesRequest(datastores);

            ApiResponse response = request.GetResponse();

            return(AwaitDatastoreChangesResponse(changed, datastores, response));
        }
Example #7
0
 /// <summary>
 /// List all dropbox datastores
 /// </summary>
 /// <param name="options">Whether to retrieve a locally cached version, or to recheck with dropbox</param>
 /// <returns>A list of all Dropbox datastores</returns>
 public IEnumerable <Datastore> List(DatastoreQueryOptions options = DatastoreQueryOptions.UseCached)
 {
     if (string.IsNullOrEmpty(_token) || options == DatastoreQueryOptions.ForceRefresh)
     {
         IApiRequest request  = ListRequest();
         var         response = request.GetResponse();
         ListResponse(response);
     }
     return(_datastores.Values);
 }
Example #8
0
        /// <summary>
        /// Gets a datastore if it already exists, otherwise it is created
        /// </summary>
        /// <param name="id">The Dropbox id of the datastore</param>
        /// <param name="options">Whether to retrieve a locally cached version, or to recheck with dropbox</param>
        /// <returns>The existing or newly created datastore</returns>
        public Datastore GetOrCreate(string id, DatastoreQueryOptions options = DatastoreQueryOptions.UseCached)
        {
            Datastore store;

            if (!_datastores.TryGetValue(id, out store) || options == DatastoreQueryOptions.ForceRefresh)
            {
                IApiRequest request  = GetOrCreateRequest(id);
                ApiResponse response = request.GetResponse();
                store = GetOrCreateResponse(id, store, response);
            }
            return(store);
        }
Example #9
0
        private void SendRequest(IApiRequest request)
        {
            Interlocked.Increment(ref ActiveRequests);

            Action send = () =>
            {
                request.GetResponse(() =>
                {
                    Interlocked.Decrement(ref ActiveRequests);
                    ProcessQueue();
                });
            };

            if (RespectBackoffs && BackoffUntil.ContainsKey(request.BackoffKey))
            {
                lock (BackoffUntil)
                {
                    if (BackoffUntil.ContainsKey(request.BackoffKey))
                    {
                        var until   = BackoffUntil[request.BackoffKey];
                        var seconds = (until - DateTime.Now).TotalSeconds;

                        if (seconds > 0)
                        {
                            var timer = new System.Timers.Timer(seconds * 1000);

                            timer.AutoReset = false;
                            timer.Elapsed  += (sender, e) => send();
                            timer.Start();
                        }
                        else
                        {
                            BackoffUntil.Remove(request.BackoffKey);
                            send();
                        }
                    }
                    else
                    {
                        send();
                    }
                }
            }
            else
            {
                send();
            }
        }
Example #10
0
        /// <summary>
        /// Pull all pending deltas (or get a new snapshot if this database hasn't been loaded before) and apply them.
        /// Will throw a DatastoreException if this method is called when any local changes are pending
        /// </summary>
        public void Pull()
        {
            foreach (var table in _tables)
            {
                if (table.Value.HasPendingChanges)
                {
                    throw new DatastoreException("Unable to pull in remote changes to Datastore with id " + Id + " as it has local changes pending");
                }
            }

            if (Rev == 0)
            {
                IApiRequest request  = GetSnapshotRequest();
                ApiResponse response = request.GetResponse();
                GetSnapshotResponse(response);
            }
            else
            {
                IApiRequest request  = GetDeltasRequest();
                ApiResponse response = request.GetResponse();
                GetDeltasResponse(response);
            }
        }