public KfsFileDownload(KfsShare s, UInt64 orderID, String lastFullPath, KfsServerFileVersion version, bool openFlag) : base(s, orderID, lastFullPath) { Version = version; OpenWhenDownloadedFlag = openFlag; }
public override void ApplyOnServerView() { KfsServerFileUploader u = GetUploader(); // Process the uploaded files. foreach (KfsServerPhase2File f in UploadArray) { KfsServerFile g = u.FileTree[f.Inode]; Debug.Assert(g.Inode == f.Inode); Debug.Assert(g.UploaderSet.Contains(u)); // Create a new file version. KfsServerFileVersion v = new KfsServerFileVersion(); v.Inode = f.Inode; v.CommitID = CommitID; v.UserID = UserID; v.Date = Date; v.Size = f.Size; v.Hash = f.Hash; // This version is more recent than the last uploaded version. if (g.CurrentVersion == null || g.CurrentVersion.CommitID < CommitID) g.CurrentVersion = v; // If this is the first upload, force an update to check the hash // of the local file against this version. if (g.PersistentLocalStatus == LocalStatus.None) g.RequestUpdate(); // If the local file appears to be modified, check if the hash of // the new version matches the hash of the local file. If so, // update the downloaded version and force the update of the // current local status. else if (g.PersistentLocalStatus == LocalStatus.Modified) { if (Base.ByteArrayEqual(g.LocalHash, v.Hash)) { g.DownloadVersion = v; g.PersistentLocalStatus = LocalStatus.Unmodified; g.RequestUpdate(); } } // Remove the file from the uploader set. g.UploaderSet.Remove(u); u.FileTree.Remove(g.Inode); } // Process the cancelled uploads. foreach (KfsServerFile g in u.FileTree.Values) { Debug.Assert(g.UploaderSet.Contains(u)); g.UploaderSet.Remove(u); } u.FileTree.Clear(); // Remove the uploader from the uploader tree. Share.ServerView.UploaderTree.Remove(u.CommitID); }
/// <summary> /// Return the full path to the file having the version specified in /// the cache. /// </summary> public String VersionCachePath(KfsServerFileVersion version) { return Share.CacheDirPath + "File_" + version.Inode + "_" + version.CommitID; }
/// <summary> /// Queue the download of the specified file version. The method checks /// if the file is already being downloaded. If the file has already been /// downloaded, the file is added to the DoneTree immediately. /// </summary> public void QueueDownload(KfsServerFileVersion version, bool openFlag) { // The download is already queued. if (InodeTree.ContainsKey(version.Inode)) { if (openFlag) InodeTree[version.Inode].OpenWhenDownloadedFlag = true; return; } // Queue the file download. UInt64 orderID = Share.TransferOrderID++; String relPath = Share.ServerView.GetObjectByInode(version.Inode).RelativePath; KfsFileDownload f = new KfsFileDownload(Share, orderID, relPath, version, openFlag); InodeTree[f.Version.Inode] = f; OrderTree[f.OrderID] = f; Share.RegisterFileTransfer(f); // The file is already in the cache. if (HasFullVersion(version)) { f.Status = FileTransferStatus.Batched; OnFileDownloadCompleted(f.OrderID); } // The file is empty. Create it immediately. else if (version.Size == 0) { Directory.CreateDirectory(Share.CacheDirPath); File.Create(VersionCachePath(version)).Close(); f.Status = FileTransferStatus.Batched; OnFileDownloadCompleted(f.OrderID); } }
/// <summary> /// Return true if the file having the version specified was fully /// downloaded in the cache. /// </summary> public bool HasFullVersion(KfsServerFileVersion version) { String path = VersionCachePath(version); if (File.Exists(path)) return (KfsPath.GetFileSize(path) == version.Size); return false; }
public KfsDownloadBatchFile(UInt64 orderID, KfsServerFileVersion version, String transferPath) : base(orderID, transferPath) { Version = version; }
/// <summary> /// Update the downloaded version of the file and force the refresh of /// the status of the file, if requested. /// </summary> public void UpdateDownloadVersion(KfsServerFileVersion NewDownloadVersion, bool refreshFlag) { DownloadVersion = NewDownloadVersion; if (refreshFlag) { PersistentLocalStatus = LocalStatus.None; CurrentLocalStatus = LocalStatus.None; RequestUpdate(); } Share.App.SetDirty("UpdateDownloadVersion"); }