Exemplo n.º 1
0
        internal RemoteFile(RemoteDirectory parent, SharedFileListing listing)
        {
            m_Parent = parent;

            m_Name = listing.Name;
            UpdateFromInfo(listing);
        }
Exemplo n.º 2
0
        public SearchResult(FileSearch search, Node node, SharedFileListing listing) : this(search, node)
        {
            if (listing == null)
            {
                throw new ArgumentNullException("listing");
            }

            m_Listing = listing;
        }
Exemplo n.º 3
0
 internal void UpdateFromInfo(SharedFileListing listing)
 {
     m_PieceLength = listing.PieceLength;
     m_Pieces      = (listing.Pieces == null) ? new string[0] : listing.Pieces;
     m_InfoHash    = listing.InfoHash;
     m_SHA1        = listing.SHA1;
     m_Type        = listing.Type;
     m_Size        = listing.Size;
 }
Exemplo n.º 4
0
        internal RemoteFile CreateFile(SharedFileListing listing)
        {
            var file = new RemoteFile(this, listing);

            var newFiles = new RemoteFile[m_Files.Length + 1];

            Array.Copy(m_Files, newFiles, m_Files.Length);
            newFiles[newFiles.Length - 1] = file;

            m_Files = newFiles;

            return(file);
        }
Exemplo n.º 5
0
        RemoteFile GetOrCreateRemoteFile(string path, SharedFileListing listing, out bool created)
        {
            created = false;

            IFile file = GetFile(path) as RemoteFile;

            if (file != null)
            {
                return((RemoteFile)file);
            }

            created = true;

            var dirPath   = string.Join("/", path.Split('/').Slice(0, -2));
            var directory = GetOrCreateRemoteDirectory(dirPath);

            file = directory.CreateFile(listing);

            return((RemoteFile)file);
        }
Exemplo n.º 6
0
        public void ProcessFileDetailsMessage(Network network, Node messageFrom, SharedFileListing info)
        {
            string fullPath = PathUtil.Join(messageFrom.Directory.FullPath, info.FullPath);

            var node = PathUtil.GetNode(fullPath);

            if (node != messageFrom)
            {
                throw new Exception("Directory was for a different node");
            }

            bool       created    = false;
            RemoteFile remoteFile = GetOrCreateRemoteFile(fullPath, info, out created);

            if (!created)
            {
                remoteFile.UpdateFromInfo(info);
            }

            lock (remoteFileCallbacks)
            {
                if (remoteFileCallbacks.ContainsKey(fullPath))
                {
                    foreach (var callback in remoteFileCallbacks[fullPath])
                    {
                        callback(remoteFile);
                    }
                }
                remoteFileCallbacks.Remove(fullPath);
            }

            network.RaiseReceivedFileDetails(remoteFile);

            // FIXME: Get rid of all this, just listen for above network.ReceivedFileDetails event!
            var transfer = this.fileTransferManager.Transfers.SingleOrDefault(t => t.File == remoteFile);

            if (transfer != null && transfer.Status == FileTransferStatus.WaitingForInfo)
            {
                ((IFileTransferInternal)transfer).DetailsReceived();
            }
        }