/// <summary> /// Validates the required attributes to render AssignmentListWebPart /// Throws SafeToDisplayException If not Valid. /// </summary> private void ValidateAlwpProperties() { //Check for Current User and QuerySet Values if (SPWeb.CurrentUser == null) { throw new UserNotFoundException(culture.Resources.SlkExUserNotFound); } if (String.IsNullOrEmpty(SlkUtilities.Trim(QuerySetOverride)) == false) { // set <querySetDef> to the QuerySetDefinition named <querySetName> QuerySetDefinition querySetDef = SlkStore.Settings.FindQuerySetDefinition(QuerySetOverride, true); if (querySetDef == null) { throw new SafeToDisplayException(culture.Resources.AlwpQuerySetNotFound, QuerySetOverride); } else { defaultQueryName = querySetDef.DefaultQueryName; } } }
private void RenderQuerySummary(HtmlTextWriter hw, QuerySetDefinition querySetDef) { using (new HtmlBlock(HtmlTextWriterTag.Tr, 1, hw)) { using (new HtmlBlock(HtmlTextWriterTag.Td, 1, hw)) { // write a hidden iframe that loads QuerySummary.aspx which, // when loaded, will // call the SetQueryCounts() JScript method in QuerySet.js to update the // query counts that are initially displayed as hourglasses hw.AddAttribute(HtmlTextWriterAttribute.Width, "1"); hw.AddAttribute(HtmlTextWriterAttribute.Height, "1"); hw.AddAttribute("frameborder", "0"); hw.Write("<iframe width=\"1\" height=\"1\" frameborder=\"0\" id=\"{0}QS\" name=\"{0}QS\"></iframe>", FrameId); WriteSummaryForm(hw); WriteResultsForm(hw); // write script code that begins loading the query counts, // and provides other information to QuerySet.js using (new HtmlBlock(HtmlTextWriterTag.Script, 1, hw)) { // Register SelectQuery Client Click JavaScript Method. RegisterQuerySetClientScriptBlock(hw); hw.WriteLine(); // tell QuerySet.js the names of the queries hw.WriteEncodedText("var QueryNames = new Array();"); hw.WriteLine(); int queryIndex = 0; int selectedQueryIndex = 0; foreach (QueryDefinition queryDef in querySetDef.Queries) { hw.Write(String.Format(CultureInfo.InvariantCulture, "QueryNames[{0}] = \"{1}\";", queryIndex, queryDef.Name)); hw.WriteLine(); if (queryDef.Name == querySetDef.DefaultQueryName) { selectedQueryIndex = queryIndex; } queryIndex++; } string scopeScript = @" var scope = parent.scope{0}; var queryInput = document.getElementById('alwpSPWebScopeQR'); queryInput.value = scope; queryInput = document.getElementById('alwpSPWebScopeQSForm'); queryInput.value = scope; "; scopeScript = string.Format(scopeScript, FrameId); hw.WriteLine(scopeScript); // tell QuerySet.js to start loading the selected query results hw.WriteEncodedText(String.Format(CultureInfo.InvariantCulture, "SelectQuery({0});", selectedQueryIndex)); hw.WriteLine(@" var summaryForm = document.getElementById('{0}QSForm'); summaryForm.submit();", FrameId); } } } }
protected void Page_Load(object sender, EventArgs e) { try { // render the HTML for the page using (HtmlTextWriter hw = new HtmlTextWriter(Response.Output, " ")) { // render the "<html>" element and its contents using (new HtmlBlock(HtmlTextWriterTag.Html, 0, hw)) { RenderHead(hw); try { string querySetName = QueryString.ParseString(QueryStringKeys.QuerySet); // set <querySetDef> to the QuerySetDefinition named <querySetName> QuerySetDefinition querySetDef = SlkStore.Settings.FindQuerySetDefinition(querySetName, true); if (querySetDef == null) { throw new SafeToDisplayException(PageCulture.Resources.AlwpQuerySetNotFound, querySetName); } // render the "<body>" element and its contents //hw.AddAttribute(HtmlTextWriterAttribute.Style, "overflow: hidden;"); hw.AddAttribute(HtmlTextWriterAttribute.Style, "width: 100%; overflow-y: auto;"); hw.AddAttribute(HtmlTextWriterAttribute.Id, "SlkAlwpQuerySet"); hw.AddAttribute(HtmlTextWriterAttribute.Onclick, string.Empty); using (new HtmlBlock(HtmlTextWriterTag.Body, 0, hw)) { AssignmentListWebPart.DumpCultures(hw, "Page_Load"); // begin the query set hw.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0"); hw.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0"); hw.AddAttribute(HtmlTextWriterAttribute.Border, "0"); hw.AddAttribute(HtmlTextWriterAttribute.Class, "ms-toolbar"); hw.AddAttribute(HtmlTextWriterAttribute.Style, "border: none; background-image: none; width:100%; height:100%;"); hw.AddAttribute(HtmlTextWriterAttribute.Onclick, string.Empty); using (new HtmlBlock(HtmlTextWriterTag.Table, 1, hw)) { RenderQueryLines(hw, querySetDef); RenderQuerySummary(hw, querySetDef); } } } catch (Exception ex) { SlkError slkError; //Handles SqlException separately to capture the deadlock //and treat it differently SqlException sqlEx = ex as SqlException; if (sqlEx != null) { slkError = WebParts.ErrorBanner.WriteException(SlkStore, sqlEx); } else { slkError = SlkError.WriteException(SlkStore, ex); } WebParts.ErrorBanner.RenderErrorItems(hw, slkError); } } } } catch (Exception ex) { Response.Write(ex.ToString()); } }
private void RenderQueryLines(HtmlTextWriter hw, QuerySetDefinition querySetDef) { hw.AddAttribute(HtmlTextWriterAttribute.Onclick, string.Empty); using (new HtmlBlock(HtmlTextWriterTag.Tr, 1, hw)) { hw.AddAttribute(HtmlTextWriterAttribute.Valign, "top"); hw.AddAttribute(HtmlTextWriterAttribute.Align, "left"); hw.AddAttribute(HtmlTextWriterAttribute.Onclick, string.Empty); using (new HtmlBlock(HtmlTextWriterTag.Td, 1, hw)) { hw.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0"); hw.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0"); hw.AddAttribute(HtmlTextWriterAttribute.Border, "0"); hw.AddAttribute(HtmlTextWriterAttribute.Class, "ms-toolbar"); hw.AddAttribute(HtmlTextWriterAttribute.Style, "border: none; background-image: none; width:100%; height:100%;"); hw.AddAttribute(HtmlTextWriterAttribute.Onclick, string.Empty); using (new HtmlBlock(HtmlTextWriterTag.Table, 1, hw)) { // write "<col>" tags: // column 1: spacer HtmlBlock.WriteFullTag(HtmlTextWriterTag.Col, 1, hw); // column 2: left pseudo-border HtmlBlock.WriteFullTag(HtmlTextWriterTag.Col, 1, hw); // column 3: label HtmlBlock.WriteFullTag(HtmlTextWriterTag.Col, 1, hw); // column 4: count hw.AddAttribute(HtmlTextWriterAttribute.Style, "text-align: right;"); HtmlBlock.WriteFullTag(HtmlTextWriterTag.Col, 1, hw); // write a spacer row hw.AddAttribute(HtmlTextWriterAttribute.Height, "8"); using (new HtmlBlock(HtmlTextWriterTag.Tr, 1, hw)) { hw.AddAttribute(HtmlTextWriterAttribute.Align, "left"); hw.AddAttribute(HtmlTextWriterAttribute.Style, "width: 3px;"); using (new HtmlBlock(HtmlTextWriterTag.Td, 1, hw)) { HtmlBlock.WriteBlankGif("8", "1", hw); } hw.AddAttribute(HtmlTextWriterAttribute.Align, "left"); hw.AddAttribute(HtmlTextWriterAttribute.Style, "width: 3px;"); HtmlBlock.WriteFullTag(HtmlTextWriterTag.Td, 1, hw); hw.AddAttribute(HtmlTextWriterAttribute.Align, "left"); hw.AddAttribute(HtmlTextWriterAttribute.Style, "width:100%;"); HtmlBlock.WriteFullTag(HtmlTextWriterTag.Td, 1, hw); hw.AddAttribute(HtmlTextWriterAttribute.Align, "left"); hw.AddAttribute(HtmlTextWriterAttribute.Style, "border-right: solid 1px #E0E0E0; "); using (new HtmlBlock(HtmlTextWriterTag.Td, 1, hw)) { HtmlBlock.WriteBlankGif("1", "1", hw); } } // write the query link rows int queryIndex = 0; foreach (QueryDefinition queryDef in querySetDef.Queries) { RenderQueryLinkRow(queryDef, queryIndex, hw); queryIndex++; } // write a row that consumes the remaining space hw.AddAttribute(HtmlTextWriterAttribute.Style, "height:100%;"); using (new HtmlBlock(HtmlTextWriterTag.Tr, 1, hw)) { hw.AddAttribute(HtmlTextWriterAttribute.Align, "left"); hw.AddAttribute(HtmlTextWriterAttribute.Style, "width: 3px;"); using (new HtmlBlock(HtmlTextWriterTag.Td, 1, hw)) HtmlBlock.WriteBlankGif("8", "1", hw); hw.AddAttribute(HtmlTextWriterAttribute.Align, "left"); hw.AddAttribute(HtmlTextWriterAttribute.Style, "width: 3px;"); HtmlBlock.WriteFullTag(HtmlTextWriterTag.Td, 1, hw); hw.AddAttribute(HtmlTextWriterAttribute.Align, "left"); hw.AddAttribute(HtmlTextWriterAttribute.Style, "width:100%;"); HtmlBlock.WriteFullTag(HtmlTextWriterTag.Td, 1, hw); hw.AddAttribute(HtmlTextWriterAttribute.Align, "left"); hw.AddAttribute(HtmlTextWriterAttribute.Style, "border-right: solid 1px #E0E0E0; "); using (new HtmlBlock(HtmlTextWriterTag.Td, 1, hw)) HtmlBlock.WriteBlankGif("1", "1", hw); } } } } }
protected void Page_Load(object sender, EventArgs e) { try { string querySetName = Request[QueryStringKeys.QuerySet]; // Only return anything if a query is passed. if (string.IsNullOrEmpty(querySetName) == false) { // create a job for executing the queries specified by <querySetDef> LearningStoreJob job = SlkStore.LearningStore.CreateJob(); // set <querySetDef> to the QuerySetDefinition named <querySetName> QuerySetDefinition querySetDef = SlkStore.Settings.FindQuerySetDefinition(querySetName, true); if (querySetDef == null) { throw new SafeToDisplayException(PageCulture.Resources.AlwpQuerySetNotFound, querySetName); } // create queries corresponding to <querySetDef> and add them to <job>; // set <numberOfQueries> to the number of queries in the query set int numberOfQueries = 0; foreach (QueryDefinition queryDef in querySetDef.Queries) { PerformQuery(queryDef, job); numberOfQueries++; } // execute the job ReadOnlyCollection <object> results = null; try { // execute the job results = job.Execute(); } catch (SqlException sqlEx) { //check whether deadlock occured and throw the exception back if (sqlEx.Number == 1205) { throw; } // don't need SlkStore.LogException(ex) because we'll write to the event log again // in RenderQueryCounts results = null; } finally { RenderQueryCounts(querySetDef, numberOfQueries, results); } } } catch (Exception ex) { Response.Write(ex.ToString()); try { SlkStore.LogException(ex); } catch (Exception exe) { Response.Write(exe.ToString()); } } }
/// <summary> /// Renders the Javascript that contains the query result counts. /// Gets the Query Count from results Collections and sets the count. /// If results collection is null Execute each Query individually /// and get the count. Set the Query count as "ERROR" for Failed one. /// </summary> private void RenderQueryCounts(QuerySetDefinition querySetDef, int numberOfQueries, ReadOnlyCollection <object> results) { // render the HTML for the page using (HtmlTextWriter hw = new HtmlTextWriter(Response.Output, " ")) { // render the "<html>" element and its contents using (new HtmlBlock(HtmlTextWriterTag.Html, 0, hw)) { // write script code that contains the query result counts using (new HtmlBlock(HtmlTextWriterTag.Script, 0, hw)) { hw.Write(String.Format(CultureInfo.InvariantCulture, "var a = new Array({0});", numberOfQueries)); hw.WriteLine(); //To Store all the Query Counts //string queryCounts = String.Empty; StringBuilder queryCounts = new StringBuilder(100); //Query Index int queryIndex = 0; //isError will be set to false if *any* query succeeded -- in this case, if //To Verify is there is an Error Processing QuerySet and setting QueryCounts bool isError = true; foreach (QueryDefinition queryDef in querySetDef.Queries) { int queryResultCount; if (results != null) { queryResultCount = ((DataTable)results[queryIndex]).Rows.Count; isError = false; } else { //One of the QueryExecution in the QuerySet failed. //while executing the Job. Execute each Query individually. queryResultCount = ExecuteQuery(queryDef); //Check for Query Result Count. //queryResultCount must return -1 for any one of the Query //as QuerySet execution failed. if (queryResultCount == -1) { isError = false; } } if (queryResultCount != -1) { queryCounts.AppendLine(String.Format(CultureInfo.InvariantCulture, "a[{0}] = {1};", queryIndex, queryResultCount)); } else { queryCounts.AppendLine(String.Format(CultureInfo.InvariantCulture, "a[{0}] = \"{1}\";", queryIndex, PageCulture.Resources.AlwpQueryResultError)); } queryIndex++; } //isError Can't be true. if QuerySet execution failed //then any of the Query Execution should have Failed. //If isError true means individual Execution of each //Query succeeds and QuerySet Execution failed always. //Which affects performance. indicate the impact in //result count by setting the count to ERROR for all results. if (isError) { // in this situation, the first time we ran the "batch" query (to get // counts for the entire query set), some query failed, but we didn't know // *which* query failed so we executed each query one at a time, and this // time, all of them succeeded -- which shouldn't have happened, so we // display "ERROR" for all counts so that the user knows something weird/bad // happened queryCounts.Length = 0; for (int i = 0; i < queryIndex; i++) { queryCounts.AppendLine(String.Format(CultureInfo.InvariantCulture, "a[{0}] = \"{1}\";", i, PageCulture.Resources.AlwpQueryResultError)); } } hw.Write(queryCounts); hw.WriteLine(); hw.Write("if (parent.SetQueryCounts != undefined)"); hw.WriteLine(); hw.Write(" parent.SetQueryCounts(a);"); } } } }