コード例 #1
0
        protected override void ExceptionHandle(Exception e)
        {
            Thread.Sleep(1000);  //****出现异常后,延迟1秒后,在处理异常
            var eType = Utility.SetException(e);

            switch (eType)
            {
            case Utility.EcpType.Normal:
                break;

            case Utility.EcpType.Null:
                break;

            case Utility.EcpType.AddressError:
                break;

            case Utility.EcpType.Disconnect:
                RundoShowDownloadFileInfo(Utility.E_Disconnect);
                RundoShowRemainTime(null);
                RundoShowDownloadSpeed(null);
                CheckInternet(3);
                break;

            case Utility.EcpType.LimitConnect:
                GlobalData.dataXML.CurrIndex++;
                doShowDownloadFileInfo(Utility.E_LimitConnect + ":" + GlobalData.dataXML.CurrIndex.ToString() + "号");
                System.Windows.Forms.Application.DoEvents();
                Utility.Delay(2);     ///**********延迟
                break;

            case Utility.EcpType.SerDisconnect:
                doShowDownloadFileInfo(Utility.E_SerDisconnect);
                break;

            case Utility.EcpType.ReceiveError:
                doShowDownloadFileInfo(Utility.E_ReceiveError);

                break;

            case Utility.EcpType.ErrorPw:
                ftp = new FTPDownload("anonymous", "*****@*****.**");
                break;

            case Utility.EcpType.FileNotFound:
                //isNewUpdate = true;
                break;

            default:
                //System.Windows.Forms.MessageBox.Show("未知错误");
                doShowDownloadFileInfo(e.Message);
                GlobalEvent.SaveDebugLog();
                Environment.Exit(0);
                break;
            }
        }
コード例 #2
0
        private static EcpType SetCurrExceptionType(Exception e)
        {
            GlobalEvent.WriteLog(e.ToString());
            EcpType currEcpType = EcpType.Normal;

            if (e is System.NotSupportedException ||
                e is System.UriFormatException)
            {
                currEcpType = EcpType.AddressError;
            }
            else if (e.Message.Contains("无法连接到远程服务器"))
            {
                currEcpType = EcpType.SerDisconnect;
            }
            else if (e.Message.Contains("421"))
            {
                currEcpType = EcpType.LimitConnect;
            }
            else if (e.Message.Contains("接收时发生错误"))
            {
                currEcpType = EcpType.ReceiveError;
            }
            else if (e.Message.Contains("操作超时"))
            {
                currEcpType = EcpType.ReceiveError;
            }
            else if (e.Message.Contains("远程主机强迫关闭了一个现有的连接"))
            {
                currEcpType = EcpType.Disconnect;
            }
            else if (e.Message.Contains("331 Password required"))
            {
                currEcpType = EcpType.ErrorPw;
            }
            else if (e.Message.Contains("文件不可用"))
            {
                currEcpType = EcpType.FileNotFound;
            }
            else if (e is System.Threading.ThreadAbortException)
            {
                currEcpType = EcpType.ThreadEcp;
            }
            else
            {
                currEcpType = EcpType.Null;
            }

            if (!Utility.IsConnectInternetPing())
            {
                currEcpType = EcpType.Disconnect;
            }
            GlobalEvent.WriteLog(e.ToString());
            GlobalEvent.SaveDebugLog();
            return(currEcpType);
        }
コード例 #3
0
 void SetInstallOver()
 {
     if (this.InvokeRequired)
     {
         this.Invoke(new V_F_V(SetInstallOver));
     }
     else
     {
         GlobalData.localFileInfo = new XMLAnalysis().GetFileInfomation(GlobalData.filePath.ConfigDataFullPath, true);
         GlobalEvent.SaveDebugLog();
         GlobalEvent.OpenProgram();
         GlobalEvent.SetUpdateState(false);
         Dispose();
     }
 }
コード例 #4
0
 public static bool OpenProgram()
 {
     if (File.Exists(GlobalData.filePath.ProgramFullPath))
     {
         Process p = new Process();
         p.StartInfo.FileName         = GlobalData.filePath.ProgramFullPath;
         p.StartInfo.WorkingDirectory = GlobalData.filePath.ProgramFullPath.Replace(GlobalData.localVersionXML.x_ProcessInfo.name, "");
         p.Start();
         GlobalEvent.WriteLog("打開程序成功:" + GlobalData.filePath.ProgramFullPath);
         GlobalEvent.SaveDebugLog();
         return(true);
     }
     GlobalEvent.WriteLog("打開程序失敗:" + GlobalData.filePath.ProgramFullPath);
     GlobalEvent.SaveDebugLog();
     return(false);
 }
