Beispiel #1
0
        // ============================================
        // PRIVATE (Methods) Event Handlers
        // ============================================
        private static void OnEndSendFilePart(object sender, EndSendFilePartArgs args)
        {
            FileSender fileSender = sender as FileSender;

            // Remove File
            Remove(fileSender.Peer, fileSender.FileName);
        }
Beispiel #2
0
        private static void OnEndSend(object sender, Exception e)
        {
            FileSender fileSender = sender as FileSender;

            // Update Num Uploads & Reset file Id if it's possible
            numUploads--;
            if (numUploads == 0)
            {
                fileId = 1;
            }

            // Upload Finished/Aborted, Remove it
            Remove(fileSender);

            if (e == null)
            {
                // Raise Finished Event
                if (Finished != null)
                {
                    Finished(fileSender);
                }
            }
            else
            {
                // Raise Aborted Event
                if (Aborted != null)
                {
                    Aborted(fileSender);
                }
            }
        }
Beispiel #3
0
        /// Remove Upload
        public static void Remove(PeerSocket peer, string path)
        {
            UserInfo userInfo = peer.Info as UserInfo;

            ArrayList fileSenderList = uploads[peer] as ArrayList;

            if (fileSenderList == null)
            {
                throw(new UploadManagerException(userInfo.Name + " File '" + path + "' Not Found"));
            }

            FileSender fileSender = null;

            foreach (FileSender fs in fileSenderList)
            {
                if (fs.FileName == path)
                {
                    fileSender = fs;
                    break;
                }
            }

            if (fileSender != null)
            {
                Remove(fileSender);
            }
        }
        // ============================================
        // PUBLIC Constructors
        // ============================================
        public FileProgressObject(FileSender snd)
        {
            this.fileSender = snd;
            InitializeObject(false);

            // Initialize Info
            UpdateFileSender(this.fileSender);
        }
Beispiel #5
0
 private static void RemoveFromAcceptList(FileSender fileSender)
 {
     if (fileSender != null)
     {
         fileSender.SendedPart -= new BlankEventHandler(OnSendedPart);
         fileSender.EndSend    -= new ExceptionEventHandler(OnEndSend);
         acceptList.Remove(fileSender.Peer, fileSender);
     }
 }
Beispiel #6
0
        /// Add Upload
        public static void Add(UserInfo userInfo, string path)
        {
            if (uploads == null)
            {
                throw(new UploadManagerException("Upload Manager Not Initialized"));
            }

            // Get File List
            PeerSocket peer           = P2PManager.KnownPeers[userInfo] as PeerSocket;
            ArrayList  fileSenderList = uploads[peer] as ArrayList;

            if (fileSenderList == null)
            {
                fileSenderList = ArrayList.Synchronized(new ArrayList());
            }

            // Initialize & Start File Sender
            string realPath = Paths.UserSharedDirectory(MyInfo.Name) + path;

            FileSender fileSender = null;

            if (File.Exists(realPath) == true)
            {
                fileSender = new FileSender(peer, realPath, path);
            }
            else
            {
                fileSender = new FileSender(peer, path);
            }

            if (fileSender == null)
            {
                throw(new UploadManagerException("File Sender Creation Faild"));
            }

            fileSender.EndSend    += new EndSendFilePartHandler(OnEndSendFilePart);
            fileSender.SendedPart += new BlankEventHandler(OnSendedFilePart);
            fileSender.Start();

            // Update Upload List
            fileSenderList.Add(fileSender);
            uploads[peer] = fileSenderList;

            // Update Num Uploads
            numUploads++;

            // Start Upload New File Event
            if (Added != null)
            {
                Added(fileSender);
            }
        }
Beispiel #7
0
        /// Start File Transfer (Accepted File)
        public static void Send(PeerSocket peer, ulong id)
        {
            FileSender fileSender = new FileSender(id);

            fileSender = (FileSender)acceptList.Search(peer, fileSender);

            // Remove From Accept and Add To The Upload List
            acceptList.Remove(peer, fileSender);
            uploadList.Add(peer, fileSender);

            // Start The File Sender
            fileSender.Start();

            // Update Num Uploads
            numUploads++;
        }
