public override void Dispose() { base.Dispose (); if (model != null) { model.Dispose (); model = null; } if (serviceModel != null) { serviceModel.Dispose (); serviceModel = null; } }
public AppReleaseInfo(UserModel m, AppRelease r) { Id = r.Id; AppVersion = r.AppVersion; AddinRootVersion = r.AddinRootVersion; LastUpdateTime = r.LastUpdateTime; if (r.CompatibleAppReleaseId != null) { var cr = m.GetAppRelease (r.CompatibleAppReleaseId.Value); CompatibleAppVersion = cr.AppVersion; } ZipUrl = "/Project/AppReleasePackage/" + Id; }
protected override void Dispose(bool disposing) { base.Dispose (disposing); if (model != null) { model.Dispose (); model = null; } if (serviceModel != null) { serviceModel.Dispose (); serviceModel = null; } }
internal static UserModel GetAdmin(int applicationId) { UserModel m = new UserModel (); m.db = DataConnection.GetConnection (); m.user = new User (); m.user.IsAdmin = true; m.application = m.db.SelectObjectById<Application> (applicationId); return m; }
public static UserModel GetForUser(string login, string password, int appId) { UserModel m = new UserModel (); m.db = DataConnection.GetConnection (); if (appId != -1) { m.application = m.db.SelectObjectById<Application> (appId); } else if (Settings.Default.SupportsMultiApps) { string app = GetCurrentAppName (); if (app != null) m.application = m.db.SelectObjectWhere<Application> ("Subdomain={0}", app); } else { m.application = m.db.SelectObjects<Application> ().FirstOrDefault (); } ServiceModel sm = ServiceModel.GetCurrent (); if (!string.IsNullOrEmpty (login)) { m.user = sm.GetUser (login); if (password != null && !m.user.CheckPassword (password)) m.user = null; } sm.Dispose (); if (m.application != null && m.user != null) { UserApplication uap = m.db.SelectObjectWhere<UserApplication> ("UserId={0} AND ApplicationId={1}", m.user.Id, m.application.Id); m.isAdmin = (uap != null && (uap.Permissions & ApplicationPermission.Administer) != 0); } else m.isAdmin = false; return m; }
static void AppendCompatibleRepo(UserModel m, string file) { string appVersion = Path.GetFileName (Path.GetDirectoryName (file)); AppRelease rel = m.GetAppReleaseByVersion (appVersion); if (rel == null || !rel.CompatibleAppReleaseId.HasValue) return; rel = m.GetAppRelease (rel.CompatibleAppReleaseId.Value); if (rel == null) return; XmlDocument repDoc = new XmlDocument (); repDoc.Load (file); XmlElement repoElem = repDoc.CreateElement ("Repository"); repDoc.DocumentElement.AppendChild (repoElem); XmlElement elem = repDoc.CreateElement ("Url"); elem.InnerText = "../" + rel.AppVersion + "/main.mrep"; repoElem.AppendChild (elem); repDoc.Save (file); }
internal static void GenerateInstallerXml(TextWriter sw, UserModel m, Release rel, params string[] platforms) { XmlTextWriter tw = new XmlTextWriter (sw); tw.Formatting = Formatting.Indented; tw.WriteStartElement ("Package"); tw.WriteStartElement ("Repositories"); foreach (string plat in platforms) { tw.WriteStartElement ("Repository"); tw.WriteAttributeString ("platform", plat); tw.WriteAttributeString ("appVersion", rel.TargetAppVersion); string url = "http://" + Settings.Default.WebSiteHost + "/" + rel.DevStatus.ToString() + "/" + plat + "/" + rel.TargetAppVersion; tw.WriteString (url); tw.WriteEndElement (); // Repository } tw.WriteEndElement (); // Repositories tw.WriteStartElement ("Addins"); tw.WriteStartElement ("Addin"); tw.WriteElementString ("Id", rel.AddinId); tw.WriteElementString ("Version", rel.Version); tw.WriteElementString ("Name", rel.AddinName); tw.WriteElementString ("Description", rel.AddinDescription); tw.WriteEndElement (); // Addin tw.WriteEndElement (); // Addins tw.WriteEndElement (); // Package }
internal static void GenerateInstallerFile(UserModel m, string packagesPath, Release rel, params string[] platforms) { string file = Path.ChangeExtension (packagesPath, m.CurrentApplication.AddinPackageExtension); using (StreamWriter sw = new StreamWriter (file)) { GenerateInstallerXml (sw, m, rel, platforms); } }
public static Release PublishRelease(UserModel m, SourceTag source, bool activate) { Release rel = m.GetPublishedRelease (source); if (rel != null) m.DeleteRelease (rel); Project p = m.GetProject (source.ProjectId); rel = new Release (); rel.ProjectId = source.ProjectId; rel.Status = p.HasFlag (ProjectFlag.AllowDirectPublish) || activate ? ReleaseStatus.PendingPublish : ReleaseStatus.PendingReview; rel.DevStatus = source.DevStatus; rel.LastChangeTime = DateTime.Now; rel.Platforms = source.Platforms; rel.TargetAppVersion = source.TargetAppVersion; rel.Version = source.AddinVersion; rel.SourceTagId = source.Id; string mpack = rel.GetFilePath (rel.PlatformsList [0]); AddinInfo ainfo = UserModel.ReadAddinInfo (mpack); rel.AddinId = Mono.Addins.Addin.GetIdName (ainfo.Id); rel.AddinName = ainfo.Name; rel.AddinDescription = ainfo.Description; m.CreateRelease (rel); if (rel.Status == ReleaseStatus.PendingPublish) BuildService.UpdateRepositories (false); return rel; }
int GetProjectId(UserModel m, string name) { var p = m.GetProjectByName (name); if (p == null) throw new Exception ("Project not found: " + name); return p.Id; }
static bool IsLatestRelease(UserModel m, List<AppRelease> allAppReleases, List<Release> releases, Release release, string platform, string targetAppVersion) { var compatReleases = GetCompatibleAppVersions (m, allAppReleases, targetAppVersion); return !releases.Any (r => r.ProjectId == release.ProjectId && r.AddinId == release.AddinId && (r.Status == ReleaseStatus.Published || r.Status == ReleaseStatus.PendingPublish) && r.PlatformsList.Contains (platform) && compatReleases.Contains (r.TargetAppVersion) && (Mono.Addins.Addin.CompareVersions (r.Version, release.Version) < 0 || (r.Version == release.Version && r.LastChangeTime > release.LastChangeTime)) ); }
static List<string> GetNewerCompatibleAppVersions(UserModel m, List<AppRelease> allAppReleases, string appVersion) { List<string> res = new List<string> (); foreach (var ar in allAppReleases) { if (GetCompatibleAppVersions (m, allAppReleases, ar.AppVersion).Contains (appVersion)) res.Add (ar.AppVersion); } return res; }
static string[] GetCompatibleAppVersions(UserModel m, List<AppRelease> allAppReleases, string appVersion) { string[] res; if (!cachedCompatibleVersions.TryGetValue (appVersion, out res)) { var appRel = m.GetAppReleaseByVersion (appVersion); List<string> versions = new List<string> (); versions.Add (appVersion); if (appRel.CompatibleAppReleaseId.HasValue) { var compatRel = m.GetAppRelease (appRel.CompatibleAppReleaseId.Value); if (compatRel != null) { foreach (var app in allAppReleases) { if (Mono.Addins.Addin.CompareVersions (app.AppVersion, appRel.AppVersion) > 0 && Mono.Addins.Addin.CompareVersions (compatRel.AppVersion, app.AppVersion) >= 0) versions.Add (app.AppVersion); } } } res = cachedCompatibleVersions [appVersion] = versions.ToArray (); } return res; }
internal StatsModel(UserModel um, MySqlConnection db) { userModel = um; this.db = db; }
void CheckIsAdmin() { using (var m = UserModel.GetCurrent()) { m.CheckIsAdmin(); } }
public static UserModel GetCurrent() { string login = HttpContext.Current.User.Identity.Name; UserModel m = new UserModel (); m.db = DataConnection.GetConnection (); if (Settings.Default.SupportsMultiApps) { string app = GetCurrentAppName (); if (app != null) m.application = m.db.SelectObjectWhere<Application> ("Subdomain={0}", app); } else { m.application = m.db.SelectObjects<Application> ().FirstOrDefault (); } ServiceModel sm = ServiceModel.GetCurrent (); if (!string.IsNullOrEmpty (login)) m.user = sm.GetUser (login); sm.Dispose (); if (m.application != null && m.user != null) { UserApplication uap = m.db.SelectObjectWhere<UserApplication> ("UserId={0} AND ApplicationId={1}", m.user.Id, m.application.Id); m.isAdmin = (uap != null && (uap.Permissions & ApplicationPermission.Administer) != 0); } else m.isAdmin = false; return m; }