public void Get_Plist_Xml()
        {
            //Arrange
            string expectedXmlStr = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<!DOCTYPE plist PUBLIC ""-//Apple//DTD PLIST 1.0//EN"" ""http://www.apple.com/DTDs/PropertyList-1.0.dtd"">
<plist version=""1.0"">
<dict>
    <key>items</key>
    <array>
      <dict>
        <key>assets</key>
        <array>
          <dict>
            <key>kind</key>
            <string>software-package</string>
            <key>url</key>
            <string>http://localhost:53322/app/FtpsSyncTest/IOS/Install/1.0.0-6992412226f84c3388fa10d851e80fd5.ipa</string>
          </dict>
          <dict>
            <key>kind</key>
            <string>full-size-image</string>
            <key>needs-shine</key>
            <false/>
            <key>url</key>
            <string>http://localhost:53322/app/FtpsSyncTest/IOS/Images/716ed7f19c2e44748a89e47a9ca084ea.jpg</string>
          </dict>
          <dict>
            <key>kind</key>
            <string>display-image</string>
            <key>needs-shine</key>
            <false/>
            <key>url</key>
            <string>http://localhost:53322/app/FtpsSyncTest/IOS/Images/716ed7f19c2e44748a89e47a9ca084ea.jpg</string>
          </dict>
        </array>
        <key>metadata</key>
        <dict>
          <key>bundle-identifier</key>
          <string>com.wistron.portalapp.dev</string>
          <key>bundle-version</key>
          <string>1.0.0</string>
          <key>kind</key>
          <string>software</string>
          <key>subtitle</key>
          <string>FtpsSyncTest</string>
          <key>title</key>
          <string>FtpsSyncTest</string>
        </dict>
      </dict>
    </array>
  </dict>
</plist>";
            //Act
            string actualXmlStr = UploadFileHepler.GetPlistXml(_ipaUrl, _iconUrl, _packageName, _version, _appName);

            //Assert
            Assert.AreEqual(expectedXmlStr, actualXmlStr);
        }
示例#2
0
        public TResult <AppOsDetailsViewModel> GetAvailbleAppDescription(string appID, int appOsID, byte osType)
        {
            List <WisAppOsOther> wisAppOsOther = new List <WisAppOsOther>();
            WisAppList           wisAppList    = _appListService.GetAppName(appID);
            List <WisAppOs>      wisAppOs      = _appListService.GetAppOs(appID);
            List <WisAppPhoto>   wisAppPhoto   = _uploadFileService.GetPhotos(appID);

            AppDescription appDescription = _mapper.Map <WisAppList, AppDescription>(wisAppList);

            //取當前版
            AppOsInfo appNowVersion = _mapper.Map <WisAppOs, AppOsInfo>(
                wisAppOs.Where(
                    p => p.OSType == osType &&
                    p.Status == AppStatus.EnableBool &&
                    p.DelFlag == false &&
                    p.WebDownFlag == true &&
                    p.AppOSID == appOsID)?.OrderByDescending(p => p.CreateDT).FirstOrDefault());

            //是否要取得多載點 的path路徑
            if (appNowVersion.MultipleDownload)
            {
                wisAppOsOther = _uploadFileService.GetWisAppOsOther(appID, appOsID.ToString());
            }

            //至少會有 WisAppOS table 原始台灣載點路徑
            wisAppOsOther.Add(new WisAppOsOther {
                Site = "WHQ", FilePath = appNowVersion.FilePath
            });

            //組成完整載點路徑: endpoint+path url
            List <DownloadUrlList> downloadUrlList = UploadFileHepler.GetDownloadUrlList(_configContext.OtherSideEndPoint, wisAppOsOther);

            //歷史紀錄 前5筆
            List <AppOsInfo> appHistory = _mapper.Map <List <WisAppOs>, List <AppOsInfo> >(
                wisAppOs.Where(
                    p => p.OSType == osType &&
                    p.DelFlag == false
                    )?.OrderByDescending(p => p.CreateDT).Take(5).ToList());

            //圖片資訊 FileNumber = 5 為 icon 圖片
            List <AppPhotoContent> photo = _mapper.Map <List <WisAppPhoto>, List <AppPhotoContent> >(wisAppPhoto.Where(p => p.AppOS == osType)?.OrderBy(p => p.FileNumber).ToList());

            AppOsDetailsViewModel viewModel = new AppOsDetailsViewModel
            {
                Description   = appDescription,
                AppNowVersion = appNowVersion,
                AppOsHistory  = appHistory,
                Photo         = photo,
                DownloadList  = downloadUrlList
            };

            return(TResult <AppOsDetailsViewModel> .OK(viewModel, "OK"));
        }
