Example #1
0
        private void GetInitFiles()
        {
            // curl "http://localhost:8080/rest/sync/changes?key=a06055a0-7605-4aee-9048-981aa6ef41a0&apiId=11111&rev=0"
            var request = newReq("/rest/sync/changes");

            SetUpRequest(request);
            request.AddParameter("rev", 0);

            var response = client.Execute<SyncList>(request);
            if (response.ResponseStatus == ResponseStatus.Completed)
            {
                SyncList list = response.Data;
                List<DiskItem> items = list.Items;

                Globals g = new Globals();
                g.Id = 1;
                g.CurrentRevision = list.LatestRevision;
                db.Insert(g);

                foreach (DiskItem i in items)
                {
                    db.Insert(i);
                }

                var queryWork = db.Table<Workspace>();
                var workspaces = queryWork.Cast<Workspace>().ToDictionary(o => o.Id, o => o);

                // Create all folders
                var toplevel = db.Query<DiskItem>("select * from DiskItem where FolderId = ? and Folder = ?", 0, true);

                foreach (var item in toplevel)
                {
                    Workspace w = workspaces[(int)item.WorkspaceId];
                    string path = Path.Combine(rootDir, w.Name, item.FileName);
                    System.IO.Directory.CreateDirectory(path);
                    //item.Path = path;
                    item.Path = item.FileName;
                    item.UpdatedOnDiskUTC = Directory.GetLastWriteTimeUtc(path);
                    item.CreatedOnDiskUTC = Directory.GetCreationTimeUtc(path);
                    db.Update(item);

                    createChildFolders(item, path);
                }

                //Download all files

                var files = db.Query<DiskItem>("select * from DiskItem where  Folder = ?", false);
                foreach (DiskItem f in files)
                {
                    DownLoadFile(f);
                }

            }
        }
Example #2
0
        private void CheckForChanges()
        {
            Globals global = null;
            try
            {
                global = db.Find<Globals>(1);
            }
            catch (SQLiteException e)
            {
            }
            if (global == null)
            {
                // this mean there was no files downloaded (as there is none on the account)
                global = new Globals();
                global.Id = 1;
                global.CurrentRevision = 0;
                db.Insert(global);
            }
            var request = newReq("/rest/sync/changes");

            SetUpRequest(request);
            request.AddParameter("rev", global.CurrentRevision);

            var response = client.Execute<SyncList>(request);
            if (response.ResponseStatus == ResponseStatus.Completed)
            {
                SyncList list = response.Data;
                List<DiskItem> items = list.Items;

                if (list.LatestRevision > global.CurrentRevision)
                {
                    global.CurrentRevision = list.LatestRevision;
                    db.Update(global);

                    foreach (DiskItem i in items)
                    {
                        if (DoesThisNeedUpdating(i))
                        {
                            switch (i.Action)
                            {
                                case "ADD":
                                    NewFileAdded(i);
                                    break;
                                case "DELETE":
                                    DeleteDiskItem(i);
                                    break;
                                case "UPDATED":
                                    UpdateDiskItem(i);
                                    break;
                                case "RENAME":
                                    DiskItemRenamed(i);
                                    break;
                            }
                        }
                    }
                }

            }
        }