예제 #1
0
        public byte[] GetFile(ClassLibrary.Entites.File file, long partNumber)
        {
            PNRPManager manager = PeerServiceHost.PNRPManager;
            List <ClassLibrary.Entites.Peer> foundPeers = manager.ResolveByPeerName(file.PeerName);

            if (foundPeers.Count != 0)
            {
                ClassLibrary.Entites.Peer peer = foundPeers.FirstOrDefault();

                EndpointAddress endpointAddress = new EndpointAddress(string.Format("net.tcp://{0}:{1}/PeerToPeerClient.Services/PeerService",
                                                                                    peer.PeerHostName, ClassLibrary.Config.LocalPort));

                NetTcpBinding     tcpBinding = new NetTcpBinding(SecurityMode.None);
                PeerServiceClient client     = new PeerServiceClient(tcpBinding, endpointAddress);

                byte[] data = null;

                try
                {
                    data = client.TransferFile(file, partNumber);
                }
                catch
                {
                    throw new Exception("Unreachable host '" + file.PeerName);
                }

                return(data);
            }

            else
            {
                throw new Exception("Unable to resolve peer " + file.PeerName);
            }
        }
예제 #2
0
 public byte[] TransferFile(ClassLibrary.Entites.File file, long partNumber)
 {
     byte[] _bytes = base.Channel.TransferFile(file, partNumber);
     return(_bytes);
 }
예제 #3
0
        public byte[] TransferFile(ClassLibrary.Entites.File file, long partNumber)
        {
            string filePath = Config.SharedFolder + @"\" + file.FileName;

            return(FileUtility.ReadFilePart(filePath, partNumber));
        }