コード例 #1
0
        public bool EqualForGC(DiskItem other)
        {
            if (other == null) return false;

            if (this.Id == other.Id &&
                this.Created == other.Created &&
                this.Updated == other.Updated &&
                this.FileName == other.FileName &&
                this.Size == other.Size &&
                this.Version == other.Version &&
                this.FolderId == other.FolderId &&
                this.Action == other.Action &&
                this.WorkspaceId == other.WorkspaceId &&
                this.Folder == other.Folder )
            {
                return true;
            }

            return false;
        }
コード例 #2
0
        public bool EqualForGC(DiskItem other)
        {
            if (other == null)
            {
                return(false);
            }

            if (this.Id == other.Id &&
                this.Created == other.Created &&
                this.Updated == other.Updated &&
                this.FileName == other.FileName &&
                this.Size == other.Size &&
                this.Version == other.Version &&
                this.FolderId == other.FolderId &&
                this.Action == other.Action &&
                this.WorkspaceId == other.WorkspaceId &&
                this.Folder == other.Folder)
            {
                return(true);
            }

            return(false);
        }
コード例 #3
0
ファイル: GCActionConsumer.cs プロジェクト: wjpp/Sync1
        private void DoNew(GCAction action)
        {
            //Does it still exist?
            if (!FileOrDirectoryExists(action.Path)) return; // can happen when creating a new folder that immediately gets a different name

            if (ThisIsFromMe(action))
            {
                return;
            }

            RestRequest request;
            FileAttributes attr = File.GetAttributes(action.Path);
            if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
            {
                request = newReq("/rest/sync/newFolder", Method.GET);
            }
            else
            {
                request = newReq("/rest/sync/new", Method.POST);
            }

            SetUpRequest(request);
            request.AddHeader("Content-Type", "multipart/form-data");

            request.AddParameter("apiId", apiId, ParameterType.QueryString);
            request.AddParameter("key", key, ParameterType.QueryString);

            DiskItem i = new DiskItem();
            Object o = FindParentDiskItem(action);
            if (o == null)
            {
                Console.Error.Write("Unknown parent DIR cannot sync ?", action.Path);
                return;
            }
            if (o is Workspace)
            {
                request.AddParameter("workspaceId", ((Workspace)o).Id, ParameterType.QueryString);
                i.WorkspaceId = ((Workspace)o).Id;
            } else if (o is DiskItem)
            {
                DiskItem f = (DiskItem)o;
                request.AddParameter("workspaceId", f.WorkspaceId, ParameterType.QueryString);
                request.AddParameter("folderId", f.Id, ParameterType.QueryString);
                i.FolderId = f.Id;
                i.WorkspaceId = f.WorkspaceId;
            }

            if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
            {
                request.AddParameter("folderName", Path.GetFileName(action.Path), ParameterType.QueryString);
                i.Folder = true;
            }
            else
            {
                request.AddFile("file", action.Path);
            }

            var response = client.Execute<NewFileMeta>(request);
            if (response.ResponseStatus == ResponseStatus.Completed)
            {
                NewFileMeta meta = response.Data;
                if (meta.success)
                {
                    // insert new DiskItem

                    i.Id = (long)meta.docId;
                    i.FileName = Path.GetFileName(action.Path);
                    i.Action = "ADD";
                    i.Created = meta.created;
                    i.Path = Path.GetFileName(action.Path);
                    if (!i.Folder)
                    {
                        FileInfo info = new FileInfo(action.Path);
                        i.Size = info.Length;
                    }
                    i.Version = 1;
                    db.Insert(i);
                }
            }
        }
コード例 #4
0
ファイル: DownloadMonitor.cs プロジェクト: wjpp/Sync1
 private void UpdateDiskItem(DiskItem i)
 {
     DiskItem original = db.Find<DiskItem>(i.Id);
     DeleteDiskItem(original);
     NewFileAdded(i);
 }
コード例 #5
0
ファイル: DownloadMonitor.cs プロジェクト: wjpp/Sync1
        private string GetRootPath(DiskItem f, string path)
        {
            if (f.FolderId > 0)
            {
                DiskItem parent = db.Find<DiskItem>(f.FolderId);
                return GetRootPath(parent, Path.Combine(parent.Path, path));
            }

            Workspace w = db.Find<Workspace>(f.WorkspaceId);
            path = Path.Combine(rootDir, w.Name,  path);

            return path;
        }
コード例 #6
0
ファイル: DownloadMonitor.cs プロジェクト: wjpp/Sync1
        private void NewFileAdded(DiskItem i)
        {
            i.Updated = DateTime.Now;
            if (i.Folder)
            {
                string newPath = Path.Combine(GetRootPath(i), i.FileName);
                System.IO.Directory.CreateDirectory(newPath);
                // i.Path = newPath;
                i.Path = i.FileName;
                i.CreatedOnDiskUTC = Directory.GetCreationTimeUtc(newPath);
                i.UpdatedOnDiskUTC = Directory.GetLastAccessTimeUtc(newPath);

                db.Insert(i);

            }
            else
            {
                db.Insert(i);
                DownLoadFile(i);
            }
        }
