private void UpdateDb(ComponentArt.Web.UI.GridItem item, string command) { IMVFormula engine = new IMVFormula(HELPERS.NewOdbcConn()); IApplication engineApp = new IApplication(HELPERS.NewOdbcConn()); switch (command) { case "INSERT": throw new Exception("Internal error PGMF#85; contact Sklar"); break; case "UPDATE": //ADDED 3 JULY 2009: support for changing application name: string origname = item["origname"] as string; string newname = item["c_u_Name"] as string; string newL4 = item["c_u_BOOLneedsLevel4"] as string; newname = newname.Trim(); if (origname != newname) { HELPERS.RenameApplication(HELPERS.NewOdbcConn(), origname, newname); } engineApp.SetApplication (int.Parse(item["c_id"] as string), newname, newL4); if ((item["MVFID"] as string) == "") { int newID = engine.NewMVFormula(item["c_u_Name"] as string); engine.SetMVFormula( newID, item["c_u_Name"] as string, null, null, null, item["c_u_Formula"] as string); } else { engine.SetMVFormula( int.Parse(item["MVFID"] as string), item["c_u_Name"] as string, null, null, null, item["c_u_Formula"] as string); } break; case "DELETE": throw new NotImplementedException(); break; } }
private Workbook XLSXgenerate (HttpContext context, OdbcDataReader dr, IMVFormula ENGINEmanif, IEntitlement ENGINEwsent, bool singlesheet, int idWS, string strRoleList) { Workbook book = new Workbook(); Worksheet sheet = null; Worksheet sheetRoleMetadata = null; Worksheet sheetEASetMetadata = null; int IDsubprocess = -1; int colnumFormula = -1; int colnumStatus = -1; int colnumBusRole = -1; int colnumIdSubprocess = -1; string currolename = null; WorksheetRow row; sheetEASetMetadata = book.Worksheets.Add("Context"); // Create an annotation row with info about the snapshot context. RoleMetadata mdat = this.GenerateRoleMetadata(null, idWS); bool boolMetadataHasBeenEmitted = false; sheetRoleMetadata = book.Worksheets.Add("Role Metadata"); if (singlesheet) { sheet = book.Worksheets.Add("Technical Framework"); row = sheet.Table.Rows.Add(); for (int i = 0; i < dr.VisibleFieldCount; i++) { switch (dr.GetName(i) as string) { case "Formula": colnumFormula = i; break; case "Mod": colnumStatus = i; row.Cells.Add(dr.GetName(i)); break; /* * case "EntID": * break; */ case "BusRole": colnumBusRole = i; row.Cells.Add(dr.GetName(i)); break; case "IDSubProcess": colnumIdSubprocess = i; break; default: row.Cells.Add(dr.GetName(i)); break; } } row.Cells.Add("Manifest"); row.Cells.Add("AutoCorrectedNulls"); } if (colnumBusRole < 0) { // We haven't even gone through the SQL result's columns to determine // key column numbers yet! Special case donehere. for (int i = 0; i < dr.VisibleFieldCount; i++) { switch (dr.GetName(i) as string) { case "Formula": colnumFormula = i; break; case "Mod": colnumStatus = i; break; /* * case "EntID": * break; * */ case "Business_Role_Name": colnumBusRole = i; break; case "IDSubProcess": colnumIdSubprocess = i; break; default: break; } } } // FOR EACH ROW while (dr.Read()) { try { if (!boolMetadataHasBeenEmitted) { EmitMetadata(sheetEASetMetadata, ref mdat, dr, colnumFormula); boolMetadataHasBeenEmitted = true; } string newrolename = dr.GetValue(colnumBusRole) as string; IDsubprocess = (int)dr.GetValue(colnumIdSubprocess); if (singlesheet) { bool isBabySheet = false; if (currolename == null) { currolename = newrolename; isBabySheet = true; } else if (currolename != newrolename) { currolename = newrolename; isBabySheet = true; } if (isBabySheet) { WorksheetRow row2 = null; if (sheetRoleMetadata.Table.Rows.Count < 3) { row2 = sheetRoleMetadata.Table.Rows.Add(); row2.Cells.Add("ROLE OWNERS/APPROVERS"); row2 = sheetRoleMetadata.Table.Rows.Add(); row2 = sheetRoleMetadata.Table.Rows.Add(); row2.Cells.Add("Role Name"); row2.Cells.Add("Type"); row2.Cells.Add("EID"); row2.Cells.Add("Name"); row2.Cells.Add("Geography"); } mdat = this.GenerateRoleMetadata(newrolename, idWS); foreach (RoleMetadataOwner x in mdat.ROLEownersident) { row2 = sheetRoleMetadata.Table.Rows.Add(); row2.Cells.Add(newrolename); row2.Cells.Add(x.rank); row2.Cells.Add(x.EID); row2.Cells.Add(x.name); row2.Cells.Add(x.geography); } } // GenMetadataSpreadsheetRow(sheetRoleMetadata, "--------", "-----------------------"); } if (!singlesheet) { bool isBabySheet = false; //Note: Excel cannot handle worksheet names longer than 31 chars string truncsheetname = newrolename; if (truncsheetname.Length > 31) { truncsheetname = truncsheetname.Substring(truncsheetname.Length - 31); } if (currolename == null) { sheet = book.Worksheets.Add(truncsheetname); currolename = newrolename; isBabySheet = true; } else if (currolename != newrolename) { sheet = book.Worksheets.Add(truncsheetname); isBabySheet = true; } if (isBabySheet) { // Create an annotation row with info about the snapshot context. mdat = this.GenerateRoleMetadata(newrolename, idWS); GenMetadataSpreadsheetRow(sheet, "Role name:", mdat.rolename); if (mdat.ROLEownersident.Count == 0) { GenMetadataSpreadsheetRow(sheet, "Role owners:", "NOT YET ENTERED"); } else { foreach (object x in mdat.ROLEownersident) { GenMetadataSpreadsheetRow(sheet, "Principal: ", x.ToString()); } } GenMetadataSpreadsheetRow(sheet, "----------", "---------------------"); /* * * row = sheet.Table.Rows.Add(); * row.Cells.Add(annotation); */ currolename = newrolename; row = sheet.Table.Rows.Add(); for (int i = 0; i < dr.VisibleFieldCount; i++) { switch (dr.GetName(i) as string) { case "Formula": colnumFormula = i; break; case "Mod": colnumStatus = i; row.Cells.Add(dr.GetName(i)); break; /* * case "EntID": * break; * */ case "BusRole": colnumBusRole = i; row.Cells.Add(dr.GetName(i)); break; case "IDSubProcess": colnumIdSubprocess = i; break; default: row.Cells.Add(dr.GetName(i)); break; } } row.Cells.Add("Manifest"); } } row = sheet.Table.Rows.Add(); int IDwsentrow = (int)(dr.GetValue(0)); returnGetEntitlement OBJwsent = ENGINEwsent.GetEntitlement(IDwsentrow); string appname = OBJwsent.Application; returnListMVFormula[] LISTformulas = ENGINEmanif.ListMVFormula(null, "\"KEYapplication\" = ?", new string[] { appname }, ""); string STRformula = ""; try { returnListMVFormula TheFormula = LISTformulas[0]; if (TheFormula.Formula == null) { TheFormula.Formula = ""; } STRformula = HttpUtility.HtmlDecode(TheFormula.Formula.Trim()); } catch (Exception eee) { } if (STRformula == "") { STRformula = "\"TBD - " + appname + "\""; //context.Response.Write("Error: the manifest formula for this application has NOT been specified."); //return; } // We have the formula; now we can evaluate. Evaluator ev = new Evaluator(Eval3.eParserSyntax.cSharp, false); ev.AddEnvironmentFunctions(this); ev.AddEnvironmentFunctions(new ManifestFormulaEvaluatorFunctions(OBJwsent)); opCode lCode; bool doMakeNullRepair2ndTry = false; try { lCode = ev.Parse(STRformula); } catch (Exception e) { row.Cells.Add("The formula for " + appname + " has parse errors: " + e.ToString()); return(book); } object RESLT = null; try { RESLT = lCode.value; } catch (NullReferenceException enull) { //row.Cells.Add("Interpreting the formula for this application resulted in an error because of references to one or more fields that are NULL in value."); //RESLT = "[ERROR: reference to one or more fields with null values]"; //row = sheet.Table.Rows.Add(); doMakeNullRepair2ndTry = true; } catch (Exception e) { row.Cells.Add("Interpreting the formula for this application resulted in this exception: " + e.ToString()); RESLT = "[ERROR: see line above for details]"; row = sheet.Table.Rows.Add(); } if (doMakeNullRepair2ndTry) { int repairCount = 0; // NULLs caused failures in the 1st try. // We will thus now repair all nulls and try again. // If succeeds, we will generate a useable row but the final column // will alert the users to the fact that autorepair was performed. TurnNullsToEmptyStrings(ref OBJwsent, ref repairCount); if (repairCount == 0) { throw new Exception("ASSERTION FAILURE: null fields expected but not found"); } opCode lCode2; ev = new Evaluator(Eval3.eParserSyntax.cSharp, false); ev.AddEnvironmentFunctions(this); ev.AddEnvironmentFunctions(new ManifestFormulaEvaluatorFunctions(OBJwsent)); lCode2 = ev.Parse(STRformula); try { RESLT = lCode2.value; } catch (Exception e) { row.Cells.Add("2nd try: Interpreting the formula for this application resulted in this exception: " + e.ToString()); RESLT = "[ERROR: see line above for details]"; row = sheet.Table.Rows.Add(); } } // NOW READY TO EMIT THE COLUMNS for (int i = 0; i < dr.VisibleFieldCount; i++) { if (i != -342350) /*used to be != 0 */ { if ((i != colnumFormula) && (i != colnumIdSubprocess)) { if (i == colnumStatus) { string statSemantics = "ERR"; switch (dr.GetValue(i) as string) { case "N": statSemantics = "New"; break; case "P": statSemantics = "New"; break; case "X": statSemantics = "Deleted"; break; case "A": statSemantics = ""; break; } row.Cells.Add(statSemantics); } else { row.Cells.Add(dr.GetValue(i).ToString()); } } } } row.Cells.Add(RESLT as string); row.Cells.Add(doMakeNullRepair2ndTry ? "Y" : ""); } catch (Exception e) { row = sheet.Table.Rows.Add(); row.Cells.Add(e.ToString() + e.StackTrace.ToString()); } } EmitRoleMetadata_AdditionalRoles (sheetRoleMetadata, strRoleList, idWS, IDsubprocess); EmitRoleMetadata_FuncAppEntsByRole (sheetRoleMetadata, strRoleList, idWS, IDsubprocess); EmitRoleMetadata_SubProcessActivities (sheetRoleMetadata, strRoleList, idWS, IDsubprocess); return(book); }
private void CSVgenerate_FullDetail(HttpContext context, OdbcDataReader dr, IMVFormula ENGINEmanif, IEntitlement ENGINEwsent, bool BOOLgenerateHeader) { int colnumFormula = -1; if (BOOLgenerateHeader) { for (int i = 0; i < dr.VisibleFieldCount; i++) { switch (dr.GetName(i) as string) { case "Formula": colnumFormula = i; break; /* * case "EntID": * break; */ default: context.Response.Write(CSVquoteize(dr.GetName(i).Replace('_', ' ')) + ","); break; } } context.Response.Write("Privilege String"); context.Response.Write("\n"); } // FOR EACH ROW while (dr.Read()) { try { int IDwsentrow = (int)(dr.GetValue(0)); object RESLT; ComputePrivilegeString(context, ENGINEmanif, ENGINEwsent, IDwsentrow, out RESLT); for (int i = 0; i < dr.VisibleFieldCount; i++) { if (i != 0) { if (i != colnumFormula) { context.Response.Write(CSVquoteize(dr.GetValue(i) as string) + ","); } } } string resultAsStr = RESLT.ToString().Replace(" ", ""); context.Response.Write(CSVquoteize(resultAsStr)); context.Response.Write("\n"); } catch (Exception e) { context.Response.Write(e.ToString() + e.StackTrace.ToString() + "\n"); } } return; }
private void ComputePrivilegeString(HttpContext context, IMVFormula ENGINEmanif, IEntitlement ENGINEwsent, int IDwsentrow, out object RESLT) { RESLT = ""; returnGetEntitlement OBJwsent = ENGINEwsent.GetEntitlement(IDwsentrow); int repaircount = 0; TurnNullsToEmptyStrings(ref OBJwsent, ref repaircount); string appname = OBJwsent.Application; returnListMVFormula[] LISTformulas = ENGINEmanif.ListMVFormula(null, "\"KEYapplication\" = ?", new string[] { appname }, ""); string STRformula = ""; try { returnListMVFormula TheFormula = LISTformulas[0]; if (TheFormula.Formula == null) { TheFormula.Formula = ""; } STRformula = HttpUtility.HtmlDecode(TheFormula.Formula.Trim()); } catch (Exception eee) { } if (STRformula == "") { STRformula = "\"TBD - " + appname + "\""; //context.Response.Write("Error: the manifest formula for this application has NOT been specified."); //return; } // We have the formula; now we can evaluate. Evaluator ev = new Evaluator(Eval3.eParserSyntax.cSharp, false); ev.AddEnvironmentFunctions(this); ev.AddEnvironmentFunctions(new ManifestFormulaEvaluatorFunctions(OBJwsent)); opCode lCode; try { lCode = ev.Parse(STRformula); } catch (Exception e) { context.Response.Write("The formula [[" + STRformula + "]] for this app [[" + appname + "]] has parse errors: " + e.ToString()); return; } try { RESLT = lCode.value; } catch (Exception e) { RESLT = "NULL"; //context.Response.Write("Interpreting the formula for this app resulted in errors: " + e.ToString()); //return; } return; }
public void ProcessRequest(HttpContext context) { int idWS = Int32.Parse(context.Request.Params["id"]); // Legal formats are: CSV and XLSX string strFormat = "XLSX"; try { strFormat = context.Request.Params["fmt"].ToUpper(); } catch (Exception eign) { } string annotation = context.Request.Params["name"]; // Comma-separated list of busrole ID numbers e.g. 34,38,47 string strRoleList = ""; try { strRoleList = context.Request.Params["brol"]; } catch (Exception eignore) { strRoleList = ""; } // Default TRUE bool singlesheet = true; try { singlesheet = bool.Parse(context.Request.Params["singlesheet"]); } catch (Exception eignore) { singlesheet = true; } // Default FALSE bool showOnlyDeltas = false; try { showOnlyDeltas = bool.Parse(context.Request.Params["deltasonly"]); } catch (Exception eignore) { showOnlyDeltas = false; } // Default TRUE bool showStatusColumn = true; try { showStatusColumn = bool.Parse(context.Request.Params["showstatus"]); } catch (Exception eignore) { showStatusColumn = true; } // THE FULL-DETAIL FORMATTING OPTION OVERRIDES ALL OTHER OPTIONS! // Default FALSE bool BOOLformatFullDetail = false; try { BOOLformatFullDetail = bool.Parse(context.Request.Params["FMTfulldetail"]); } catch (Exception eignore) { BOOLformatFullDetail = false; } bool BOOLformatIdmReconcil = false; try { BOOLformatIdmReconcil = bool.Parse(context.Request.Params["FMTidm3col"]); } catch (Exception eignore) { BOOLformatIdmReconcil = false; } if (BOOLformatFullDetail || BOOLformatIdmReconcil) { strFormat = "CSV"; showOnlyDeltas = false; singlesheet = true; showStatusColumn = false; } OdbcCommand cmd = new OdbcCommand(); cmd.Connection = HELPERS.NewOdbcConn(); if (strFormat == "CSV") { context.Response.ContentType = "text/csv"; context.Response.AddHeader("Content-Disposition", "filename=export.csv;attachment"); } string extraconds = ""; if (strRoleList != null) { if (strRoleList != "") { extraconds = " AND (TEASS.c_r_BusRole IN (" + strRoleList + ")) "; } } if (showOnlyDeltas) { extraconds += " AND (TEASS.c_u_Status NOT IN ('A')) "; } else { extraconds += " AND (TENT.c_u_Status NOT IN ('X')) "; } cmd.CommandText = @" SELECT TENT.c_id as EntID,"; if (showStatusColumn) { cmd.CommandText += "TEASS.c_u_Status as Mod,"; } else { // If not showing status column, this should be an active entitlement set, not a workspace. // Thus, eliminate rows that are marked as having been deleted when that active EASet was published. extraconds += " AND (TEASS.c_u_Status NOT IN ('X')) "; } cmd.CommandText += @" BROL.c_u_Name as Business_Role_Name, BROL.c_u_Description as Business_Role_Description, TENT.c_u_StandardActivity as Standard_Activity, TENT.c_u_RoleType as Role_Type, TENT.c_u_Application as Application, TENT.c_u_System as System, TENT.c_u_Platform as Platform, TENT.c_u_EntitlementName as Entitlement_Name, TENT.c_u_EntitlementValue as Entitlement_Value, TENT.c_u_AuthObjValue as Authorization_Object_Value, TENT.c_u_FieldSecName as Field_Security_Name, TENT.c_u_FieldSecValue as Field_Security_Value, TENT.c_u_Level4SecName as Fourth_Level_Security_Name, TENT.c_u_Level4SecValue as Fourth_Level_Security_Value, TENT.c_u_Commentary as Commentary, MVF.c_u_Formula as Formula, SUBPR.c_u_Name as NameSubProcess, SUBPR.c_id as IDSubProcess, PR.c_u_Name as NameProcess FROM t_RBSR_AUFW_u_EntAssignment TEASS LEFT OUTER JOIN t_RBSR_AUFW_u_Entitlement TENT ON TEASS.c_r_Entitlement = TENT.c_id LEFT OUTER JOIN t_RBSR_AUFW_u_EntAssignmentSet TEASET ON TEASS.c_r_EntAssignmentSet = TEASET.c_id LEFT OUTER JOIN t_RBSR_AUFW_u_BusRole BROL ON BROL.c_id = TEASS.c_r_BusRole LEFT OUTER JOIN t_RBSR_AUFW_u_SubProcess SUBPR ON SUBPR.c_id = TEASET.c_r_SubProcess LEFT OUTER JOIN t_RBSR_AUFW_u_Process PR ON PR.c_id = SUBPR.c_r_Process LEFT OUTER JOIN t_RBSR_AUFW_u_MVFormula MVF ON MVF.c_u_KEYapplication = TENT.c_u_Application WHERE (TEASS.c_r_EntAssignmentSet = ?) " + extraconds + " ORDER BY TEASS.c_r_BusRole;"; cmd.Parameters.Add("c_r_EditingWorkspace", OdbcType.Int); cmd.Parameters["c_r_EditingWorkspace"].Value = (object)idWS; OdbcDataReader dr = cmd.ExecuteReader(); OdbcConnection conn2 = HELPERS.NewOdbcConn_FORCE(); IMVFormula ENGINEmanif = new IMVFormula(conn2); IEntitlement ENGINEwsent = new IEntitlement(conn2); if (strFormat == "CSV") { if (BOOLformatFullDetail) { CSVgenerate_FullDetail(context, dr, ENGINEmanif, ENGINEwsent, true /*generate header row*/); } if (BOOLformatIdmReconcil) { CSVgenerate_IDMreconciliation_3column (context, dr, ENGINEmanif, ENGINEwsent, true /*generate header row*/); } } if (strFormat == "XLSX") { Workbook book = XLSXgenerate(context, dr, ENGINEmanif, ENGINEwsent, singlesheet, idWS, strRoleList); context.Response.ContentType = "application/vnd.xls"; // used to be "text/xml" but never worked in chrome // If the suffix is xlsx, it works in OpenOffice but not in MSOffice! // Now trying xls ! context.Response.AddHeader("Content-Disposition", "filename=export.xls;attachment"); book.Save(context.Response.OutputStream); } dr.Close(); }
private void CSVgenerate_IDMreconciliation_3column (HttpContext context, OdbcDataReader dr, IMVFormula ENGINEmanif, IEntitlement ENGINEwsent, bool BOOLgenerateHeader) { int colnumFormula = -1; int colnumRolename = -1; int colnumRoledescr = -1; OdbcConnection tempconn = HELPERS.NewOdbcConn_FORCE(); IBusRole engineBR = new IBusRole(tempconn); IBusRoleOwner engineBRole = new IBusRoleOwner(tempconn); Dictionary <string, bool> DICTboolHaveSeenThisRole = new Dictionary <string, bool>(); for (int i = 0; i < dr.VisibleFieldCount; i++) { switch (dr.GetName(i) as string) { case "Formula": colnumFormula = i; break; case "Business_Role_Name": colnumRolename = i; break; case "Business_Role_Description": colnumRoledescr = i; break; } } if (BOOLgenerateHeader) { context.Response.Write("RoleName,Entitlement,ComparisonObject\n"); } // FOR EACH ROW while (dr.Read()) { try { int IDwsentrow = (int)(dr.GetValue(0)); object RESLT; ComputePrivilegeString(context, ENGINEmanif, ENGINEwsent, IDwsentrow, out RESLT); string resultAsStr = RESLT.ToString().Replace(" ", ""); // If the first time we are seeing this role, emit its description text. if (!DICTboolHaveSeenThisRole.ContainsKey(dr.GetValue(colnumRolename) as string)) { string rolename = dr.GetValue(colnumRolename) as string; context.Response.Write(CSVquoteize(rolename) + ","); context.Response.Write(CSVquoteize(dr.GetValue(colnumRoledescr) as string) + ","); context.Response.Write("RoleDescription"); context.Response.Write("\n"); DICTboolHaveSeenThisRole[rolename] = true; returnListBusRole[] retFindBRole = engineBR.ListBusRole(null, "\"Name\" = ?", new string[] { rolename }, ""); int roleID = retFindBRole[0].ID; returnListBusRoleOwnerByBusRole[] roleowners = engineBRole.ListBusRoleOwnerByBusRole(null, roleID); foreach (returnListBusRoleOwnerByBusRole roleowner in roleowners) { context.Response.Write(CSVquoteize(rolename) + ","); context.Response.Write(roleowner.EID + ","); context.Response.Write(roleowner.RankFriendly.Replace(" ", "")); context.Response.Write("\n"); } } context.Response.Write(CSVquoteize(dr.GetValue(colnumRolename) as string) + ","); context.Response.Write(CSVquoteize(resultAsStr.Replace(" ", "")) + ","); context.Response.Write("Entitlement"); context.Response.Write("\n"); } catch (Exception e) { context.Response.Write(e.ToString() + e.StackTrace.ToString() + "\n"); } } return; }
public void ProcessRequest(HttpContext context) { OdbcConnection conn = HELPERS.NewOdbcConn(); int IDwsentrow = int.Parse(context.Request.Params["IDwsent"]); context.Response.ContentType = "text/plain"; IMVFormula ENGINEmanif = new IMVFormula(conn); IEntitlement ENGINEwsent = new IEntitlement(conn); OBJwsent = ENGINEwsent.GetEntitlement(IDwsentrow); string appname = OBJwsent.Application; returnListMVFormula[] LISTformulas = ENGINEmanif.ListMVFormula(null, "\"KEYapplication\" = ?", new string[] { appname }, ""); // Currently, we only allow one formula per manifest. // Later we might have richer selection process where other fields // get to play a role in which formula is used. if (LISTformulas.Length > 1) { context.Response.Write("Error: more than one manifest formula for this app."); return; } if (LISTformulas.Length < 1) { context.Response.Write("Error: there is no manifest formula for this app."); return; } returnListMVFormula TheFormula = LISTformulas[0]; if (TheFormula.Formula == null) { TheFormula.Formula = ""; } string STRformula = TheFormula.Formula.Trim(); if (STRformula == "") { context.Response.Write("Error: the manifest formula for this application has NOT been specified."); return; } // We have the formula; now we can evaluate. Evaluator ev = new Evaluator(Eval3.eParserSyntax.cSharp, false); ev.AddEnvironmentFunctions(this); ev.AddEnvironmentFunctions(new ManifestFormulaEvaluatorFunctions(OBJwsent)); opCode lCode; try { lCode = ev.Parse(STRformula); } catch (Exception e) { context.Response.Write("The formula [[" + STRformula + "]] for this app [[" + appname + "]] has parse errors: " + e.ToString()); return; } object RESLT; try { RESLT = lCode.value; } catch (Exception e) { context.Response.Write("Interpreting the formula for this app resulted in errors: " + e.ToString()); return; } context.Response.Write(RESLT.ToString().Replace(" ", "")); }