/// <summary> /// 获得分片数据 /// </summary> /// <returns></returns> private List <SlicingDataInfo> GetSlicingFiles(string fileName) { DirectoryInfo d = new DirectoryInfo(this.DPath); //得到目录下所有的分片数据 FileInfo[] files = d.GetFiles(fileName); List <SlicingDataInfo> slicingDataList = new List <SlicingDataInfo>(); for (int i = 0; i < files.Length; i++) { //得到目录中每片分片的数据,行号,列号,并存入list集合 SlicingDataInfo sd = new SlicingDataInfo() { ColNum = Path.GetFileNameWithoutExtension(files[i].Name).Split('_')[2], RowNum = Path.GetFileNameWithoutExtension(files[i].Name).Split('_')[1], Data = File.ReadAllBytes(files[i].FullName) }; slicingDataList.Add(sd); } return(slicingDataList); }
/// <summary> /// 创建异或文件 /// </summary> /// <param name="slicingDataList"></param> private void CreateXORFile(List <SlicingDataInfo> slicingDataList) { for (int i = 1; i <= this.SliceNum; i++) { //遍历集合中数据,把同一行,同一列的数据放入同一集合中。 List <SlicingDataInfo> listR = new List <SlicingDataInfo>(); List <SlicingDataInfo> listC = new List <SlicingDataInfo>(); for (int j = 0; j < slicingDataList.Count; j++) { if (listC.Count != this.SliceNum) { if (slicingDataList[j].ColNum == i.ToString()) { SlicingDataInfo sd = new SlicingDataInfo() { ColNum = i.ToString(), Data = slicingDataList[j].Data, RowNum = (this.SliceNum + 1).ToString() }; listC.Add(sd); } } if (listR.Count != this.SliceNum) { if (slicingDataList[j].RowNum == i.ToString()) { SlicingDataInfo sd = new SlicingDataInfo() { RowNum = i.ToString(), Data = slicingDataList[j].Data, ColNum = (this.SliceNum + 1).ToString() }; listR.Add(sd); } } } //得到同一行的所有 分片数据,去进行异或运算 GoCreateXORFile(listR, "slice_" + listR[0].RowNum + "_" + listR[0].ColNum + ".dat"); //得到同一列的所有分片数据,去进行异或运算 GoCreateXORFile(listC, "slice_" + listC[0].RowNum + "_" + listC[0].ColNum + ".dat"); } }