internal AppVersionInfo GetModelFromDataReader(IDataReader dr) { AppVersionInfo model = new AppVersionInfo(); model.ID = dr["ID"].ToInt32(); model.AppName = dr["AppName"].ToDBString(); model.AppVersion = dr["AppVersion"].ToDBString(); model.VersionType = dr["VersionType"].ToInt32(); model.VersionLevel = dr["VersionLevel"].ToInt32(); model.VersionTitle = dr["VersionTitle"].ToDBString(); model.VersionDesc = dr["VersionDesc"].ToDBString(); model.Creater = dr["Creater"].ToDBString(); model.CreateTime = dr["CreateTime"].ToDateTime(); if (Common_Func.readerExists(dr, "StrVersionType")) { model.StrVersionType = dr["StrVersionType"].ToDBString(); } if (Common_Func.readerExists(dr, "StrVersionLevel")) { model.StrVersionLevel = dr["StrVersionLevel"].ToDBString(); } return(model); }
public bool GetAppVersionByVersion(ref AppVersionInfo model, ref string strError) { try { using (IDataReader dr = _db.GetAppVersionByVersion(model)) { if (dr.Read()) { model = (GetModelFromDataReader(dr)); return(true); } else { strError = "找不到任何数据"; return(false); } } } catch (Exception ex) { strError = ex.Message; return(false); } finally { } }
private bool CompareVersion(AppVersionInfo appversion) { if (string.IsNullOrEmpty(appversion.AppVersion)) { return(false); } if (string.IsNullOrEmpty(appversion.LocalVersion)) { return(true); } string[] arrService = appversion.AppVersion.Split('.'); string[] arrLocal = appversion.LocalVersion.Split('.'); if (arrService.Length != 4) { return(false); } if (arrLocal.Length != 4) { return(true); } long lService = arrService[0].ToLong() * 1000000000L + arrService[1].ToLong() * 1000000L + arrService[2].ToLong() * 1000L + arrService[3].ToLong(); long lLocal = arrLocal[0].ToLong() * 1000000000L + arrLocal[1].ToLong() * 1000000L + arrLocal[2].ToLong() * 1000L + arrLocal[3].ToLong(); return(lService > lLocal); }
internal IDataReader GetAppVersionByVersion(AppVersionInfo model) { string strSql = string.Empty; strSql = string.Format("SELECT * FROM T_AppVersionLog WHERE AppName = '{0}' AND AppVersion = '{1}' ", model.AppName, model.AppVersion); return(dbFactory.ExecuteReader(CommandType.Text, strSql, null)); }
/// <summary> /// 检查版本更新 /// </summary> /// <param name="appversion">版本信息</param> /// <returns>是否需要更新</returns> public bool VerifyVersion(ref AppVersionInfo appversion, ref string strError) { try { string UpdateIP = string.Empty; string UpdateDir = string.Empty; Match m = Regex.Match(appversion.UpdateUrl, @"\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}"); if (m.Success) { UpdateIP = m.Value; UpdateDir = appversion.UpdateUrl.Substring(appversion.UpdateUrl.IndexOf('/', appversion.UpdateUrl.IndexOf(UpdateIP) + UpdateIP.Length) + 1); } else { //strError = "更新地址请使用IP域名"; //return false; } string NewAppPath = string.Empty; if (!string.IsNullOrEmpty(UpdateIP) && GetIPListByHostAddresses().Contains(UpdateIP)) { NewAppPath = string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, Path.Combine(UpdateDir, appversion.FileName)); if (!File.Exists(NewAppPath)) { //strError = "没有找到可对比的程序"; return(false); } FileVersionInfo fv = FileVersionInfo.GetVersionInfo(NewAppPath); appversion.AppVersion = fv.FileVersion; } else { string LocalPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, appversion.FileName); NewAppPath = Path.Combine(appversion.UpdateUrl, appversion.FileName); DownloadFile(appversion.FileName, NewAppPath); if (!File.Exists(LocalPath)) { //strError = "没有找到可对比的程序"; return(false); } FileVersionInfo fv = FileVersionInfo.GetVersionInfo(LocalPath); appversion.AppVersion = fv.FileVersion; File.Delete(LocalPath); } if (CompareVersion(appversion)) { AppVersionInfo model = new AppVersionInfo(); model.AppVersion = appversion.AppVersion; model.AppName = appversion.AppName; if (GetAppVersionByVersion(ref model, ref strError)) { model.LocalVersion = appversion.LocalVersion; model.UpdateUrl = appversion.UpdateUrl; model.UpdateAppName = appversion.UpdateAppName; model.UpdateAppPath = appversion.UpdateAppPath; model.FileName = appversion.FileName; appversion = model; } return(true); } else { //strError = "当前程序已经是最新版本"; return(false); } } catch (Exception ex) { strError = ex.Message; return(false); } }