Exemple #1
0
        private void UnzipTrigger(File_DownloadItemViewModel fileItem)
        {
            if (fileItem == null)
            {
                return;
            }
            bool flag = false;

            if (this.MeetingDataCT_UnZip_Event != null)
            {
                this.MeetingDataCT_UnZip_Event(fileItem);
            }
            try
            {
                UnZipTool unZipTool = new UnZipTool();
                flag = unZipTool.UnZip(fileItem.StorageFilePath, fileItem.UnZipFilePath, "", true);
            }
            catch (Exception ex)
            {
                LogTool.Debug(ex);
            }
            if (flag)
            {
                UpdateToDB(fileItem, true);
                fileItem.FileType = MeetingFileType.已下載完成;
                return;
            }
            ResetFileItemDB(fileItem);
            fileItem.FileType = MeetingFileType.解壓縮失敗;
            DeleteFiles(fileItem);
            if (this.MeetingDataCT_UnZipError_Event != null)
            {
                this.MeetingDataCT_UnZipError_Event(fileItem);
            }
            if (this.Home_UnZipError_Event != null)
            {
                this.Home_UnZipError_Event(string.Format("檔名: {0},{1}", fileItem.FileName, Enum.GetName(typeof(MeetingFileType), MeetingFileType.解壓縮失敗)));
            }
        }
        private void UnzipTrigger(File_DownloadItemViewModel fileItem)
        {
            if (fileItem == null)
            {
                return;
            }

            bool success = false;

            if (MeetingDataCT_UnZip_Event != null)
            {
                MeetingDataCT_UnZip_Event(fileItem);
            }

            // 解壓縮時會自動檢查目的地資料是否存在
            // 所以不用檢查了
            // Directory.CreateDirectory(fileItem.UnZipFilePath);
            try
            {
                UnZipTool uz = new UnZipTool();
                success = uz.UnZip(fileItem.StorageFilePath, fileItem.UnZipFilePath, "", true);
            }
            catch (Exception ex)
            {
                LogTool.Debug(ex);
            }
            if (success == true)
            {
                // 儲存下載狀態
                UpdateToDB(fileItem, true);

                //  解壓縮成功
                fileItem.FileType = MeetingFileType.已下載完成;

                //if (MeetingDataCT_DownloadFileCompleted_Event != null)
                //    MeetingDataCT_DownloadFileCompleted_Event(fileItem);

                //if (MeetingRoom_DownloadProgressChanged_Event != null)
                //    MeetingRoom_DownloadProgressChanged_Event(fileItem, false);
            }
            else
            {
                ResetFileItemDB(fileItem);


                fileItem.FileType = MeetingFileType.解壓縮失敗;

                // 解壓縮失敗,要記得把原始檔案和解壓縮資料夾一起刪除
                DeleteFiles(fileItem);

                if (MeetingDataCT_UnZipError_Event != null)
                {
                    MeetingDataCT_UnZipError_Event(fileItem);
                }

                if (Home_UnZipError_Event != null)
                {
                    Home_UnZipError_Event(string.Format("檔名: {0},{1}"
                                                        , fileItem.FileName
                                                        , Enum.GetName(typeof(MeetingFileType), MeetingFileType.解壓縮失敗)));
                }
            }
        }
        private void UnzipTrigger(Law_DownloadItemViewModel lawItem)
        {
            if (lawItem == null)
            {
                return;
            }

            if (lawItem.FileType == LawFileType.已下載完成)
            {
                lawItem.FileType = LawFileType.解壓縮中;
            }
            else //LawFileType.更新檔已下載完成
            {
                lawItem.FileType = LawFileType.更新檔解壓縮中;
            }


            bool success = false;

            if (LawListCT_UnZip_Event != null)
            {
                LawListCT_UnZip_Event(lawItem);
            }

            try
            {
                UnZipTool uz = new UnZipTool();
                success = uz.UnZip(lawItem.StorageFilePath, lawItem.UnZipFilePath, "", true);
            }
            catch (Exception ex)
            {
                LogTool.Debug(ex);
                // 解壓縮失敗
            }

            // 解壓縮成功
            if (success == true)
            {
                // 一般檔案解壓縮中
                if (lawItem.FileType == LawFileType.解壓縮中)
                {
                    lawItem.FileType = LawFileType.已下載完成;
                }
                else // 更新檔解壓縮中
                {
                    lawItem.FileType = LawFileType.更新檔已下載完成;
                }
            }
            else // 解壓縮失敗
            {
                // 一般檔案解壓縮失敗
                // 只有一般檔案解壓縮失敗才要寫DB
                if (lawItem.FileType == LawFileType.解壓縮中)
                {
                    lawItem.DownloadBytes  = 0;
                    lawItem.TotalBytes     = 0;
                    lawItem.LastPercentage = 0;

                    if (File.Exists(lawItem.StorageFilePath) == true)
                    {
                        File.Delete(lawItem.StorageFilePath);
                    }
                    //寫DB
                    string SQL        = @"update  LawRow set AtDownloadFinished_XmlUpDate=@1
                                           , Link=@2,StorageFileName=@3
                                           , DownloadBytes=@4,TotalBytes=@5 where ID=@6 and UserID=@7";
                    int    successNum = MSCE.ExecuteNonQuery(SQL
                                                             , lawItem.UpDate.ToString("yyyy/MM/dd HH:mm:ss")
                                                             , lawItem.Link
                                                             , lawItem.StorageFileName
                                                             , lawItem.DownloadBytes.ToString()
                                                             , lawItem.TotalBytes.ToString()
                                                             , lawItem.ID
                                                             , lawItem.UserID);

                    if (successNum < 1)
                    {
                        LogTool.Debug(new Exception("DB失敗:" + SQL));
                    }
                }
                else
                {
                    // 更新檔解壓縮失敗
                    // 不寫DB
                }

                // 一般檔案解壓縮失敗
                if (lawItem.FileType == LawFileType.解壓縮中)
                {
                    lawItem.FileType = LawFileType.解壓縮失敗;
                    if (LawListCT_UnZipError_Event != null)
                    {
                        LawListCT_UnZipError_Event(lawItem);
                    }

                    if (Home_UnZipError_Event != null)
                    {
                        Home_UnZipError_Event(string.Format("{0} {1}"
                                                            , PaperLess_Emeeting.Properties.Settings.Default.LawButtonName
                                                            , Enum.GetName(typeof(LawFileType), LawFileType.解壓縮失敗)));
                    }
                    lawItem.FileType = LawFileType.從未下載;
                }
                else // 更新的檔案解壓縮失敗
                {
                    lawItem.FileType = LawFileType.更新檔解壓縮失敗;
                    if (LawListCT_UnZipError_Event != null)
                    {
                        LawListCT_UnZipError_Event(lawItem);
                    }

                    if (Home_UnZipError_Event != null)
                    {
                        Home_UnZipError_Event(string.Format("檔名: {0},{1}"
                                                            , PaperLess_Emeeting.Properties.Settings.Default.LawButtonName
                                                            , Enum.GetName(typeof(LawFileType), LawFileType.更新檔解壓縮失敗)));
                    }
                    lawItem.FileType = LawFileType.更新檔未下載;
                }
            }
        }
        private void UnzipTrigger(Law_DownloadItemViewModel lawItem)
        {
            if (lawItem == null)
            {
                return;
            }
            if (lawItem.FileType == LawFileType.已下載完成)
            {
                lawItem.FileType = LawFileType.解壓縮中;
            }
            else
            {
                lawItem.FileType = LawFileType.更新檔解壓縮中;
            }
            bool flag = false;

            if (this.LawListCT_UnZip_Event != null)
            {
                this.LawListCT_UnZip_Event(lawItem);
            }
            try
            {
                UnZipTool unZipTool = new UnZipTool();
                flag = unZipTool.UnZip(lawItem.StorageFilePath, lawItem.UnZipFilePath, "", true);
            }
            catch (Exception ex)
            {
                LogTool.Debug(ex);
            }
            if (flag)
            {
                if (lawItem.FileType == LawFileType.解壓縮中)
                {
                    lawItem.FileType = LawFileType.已下載完成;
                }
                else
                {
                    lawItem.FileType = LawFileType.更新檔已下載完成;
                }
                return;
            }
            if (lawItem.FileType == LawFileType.解壓縮中)
            {
                lawItem.DownloadBytes  = 0L;
                lawItem.TotalBytes     = 0L;
                lawItem.LastPercentage = 0.0;
                if (File.Exists(lawItem.StorageFilePath))
                {
                    File.Delete(lawItem.StorageFilePath);
                }
                string text = "update  LawRow set AtDownloadFinished_XmlUpDate=@1\r\n                                           , Link=@2,StorageFileName=@3\r\n                                           , DownloadBytes=@4,TotalBytes=@5 where ID=@6 and UserID=@7";
                int    num  = MSCE.ExecuteNonQuery(text, lawItem.UpDate.ToString("yyyy/MM/dd HH:mm:ss"), lawItem.Link, lawItem.StorageFileName, lawItem.DownloadBytes.ToString(), lawItem.TotalBytes.ToString(), lawItem.ID, lawItem.UserID);
                if (num < 1)
                {
                    LogTool.Debug(new Exception("DB失敗:" + text));
                }
            }
            if (lawItem.FileType == LawFileType.解壓縮中)
            {
                lawItem.FileType = LawFileType.解壓縮失敗;
                if (this.LawListCT_UnZipError_Event != null)
                {
                    this.LawListCT_UnZipError_Event(lawItem);
                }
                if (this.Home_UnZipError_Event != null)
                {
                    this.Home_UnZipError_Event(string.Format("{0} {1}", Settings.Default.LawButtonName, Enum.GetName(typeof(LawFileType), LawFileType.解壓縮失敗)));
                }
                lawItem.FileType = LawFileType.從未下載;
            }
            else
            {
                lawItem.FileType = LawFileType.更新檔解壓縮失敗;
                if (this.LawListCT_UnZipError_Event != null)
                {
                    this.LawListCT_UnZipError_Event(lawItem);
                }
                if (this.Home_UnZipError_Event != null)
                {
                    this.Home_UnZipError_Event(string.Format("檔名: {0},{1}", Settings.Default.LawButtonName, Enum.GetName(typeof(LawFileType), LawFileType.更新檔解壓縮失敗)));
                }
                lawItem.FileType = LawFileType.更新檔未下載;
            }
        }