コード例 #7
0
ファイル: DownloadMonitor.cs プロジェクト: wjpp/Sync1
        private void DownLoadFile(DiskItem f)
        {
            var path = GetRootPath(f);
            var fullpath = Path.Combine(path, f.FileName);

            // conflict?
            if (File.Exists(fullpath))
            {
                bool conflict = true;
                int count = 1;
                while (conflict)
                {
                    string name = Path.GetFileNameWithoutExtension(f.FileName);
                    name = name + "(" + count + ")" + Path.GetExtension(f.FileName);
                    if (File.Exists(Path.Combine(path, name)))
                    {
                        count++;
                    }
                    else
                    {
                        fullpath = Path.Combine(path, name);
                        conflict = false;
                        f.FileName = name;
                    }
                }
            }

            // f.Path = fullpath;
            f.Path = f.FileName;

            db.Update(f);

            using (var client = new WebClient())
            {
                string url = server + "rest/sync/get?key=" + key + "&apiId=" + apiId + "&docId=" + f.Id;
                try {
                    client.DownloadFile(url, fullpath);
                    var length = new System.IO.FileInfo(fullpath).Length;
                    f.Size = length;
                    f.Updated = DateTime.Now;
                    f.UpdatedOnDiskUTC = File.GetLastWriteTimeUtc(fullpath);
                    f.CreatedOnDiskUTC = File.GetCreationTimeUtc(fullpath);
                    db.Update(f);
                }
                catch(WebException e)
                {
                    Console.Error.Write("Problem connecting to Glasscubes");
                    Console.Error.Write(e);
                }
            }
        }
コード例 #8
0
ファイル: DownloadMonitor.cs プロジェクト: wjpp/Sync1
        private bool DoesThisNeedUpdating(DiskItem i)
        {
            DiskItem di = db.Find<DiskItem>(i.Id);
            if (di == null)
            {
                return true;
            }

            switch (i.Action)
            {
                case "ADD":
                    return false;
                case "DELETE":
                    return true;
                case "UPDATED":
                    if (di.Updated != i.Updated ||
                      di.FileName != i.FileName ||
                      di.Version != i.Version ||
                      di.Size != i.Size)
                    {
                        return true;
                    }
                    return false;
                case "RENAME":
                    if (di.FileName != i.FileName)
                    {
                        return true;
                    }
                    return false;
            }

            return true;
        }
コード例 #9
0
ファイル: DownloadMonitor.cs プロジェクト: wjpp/Sync1
        private void DiskItemRenamed(DiskItem i)
        {
            try
            {
                DiskItem orig = db.Find<DiskItem>(i.Id);
                string root = GetRootPath(orig);
                string newFullPath = Path.Combine(root, i.FileName);
                if (i.Folder)
                {
                    Directory.Move(Path.Combine(root, orig.FileName), newFullPath);
                }
                else
                {
                    File.Move(Path.Combine(root, orig.FileName), newFullPath);
                }
                //i.Path = Path.Combine(root, i.FileName).ToString();
                i.Path = i.FileName;

                DateTime now = DateTime.Now;
                i.Updated = now;

                if (i.Folder)
                {
                    Directory.SetLastWriteTime(newFullPath, now);
                    i.UpdatedOnDiskUTC = Directory.GetLastWriteTimeUtc(newFullPath);
                }
                else
                {
                    File.SetLastWriteTime(newFullPath, now);
                    i.UpdatedOnDiskUTC = File.GetLastWriteTimeUtc(newFullPath);
                }
                db.Update(i);
            }
            catch (SQLiteException e)
            {
                //TODO
            }
        }
コード例 #10
0
ファイル: DownloadMonitor.cs プロジェクト: wjpp/Sync1
 private void DeleteDiskItem(DiskItem i)
 {
     db.Delete(i);
     var path = Path.Combine(GetRootPath(i), i.FileName);
     if (File.Exists(path) && !i.Folder)
     {
         File.Delete(path);
     }
     if (Directory.Exists(path) && i.Folder)
     {
         Directory.Delete(path, true);
     }
 }
コード例 #11
0
ファイル: DownloadMonitor.cs プロジェクト: wjpp/Sync1
        private void createChildFolders(DiskItem item, string path)
        {
            var folders = db.Query<DiskItem>("select * from DiskItem where FolderId = ? and Folder = ?", item.Id, true);
            foreach (var f in folders)
            {
                string newPath = Path.Combine(path, f.FileName);
                System.IO.Directory.CreateDirectory(newPath);
                //f.Path = newPath;
                f.Path = f.FileName;
                f.Updated = DateTime.Now;
                f.UpdatedOnDiskUTC = Directory.GetLastWriteTimeUtc(newPath);
                f.CreatedOnDiskUTC = Directory.GetCreationTimeUtc(newPath);
                db.Update(f);

                createChildFolders(f, newPath);
            }
        }