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; }
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); }
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(" ", "")); }