/// <summary> /// 下载Apk文件 /// </summary> /// <param name="Path"></param> /// <param name="Id"></param> /// <returns></returns> public ActionResult DownApkFile(string Path, int Id) { IMobileVersionBLL mobileVersionBll = BLLFactory <IMobileVersionBLL> .GetBLL("MobileVersionBLL"); T_MobileVersion mobileVersion = mobileVersionBll.GetEntity(u => u.Id == Id); //获取文件的相对路径 var path = Server.MapPath(Path); //如果客户端信息版本不存在 if (mobileVersion != null) { //获取文件名 var item = mobileVersion.ApkFilePath.Substring(12); //如果不包含改路径 if (!System.IO.File.Exists(path)) { return(RedirectToAction("MobileVersion", "Error404")); } return(File(path, "application/octet-stream", item)); } return(RedirectToAction("MobileVersion", "VersionList")); }
public JsonResult DeleteVersion(int id) { JsonModel jm = new JsonModel(); IMobileVersionBLL mobileVersionBll = BLLFactory <IMobileVersionBLL> .GetBLL("MobileVersionBLL"); // 根据指定id值获取实体对象 var versionInfo = mobileVersionBll.GetEntity(index => index.Id == id); if (versionInfo != null) { //修改平台用户对应的角色集合 if (mobileVersionBll.DeleteVersion(id)) { //删除apk文件 string apkPath = versionInfo.ApkFilePath; string fullDirectory = Server.MapPath(apkPath); if (!string.IsNullOrEmpty(apkPath)) { FileInfo f = new FileInfo(fullDirectory); if (f.Exists) { f.Delete(); } } jm.Content = "删除指定版本" + versionInfo.VersionName + "成功"; } } else { jm.Msg = "该版本不存在"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public void DownStoreApk() { //调用版本信息BLL层获取最新的版本信息 IMobileVersionBLL versionBll = BLLFactory <IMobileVersionBLL> .GetBLL("MobileVersionBLL"); var Versions = versionBll.GetList(v => v.Type == ConstantParam.MOBILE_TYPE_SHOP, "VersionCode", false); //如果版本信息不为空 if (Versions != null && Versions.Count() > 0) { var highestVersion = Versions.First(); if (highestVersion != null) { string filePath = Server.MapPath(highestVersion.ApkFilePath);//路径 FileInfo fileInfo = new FileInfo(filePath); string fileName = fileInfo.Name; Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName); Response.AddHeader("Content-Length", fileInfo.Length.ToString()); Response.AddHeader("Content-Transfer-Encoding", "binary"); Response.ContentType = "application/octet-stream"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); Response.WriteFile(fileInfo.FullName); Response.Flush(); Response.End(); } } }
public ApiResultModel GetVersionInfo([FromUri] TokenModel model) { ApiResultModel resultModel = new ApiResultModel(); try { //获取当前用户 IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //如果验证Token不通过或已过期 if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); userBll.Update(user); //调用版本信息BLL层获取最新的版本信息 IMobileVersionBLL versionBll = BLLFactory <IMobileVersionBLL> .GetBLL("MobileVersionBLL"); var Versions = versionBll.GetList(v => v.Type == ConstantParam.MOBILE_TYPE_PROPERTY, "VersionCode", false); //如果版本信息不为空 if (Versions != null && Versions.Count() > 0) { var highestVersion = Versions.First(); if (highestVersion != null) { resultModel.result = new { VersionCode = highestVersion.VersionCode, VersionName = highestVersion.VersionName, Desc = highestVersion.Desc, ApkFilePath = highestVersion.ApkFilePath }; } } else { resultModel.Msg = APIMessage.NO_APP; } } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public JsonResult AddVersion(MobileVersionModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { string apkFilePath = ""; // 判断apk文件夹是否存在 if (Directory.Exists(Server.MapPath(ConstantParam.APK_FILE_DIR)) == false) { Directory.CreateDirectory(Server.MapPath(ConstantParam.APK_FILE_DIR)); } // 上传单个文件 if (System.Web.HttpContext.Current.Request.Files.Count > 0) { HttpPostedFile PostedFile = System.Web.HttpContext.Current.Request.Files[0]; if (PostedFile.ContentLength > 0) { string FileName = PostedFile.FileName; string strExPrentFile = FileName.Substring(FileName.LastIndexOf(".") + 1); var formatName = (model.Type == 0 ? "Owner_" : "Property_") + model.VersionCode; apkFilePath = ConstantParam.APK_FILE_DIR + formatName + "." + strExPrentFile; var path = Server.MapPath(apkFilePath); PostedFile.SaveAs(path); // 保存表单内容 IMobileVersionBLL mobileVersionBll = BLLFactory <IMobileVersionBLL> .GetBLL("MobileVersionBLL"); T_MobileVersion newVersion = new T_MobileVersion() { VersionCode = model.VersionCode, VersionName = model.VersionName, Type = model.Type, Desc = model.Desc, ApkFilePath = apkFilePath }; // 保存到数据库 mobileVersionBll.Save(newVersion); } else { jm.Msg = "不能上传空文件"; } //日志记录 jm.Content = "新增移动端版本" + model.VersionName; } } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult VersionList(MobileVersionSearchModel model) { IMobileVersionBLL mobileVersionBll = BLLFactory <IMobileVersionBLL> .GetBLL("MobileVersionBLL"); Expression <Func <T_MobileVersion, bool> > where = u => (model.Type == null ? true : u.Type == model.Type) && (string.IsNullOrEmpty(model.Desc) ? true : u.Desc.Contains(model.Desc)); //排序 var sortModel = this.SettingSorting("Id", false); model.List = mobileVersionBll.GetPageList(where, sortModel.SortName, sortModel.IsAsc, model.PageIndex) as PagedList <T_MobileVersion>; model.TypeList = getTypeList(); return(View(model)); }
/// <summary> /// 远程验证指定版本名称是否存在 /// </summary> /// <param name="UserName">版本名称</param> /// <param name="UserId">版本id,新增时恒为0</param> public ContentResult RemoteCheckExist(int Id, int type, string versionName) { IMobileVersionBLL mobileVersionBll = BLLFactory <IMobileVersionBLL> .GetBLL("MobileVersionBLL"); // 版本名称已存在 if (mobileVersionBll.Exist(m => m.VersionName == versionName && m.Type == type && m.Id != Id)) { // 校验不通过 return(Content("false")); } else { return(Content("true")); } }