// Publishing the file via the DHT public Int32 PublishFileViaDHT(string fileAbsolutePath, out FileDetails _fd) { // Verify if we have already tried to publish this file or not if (!mainFilesDic.ContainsKey(Path.GetFileName(fileAbsolutePath))) { // Get file details Bsed on its path FileInfo fi = new FileInfo(fileAbsolutePath); FilePublishingStatus fd = new FilePublishingStatus(true, fi.Name, fi.Length, "", 0, fileAbsolutePath); fd.DataDescription = null; int res = filePublisher.PulishFileViaDht(fd); if (res == 1) { _fd = fd; // Adding the published file to the local dict AddFile(fi.Name, (FileDetails)fd); } else _fd = null; return res; } else { // Already exists in the dict FileDetails fd = mainFilesDic[Path.GetFileName(fileAbsolutePath)]; int res = filePublisher.PulishFileViaDht(fd); if (res == 1) _fd = fd; else _fd = null; return res; } }
public void UpdateFilePublishingStatus(ref string fileName, bool status) { if (mainFilesDic.ContainsKey(fileName)) { FileDetails fd = (FileDetails)mainFilesDic[fileName]; if (fd is FileDownloadStatus ) { // Move the file from the downloaded status to published local file // We have to provide some description for the file we downloaded, or just // Download the remote description FilePublishingStatus fps = new FilePublishingStatus(fd.StorageStatus, fd.FileName, fd.FileSize, fd.RemoteHostIp, fd.RemoteHostPort, fd.LocalFilePath); fps.Published = status; mainFilesDic.Remove(fileName); mainFilesDic.Add(fileName, fps); } else { FilePublishingStatus fps = (FilePublishingStatus)mainFilesDic[fileName]; fps.Published = status; } } }
// Default publishing method via the local tracker public void PublishFile(string fileAbsolutePath, out FileDetails _fd) { FilePublisherThreadParam tp = new FilePublisherThreadParam(this); // Verify if we have already tried to publish this file or not if (!mainFilesDic.ContainsKey(Path.GetFileName(fileAbsolutePath))) { // Get file details Bsed on its path FileInfo fi = new FileInfo(fileAbsolutePath); FilePublishingStatus fd = new FilePublishingStatus(true, fi.Name, fi.Length, "", 0, fileAbsolutePath); FileDescription fileDescriptionDialog = new FileDescription(); fileDescriptionDialog.Closed += new EventHandler(fileDescriptionDialog_Closed); fileDescriptionDialog.ShowDialog(); fd.DataDescription = CurrentDataDescription; tp.CurrentFileDetails = fd; tp.CurrentFileDescription = fi.Name; filePublisher.PulishFile(tp); _fd = fd; // Adding the published file to the local dict AddFile(fi.Name, (FileDetails)fd); } else { // Already exists in the dict FileDetails fd = mainFilesDic[Path.GetFileName(fileAbsolutePath)]; _fd = fd; tp.CurrentFileDetails = fd; tp.CurrentFileDescription = fd.FileName; filePublisher.PulishFile(tp); } }