public void InstallClicked() { string sessionId = Session.Current?.SessionId; long hives = Db.SlowSQL<long>("SELECT count(*) FROM PlaygroundKeeper.Playground o WHERE o.Owner = ?", SystemUser.GetCurrentSystemUser()).First; if (hives == 0) { long hosts = Db.SlowSQL<long>("SELECT count(*) FROM PlaygroundKeeper.PlaygroundHost o").First; if (hosts == 0) { Utils.ScheduleTaskHelper(sessionId, (session, id) => { if (session != null) { this.OnError(Utils.GenerateError("There is no host configured, Go to settings and add one.")); session.CalculatePatchAndPushOnWebSocket(); } }); } else if (hosts > 1) { // Select host SelectHostPage page = new SelectHostPage(); this.Partial = page; page.SelectedCallback = this.CreateHiveAndInstallSoftware; } else { // Create hive and Install app PlaygroundHost host = Db.SQL<PlaygroundHost>("SELECT o FROM PlaygroundKeeper.PlaygroundHost o").First; this.CreateHiveAndInstallSoftware(host); } } else { if (hives > 0) { // Select hive SelectHivePage page = new SelectHivePage(); this.Partial = page; page.NewHiveCallback = new Action(() => { long hosts = Db.SlowSQL<long>("SELECT count(*) FROM PlaygroundKeeper.PlaygroundHost o").First; if (hosts == 0) { Utils.ScheduleTaskHelper(sessionId, (session, id) => { if (session != null) { this.OnError(Utils.GenerateError("There is no host configured, Go to settings and add one.")); session.CalculatePatchAndPushOnWebSocket(); } }); } else if (hosts > 1) { // Select host SelectHostPage page2 = new SelectHostPage(); this.Partial = page2; page2.SelectedCallback = this.CreateHiveAndInstallSoftware; } else { // Create hive and Install app PlaygroundHost host = Db.SQL<PlaygroundHost>("SELECT o FROM PlaygroundKeeper.PlaygroundHost o").First; this.CreateHiveAndInstallSoftware(host); } }); page.SelectedCallback = new Action<Playground>((hive) => { // Install app this.InstallSoftware(hive); }); } else { // Install app Playground hive = Db.SQL<Playground>("SELECT o FROM PlaygroundKeeper.Playground o WHERE o.Owner = ?", SystemUser.GetCurrentSystemUser()).First; this.InstallSoftware(hive); } } }
/// <summary> /// Uninstall software /// </summary> /// <remarks> /// Not implmented /// </remarks> /// <param name="action"></param> void Handle(Input.UnInstall action) { string sessionId = Session.Current?.SessionId; // Check number of hives. long hives = Db.SlowSQL<long>("SELECT count(*) FROM PlaygroundKeeper.Playground o WHERE o.Owner = ?", SystemUser.GetCurrentSystemUser()).First; if (hives > 1) { // Let user select one this.SetSoftware(); SelectHivePage page = new SelectHivePage(); page.SelectedCallback = new Action<Playground>((hive) => { // TODO: Start uninstalling software Utils.ScheduleTaskHelper(sessionId, (session, id) => { if (session != null) { this.OnError(Utils.GenerateError("Uninstalling is not implemented.")); session.CalculatePatchAndPushOnWebSocket(); } }); }); this.Partial = page; } else { // TODO: Start uninstalling software Utils.ScheduleTaskHelper(sessionId, (session, id) => { if (session != null) { this.OnError(Utils.GenerateError("Uninstalling is not implemented.")); session.CalculatePatchAndPushOnWebSocket(); } }); } }