public void InstallUpdates() { if (!this.IsValidRequest()) { this.Notify("Cannot Update", Warnings.AccessIsDenied); return; } string downloadUrl = string.Empty; string[] toBackup = { DbConfig.GetAttachmentParameter(AppUsers.GetCurrentUserDB(), "AttachmentsDirectory"), ConfigurationHelper.GetDbServerParameter("DatabaseBackupDirectory") }; Release release = new Release(); try { UpdateManager updater = new UpdateManager(); Task task = Task.Run(async () => { release = await updater.GetLatestReleaseAsync(); }); task.Wait(); } catch { this.Notify("Cannot Update", "Cannot start the update because no release was found."); return; } string keyword = Config.UpdateKeyword; Asset ass = release.Assets.FirstOrDefault(a => a.Name.ToUpperInvariant().Contains(keyword.ToUpperInvariant())); if (ass != null) { downloadUrl = ass.DownloadUrl; } if (string.IsNullOrWhiteSpace(downloadUrl)) { this.Notify("Cannot Update", "Cannot start the update because no download was found on the release."); return; } this.InstallUpdate(downloadUrl, toBackup); }
public static Release Parse(dynamic toParse, string assetsKey) { List<Asset> assets = new List<Asset>(); foreach(dynamic asset in toParse[assetsKey]) { assets.Add(Asset.Parse(asset)); } var release = new Release { Assets = assets, CreatedAt = Conversion.TryCastDate(toParse[Config.CreatedAtKey]), Draft = toParse[Config.DraftKey], Id = toParse[Config.IdKey], Name = toParse[Config.NameKey], TagName = toParse[Config.TagNameKey], Body = toParse[Config.BodyKey], PublishedAt = Conversion.TryCastDate(toParse[Config.PublishedAtKey]) }; release.Body = ParseMarkdown(release.Body); return release; }
protected void Page_Init(object sender, EventArgs e) { string userName = AppUsers.GetCurrent().View.UserName; string ipAddress = AppUsers.GetCurrent().View.IpAddress; bool isDevelopmentMode = DbConfig.GetMixERPParameter(AppUsers.GetCurrentUserDB(), "Mode").ToUpperInvariant().Equals("DEVELOPMENT"); bool isLocalHost = PageUtility.IsLocalhost(this.Page); bool isAdmin = AppUsers.GetCurrent().View.IsAdmin.ToBool(); //isLocalHost = false; bool hasAccess = false; if (isAdmin) { if (isDevelopmentMode && isLocalHost) { hasAccess = true; } if (!isDevelopmentMode) { hasAccess = true; } } if (!hasAccess) { Log.Information("Access to {Page} is denied to {User} from {IP}.", this, userName, ipAddress); this.ReleasePanel.Visible = false; this.Page.Server.Transfer("~/Site/AccessIsDenied.aspx", false); return; } UpdateManager updater = new UpdateManager(); try { Task<Release> task = Task.Run(() => updater.GetLatestReleaseAsync()); this._release = task.Result; } catch { this.ReleasePanel.Visible = false; this.UpToDatePanel.Visible = true; return; } if (this._release == null) { this._release = new Release(); } else { string keyword = Config.UpdateKeyword; Asset ass = this._release.Assets.FirstOrDefault(a => a.Name.ToUpperInvariant().Contains(keyword.ToUpperInvariant())); if (ass != null) { this._downloadUrl = ass.DownloadUrl; } } if (string.IsNullOrWhiteSpace(this._downloadUrl)) { this.ErrorLabel.Text = "This release does not contain any update."; } this.OverridePath = "/Dashboard/Index.aspx"; }