public void Test_DeleteAppFilePath()
 {
     _targetObj.DeleteAppFilePath("", "");
 }
Esempio n. 2
0
        /// <summary>
        /// 因實體檔案 目前已 dev server C:/AppOs 路徑下為主 所以再本機 測試 會有無法刪除檔案情形
        /// </summary>
        /// <param name="appListItem"></param>
        /// <returns></returns>
        public TResult <bool> DeleteFile(AppListItem appListItem)
        {
            bool deleted = false;

            if (string.IsNullOrEmpty(appListItem.AppOSID))
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "無法刪除實體檔案 因為 AppOsId 為空值"));
            }

            if (string.IsNullOrEmpty(appListItem.FilePath))
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "無實體安裝檔案"));
            }

            //IOS 刪除檔案
            if (appListItem.OSType == "IOS")
            {
                //Plist 檔案
                string filePath = $"{_configContext.UploadPath}/{appListItem.FilePath}";
                //ipa 檔案
                string fileName = $"{_configContext.UploadPath}/{appListItem.FileName}";

                if (!File.Exists(filePath))
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, " 無實體安裝Plist路徑檔案"));
                }

                if (!File.Exists(fileName))
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, " 無實體安裝ipa路徑檔案"));
                }

                //刪除實體檔案
                File.Delete(filePath);
                File.Delete(fileName);
            }

            //Android 刪除檔案
            if (appListItem.OSType == "Android")
            {
                //apk 檔案 Android filePath  為 .apk 檔案路徑 fileName 為原.apk 黨案名稱
                string filePath = $"{_configContext.UploadPath}/{appListItem.FilePath}";

                if (!File.Exists(filePath))
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, " 無實體安裝apk路徑檔案"));
                }

                //刪除實體檔案
                File.Delete(filePath);
            }

            //DB 更新
            deleted = _appListService.DeleteAppFilePath(appListItem.AppOSID);

            if (deleted)
            {
                return(TResult <bool> .OK(true, "OK"));
            }
            else
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "再刪除資料庫 欄位 FilePath出現錯誤"));
            }
        }