示例#3
0
        /// <summary>
        /// 上傳 Ios Android 安裝檔案
        /// </summary>
        /// <param name="appOsInfo"></param>
        /// <param name="uploadFile"></param>
        /// <returns></returns>
        public async Task <TResult <AppOsInfo> > UploadInstallFile(AppOsInfo appOsInfo, IMatFileUploadEntry uploadFile)
        {
            //存放多載點 plist 檔案名稱
            List <DownloadUrlList> downloadUrlList = new List <DownloadUrlList>();

            #region 驗證檔案格式

            int findExtension = uploadFile.Name.LastIndexOf(".");

            if (string.IsNullOrEmpty(appOsInfo.Version))
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_VERSIONREQUIRED, "必須輸入 版本號碼"));
            }

            if (appOsInfo.Photo.Where(p => p.FileNumber == 5).FirstOrDefault() == null)
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "必須上傳 Icon 圖片"));
            }

            if (findExtension == -1)
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "檔案格式錯誤: 無附檔名"));
            }

            string extension = uploadFile.Name.Substring(uploadFile.Name.LastIndexOf(".")).ToLower();

            //驗證 Ios 是否符合格式 目前只看.ipa 檔案
            if (appOsInfo.OSType == OsType.Ios && !extension.Equals(".ipa"))
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "檔案格式限制:  IOS 安裝檔應為 .ipa 格式"));
            }

            //驗證 Android 是否符合格式 目前只看.apk 檔案
            if (appOsInfo.OSType == OsType.Android && !extension.Equals(".apk"))
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "檔案格式限制:  Android 安裝檔應為 .apk 格式"));
            }

            #endregion

            string fileName = $"{appOsInfo.Version}-{Guid.NewGuid().ToString("N")}{extension}"; //Create a new Name
            string osPath   = OsType.Ios == appOsInfo.OSType ? "IOS" : "Android";
            string filePath = Path.Combine(_configContext.UploadPath, appOsInfo.AppNameEn.Replace(" ", ""), osPath, "Install");

            //檔案資料夾路徑不存在就新增
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            using (var fs = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write))
            {
                await uploadFile.WriteToStreamAsync(fs);
            }

            #region 如果是 IOS 必須做出 Plist 檔案 和多載點 plist

            //如果是IOS 除了上傳.ipa 檔案 還要上傳 Plist xml file
            if (appOsInfo.OSType == OsType.Ios)
            {
                //圖片 url 路徑
                AppPhotoContent iosIconPhoto = appOsInfo.Photo.Where(P => P.FileNumber == 5).FirstOrDefault();

                //多載點 plist
                foreach (OtherSideEndPoint endPoint in _configContext.OtherSideEndPoint)
                {
                    // 組plist 黨案名稱
                    string pListFileName = $"{Guid.NewGuid().ToString("N")}{".plist"}";

                    // 組 ipa url 路徑
                    string ipaPath = $"{endPoint.Url}/{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}";

                    // 組圖片 url 路徑
                    string iconPath = iosIconPhoto != null ? $"{endPoint.Url}/{iosIconPhoto.FilePath.Replace(" ", "")}" : "";

                    //做出 plist xml 內容物
                    string plistXml = UploadFileHepler.GetPlistXml(ipaPath, iconPath, appOsInfo.PackageName, appOsInfo.Version, appOsInfo.AppNameEn);

                    //存入 Plist 實體路徑
                    File.WriteAllText(Path.Combine(filePath, pListFileName), plistXml);

                    //原始路徑 存在Wis_AppOS table
                    if (endPoint.Site == "WHQ")
                    { //原始載點不加入 DownloadUrlList
                      //為 plist 檔案路徑
                        appOsInfo.FilePath = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{pListFileName}";

                        //為 .ipa 檔案路徑
                        appOsInfo.FileName = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}";
                    }
                    else
                    {//多載點資訊 存在 Wis_AppOs_Other
                        downloadUrlList.Add(new DownloadUrlList
                        {
                            Site = endPoint.Site,
                            Url  = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{pListFileName}"//plist 路徑
                        });
                    }
                }

                //前端必須按下儲存按鈕  url資訊才會寫入 DB
                //Ios 上傳檔案路徑 是 plist檔案路徑
                appOsInfo.DownloadUrlList = downloadUrlList;
            }

            #endregion

            #region Android 處理檔案 路徑

            //Android 直接存放 apk 檔案路徑
            if (appOsInfo.OSType == OsType.Android)
            {
                foreach (OtherSideEndPoint endPoint in _configContext.OtherSideEndPoint)
                {
                    //Wis_AppOS url 路徑處理
                    if (endPoint.Site == "WHQ")
                    {
                        //為 .apk 檔案路徑
                        appOsInfo.FilePath = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}";

                        //為 .apk 原檔案名稱
                        appOsInfo.FileName = uploadFile.Name;
                    }
                    else
                    {//Wis_AppOs_Other 資訊
                        downloadUrlList.Add(new DownloadUrlList
                        {
                            Site = endPoint.Site,
                            Url  = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}"//.apk 檔案路徑
                        });
                    }
                }
                //Android 上傳檔案路徑 是apk檔案路徑 與原本路徑一模一樣
                appOsInfo.DownloadUrlList = downloadUrlList;
            }
            #endregion

            return(TResult <AppOsInfo> .OK(appOsInfo, "OK"));
        }