Beispiel #1
0
 UnAttrRst UnIntUdpServer.msgReceived(EndPoint point, UnUdpEntity entity)
 {
     UnAttrRst rst = new UnAttrRst();
     return new UnAttrRst();
 }
Beispiel #2
0
 UnAttrRst UnIntUdpServer.proPackage(EndPoint point, UnUdpEntity entity)
 {
     UnAttrRst rst = new UnAttrRst();
     if (entity == null)
     {
         // 超过最大包速则丢弃
         if (server.getStati().getReceiveNumSpeed() > packSpeed)
         {
             rst.code = -1;
         }
     }
     else
     {
         // 超过最大任务数则丢弃
         if (entity.PackNo == 1)
         {
             if (server.getStati().getUpTaskNum() > tasks)
             {
                 rst.code = -2;
             }
         }
     }
     return rst;
 }
Beispiel #3
0
 // UpFile-返回包处理
 private void udpProUpFileBack(UnUdpEntity etBack)
 {
     // 刷新超时时间戳
     timeOutTicks = UnDate.ticksMSec();
     switch (etBack.Event.getUnUdpEveEnum())
     {
         case UnUdpEveEnum.upFileQueryBack:
             sleepTime = Convert.ToInt32(UnDate.ticksMSec() - traTicks) + 1;
             if (sleepTime > 10000)
             {
                 sleepTime = 2000;
             }
             switch (etBack.State)
             {
                 case 1:
                 case 2:
                     _isFinish = true;
                     if (intTransfer != null)
                     {
                         UnAttrRst rst = (UnAttrRst)UnXMMPXml.xmlToT(typeof(UnAttrRst), UnInit.getEncoding().GetString(etBack.PackData));
                         rst.pid = _pid;
                         intTransfer.success(rst);
                     }
                     break;
                 case -1:
                 case -2:
                     _isFinish = true;
                     if (intTransfer != null)
                     {
                         UnAttrRst rst = (UnAttrRst)UnXMMPXml.xmlToT(typeof(UnAttrRst), UnInit.getEncoding().GetString(etBack.PackData));
                         rst.pid = _pid;
                         intTransfer.error(rst);
                     }
                     break;
                 default:
                     // 首次则累加
                     if (queryState == 1)
                     {
                         queryState++;
                     }
                     sendIntervals = new List<UnUdpEntity>();
                     for (long i = etBack.IntMin; i <= etBack.IntMax; i++)
                     {
                         UnUdpEntity uup = new UnUdpEntity();
                         uup.PackNo = i;
                         upp.isSend = false;
                         sendIntervals.Add(uup);
                     }
                     break;
             }
             break;
         case UnUdpEveEnum.upFilePackageBack:
             UnUdpEntity up = sendIntervals.Find(t => t.PackNo == etBack.PackNo);
             if (up != null)
             {
                 up.isSend = true;
                 ss.addSendLength(etBack.PackSize);
             }
             udpAddUpProgress(etBack);
             break;
     }
 }
Beispiel #4
0
 UnAttrRst UnIntUdpServer.downCodeAnalyze(EndPoint point, UnUdpEntity entity)
 {
     return new UnAttrRst();
 }
