/// <summary> /// Print queried data in the dynamic page to any format depends on the implementation. /// </summary> /// <param name="dynamicPageService">The dynamic page handler.</param> /// <param name="queryStringParameters">The query string parameters.</param> /// <returns></returns> public DynamicPagePrintResult Print(IDynamicPage dynamicPageService, NameValueCollection queryStringParameters) { try { QueryParameter queryParameter = QueryParameter.CreateQueryParameter(dynamicPageService, queryStringParameters, 0, int.MaxValue, null, null); // Execute query. QueryResults queryResults = dynamicPageService.Query(queryParameter); DataSource dataSource = ConvertQueryResults(dynamicPageService, queryResults.Results); return TransformDataSource(dataSource); } catch (ValidationException exp) { Logger.Instance(typeof(DynamicPagePrinter)).Warn(exp); throw; } catch (Exception exp) { Logger.Instance(typeof(DynamicPagePrinter)).Error(exp); throw; } }
/// <summary> /// Execute query for specified dynamic page by object id. /// </summary> /// <param name="dynamicPageService">dynamic page service</param> /// <param name="start">start offset of returned results</param> /// <param name="limit">total count of returned results</param> /// <param name="sortField">sorting field name</param> /// <param name="sortDirection">sorting field direction</param> /// <param name="errorMessage">error messages response to the client.</param> /// <returns>returns json-serialized string from <see cref="QueryResultObject"/></returns> private static string ExecuteQuery(IDynamicPage dynamicPageService, int start, int limit, string sortField, string sortDirection, string errorMessage) { IEnumerable convertedQueryResults = null; int totalRecordCount = 0; string returnedErrorMessage = errorMessage; if (string.IsNullOrEmpty(returnedErrorMessage)) { try { QueryParameter queryParameter = QueryParameter.CreateQueryParameter(dynamicPageService, HttpContext.Current.Request.QueryString, start, limit, sortField, sortDirection); // Execute query. QueryResults queryResults = dynamicPageService.Query(queryParameter); convertedQueryResults = ConvertQueryResults(dynamicPageService, queryResults.Results); totalRecordCount = queryResults.RecordCount; } catch (ValidationException exp) { returnedErrorMessage = exp.Message; } catch (Exception exp) { returnedErrorMessage = Resources.DP_UnknownErrorDetail; Logger.Instance(typeof(DynamicPageDataServiceHandler)).Error(exp); } } // Construct query result object for serialization. QueryResultObject queryResultObject = new QueryResultObject { Records = convertedQueryResults, TotalRecordCount = totalRecordCount, Start = start, Limit = limit, HasError = !string.IsNullOrEmpty(returnedErrorMessage), ErrorMessage = returnedErrorMessage }; return serializer.Serialize(queryResultObject); }