public JsonResult UpdatePackage(FormCollection form) { JsonReturnMessages data = new JsonReturnMessages() { IsSuccess = true, Msg = "操作成功" }; Package4AI package = new Package4AI(); SMC_PackageExtHistory history = new SMC_PackageExtHistory(); package.CreateUid = form["packageCreateUser"]; package.UpdateUid = CurrentUser.UserUId; package.CreateTime = Convert.ToDateTime(form["packageCreateDateTime"]); package.UpdateTime = DateTime.Now; package.DownloadUri = form["packageFileName"]; package.Name = form["packageName"]; package.DisplayName = form["packageDisplayName"]; package.ClientType = form["packageClientType"]; package.Type = form["packageType"]; package.Version = form["packageVersion"]; package.BuildVer = Convert.ToInt32(form["packageBuildVer"]); package.Description = form["packageDescription"]; package.ID = Convert.ToInt32(form["packageID"]); SMC_PackageExt ext = BoFactory.GetAppCenterBO.GetPackageExt(package.ID); string tableName = ext.TableName.ToLower(); if (tableName != "webapplication" && tableName != "smc_package4out") { package.ID = ext.TableID; } for (int appIndex = 0; appIndex < Convert.ToInt32(form["applicationCount"]); appIndex++) { App4AI app4AI = new App4AI(); if (!"".Equals(form["AppCode_" + appIndex.ToString()])) { app4AI.AppID = Convert.ToInt32(form["AppCode_" + appIndex.ToString()]); } app4AI.AppCode = form["AppName_" + appIndex.ToString()]; app4AI.ClientType = form["AppCheckClentType_" + appIndex.ToString()]; app4AI.IconUri = form["AppIco_" + appIndex.ToString()]; app4AI.Seq = 1; app4AI.CreateTime = package.CreateTime; app4AI.UpdateTime = DateTime.Now; app4AI.CreateUid = package.CreateUid; app4AI.UpdateUid = CurrentUser.UserUId; for (int activtyIndex = 0; activtyIndex < Convert.ToInt32(form["activityCount_" + appIndex.ToString()]); activtyIndex++) { Action4Android action4Android = new Action4Android(); action4Android.Seq = Convert.ToInt32(form["ActivitySeq_" + appIndex.ToString() + "_" + activtyIndex.ToString()]); action4Android.DisplayName = form["ActivityDisplayName_" + appIndex.ToString() + "_" + activtyIndex.ToString()]; action4Android.IsLaunch = Convert.ToBoolean(form["ActivityLaunch_" + appIndex.ToString() + "_" + activtyIndex.ToString()]); action4Android.IconUri = form["ActivityIco_" + appIndex.ToString() + "_" + activtyIndex.ToString()]; action4Android.ShortName = form["ActivityShortName_" + appIndex.ToString() + "_" + activtyIndex.ToString()]; action4Android.Name = form["ActivityName_" + appIndex.ToString() + "_" + activtyIndex.ToString()]; action4Android.CreateTime = package.CreateTime; action4Android.UpdateTime = DateTime.Now; action4Android.CreateUid = package.CreateUid; action4Android.UpdateUid = CurrentUser.UserUId; app4AI.Package4AIID = package.ID; action4Android.App4AIID = package.ID; Action4Android a4a = BoFactory.GetAction4AndroidBO.Get(action4Android.Name); if (a4a == null) app4AI.ActionList.Add(action4Android); } IList<KeyValuePair<string, object>> pars = new List<KeyValuePair<string, object>>(); pars.Add(new KeyValuePair<string, object>("Package4AIID", app4AI.Package4AIID)); pars.Add(new KeyValuePair<string, object>("AppCode", app4AI.AppCode)); pars.Add(new KeyValuePair<string, object>("ClientType", app4AI.ClientType)); App4AI _app4ai = BoFactory.GetApp4AIBO.Get(pars); if (_app4ai == null) { package.App4AIList.Add(app4AI); } else { _app4ai.AppID = app4AI.AppID; BoFactory.GetApp4AIBO.Update(_app4ai); } } try { string saveFileName = string.Format("{0}_v{1}_{2}{3}", package.Name, package.BuildVer, DateTime.Now.ToString("yyyyMMddHHmmss"), Path.GetExtension(package.DownloadUri)); string tempFilePath = Path.Combine(TEMPPATH, package.DownloadUri); string saveFilePath = Path.Combine(SAVEPATH, saveFileName); if (package.ClientType.EndsWith("ios", StringComparison.CurrentCultureIgnoreCase)) { string padUrl = string.Empty; string phoneUrl = string.Empty; Common.Configuration.IOSConfiguration iosConfig = (Common.Configuration.IOSConfiguration)System.Configuration.ConfigurationManager.GetSection("PublishConfig"); if (iosConfig != null && iosConfig.IOSPublishs != null) { foreach (Common.Configuration.IOSPublishElement item in iosConfig.IOSPublishs) { if (item.ClientType.StartsWith("Pad/iOS", StringComparison.CurrentCultureIgnoreCase)) padUrl = item.Url; if (item.ClientType.StartsWith("Phone/iOS", StringComparison.CurrentCultureIgnoreCase)) phoneUrl = item.Url; } } if (package.Type.Equals("Main", StringComparison.CurrentCultureIgnoreCase)) { if (package.ClientType.StartsWith("Pad", StringComparison.CurrentCultureIgnoreCase)) { package.DownloadUri = @"itms-services://?action=download-manifest&url=" + padUrl; } else if (package.ClientType.StartsWith("Phone", StringComparison.CurrentCultureIgnoreCase)) { package.DownloadUri = @"itms-services://?action=download-manifest&url=" + phoneUrl; } } } else { string padUrl = string.Empty; string phoneUrl = string.Empty; Common.Configuration.IOSConfiguration iosConfig = (Common.Configuration.IOSConfiguration)System.Configuration.ConfigurationManager.GetSection("PublishConfig"); if (iosConfig != null && iosConfig.IOSPublishs != null) { foreach (Common.Configuration.IOSPublishElement item in iosConfig.IOSPublishs) { if (item.ClientType.StartsWith("Pad/Android", StringComparison.CurrentCultureIgnoreCase)) padUrl = item.Url; if (item.ClientType.StartsWith("Phone/Android", StringComparison.CurrentCultureIgnoreCase)) phoneUrl = item.Url; } } if (package.Type.Equals("Main", StringComparison.CurrentCultureIgnoreCase)) { package.DownloadUri = Path.Combine(AppConfig.PackUrl, saveFileName); } } SMC_PackageExt _ext = BoFactory.GetAppCenterBO.GetPackage("Package4AI", package.ID.ToString()); _ext.pe_LastVersion = _ext.pe_Version; _ext.pe_Version = package.Version; _ext.pe_FileUrl = "~/PackageExt/" + _ext.pe_id + "/" + Path.GetFileName(tempFilePath); GlobalParam parm = Bo.BoFactory.GetGlobalParamBO.GetGlobalParam("app_sj_need_auth"); if (parm.ConfigValue != "0") { string serializationPath = Server.MapPath("~/PackageSerialization/") + _ext.pe_id + "/"; if (!Directory.Exists(serializationPath)) Directory.CreateDirectory(serializationPath); using (Stream fStream = new FileStream(serializationPath + "package.xml", FileMode.Create, FileAccess.ReadWrite)) { XmlSerializer xmlFormat = new XmlSerializer(typeof(Package4AI)); xmlFormat.Serialize(fStream, package); fStream.Close(); fStream.Dispose(); } XmlDocument xmlDoc = new XmlDocument(); string content = String.Format("<PackagePath><TempFilePath>{0}</TempFilePath><SaveFileName>{1}</SaveFileName></PackagePath>", tempFilePath, saveFilePath); xmlDoc.LoadXml(content); xmlDoc.Save(serializationPath + "path.xml"); //审核通过后再同步到Package4AI表 _ext.pe_UsefulStstus = "0";//上架状态 _ext.pe_AuthStatus = 0; _ext.pe_AuthSubmitName = CurrentUser.FullName; _ext.pe_AuthSubmitTime = DateTime.Now; _ext.pe_AuthSubmitUID = CurrentUser.UserUId; _ext.pe_UsefulTime = DateTime.Now; _ext.pe_UsefulOperatorUID = CurrentUser.UserUId; _ext.pe_UsefulOperatorName = CurrentUser.FullName; if (package.ClientType.ToLower().IndexOf("ios") != -1) _ext.pe_DownloadUri = package.DownloadUri; } _ext.pe_Version = form["packageVersion"]; _ext.pe_BuildVer = form["packageBuildVer"]; Bo.BoFactory.GetSMC_PackageExtBO.Save(_ext); if (parm.ConfigValue == "0") { //不需要审核,直接同步到应用中心 //同步至外网数据 BoFactory.GetVersionTrackBo.UpdatePackage(package, tempFilePath, saveFilePath); _ext.pe_UsefulStstus = "1";//上架状态 _ext.pe_UsefulTime = DateTime.Now; _ext.pe_UsefulOperatorUID = CurrentUser.UserUId; _ext.pe_UsefulOperatorName = CurrentUser.FullName; _ext.pe_AuthStatus = 1;//审核通过 _ext.pe_AuthTime = DateTime.Now; _ext.pe_AuthManUID = CurrentUser.UserUId; _ext.pe_AuthMan = CurrentUser.FullName; _ext.pe_DownloadUri = ConfigurationManager.AppSettings["packUrl"] + saveFileName; if (package.ClientType.ToLower().IndexOf("ios") != -1) _ext.pe_DownloadUri = package.DownloadUri; //内部发布到Package4AI BoFactory.GetCommonBO.SMC_PackageExtInternalRelease(_ext); //同步到应用中心 _SyncPackageExt(_ext); } #region 上传文件自动发布 if (package.Type.Equals("Main", StringComparison.CurrentCultureIgnoreCase)) { //更新server缓存 try { SmartBox.Console.Service.ServiceReference1.ManagerServiceClient cli = new Service.ServiceReference1.ManagerServiceClient(); cli.ResetClientVer(); } catch { data.Msg = "操作成功,更新Server缓存失败。如遇到未提示版本更新问题请联系管理员重启服务。"; } } #endregion } catch (Exception ex) { Log4NetHelper.Error(ex); data.IsSuccess = false; data.Msg = ex.Message; } return Json(data); }
public JsonResult UploadUpdatePackage(FormCollection form, string packageID, string filePath) { JsonReturnMessages data = new JsonReturnMessages(); data.IsSuccess = true; data.Msg = "操作成功"; string packageFileName = ""; string tempPackagePath = ""; HttpPostedFileBase file = null; try { if (string.IsNullOrEmpty(filePath)) { file = Request.Files[0]; packageFileName = Path.GetFileName(file.FileName); } else { packageFileName = Path.GetFileName(filePath); } tempPackagePath = System.IO.Path.Combine(TEMPPATH, packageFileName); //取出老的安装包信息 string packageid = packageID;//form["packageID"]; SMC_PackageExt ext = BoFactory.GetAppCenterBO.GetPackageExt(Convert.ToInt32(packageid)); string tableName = ext.TableName.ToLower(); if (tableName != "webapplication" && tableName != "smc_package4out") { packageid = ext.TableID.ToString(); } if (string.IsNullOrEmpty(packageid)) { throw new Exception("未找到参数packageID"); } Package4AI oldPackage = BoFactory.GetVersionTrackBo.GetPackage4AI(packageid); if (oldPackage == null) { //throw new Exception("未找到要更新的安装包!请稍候再试"); } //上传新安装包 bool isAndroidPackage = true; if (".apk".Equals(Path.GetExtension(packageFileName), StringComparison.CurrentCultureIgnoreCase)) { isAndroidPackage = true; } else if (".ipa".Equals(Path.GetExtension(packageFileName), StringComparison.CurrentCultureIgnoreCase)) { isAndroidPackage = false; } else { throw new Exception("只能上传Android和IOS的安装包"); } SMC_PackageExtHistory history = null; List<KeyValuePair<string, object>> pars = new List<KeyValuePair<string, object>>(); pars.Add(new KeyValuePair<string, object>("pe_id", ext.pe_id)); pars.Add(new KeyValuePair<string, object>("pe_version", ext.pe_Version)); history = Bo.BoFactory.GetSMC_PackageExtHistoryBO.Get(pars); bool newhistory = false; if (history == null) { history = new SMC_PackageExtHistory(); newhistory = true; } history.pe_Version = ext.pe_Version; string vhistorypath = "~/PackageExtHistory/" + ext.pe_id + "/" + ext.pe_Version + "/"; string vsourcepath = "~/PackageExt/" + ext.pe_id + "/"; string historypath = Server.MapPath(vhistorypath); if (!Directory.Exists(historypath)) { Directory.CreateDirectory(historypath); } string sourcepath = Server.MapPath(vsourcepath); if (!Directory.Exists(sourcepath)) { Directory.CreateDirectory(sourcepath); } string[] files = Directory.GetFiles(sourcepath); string fPath = ""; if (files != null && files.Length > 0) { foreach (string f in files) { if (f.EndsWith(".ipa") || f.EndsWith(".apk")) { fPath = f; break; } } } string filename = Path.GetFileName(fPath); historypath = historypath + filename; vhistorypath = vhistorypath + filename; try { if (!String.IsNullOrEmpty(fPath) && System.IO.File.Exists(fPath)) { //将原来的文件复制到历史目录里 System.IO.File.Move(fPath, historypath); } } catch (Exception ex) { } if (vhistorypath.EndsWith(".apk") || vhistorypath.EndsWith(".ipa")) history.pe_PackageUrl = vhistorypath; history.pe_Version = ext.pe_Version; history.pe_CreateTime = DateTime.Now; history.pe_id = ext.pe_id; if (newhistory) Bo.BoFactory.GetSMC_PackageExtHistoryBO.Insert(history); else Bo.BoFactory.GetSMC_PackageExtHistoryBO.Update(history); //if (string.IsNullOrEmpty(filePath)) //{ //保存文件 string saveDir = Path.GetDirectoryName(tempPackagePath); if (!System.IO.Directory.Exists(saveDir)) { System.IO.Directory.CreateDirectory(saveDir); } if (System.IO.File.Exists(tempPackagePath)) { System.IO.File.Delete(tempPackagePath); } if (!string.IsNullOrEmpty(filePath)) { System.IO.File.Copy(filePath, tempPackagePath); System.IO.File.Copy(tempPackagePath, sourcepath + Path.GetFileName(tempPackagePath));//复制到PackageExt目录 } else { file.SaveAs(tempPackagePath); System.IO.File.Copy(tempPackagePath, sourcepath + Path.GetFileName(tempPackagePath), true);//复制到PackageExt目录 } //} //读取文件配置 Package4AI newpackage; if (isAndroidPackage) { newpackage = ReadAndroidPackage(tempPackagePath); } else { newpackage = ReadIOSPackage(tempPackagePath); } string debug_mode = ConfigurationManager.AppSettings["debug_mode"]; if (!String.IsNullOrEmpty(debug_mode) && debug_mode.ToLower() == "true") { } else { if (!newpackage.Name.Equals(oldPackage.Name)) { throw new Exception("安装包名称不匹配,不能更新!"); } if (newpackage.BuildVer <= oldPackage.BuildVer) { throw new Exception("当前版本号是" + oldPackage.BuildVer + " ! 上传包版本号小于当前版本号,不能更新!"); } } //将旧安装包信息覆盖到新安装包中 if (oldPackage != null) { newpackage.ID = oldPackage.ID; newpackage.DisplayName = oldPackage.DisplayName; newpackage.Description = oldPackage.Description; newpackage.CreateTime = oldPackage.CreateTime; newpackage.CreateUid = oldPackage.CreateUid; foreach (App4AI app4ai in newpackage.App4AIList) { List<App4AI> oldApp4AIList = oldPackage.App4AIList.Where(x => x.AppCode.Equals(app4ai.AppCode, StringComparison.CurrentCultureIgnoreCase)).ToList(); if (oldApp4AIList.Count <= 0) { app4ai.AppID = -1; continue; } App4AI oldApp4AI = oldApp4AIList[0]; app4ai.AppID = oldApp4AI.AppID; app4ai.CreateUid = oldApp4AI.CreateUid; app4ai.CreateTime = oldApp4AI.CreateTime; app4ai.IconUri = oldApp4AI.IconUri; app4ai.Seq = oldApp4AI.Seq; foreach (Action4Android action in app4ai.ActionList) { List<Action4Android> oldActionList = oldApp4AI.ActionList.Where(x => x.Name.Equals(action.Name)).ToList(); if (oldActionList.Count <= 0) { continue; } Action4Android oldAction = oldActionList[0]; action.DisplayName = oldAction.DisplayName; action.IconUri = oldAction.IconUri; action.Seq = oldAction.Seq; action.CreateTime = oldAction.CreateTime; action.CreateUid = oldAction.CreateUid; } } } else { newpackage.CreateTime = DateTime.Now; } data.Data = newpackage; } catch (Exception ex) { Log4NetHelper.Error(ex); data.IsSuccess = false; data.Msg = ex.Message; } return Json(data, "text/html"); }
public JsonResult EditOutPackage(FormCollection form) { JsonReturnMessages data = new JsonReturnMessages() { IsSuccess = true, Msg = "操作成功" }; string id = form["po_ID"];//外部应用ID string packageId = BoFactory.GetVersionTrackBo.GetPeId(id, "SMC_Package4Out"); SMC_PackageExt pe = BoFactory.GetVersionTrackBo.GetPackageExt(packageId); SMC_Package4Out packageOut = BoFactory.GetVersionTrackBo.GetPackage4Out(id); packageOut.ClientType = form["cType"]; packageOut.DisplayName = form["DisplayName"]; packageOut.Description = form["Description"]; pe.pe_LastVersion = pe.pe_Version; pe.pe_Version = form["Version"]; packageOut.Version = form["Version"]; //文件更新 int i = Request.Files.Count; HttpPostedFileBase file = null; string filePath = ""; string packageFileName = ""; string conSolePath = HttpRuntime.AppDomainAppPath;//服务器路径 string pDir = SAVEOUTPATH + @"/" + packageId;//相对路径 用安装包ID做文件夹名 string saveDir = conSolePath + pDir; string svpath = "~/PackageExt/" + pe.pe_id + "/"; string spath = Server.MapPath(svpath); string dvpath = "~/PackageExtHistory/" + pe.pe_id + "/"; string dpath = Server.MapPath(dvpath); if (Directory.Exists(dpath) == false) Directory.CreateDirectory(dpath); SMC_PackageExtHistory his = null; bool is_pe_his_new = false; List<KeyValuePair<string, object>> pars = new List<KeyValuePair<string, object>>(); pars.Add(new KeyValuePair<string, object>("pe_id", pe.pe_id)); pars.Add(new KeyValuePair<string, object>("pe_Version", pe.pe_LastVersion)); his = Bo.BoFactory.GetSMC_PackageExtHistoryBO.Get(pars); if (his == null) { his = new SMC_PackageExtHistory(); his.pe_Version = pe.pe_LastVersion; his.pe_id = pe.pe_id; is_pe_his_new = true; } his.pe_CreateTime = DateTime.Now; his.pe_Version = pe.pe_LastVersion; if (i > 0) { //有新安装包文件更新 if (Request.Files[0].ContentLength > 0) { //删除旧文件 //string oldDir = conSolePath + SAVEOUTPATH + packageOut.DownloadUri; string oldDir = Server.MapPath(packageOut.DownloadUri.Replace(AppConfig.OutWebHost, "")); if (System.IO.File.Exists(oldDir)) { //System.IO.File.Delete(oldDir); } //创建新文件 file = Request.Files[0]; filePath = file.FileName; packageFileName = "外部安装包文件-" + Path.GetFileName(filePath); string savePath = System.IO.Path.Combine(saveDir, packageFileName); //移动附件到历史文件夹 string[] sfiles = Directory.GetFiles(spath); if (sfiles != null && sfiles.Length > 0) { foreach (string f in sfiles) { if (f.EndsWith(".apk") || f.EndsWith(".ipa")) { string filename = Path.GetFileName(f); try { System.IO.File.Move(spath + filename, dpath + filename); } catch { } his.pe_PackageUrl = dvpath + filename; } } } if (!System.IO.Directory.Exists(saveDir)) { System.IO.Directory.CreateDirectory(saveDir); } if (System.IO.File.Exists(savePath)) { System.IO.File.Delete(savePath); } pe.pe_FileUrl = svpath + Path.GetFileName(file.FileName); file.SaveAs(savePath); string sOutWebHost = AppConfig.OutWebHost; if (sOutWebHost.EndsWith("/")) sOutWebHost = AppConfig.OutWebHost.TrimEnd("/".ToCharArray()); packageOut.DownloadUri = sOutWebHost + "/" + AppConfig.OutPackUploadFolder + "/" + packageId.ToString() + @"/" + packageFileName; pe.pe_DownloadUri = packageOut.DownloadUri; } //有新的图标更新 if (Request.Files[1].ContentLength > 0) { //删除旧文件 string oldDir = "~/" + AppConfig.OutPackUploadFolder + "/" + packageId + "/AppIcon.png"; oldDir = Server.MapPath(oldDir); if (System.IO.File.Exists(oldDir)) { System.IO.File.Delete(oldDir); } //创建新文件 file = Request.Files[1]; packageFileName = "AppIcon.png"; string savePath = System.IO.Path.Combine(saveDir, packageFileName); if (!System.IO.Directory.Exists(saveDir)) { System.IO.Directory.CreateDirectory(saveDir); } if (System.IO.File.Exists(savePath)) { System.IO.File.Delete(savePath); } file.SaveAs(savePath); pe.pe_PictureUrl = "~/" + AppConfig.OutPackUploadFolder + "/" + packageId.ToString() + @"/" + packageFileName; } } if (is_pe_his_new) Bo.BoFactory.GetSMC_PackageExtHistoryBO.Insert(his); else Bo.BoFactory.GetSMC_PackageExtHistoryBO.Update(his); BoFactory.GetVersionTrackBo.UpdatePackage4Out(packageOut); pe.pe_UpdateTime = DateTime.Now; pe.pe_UpdateUid = CurrentUser.UserUId; pe.pe_IsTJ = form["pe_IsTJ"]; pe.pe_IsBB = form["pe_IsBB"]; pe.pe_ClientType = form["cType"]; pe.pe_UnitCode = form["Unit"]; pe.pe_UnitName = BoFactory.GetSMC_UnitBo.Get(pe.pe_UnitCode).Unit_Name; pe.pe_CategoryID = form["AppID"]; pe.pe_Category = BoFactory.GetVersionTrackBo.GetApplicationCategory(form["AppID"]).DisplayName; BoFactory.GetVersionTrackBo.UpdatePackageExt(pe); return Json(data, "text/html"); }