コード例 #5
0
 private void button1_Click(object sender, EventArgs e)
 {
     GlobalEvent.SaveDebugLog();
 }
コード例 #6
0
ファイル: FTPDownload.cs プロジェクト: yungshing/UpdateSystem
 /// <summary>
 /// 路径要带后缀名
 /// </summary>
 /// <param name="downloadPath"></param>
 /// <param name="savePath"></param>
 /// <returns></returns>
 public bool Download(string downloadPath, string savePath)
 {
     try
     {
         while (Pause)
         {
             continue;
         }
         SetProgressBar(0, 1);
         ShowPercent("0%");
         if (savePath.Contains("data.config.tmp"))
         {
             GlobalEvent.SaveDebugLog();
         }
         SetProgressBar(0, 1);
         ShowPercent("0%");
         SetProgressBar(0, 1);
         ShowPercent("0%");
         ConnectFTP(downloadPath);
         long   downloadBytes = 0;
         long   TotalBytes    = 0;
         string _path_Tmp     = savePath + ".zzfz";
         if (File.Exists(savePath))
         {
             SetProgressBar(1, 1);
             ShowRemainTime("0");
             ShowPercent("100%");
             ShowDownloadSpeed("已下载");
             return(true);
         }
         ///断点续传
         if (File.Exists(_path_Tmp))
         {
             wrStream      = File.OpenWrite(_path_Tmp);
             downloadBytes = wrStream.Length;
             wrStream.Seek(downloadBytes, SeekOrigin.Current);
             request.ContentOffset = downloadBytes;
             TotalBytes            = Size(downloadPath);
             SetProgressBar((int)downloadBytes, (int)TotalBytes);
             if (wrStream.Length == TotalBytes)
             {
                 Dispose();
                 File.Move(_path_Tmp, savePath);
                 return(true);
             }
         }
         else
         {
             var d1 = new FileInfo(_path_Tmp);
             if (!Directory.Exists(d1.Directory.FullName))
             {
                 Directory.CreateDirectory(d1.Directory.FullName);
             }
             wrStream   = new FileStream(_path_Tmp, FileMode.Create, FileAccess.ReadWrite);
             TotalBytes = Size(downloadPath);
         }
         Stopwatch stopWatch = new Stopwatch();
         ShowDownloadSpeed("接收数据中..");
         response  = (FtpWebResponse)request.GetResponse();
         getStream = response.GetResponseStream();
         int RemainTime = 0;
         int n          = 1;
         var bytes      = new byte[102400];
         stopWatch.Reset();
         stopWatch.Start();
         int speed_tmp = 0;
         while (n > 0)
         {
             if (Pause)
             {
                 continue;
             }
             n              = getStream.Read(bytes, 0, bytes.Length);
             downloadBytes += n;
             SetProgressBar((int)downloadBytes, (int)TotalBytes);
             var f = (float)downloadBytes / (float)TotalBytes;
             f = f * 100f;
             ShowPercent(((int)f).ToString() + "%");
             speed_tmp += n;
             if (stopWatch.ElapsedMilliseconds >= 800)
             {
                 stopWatch.Stop();
                 DownloadSpeed = speed_tmp * 1000f / stopWatch.ElapsedMilliseconds;
                 ShowDownloadSpeed(DownloadSpeed.ToString());
                 RemainTime = (int)((TotalBytes - downloadBytes) / DownloadSpeed);
                 ShowRemainTime(RemainTime.ToString());
                 speed_tmp = 0;
                 stopWatch.Reset();
                 stopWatch.Start();
             }
             wrStream.Write(bytes, 0, n);
         }
         getStream.Dispose();
         wrStream.Dispose();
         File.Move(_path_Tmp, savePath);
         Dispose();
         return(true);
     }
     catch (Exception e)
     {
         this.e = e;
         GlobalEvent.WriteLog(e.Message);
         Dispose();
         return(false);
     }
     finally
     {
         Dispose();
     }
 }