Exemplo n.º 1
0
        static void Main(string[] args)
        {
            string addr = String.Format("http://localhost:{0}/FileService", Properties.Settings.Default.Port);
            Uri baseAddress = new Uri(addr);
            int id = Convert.ToInt32(Properties.Settings.Default.ServerId);
            BasicHttpBinding binding = new BasicHttpBinding();
            binding.Name = "IFileService";
            // Create a ServiceHost for the StreamingService type
            using (ServiceHost serviceHost = new ServiceHost(typeof(FileService), baseAddress))
            {
                binding.MaxReceivedMessageSize = 2000000000;
                binding.TransferMode = TransferMode.Streamed;
                serviceHost.AddServiceEndpoint(typeof(IFileService), binding, baseAddress);
                // Open the ServiceHostBase to create listeners and start listening for messages.
                serviceHost.Open();
                NameNodeServiceClient client = new NameNodeServiceClient();
                client.Register(id, addr);

                Console.WriteLine("File Server " + id + " started, service is ready at " + addr);
                Console.WriteLine("Press <ENTER> to terminate service.");

                while (true)
                {
                    client.HeartBeat(id);
                    Console.WriteLine("Sending Heart Beat to Name Node");
                    System.Threading.Thread.Sleep(10000);
                }

                // The service can now be accessed.

            }
        }
Exemplo n.º 2
0
 static void List()
 {
     var client = new NameNodeServiceClient();
     var list = client.GetFileList();
     foreach(var file in list)
     {
         Console.WriteLine(file);
     }
 }
Exemplo n.º 3
0
        static void DownLoadFile(string fileName)
        {
            NameNodeServiceClient client = new NameNodeServiceClient();
            var downInfo = client.GetDownLoadInfo(fileName);

            var chunks = downInfo.Chunks.GroupBy(x=>x.Order).OrderBy(x=>x.First().Order);
            FileStream writer = new FileStream(fileName, FileMode.Create);
            foreach(var chunkGroup in chunks)
            {
                var chunk = chunkGroup.First();
                var server = chunk.FileServer;
                FileServiceClient serverClient = new FileServiceClient("BasicHttpBinding_IFileService", server.FileServerServicePoint);
                var remoteStream = serverClient.GetChunkByGUID(chunk.GUID);
                CopyStream(remoteStream, writer);
                remoteStream.Close();
            }

            writer.Close();
        }
Exemplo n.º 4
0
 static void Test()
 {
     UploadFile(@"D:\Research\KB\kb.entity.subset");
     DownLoadFile("kb.entity.subset");
     var wclient = new NameNodeServiceClient();
     wclient.DeleteFile("kb.entity.subset");
     FileServiceClient client = new FileServiceClient("BasicHttpBinding_IFileService", "http://*****:*****@"D:\Research\KB\kb.entity", FileMode.Open);
     var stream = new CombinedStream(streams);
     client.UploadChunk(stream);
 }
Exemplo n.º 5
0
 private static void DeleteFile(string p)
 {
     var client = new NameNodeServiceClient();
     client.DeleteFile(p);
 }
Exemplo n.º 6
0
        static void UploadFile(string filePath)
        {
            var fileInfo = new FileInfo(filePath);
            NameNodeServiceClient client = new NameNodeServiceClient();
            var uploadInfo = client.GetUploadInfo(fileInfo.Name, fileInfo.Length);

            int numOfChunks = uploadInfo.Chunks.Select(x => x.Order).Distinct().Count();
            int bufferSize = 1024 * 8 * 64;
            using (FileStream reader = new FileStream(filePath, FileMode.Open))
            {
                long byteNumPerChunk = reader.Length / numOfChunks;
                for (int i = 0; i < numOfChunks; i++)
                {
                    var bytes = new byte[bufferSize];
                    long end = i == numOfChunks - 1 ? reader.Length : byteNumPerChunk * (i + 1);
                    int curBufferSize = byteNumPerChunk > (long)bufferSize ? bufferSize : (int)byteNumPerChunk;

                    string tempFileName = filePath + "_" + i;

                    using (FileStream writer = new FileStream(tempFileName, FileMode.Create))
                    {
                        int size;
                        while (reader.Position < end && (size = reader.Read(bytes, 0, curBufferSize)) > 0)
                        {
                            writer.Write(bytes, 0, size);
                            if (end - reader.Position < (long)bufferSize)
                            {
                                curBufferSize = (int)(end - reader.Position);
                            }
                        }
                    }

                    var chunks = uploadInfo.Chunks.Where(x => x.Order == i);
                    foreach(var chunk in chunks)
                    {
                        var streams = new Stream[2];
                        streams[0] = new MemoryStream(Guid.Parse(chunk.GUID).ToByteArray());
                        streams[1] = new FileStream(tempFileName, FileMode.Open);
                        var uploadStream = new CombinedStream(streams);
                        FileServiceClient serverClient = new FileServiceClient("BasicHttpBinding_IFileService", chunk.FileServer.FileServerServicePoint);
                        serverClient.UploadChunk(uploadStream);
                        streams[0].Close();
                        streams[1].Close();
                    }
                    File.Delete(tempFileName);
                }
            }
        }