Beispiel #8
0
        private static void Abort(FileSender fileSender)
        {
            // Abort Upload
            fileSender.Abort();

            // Update Num Uploads & Reset file Id if it's possible
            numUploads--;
            if (numUploads == 0)
            {
                fileId = 1;
            }

            // Raise Aborted Event
            if (Aborted != null)
            {
                Aborted(fileSender);
            }
        }
Beispiel #9
0
        // ============================================
        // PUBLIC Methods
        // ============================================
        /// Add New Upload
        public static void Add(PeerSocket peer, string path)
        {
            // Create New File Sender && Update File ID
            FileSender fileSender = new FileSender(fileId++, peer, path);

            fileSender.SendedPart += new BlankEventHandler(OnSendedPart);
            fileSender.EndSend    += new ExceptionEventHandler(OnEndSend);

            // Add to Accept List
            acceptList.Add(peer, fileSender);

            // Send Accept Message
            fileSender.Ask();

            // Raise Upload Added Event
            if (Added != null)
            {
                Added(fileSender);
            }
        }
Beispiel #10
0
        /// Abort Upload from Disk Name
        public static void Abort(string fileName)
        {
            FileSender fileSender = null;

            if ((fileSender = (FileSender)acceptList.Search(fileName)) != null)
            {
                RemoveFromAcceptList(fileSender);
            }
            else
            {
                fileSender = (FileSender)uploadList.Search(fileName);
                if (fileSender == null)
                {
                    return;
                }
                Remove(fileSender);
            }

            Abort(fileSender);
        }
Beispiel #11
0
        /// Abort File Upload
        public static void Abort(PeerSocket peer, ulong id)
        {
            FileSender fileSender = new FileSender(id);

            if ((fileSender = (FileSender)acceptList.Search(peer, fileSender)) != null)
            {
                RemoveFromAcceptList(fileSender);
            }
            else
            {
                fileSender = (FileSender)uploadList.Search(peer, new FileSender(id));
                if (fileSender == null)
                {
                    return;
                }
                Remove(fileSender);
            }

            Abort(fileSender);
        }
Beispiel #12
0
        /// Remove Upload
        public static void Remove(FileSender fileSender)
        {
            ArrayList fileSenderList = uploads[fileSender.Peer] as ArrayList;

            // Stop File Sender Transfer
            fileSender.EndSend -= new EndSendFilePartHandler(OnEndSendFilePart);
            fileSender.Stop();

            // Remove File & Update Upload List
            fileSenderList.Remove(fileSender);
            uploads[fileSender.Peer] = fileSenderList;

            // Update Num Uploads
            numUploads--;

            // Start Upload New File Event
            if (Finished != null)
            {
                Finished(fileSender);
            }
        }
Beispiel #13
0
        /// Start File Transfer (Send By Name)
        public static void Send(PeerSocket peer, string path)
        {
            // Create New File Sender && Update File ID
            FileSender fileSender = new FileSender(fileId++, peer, path);

            fileSender.SendedPart += new BlankEventHandler(OnSendedPart);
            fileSender.EndSend    += new ExceptionEventHandler(OnEndSend);

            // Add File Sender To The List
            uploadList.Add(peer, fileSender);

            // Start The File Sender
            fileSender.Start();

            // Update Num Uploads
            numUploads++;

            // Raise Upload Added Event
            if (Added != null)
            {
                Added(fileSender);
            }
        }
Beispiel #14
0
 /// Abort Upload
 public static void Abort(FileSender fileSender)
 {
     SendFileAbort(fileSender.Peer,
                   fileSender.FileName, fileSender.FileSize);
     Remove(fileSender);
 }
 // ============================================
 // PRIVATE Methods
 // ============================================
 private void SetTransferInfo(FileProgressObject obj, FileSender fs)
 {
     if (obj == null) return;
     obj.SetTransferInfo(fs.SendedSize, fs.Size, fs.SendedPercent);
 }