示例#1
0
 private void PrintDfsInfo(DFSFileInfo dfsFileInfo, string p)
 {
     Console.WriteLine(p + " Operation.");
     foreach(var chunk in dfsFileInfo.Chunks)
     {
         Console.WriteLine(String.Format("\tChunk {0} Order {1} at FileServer {2}", chunk.GUID, chunk.Order, chunk.FileServer.Id));
     }
 }
示例#2
0
        public DFSFileInfo GetDownLoadInfo(string fileName)
        {
            var chunks = fileList[fileName].Chunks.Where(x => x.FileServer.Available).GroupBy(x => x.Order).Select(x => x.First());
            var chunkNum = fileList[fileName].Chunks.Select(x => x.Order).Distinct().Count();
            if (chunks.Count() < chunkNum)
                return null;

            var dfsFileInfo = new DFSFileInfo()
            {
                Chunks = chunks.ToList()
            };

            PrintDfsInfo(dfsFileInfo, "DownLoad");

            return dfsFileInfo;
        }
示例#3
0
        public DFSFileInfo GetUploadInfo(string fileName, long size)
        {
            int chunkNum = (int)(size / (long)chunkSize);
            if (chunkNum == 0)
                ++chunkNum;

            DFSFileInfo dfsFileInfo = new DFSFileInfo();
            Random rand = new Random();

            for (int i = 0; i < chunkNum; ++i)
            {
                var chunk = new Chunk()
                {
                    GUID = Guid.NewGuid().ToString(),
                    Order = i,
                    FileServer = getServerForChunk(i)
                };

                dfsFileInfo.Chunks.Add(chunk);

                int backUpChunkServerId = chunk.FileServer.Id;

                while (backUpChunkServerId == chunk.FileServer.Id)
                {
                    backUpChunkServerId = ServerList.Values.Where(x=>x.Available).Select(x => x.Id).OrderBy(x => rand.Next()).First();
                }

                dfsFileInfo.Chunks.Add(new Chunk()
                {
                    GUID = Guid.NewGuid().ToString(),
                    Order = i,
                    FileServer = ServerList[backUpChunkServerId]
                });
            }
            fileList[fileName] = dfsFileInfo;

            PrintDfsInfo(dfsFileInfo, "Upload");

            return dfsFileInfo;
        }