// DownFile-处理数据包 private byte[] proDownFilePackage(EndPoint point, UnUdpEntity entity) { byte[] data = null; UnUdpEntity downBack = new UnUdpEntity(); UnUdpEntity p = downFileClients.Find(t => t.Point.GetHashCode() == point.GetHashCode()); // 建立客户端表 if (p == null) { p = new UnUdpEntity(); p.Point = point; downFileClients.Add(p); ss.addDownTaskNum(1); } p.WakeTimeStamp = UnDate.ticksSec(); // 建立配置文件 UnUdpEntity config = downFileConfigs.Find(t => t.PackMD5 == entity.PackMD5); if (config == null) { //UnFile.writeLog("downMD5", entity.PackMD5); string filePath = null; if (intServer != null) { UnAttrRst rst = intServer.downCodeAnalyze(point, entity); if (rst != null) { if (rst.code > 0) { filePath = rst.back; } else { return null; } } } if (!File.Exists(filePath)) { return null; } config = new UnUdpEntity(filePath, subSize_down); config.PackMD5 = entity.PackMD5; downFileConfigs.Add(config); ss.addDownFileNum(1); } config.WakeTimeStamp = UnDate.ticksSec(); switch (entity.Event.getUnUdpEveEnum()) { case UnUdpEveEnum.downFileQuery: downBack.Event = UnUdpEveEnum.downFileQueryBack.getText(); downBack.Extent = config.Extent; downBack.HashCode = config.HashCode; downBack.TotalPacks = config.TotalPacks; downBack.TotalSize = config.TotalSize; downBack.SubSize = config.SubSize; long[] ls = UnUdpHelp.waitUps(entity.PackNo + 1, config.TotalPacks, interval); downBack.IntMin = ls[0]; downBack.IntMax = ls[1]; data = UnUdpHelp.assemblePackage(downBack); return data; case UnUdpEveEnum.downFile: UnUdpEntity cache = null; lock (cacheLock) { cache = downFileCaches.Find(t => t.PackNo == entity.PackNo && t.PackMD5 == config.PackMD5); // 添加缓存 if (cache == null) { data = config.getDownFileBackPackage(entity.PackNo); if (downFileCaches.Count < cacheQueueSize) { cache = new UnUdpEntity(); cache.PackMD5 = config.PackMD5; cache.PackNo = entity.PackNo; cache.PackData = data; cache.WakeTimeStamp = UnDate.ticksSec(); downFileCaches.Add(cache); ss.addDownCacheNum(1); } } else { data = cache.PackData; cache.WakeTimeStamp = UnDate.ticksSec(); } ss.addProLength(config.SubSize); } return data; } return null; }