public CodeCoverageProcessor(DbTraceCodeFormatter dbCodeFormatter, HighlightCodeProvider highlightCodeProvider) { _dbCodeFormatter = dbCodeFormatter; _highlightCodeProvider = highlightCodeProvider; _dataScrubber = new DataScrubber(dbCodeFormatter); _highlightMarkUpLength = _dbCodeFormatter.StartHighlightMarkUp.Length + _dbCodeFormatter.EndHighlightMarkUp.Length; }
public void CleanTables_BulkInsertFRFException_LogError() { // Arrange const string ExpectedLogMessage = "Error cleaning lst tables. Error"; const string ExpectedTableName = "FRF"; var destinationTable = string.Empty; var bulkInserted = false; var logMessages = new List <string>(); ShimSqlBulkCopy.AllInstances.WriteToServerDataTable = (_, dataTable) => { if (destinationTable == ExpectedTableName && dataTable.Rows.Count > 0 && !bulkInserted) { throw new Exception(); } }; ShimSqlBulkCopy.AllInstances.DestinationTableNameSetString = (_, name) => { destinationTable = name; }; ShimEPMData.AllInstances.LogStatusStringStringStringStringInt32Int32String = (_, listId, listName, shortMsg, longMsg, level, type, guid) => { logMessages.Add(shortMsg); logMessages.Add(longMsg); return(true); }; // Act DataScrubber.CleanTables(spSite, epmData, DummyGuid, ref ErrMsg); // Assert Assert.IsTrue(logMessages.Any(log => log.Contains(ExpectedLogMessage))); }
public void CleanTables_BulkInsertFRF_ExecutsCorrectly() { // Arrange var destinationTable = string.Empty; const string ExpectedTableNAme = "FRF"; var bulkInserted = false; var site = new ShimSPSite(); var epmData = new ShimEPMData(); ShimSqlBulkCopy.AllInstances.WriteToServerDataTable = (_, dataTable) => { if (destinationTable == ExpectedTableNAme && dataTable.Rows.Count > 0 && !bulkInserted) { bulkInserted = true; } }; ShimSqlBulkCopy.AllInstances.DestinationTableNameSetString = (_, name) => { destinationTable = name; }; // Act DataScrubber.CleanTables(site, epmData, DummyGuid, ref ErrMsg); // Assert Assert.IsTrue(bulkInserted); }
public void CleanTables_Should_WipeTables() { // Arrange const string WipeReportListIds = "DELETE FROM ReportListIds"; const string WipeRPTWeb = "DELETE FROM RPTWeb"; const string WipeRPTWebGroups = "DELETE FROM RPTWEBGROUPS"; var commandsExecuted = new List <string>(); var site = new ShimSPSite { IDGet = () => DummyGuid }.Instance; var epmData = new ShimEPMData().Instance; ShimDataTable.AllInstances.RowsGet = _ => new ShimDataRowCollection { AddObjectArray = parameters => new ShimDataRow().Instance, CountGet = () => 0, GetEnumerator = () => new List <DataRow>().GetEnumerator() }; ShimSqlCommand.AllInstances.ExecuteNonQuery = instance => { commandsExecuted.Add(instance.CommandText); return(1); }; // Act DataScrubber.CleanTables(site, epmData, DummyGuid, ref ErrMsg); // Assert Assert.IsTrue(commandsExecuted.Contains(WipeReportListIds)); Assert.IsTrue(commandsExecuted.Contains(WipeRPTWeb)); Assert.IsTrue(commandsExecuted.Contains(WipeRPTWebGroups)); }
public void CleanTables_Invoke_VerifyMemoryLeak() { // Arrange var sqlCommandConstructorInvoked = 0; var sqlCommandDisposeCalled = 0; var destinationTable = string.Empty; const string ExpectedTableNAme = "ReportListIds"; var bulkInserted = false; var site = new ShimSPSite(); var epmData = new ShimEPMData(); ShimSqlBulkCopy.AllInstances.WriteToServerDataTable = (_, dataTable) => { if (destinationTable == ExpectedTableNAme && dataTable.Rows.Count > 0 && !bulkInserted) { bulkInserted = true; } }; ShimSqlBulkCopy.AllInstances.DestinationTableNameSetString = (_, name) => destinationTable = name; ShimSqlCommand.ConstructorStringSqlConnection = (command, s, arg3) => sqlCommandConstructorInvoked++; ShimComponent.AllInstances.Dispose = component => { if (component is SqlCommand) { sqlCommandDisposeCalled++; } }; // Act DataScrubber.CleanTables(site, epmData, DummyGuid, ref ErrMsg); // Assert this.ShouldSatisfyAllConditions( () => sqlCommandConstructorInvoked.ShouldBeGreaterThanOrEqualTo(7), () => sqlCommandDisposeCalled.ShouldBeGreaterThanOrEqualTo(7), () => sqlCommandDisposeCalled.ShouldBe(sqlCommandConstructorInvoked)); }
public void execute(SPSite site, SPWeb web, string data) { sbErrors = new StringBuilder(); EPMData epmdata = null; Hashtable hshMessages = null; SPWeb rootWeb = null; try { hshMessages = new Hashtable(); #region Process security try { totalCount = site.AllWebs.Count; epmdata = new EPMData(site.ID); epmdata.LogStatus("", "", "Reporting Refresh Collect Job", "Reporting refresh process started.", 2, 3, Convert.ToString(JobUid)); try { epmdata.LogStatus("", "", "Reporting Refresh Collect Job", string.Format("Started processing security groups for site: {0}", site.Url), 2, 3, Convert.ToString(JobUid)); ProcessSecurity.ProcessSecurityGroups(site, epmdata.GetClientReportingConnection, ""); sbErrors.Append("Completed processing security groups for site: " + site.Url + ".</br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job", string.Format("Completed processing security groups for site: {0}", site.Url), 2, 3, Convert.ToString(JobUid)); } catch (Exception ex) { var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; bErrors = true; sbErrors.Append("<font color=\"red\">Error processing security on site: " + site.Url + ". Error: " + message + "</font><br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job", string.Format("Error processing security on site: {0}. Error: {1}", site.Url, message), 2, 3, Convert.ToString(JobUid)); } if (string.IsNullOrEmpty(data)) { //try //{ // data = epmdata.GetListNames(); //} //catch (Exception exData) //{ // bErrors = true; // sErrors += "<font color=\"red\">Error while retrieving list names: " + exData.Message + "</font><br>"; //} try { epmdata.LogStatus("", "", "Reporting Refresh Collect Job", string.Format("Started updating reporting settings for site: {0}.", site.Url), 2, 3, Convert.ToString(JobUid)); setRPTSettings(epmdata, site); epmdata.LogStatus("", "", "Reporting Refresh Collect Job", string.Format("Completed updating reporting settings for site: {0}.", site.Url), 2, 3, Convert.ToString(JobUid)); } catch (Exception ex) { var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; bErrors = true; sbErrors.Append("<font color=\"red\">Error Updating RPTSettings: " + message + "</font><br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job", string.Format("Updating reporting settings failed for site: {0}. ,Error {1}", site.Url, message), 2, 3, Convert.ToString(JobUid)); } } } catch (Exception ex) { bErrors = true; sbErrors.Append("<font color=\"red\">Error Updating base: " + ex.Message + "</font><br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job", string.Format("Updating reporting settings failed for site: {0}. ,Error {1}", site.Url, ex.Message), 2, 3, Convert.ToString(JobUid)); } #endregion #region History //try //{ // data = epmdata.UpdateListNames(data); //} //catch (Exception ex) //{ // bErrors = true; // sErrors += "<font color=\"red\">Error Updating List Names: " + ex.Message + "</font><br>"; //} // TODO: We need to make sure this doesn't break anything!!!! //foreach (SPWeb w in site.AllWebs) //{ // // IGNORE SPDispose 130 error, web is being disposed // try // { // List<string> allLists = new List<string>(data.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); // List<SPList> allSpLists = new List<SPList>(); // foreach (string l in allLists) // { // SPList list = w.Lists.TryGetList(l); // if (list == null || // list.Title == "Work Hours" || // list.Title == "Resources") // { // continue; // } // if (list != null) // { // allSpLists.Add(list); // } // } // ProcessSecurity.ProcessSecurityOnRefreshAll(w, allSpLists, epmdata.GetClientReportingConnection); // if (w != null) // { // w.Dispose(); // } // } // catch // { // if (w != null) // { // w.Dispose(); // } // } //} #endregion #region Process TimeSheet Data try { string err = ""; bool consolidationdone = false; bool reportingRefreshBatch = false; epmdata.LogStatus("", "", "Reporting Refresh Collect Job Process TimeSheet Data", string.Format("Starting Process TimeSheet Data for site: {0}.", site.Url), 2, 3, Convert.ToString(JobUid)); bool.TryParse(EPMLiveCore.CoreFunctions.getConfigSetting(web, "epmliveconsolidation"), out consolidationdone); bool.TryParse(EPMLiveCore.CoreFunctions.getConfigSetting(web, "epmlivereportingrefreshbatch"), out reportingRefreshBatch); bool bErrorRefreshTimesheet = false; if (reportingRefreshBatch) { int pageSize = 0; int.TryParse(EPMLiveCore.CoreFunctions.getConfigSetting(web, "epmliverepotingrefreshbatchpagesize"), out pageSize); bErrorRefreshTimesheet = epmdata.RefreshTimesheetBatch(out err, base.JobUid, pageSize); } else { bErrorRefreshTimesheet = epmdata.RefreshTimesheets(out err, base.JobUid, consolidationdone); } if (bErrorRefreshTimesheet) { bErrors = true; sbErrors.Append("<font color=\"red\">Error Processing Timesheets: " + err + "</font><br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Process TimeSheet Data", string.Format("Process TimeSheet Data failed for site: {0}. Error {1}", site.Url, err), 2, 3, Convert.ToString(JobUid)); } else { sbErrors.Append("Processed Timesheets<br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Process TimeSheet Data", string.Format("Completed timeSheet data processing for site: {0}", site.Url), 2, 3, Convert.ToString(JobUid)); } } catch (Exception ex) { var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; bErrors = true; sbErrors.Append("<font color=\"red\">Error Processing Timesheets: " + message + "</font><br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Process TimeSheet Data", string.Format("Process TimeSheet Data failed for site: {0}. Error {1}", site.Url, message), 2, 3, Convert.ToString(JobUid)); } #endregion #region Process PFE Data try { if (site.Features[new Guid("158c5682-d839-4248-b780-82b4710ee152")] != null) { epmdata.LogStatus("", "", "Reporting Refresh Collect Job Process PFE Data", string.Format("Processing PFE Data for site: {0}", site.Url), 2, 3, Convert.ToString(JobUid)); rootWeb = site.RootWeb; string basePath = CoreFunctions.getConfigSetting(rootWeb, "epkbasepath"); string ppmId = CoreFunctions.getConfigSetting(rootWeb, "ppmpid"); string ppmCompany = CoreFunctions.getConfigSetting(rootWeb, "ppmcompany"); string ppmDbConn = CoreFunctions.getConfigSetting(rootWeb, "ppmdbconn"); Assembly assemblyInstance = Assembly.Load( "PortfolioEngineCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5"); Type thisClass = assemblyInstance.GetType("PortfolioEngineCore.WEIntegration.WEIntegration"); object classObject = Activator.CreateInstance(thisClass, new object[] { basePath, site.WebApplication.ApplicationPool.Username, ppmId, ppmCompany, ppmDbConn, false }); MethodInfo m = thisClass.GetMethod("ExecuteReportExtract"); var message = (string) m.Invoke(classObject, new object[] { "<ExecuteReportExtract><Params /><Data><ReportExtract Connection=\"" + getReportingConnection(web) + "\" Execute=\"1\" /></Data></ExecuteReportExtract>" }); sbErrors.Append("Processed PfE Reporting: " + message + "<br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Process PFE Data", string.Format("Completed Processing PFE Data for site: {0}", site.Url), 2, 3, Convert.ToString(JobUid)); } } catch (Exception ex) { var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; bErrors = true; sbErrors.Append("<font color=\"red\">Error Processing PfE Reporting: " + message + "</font><br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Process PFE Data", string.Format("Error Processing PfE Reporting for site: {0} Error {1}", site.Url, message), 2, 3, Convert.ToString(JobUid)); } #endregion Process PFE Data #region Clean Data try { string errMsg = string.Empty; epmdata.LogStatus("", "", "Reporting Refresh Collect Job DataScrubber CleanTables", string.Format("Started DataScrubber.CleanTables for site: {0}", site.Url), 2, 3, Convert.ToString(JobUid)); bool bErrorCleanTables = DataScrubber.CleanTables(site, epmdata, base.JobUid, ref errMsg); if (bErrorCleanTables) { bErrors = true; sbErrors.Append("<font color=\"red\">Error while cleaning tables: " + errMsg + "</font><br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job DataScrubber CleanTables", string.Format("Error while cleaning tables for site: {0} error {1}", site.Url, errMsg), 2, 3, Convert.ToString(JobUid)); } else { epmdata.LogStatus("", "", "Reporting Refresh Collect Job DataScrubber CleanTables", string.Format("Completed DataScrubber.CleanTables for site: {0}", site.Url), 2, 3, Convert.ToString(JobUid)); } } catch (Exception ex) { var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; bErrors = true; sbErrors.Append("<font color=\"red\">Error while cleaning tables: " + message + "</font><br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job DataScrubber CleanTables", string.Format("Error while cleaning tables for site: {0} error {1}", site.Url, message), 2, 3, Convert.ToString(JobUid)); } #endregion #region Update Status Field try { if (string.IsNullOrEmpty(data)) { DataSet ds = null; try { ds = new DataSet(); using (var cmd1 = new SqlCommand("SELECT TABLENAME FROM RPTList", epmdata.GetClientReportingConnection)) { epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Started Update Status Field for site: {0} ,SQL (SELECT TABLENAME FROM RPTList) ", site.Url), 2, 3, Convert.ToString(JobUid)); using (SqlDataAdapter da = new SqlDataAdapter(cmd1)) { da.Fill(ds); foreach (DataRow dr in ds.Tables[0].Rows) { using (var cmd2 = new SqlCommand("spUpdateStatusFields", epmdata.GetClientReportingConnection)) { cmd2.CommandType = CommandType.StoredProcedure; cmd2.Parameters.AddWithValue("@listtable", dr[0].ToString()); cmd2.ExecuteNonQuery(); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Executing store procedure spUpdateStatusFields '{0}'", dr[0].ToString()), 2, 3, Convert.ToString(JobUid)); } } } } } catch (Exception ex) { var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; bErrors = true; sbErrors.Append("<font color=\"red\">Error updating status fields: " + message + "</font><br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Error updating status fields: for site {0},error {1} ", site.Url, message), 2, 3, Convert.ToString(JobUid)); } finally { if (ds != null) { ds.Dispose(); } } } else { try { foreach (string sList in data.Split(',')) { if (sList != "") { DataSet ds = null; SPList list = null; try { list = web.Lists[sList]; ds = new DataSet(); using (var cmd1 = new SqlCommand("SELECT TABLENAME FROM RPTList where listid=@listid", epmdata.GetClientReportingConnection)) { epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("SELECT TABLENAME FROM RPTList where listid={0} ", list.ID), 2, 3, Convert.ToString(JobUid)); cmd1.Parameters.AddWithValue("@listid", list.ID); using (SqlDataAdapter da = new SqlDataAdapter(cmd1)) { da.Fill(ds); using (var cmd2 = new SqlCommand("spUpdateStatusFields", epmdata.GetClientReportingConnection)) { cmd2.CommandType = CommandType.StoredProcedure; cmd2.Parameters.AddWithValue("@listtable", ds.Tables[0].Rows[0][0].ToString()); cmd2.ExecuteNonQuery(); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Executed spUpdateStatusFields '{0}' ", Convert.ToString(ds.Tables[0].Rows[0][0])), 2, 3, Convert.ToString(JobUid)); } } } } catch (Exception ex) { var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; bErrors = true; sbErrors.Append("<font color=\"red\">Error updating status fields (" + sList + "): " + message + "</font><br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Error updating status fields ({0}) Error {1}", sList, message), 2, 3, Convert.ToString(JobUid)); } finally { if (ds != null) { ds.Dispose(); } list = null; } } } } catch (Exception ex) { var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; bErrors = true; sbErrors.Append("<font color=\"red\">Error updating status fields: " + message + "</font><br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Error updating status fields Error {0}", message), 2, 3, Convert.ToString(JobUid)); } } foreach (string list in data.Split(',')) { if (list != "") { try { using (var cmd2 = new SqlCommand("spUpdateStatusFields", epmdata.GetClientReportingConnection)) { cmd2.CommandType = CommandType.StoredProcedure; cmd2.Parameters.AddWithValue("@listtable", list); cmd2.ExecuteNonQuery(); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Executed spUpdateStatusFields '{0}'", list), 2, 3, Convert.ToString(JobUid)); } } catch (Exception ex) { var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; bErrors = true; sbErrors.Append("<font color=\"red\">Error running schedule field update for (" + list + "): " + message + "</font><br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Error running schedule field update for ({0}) error {1}.", list, message), 2, 3, Convert.ToString(JobUid)); } if (!hshMessages.Contains(list)) { hshMessages.Add(list, ""); } } } sbErrors.Append("<br>Updated Status Fields<br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Complete running Updated Status Fields"), 2, 3, Convert.ToString(JobUid)); } catch (Exception ex) { var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; bErrors = true; sbErrors.Append("<font color=\"red\">Error running schedule field update: " + message + "</font><br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Error running schedule field update: {0}", message), 2, 3, Convert.ToString(JobUid)); } #endregion #region Clear Cache try { epmdata.LogStatus("", "", "Reporting Refresh Collect Job Clear Cache", string.Format("Started Cleaning cache for site : {0}", site.Url), 2, 3, Convert.ToString(JobUid)); CacheStore.Current.RemoveSafely(web.Url, new CacheStoreCategory(web).Navigation); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Clear Cache", string.Format("Completed Cleaning cache for site : {0}", site.Url), 2, 3, Convert.ToString(JobUid)); } catch (Exception ex) { var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; bErrors = true; sbErrors.Append("<font color=\"red\">Clear Cache Error: " + message + "</font><br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job Clear Cache", string.Format("Cleaning Cache Failed for site : {0} error {1}", site.Url, message), 2, 3, Convert.ToString(JobUid)); } #endregion } catch (Exception ex) { var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; bErrors = true; sbErrors.Append("<font color=\"red\">General Execute Error: " + message + "</font><br>"); epmdata.LogStatus("", "", "Reporting Refresh Collect Job", string.Format("General Execute Error for site : {0} error {1}", site.Url, message), 2, 3, Convert.ToString(JobUid)); } finally { sErrors = sbErrors.ToString(); sbErrors = null; //Already calling from TimerClass //finishJob(); hshMessages = null; if (epmdata != null) { epmdata.Dispose(); } if (web != null) { web.Dispose(); } if (rootWeb != null) { rootWeb.Dispose(); } if (site != null) { site.Dispose(); } data = null; } }
public MsSqlDbTraceCodeFormatter() { _dataScrubber = new DataScrubber(this, "format.scrub"); }