private void WriteToAnalytics(Durados.EditEventArgs e) { try { string username = GetUsername(); Durados.WorkflowAction workflowAction = GetActionType(e); string name = GetActionName(e); string type = IsFunction(e) ? "function" : "action"; switch (workflowAction) { case Durados.WorkflowAction.NodeJS: SendAnalyticsInfo(username, "LambdaDeployed", new Dictionary <string, object>() { { "rule", name }, { "type", type } }); break; default: break; } } catch { } }
protected override void BeforeEdit(Durados.EditEventArgs e) { ValidateAuthApp(e); if (e.Values.ContainsKey("Name")) { MapDataSet.durados_AppRow appRow = (MapDataSet.durados_AppRow)e.PrevRow; string oldName = appRow.Name; string newName = GetCleanName(e.Values["Name"].ToString()); if (!oldName.Equals(newName)) { string urlFieldName = "Url"; if (e.Values.ContainsKey(urlFieldName)) { e.Values[urlFieldName] = e.Values[urlFieldName].ToString().Replace("appName=" + oldName, "appName=" + newName); } else { e.Values.Add(urlFieldName, appRow[urlFieldName].ToString().Replace("appName=" + oldName, "appName=" + newName)); } e.Values["Name"] = newName; } } base.BeforeEdit(e); }
protected override void AfterEditAfterCommit(Durados.EditEventArgs e) { base.AfterEditAfterCommit(e); if (e.Values != null && e.Values.ContainsKey("Name")) { MapDataSet.durados_AppRow appRow = (MapDataSet.durados_AppRow)e.PrevRow; string oldName = appRow.Name; string newName = e.Values["Name"].ToString(); if (!oldName.Equals(newName)) { //Maps.Instance.ChangeName(oldName, newName); //CreateDns(newName); Maps.Instance.Restart(oldName); } //SqlProduct product = Maps.GetSqlProduct(newName); //if (product == SqlProduct.MySql) //{ // string url = Maps.GetAppUrl(newName); // string[] split = url.Split(':'); // url = split[0] + ":" + split[1] + ":" + Maps.ProductsPort[product] + "/Admin/Restart?id=" + Map.Database.GetUserGuid(); // Infrastructure.Http.CallWebRequest(url); //} //else //{ //Maps.Instance.Restart(oldName); //} } }
protected override void AfterEditAfterCommit(Durados.EditEventArgs e) { base.AfterEditAfterCommit(e); if (Map.Database.AutoCommit) { RefreshConfigCache(); } }
private bool IsNodeJSFunction(Durados.EditEventArgs e) { DataRow ruleRow = e.PrevRow; if (ruleRow == null) { ruleRow = Map.GetConfigDatabase().Views["Rule"].GetDataRow(e.PrimaryKey); } return(IsNodeJSFunction(ruleRow["WorkflowAction"])); }
protected override void BeforeEdit(Durados.EditEventArgs e) { if (IsNodeJSFunction(e)) { UpdateNodeJSFunction(e); } WriteToAnalytics(e); base.BeforeEdit(e); }
protected override void AfterEditBeforeCommit(Durados.EditEventArgs e) { base.AfterEditBeforeCommit(e); try { if (databaseSettings != null && appName != null) { Map map = Maps.Instance.GetMap(appName); if (System.Web.HttpContext.Current.Items.Contains(Durados.Database.AppName)) { System.Web.HttpContext.Current.Items[Durados.Database.AppName] = appName; } else { System.Web.HttpContext.Current.Items.Add(Durados.Database.AppName, appName); } View view = (View)map.GetConfigDatabase().Views["Database"]; view.Edit(GetAdjustedValues(view, databaseSettings), "0", view_BeforeEdit, view_BeforeEditInDatabase, view_AfterEditBeforeCommit, view_AfterEditAfterCommit); UpdateAnonymousUserRole(map, databaseSettings); //if (e.Values.ContainsKey("IsAuthApp")) //{ // bool isAuthApp = Convert.ToBoolean(e.Values["IsAuthApp"]); // if (!isAuthApp.Equals(map.IsAuthApp)) // { // UpdateIsAuthApp(map, isAuthApp); // } //} if (newAppName != null) { map.AppName = newAppName; } RefreshConfigCache(map); if (!string.IsNullOrEmpty(newAppName) && !appName.Equals(newAppName)) { Maps.Instance.Rename(appName, newAppName); } } } catch (ValidateAuthAppException exception) { e.Cancel = true; throw exception; } catch (Exception exception) { e.Cancel = true; throw new Durados.DuradosException("Failed to update database configuration: " + exception.Message, exception); } }
private void UpdateNodeJSFunction(Durados.EditEventArgs e) { NodeJS nodeJS = new NodeJS(); string fileName = null; if (e.Values.ContainsKey(FileName)) { fileName = e.Values[FileName].ToString(); } string ruleId = e.PrimaryKey; DataRow ruleRow = Map.GetConfigDatabase().Views[Rule].GetDataRow(ruleId); string viewId = ruleRow[Rules].ToString(); string viewName = null; if (viewId != null) { viewName = new ConfigAccess().GetViewNameByPK(viewId, Map.GetConfigDatabase().ConnectionString); if (string.IsNullOrEmpty(viewName)) { throw new Durados.DuradosException(string.Format(Messages.ViewNameNotFound, viewId)); } } else { throw new Durados.DuradosException(string.Format(Messages.ViewNameNotFound, string.Empty)); } string actionName = ruleRow[Name].ToString(); if (fileName == null) { fileName = actionName + ".zip"; } string functionName = Map.AppName + "_" + viewName + "_" + actionName; string folder = Map.AppName + "/" + viewName + "/" + actionName; nodeJS.Update(Maps.NodeJSBucket, folder, fileName, functionName); }
private void ValidateAuthApp(Durados.EditEventArgs e) { if (!e.View.Database.IsConfig) { return; } if (!e.Values.ContainsKey("AuthAppId")) { return; } if (e.Values["AuthAppId"] == null) { return; } if (e.Values["AuthAppId"].Equals(string.Empty)) { return; } if (!e.PrevRow.IsNull("AuthAppId") && e.PrevRow["AuthAppId"].Equals(e.Values["AuthAppId"])) { return; } int appId; if (!Int32.TryParse((string)e.Values["AuthAppId"], out appId)) { throw new ValidateAuthAppException("AuthAppId must be numeric"); } if (!IsAuthAppBelongToUser(appId)) { throw new ValidateAuthAppException("AuthAppId " + appId + " does not belong to " + Map.Database.GetCurrentUsername()); } }