Beispiel #5
0
        // DonwFile-返回包处理
        private void udpProDownFileBack(UnUdpEntity etBack)
        {
            // 刷新超时时间戳
            timeOutTicks = UnDate.ticksMSec();
            switch (etBack.Event.getUnUdpEveEnum())
            {
                case UnUdpEveEnum.downFileQueryBack:
                    sleepTime = Convert.ToInt32(UnDate.ticksMSec() - traTicks) + 1;
                    if (sleepTime > 10000)
                    {
                        sleepTime = 2000;
                    }
                    // 初始化
                    FileInfo cofFi = new FileInfo(UnUdpHelp.getDownFileTmpConfigPath(etBack.HashCode));
                    FileInfo tmpFi = new FileInfo(UnUdpHelp.getDownFileReceivePath(etBack.HashCode));
                    if (!cofFi.Exists)
                    {
                        DirectoryInfo di = new DirectoryInfo(UnUdpHelp.getDownFileTmpDirectory(etBack.HashCode));
                        if (!di.Exists)
                        {
                            di.Create();
                        }
                        cofFi.Create().Dispose();
                        tmpFi.Create().Dispose();
                        downQuery = etBack;
                    }

                    // 第一次初始化
                    if (downQuery.TotalPacks == 0)
                    {
                        // 获得配置文件
                        using (FileStream fs = cofFi.OpenRead())
                        {
                            byte[] b = new byte[fs.Length];
                            fs.Read(b, 0, b.Length);
                            downQuery = UnUdpHelp.analyzePackage(b);
                        }
                    }
                    else
                    {
                        downQuery.IntMin = etBack.IntMin;
                        downQuery.IntMax = etBack.IntMax;
                    }

                    // 写入配置文件
                    using (FileStream fs = new FileStream(UnUdpHelp.getDownFileTmpConfigPath(etBack.HashCode), FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                    {
                        byte[] prgBackBts = UnUdpHelp.assemblePackage(downQuery);
                        fs.SetLength(0);
                        fs.Seek(0, SeekOrigin.Begin);
                        fs.Write(prgBackBts, 0, prgBackBts.Length);
                    }

                    // 建立窗口
                    downIntervals = new List<UnUdpEntity>();
                    for (long i = downQuery.IntMin; i <= downQuery.IntMax; i++)
                    {
                        UnUdpEntity uup = new UnUdpEntity();
                        uup.PackNo = i;
                        upp.isSend = false;
                        downIntervals.Add(uup);
                    }
                    isdbPer = true;
                    break;
                case UnUdpEveEnum.downFileBack:
                    UnUdpEntity up = downIntervals.Find(t => t.PackNo == etBack.PackNo && t.isSend == false);
                    string tmpPath = UnUdpHelp.getDownFileReceivePath(downQuery.HashCode);
                    if (up != null)
                    {
                        // 写入数据
                        using (FileStream fs = new FileStream(tmpPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                        {
                            fs.Lock(etBack.PackOffset, etBack.PackData.Length);
                            fs.Seek(etBack.PackOffset, SeekOrigin.Begin);
                            fs.Write(etBack.PackData, 0, etBack.PackData.Length);
                            fs.Unlock(etBack.PackOffset, etBack.PackData.Length);
                            downQuery.UpCount++;
                            up.isSend = true;
                        }
                        udpAddDownProgress(downQuery);
                    }
                    // 下载完成
                    if (downQuery.UpCount == downQuery.TotalPacks)
                    {
                        _isFinish = true;
                        // 转正式文件
                        string newPath = UnUdpHelp.getDownFileSavePath(downQuery.HashCode, downQuery.Extent);
                        UnFile.move(tmpPath, newPath, true);
                        // 删除临时文件夹
                        File.Delete(UnUdpHelp.getDownFileTmpConfigPath(downQuery.HashCode));
                        Directory.Delete(UnUdpHelp.getDownFileTmpDirectory(downQuery.HashCode));
                        if (intTransfer != null)
                        {
                            UnAttrRst rst = new UnAttrRst();
                            rst.pid = _pid;
                            rst.code = 1;
                            rst.msg = "下载完成";
                            rst.back = newPath;
                            intTransfer.success(rst);
                        }
                    }
                    break;
            }
        }
Beispiel #6
0
 // SendMsg-返回包处理
 private void udpProMsgBack(UnUdpEntity etBack)
 {
     switch (etBack.Event.getUnUdpEveEnum())
     {
         case UnUdpEveEnum.msgPackageBack:
             if (sendIntervals[0].HashCode == etBack.HashCode)
             {
                 _isFinish = true;
                 sendIntervals.RemoveAt(0);
                 if (intTransfer != null)
                 {
                     UnAttrRst rst = (UnAttrRst)UnXMMPXml.xmlToT(typeof(UnAttrRst), UnInit.getEncoding().GetString(etBack.PackData));
                     rst.pid = _pid;
                     intTransfer.success(rst);
                 }
             }
             break;
     }
 }
Beispiel #7
0
 // SendMsg
 private void sendMsg(string msg)
 {
     if (_isFinish)
     {
         upp = new UnUdpEntity(UnInit.getEncoding().GetBytes(msg));
         // 添加待发送窗口
         sendIntervals.Clear();
         sendIntervals.Add(upp);
         // 启动监听、发送、业务线程
         _isFinish = false;
         setPause(false);
         new Thread(udpListenHandle).Start();
         new Thread(udpMsgSendHandle).Start();
         new Thread(udpTimerHandle).Start();
     }
 }
Beispiel #8
0
 // Msg-处理数据包
 private byte[] proMsgPackage(EndPoint point, UnUdpEntity entity)
 {
     UnUdpEntity msgBack = new UnUdpEntity();
     msgBack.Event = UnUdpEveEnum.msgPackageBack.getText();
     msgBack.HashCode = entity.HashCode;
     UnAttrRst rst = new UnAttrRst();
     rst.code = 0;
     rst.msg = "success";
     rst.back = "";
     if (intServer != null)
     {
         rst = intServer.msgReceived(point, entity);
     }
     return UnUdpHelp.assemblePackage(msgBack);
 }
Beispiel #9
0
 /// <summary>
 /// DownFile
 /// </summary>
 /// <param name="downCode"></param>
 public void downFile(string downCode)
 {
     if (_isFinish)
     {
         upp = new UnUdpEntity(downCode, true);
         // 启动监听、发送、业务线程
         _isFinish = false;
         setPause(false);
         new Thread(udpListenHandle).Start();
         new Thread(udpDownFileSendHandle).Start();
         new Thread(udpTimerHandle).Start();
     }
 }
Beispiel #10
0
 /// <summary>
 /// 上传文件
 /// </summary>
 /// <param name="filePath">文件路径</param>
 public void upFile(string filePath)
 {
     if (_isFinish)
     {
         upp = new UnUdpEntity(filePath, subSize_up);
         // 启动监听、发送、业务线程
         _isFinish = false;
         setPause(false);
         new Thread(udpListenHandle).Start();
         new Thread(udpUpFileSendHandle).Start();
         new Thread(udpTimerHandle).Start();
     }
 }
Beispiel #11
0
        /// <summary>
        /// 解析数据包
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static UnUdpEntity analyzePackage(byte[] data)
        {
            // 包最小为512
            if (data == null && data.Length < 512)
            {
                return null;
            }

            UnUdpEntity ue = new UnUdpEntity();
            // 包开头必须为:a:000;即最多6字节
            byte[] head = new byte[6];
            Buffer.BlockCopy(data, 0, head, 0, 6);

            // 取出包头大小
            string v = null;
            v = head.subStringBetween("a:", ";");
            if (v != null)
            {
                // 取出包头数据
                ue.HeadSize = Convert.ToInt32(v);
                head = new byte[ue.HeadSize];
                Buffer.BlockCopy(data, 0, head, 0, ue.HeadSize);
            }
            else
            {
                // 错误格式忽略
                return null;
            }

            ue.Event = head.subStringBetween("b:", ";");
            ue.Extent = head.subStringBetween("c:", ";");
            ue.HashCode = head.subStringBetween("d:", ";");
            ue.PackMD5 = head.subStringBetween("e:", ";");
            v = head.subStringBetween("f:", ";");
            if (v != null)
            {
                ue.PackNo = Convert.ToInt64(v);
            }
            v = head.subStringBetween("g:", ";");
            if (v != null)
            {
                ue.PackOffset = Convert.ToInt64(v);
            }
            v = head.subStringBetween("g:", ";");
            if (v != null)
            {
                ue.PackOffset = Convert.ToInt64(v);
            }
            v = head.subStringBetween("h:", ";");
            if (v != null)
            {
                ue.PackSize = Convert.ToInt32(v);
            }
            v = head.subStringBetween("i:", ";");
            if (v != null)
            {
                ue.SubSize = Convert.ToInt32(v);
            }
            v = head.subStringBetween("j:", ";");
            if (v != null)
            {
                ue.TotalPacks = Convert.ToInt64(v);
            }
            v = head.subStringBetween("k:", ";");
            if (v != null)
            {
                ue.TotalSize = Convert.ToInt64(v);
            }
            v = head.subStringBetween("l:", ";");
            if (v != null)
            {
                ue.UpCount = Convert.ToInt64(v);
            }
            v = head.subStringBetween("m:", ";");
            if (v != null)
            {
                ue.IntMin = Convert.ToInt64(v);
            }
            v = head.subStringBetween("n:", ";");
            if (v != null)
            {
                ue.IntMax = Convert.ToInt64(v);
            }
            v = head.subStringBetween("o:", ";");
            if (v != null)
            {
                ue.State = Convert.ToInt32(v);
            }

            // 取出包体
            ue.PackData = new byte[ue.PackSize];
            Buffer.BlockCopy(data, ue.HeadSize, ue.PackData, 0, ue.PackData.Length);
            return ue;
        }
Beispiel #12
0
        /// <summary>
        /// 组装数据包
        /// </summary>
        /// <param name="ue"></param>
        /// <returns></returns>
        public static byte[] assemblePackage(UnUdpEntity ue)
        {
            // 包体大小
            if (ue.PackData == null)
            {
                ue.PackData = new byte[0];
            }
            ue.PackSize = ue.PackData.Length;

            // 组装包头
            StringBuilder str = new StringBuilder();
            str.AppendFormat("{0}:{1};", new string[] { "b", ue.Event });                      //事件
            if (ue.Extent != null)
            {
                str.AppendFormat("{0}:{1};", new string[] { "c", ue.Extent });                     //文件扩展名
            }
            if (ue.HashCode != null)
            {
                str.AppendFormat("{0}:{1};", new string[] { "d", ue.HashCode });                   //文件MD5
            }
            if (ue.PackMD5 != null)
            {
                str.AppendFormat("{0}:{1};", new string[] { "e", ue.PackMD5 });                    //包MD5
            }
            if (ue.PackNo > 0)
            {
                str.AppendFormat("{0}:{1};", new string[] { "f", ue.PackNo.ToString() });          //包编号,1开始
            }
            if (ue.PackOffset > 0)
            {
                str.AppendFormat("{0}:{1};", new string[] { "g", ue.PackOffset.ToString() });      //包偏移量
            }
            if (ue.PackSize > 0)
            {
                str.AppendFormat("{0}:{1};", new string[] { "h", ue.PackSize.ToString() });        //包大小
            }
            if (ue.SubSize > 0)
            {
                str.AppendFormat("{0}:{1};", new string[] { "i", ue.SubSize.ToString() });         //分包大小
            }
            if (ue.TotalPacks > 0)
            {
                str.AppendFormat("{0}:{1};", new string[] { "j", ue.TotalPacks.ToString() });      //总包数
            }
            if (ue.TotalSize > 0)
            {
                str.AppendFormat("{0}:{1};", new string[] { "k", ue.TotalSize.ToString() });       //总大小
            }
            if (ue.UpCount > 0)
            {
                str.AppendFormat("{0}:{1};", new string[] { "l", ue.UpCount.ToString() });         //已上传数量
            }
            if (ue.IntMin != 0)
            {
                str.AppendFormat("{0}:{1};", new string[] { "m", ue.IntMin.ToString() });          //左区间
            }
            if (ue.IntMax != 0)
            {
                str.AppendFormat("{0}:{1};", new string[] { "n", ue.IntMax.ToString() });          //右区间
            }
            if (ue.State != 0)
            {
                str.AppendFormat("{0}:{1};", new string[] { "o", ue.State.ToString() });           //状态
            }

            // 包头长度 = 包体长度 + 包开头字符串长度(默认6)
            int headSize = (str.Length + 6);
            // 包开头字符串
            string al = "a:" + headSize + ";";
            // 小于6位则补齐
            if (al.Length < 6)
            {
                al = "a:0" + headSize + ";";
            }
            // 插入首位
            str.Insert(0, al);

            byte[] head = UnInit.getEncoding().GetBytes(str.ToString());
            byte[] pack = new byte[headSize + ue.PackSize];
            try
            {
                // 组装包
                Buffer.BlockCopy(head, 0, pack, 0, head.Length);
                Buffer.BlockCopy(ue.PackData, 0, pack, headSize, ue.PackData.Length);
            }
            catch (Exception e)
            {
                UnFile.writeLog("assemblePackage", e.ToString() + "\r\n" + headSize + "\r\n" + str.ToString());
                return null;
            }
            return pack;
        }
Beispiel #13
0
        // UpFile-处理数据包
        private byte[] proUpFilePackage(EndPoint point, UnUdpEntity entity)
        {
            byte[] data = null;
            // 配置文件
            UnUdpEntity cofUPP = upFileConfigs.Find(t => t.HashCode == entity.HashCode);
            if (cofUPP == null)
            {
                cofUPP = new UnUdpEntity();
                cofUPP.HashCode = entity.HashCode;
                cofUPP.TotalPacks = entity.TotalPacks;
                cofUPP.TotalSize = entity.TotalSize;
                cofUPP.Extent = entity.Extent;
                cofUPP.SubSize = entity.SubSize;
                FileInfo cofFi = new FileInfo(UnUdpHelp.getUpFileTmpConfigPath(cofUPP.HashCode));
                FileInfo tmpFi = new FileInfo(UnUdpHelp.getUpFileReceivePath(cofUPP.HashCode));
                if (!cofFi.Exists)
                {
                    long[] ls = UnUdpHelp.waitUps(1, entity.TotalPacks, interval);
                    cofUPP.IntMin = ls[0];
                    cofUPP.IntMax = ls[1];
                    cofUPP.isReceived = new List<long>();
                    DirectoryInfo di = new DirectoryInfo(UnUdpHelp.getUpFileTmpDirectory(cofUPP.HashCode));
                    if (!di.Exists)
                    {
                        di.Create();
                    }
                    // 创建配置文件
                    using (FileStream fs = cofFi.Create())
                    {
                        byte[] prgBackBts = UnUdpHelp.assemblePackage(cofUPP);
                        fs.Seek(0, SeekOrigin.Begin);
                        fs.Write(prgBackBts, 0, prgBackBts.Length);
                    }
                    // 创建临时文件
                    tmpFi.Create().Dispose();
                }
                else
                {
                    // 获得配置文件
                    using (FileStream fs = cofFi.OpenRead())
                    {
                        byte[] b = new byte[fs.Length];
                        fs.Read(b, 0, b.Length);
                        cofUPP = UnUdpHelp.analyzePackage(b);
                        if (cofUPP != null)
                        {
                            if (cofUPP.IntMin > 0)
                            {
                                cofUPP.UpCount = cofUPP.IntMin - 1;
                            }
                            else
                            {
                                cofUPP.UpCount = cofUPP.TotalPacks;
                            }
                        }
                    }
                }
                // 配置文件出错则删除重置
                if (cofUPP == null)
                {
                    cofFi.Delete();
                    return null;
                }
                ss.addUpTaskNum(1);
                upFileConfigs.Add(cofUPP);
            }
            // 唤醒时间
            cofUPP.WakeTimeStamp = UnDate.ticksSec();
            // 返回对象
            UnUdpEntity back = new UnUdpEntity();
            UnAttrRst rst = new UnAttrRst();

            switch (entity.Event.getUnUdpEveEnum())
            {
                case UnUdpEveEnum.upFileQuery:
                    back.IntMin = cofUPP.IntMin;
                    back.IntMax = cofUPP.IntMax;
                    back.TotalPacks = cofUPP.TotalPacks;
                    back.TotalSize = cofUPP.TotalSize;
                    back.UpCount = cofUPP.UpCount;
                    back.SubSize = cofUPP.SubSize;
                    back.Event = UnUdpEveEnum.upFileQueryBack.getText();

                    // 是否秒传
                    bool isMC = false;
                    // 开始上传
                    if (entity.State == 1)
                    {
                        if (intServer != null)
                        {
                            rst = intServer.upStart(point, entity);
                            if (rst != null)
                            {
                                cofUPP.State = rst.code;
                                back.State = cofUPP.State;
                                switch (cofUPP.State)
                                {
                                    case 1:// 传输完成
                                        cofUPP.UpCount = back.TotalPacks;
                                        back.UpCount = cofUPP.UpCount;
                                        cofUPP.WakeTimeStamp -=30;
                                        isMC = true;
                                        break;
                                    case -1:
                                    case -2:
                                        cofUPP.WakeTimeStamp -= 30;
                                        break;
                                }
                            }
                        }
                        // 默认处理
                        if (rst == null)
                        {
                            rst = new UnAttrRst();
                            rst.code = 0;
                            rst.msg = "传输中";
                        }
                    }

                    // 文件不是秒传,上传成功处理临时文件
                    if (!isMC && cofUPP.UpCount == cofUPP.TotalPacks)
                    {
                        cofUPP.State = 1;
                        back.State = cofUPP.State;
                        // 临时路径
                        string oldPath = UnUdpHelp.getUpFileReceivePath(cofUPP.HashCode);
                        if (intServer != null)
                        {
                            entity.TmpPath = oldPath;
                            rst = intServer.upSuccess(point, entity);
                            if (rst != null)
                            {
                                rst.code = 1;
                                rst.msg = "传输完成";
                            }
                        }
                        // 默认处理
                        if (rst == null)
                        {
                            // 转正式文件
                            string newPath = UnUdpHelp.getUpFileSavePath(cofUPP.HashCode, cofUPP.Extent);
                            UnFile.move(oldPath, newPath, true);
                            rst = new UnAttrRst();
                            rst.code = 1;
                            rst.msg = "上传成功";
                            rst.back = newPath;
                        }
                        cofUPP.WakeTimeStamp -= 25;
                    }

                    back.PackData = UnInit.getEncoding().GetBytes(UnXMMPXml.tToXml(typeof(UnAttrRst), rst));
                    data = UnUdpHelp.assemblePackage(back);
                    return data;
                case UnUdpEveEnum.upFilePackage:
                    // 在区间内且上传未完成
                    if (entity.PackNo >= cofUPP.IntMin && entity.PackNo <= cofUPP.IntMax && cofUPP.UpCount < cofUPP.TotalPacks)
                    {
                        // 是否已传
                        bool isHave = cofUPP.isReceived.Exists(t => t == entity.PackNo);
                        if (!isHave)
                        {
                            // 写入数据
                            using (FileStream fs = new FileStream(UnUdpHelp.getUpFileReceivePath(cofUPP.HashCode), FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                            {
                                fs.Lock(entity.PackOffset, entity.PackData.Length);
                                fs.Seek(entity.PackOffset, SeekOrigin.Begin);
                                fs.Write(entity.PackData, 0, entity.PackData.Length);
                                cofUPP.UpCount++;
                                cofUPP.isReceived.Add(entity.PackNo);

                                // 修改配置
                                if (cofUPP.UpCount == cofUPP.IntMax)
                                {
                                    long[] ls = UnUdpHelp.waitUps(cofUPP.IntMax + 1, entity.TotalPacks, interval);
                                    cofUPP.IntMin = ls[0];
                                    cofUPP.IntMax = ls[1];
                                    cofUPP.isReceived = new List<long>();
                                }
                                fs.Unlock(entity.PackOffset, entity.PackData.Length);
                            }
                        }
                    }

                    back.Event = UnUdpEveEnum.upFilePackageBack.getText();
                    back.PackNo = entity.PackNo;
                    back.UpCount = cofUPP.UpCount;
                    data = UnUdpHelp.assemblePackage(back);
                    return data;
            }
            return data;
        }
Beispiel #14
0
            UnAttrRst UnIntUdpServer.upStart(EndPoint point, UnUdpEntity entity)
            {
                UnAttrRst rst = new UnAttrRst();
                BackInfo bi = new BackInfo();

                // 类型检测
                if (fileTypes.IndexOf(".*") < 0 && ("," + fileTypes.ToLower() + ",").IndexOf("," + entity.Extent.ToLower() + ",") < 0)
                {
                    bi.ReturnCode = -1;
                    bi.ReturnMsg = "只允许: " + fileTypes + " 格式";

                    rst.code = -1;
                    rst.msg = "文件类型错误";
                    rst.back = UnXMMPXml.tToXml(typeof(BackInfo), bi);
                    return rst;
                }
                // 大小检测
                if (entity.TotalSize > fileSize)
                {
                    bi.ReturnCode = -2;
                    bi.ReturnMsg = "文件超过: " + fileSize + " 字节";

                    rst.code = -2;
                    rst.msg = "文件大小错误";
                    rst.back = UnXMMPXml.tToXml(typeof(BackInfo), bi);
                    return rst;
                }
                // 查询文件是否已存在
                UnFileInfo fi = UnFile.findFromDir(Img1_Path, entity.HashCode);
                if (fi != null)
                {
                    bi.ReturnCode = 2;
                    bi.ReturnMsg = "极速秒传";
                    bi.MD5 = entity.HashCode;
                    bi.Url = Img1_Domain + fi.fullName.Replace(Img1_Path, "");

                    rst.code = 1;
                    rst.msg = "传输完成";
                    rst.back = UnXMMPXml.tToXml(typeof(BackInfo), bi);

                    Console.WriteLine("***************极速秒传***************");
                    Console.WriteLine("【路径】" + fi.fullName);
                    Console.WriteLine("【URL】" + bi.Url);

                    return rst;
                }
                return null;
            }
Beispiel #15
0
 // UpFile-添加进度
 private void udpAddUpProgress(UnUdpEntity up)
 {
     UnAttrPgs pgs = new UnAttrPgs();
     pgs.pid = _pid;
     if (up.UpCount < upp.TotalPacks - 1)
     {
         pgs.length = up.UpCount * upp.SubSize;
     }
     else
     {
         if (up.UpCount == upp.TotalPacks)
         {
             prgMax = 0;
             pgss.Clear();
         }
         pgs.length = upp.TotalSize;
     }
     pgs.totalLength = upp.TotalSize;
     float per = pgs.percentage();
     if (per > prgMax)
     {
         if (pgss.Count < 20)
         {
             prgMax = per;
             pgss.Add(pgs);
         }
         else
         {
             if ((int)per > (int)prgMax)
             {
                 prgMax = per;
                 pgss.Add(pgs);
                 pgss.RemoveAt(0);
             }
         }
     }
 }
Beispiel #16
0
            UnAttrRst UnIntUdpServer.upSuccess(EndPoint point, UnUdpEntity entity)
            {
                // 转正式文件
                string dicName = DateTime.Now.ToString("yyyy-MM-dd") + "/" + entity.HashCode + entity.Extent;
                string newPath = Img1_Path + dicName;
                UnFile.move(entity.TmpPath, newPath, true);

                // 自定义返回
                BackInfo bi = new BackInfo();
                bi.ReturnCode = 1;
                bi.ReturnMsg = "上传成功";
                bi.MD5 = entity.HashCode;
                bi.Url = Img1_Domain + dicName;

                UnAttrRst rst = new UnAttrRst();
                rst.back = UnXMMPXml.tToXml(typeof(BackInfo), bi);

                Console.WriteLine("***************上传成功***************");
                Console.WriteLine("【路径】" + newPath);
                Console.WriteLine("【URL】" + bi.Url);
                return rst;
            }
Beispiel #17
0
        // 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;
        }