Ejemplo n.º 1
0
        public static DataTable LoadReportDataTable(string reportId, string dataSetName, IDictionary <string, object> parameterValues, DataTableCallback callback)
        {
            string  reportPath = ConfigurationManager.AppSettings["VB.Reports.App.ReportDefinitionLibrary.Xml.Serialization.ReportMetadata.Path"];
            IReport report     = ReportFactory.NewReportFactory(reportPath).FindReport(reportId);
            ILocalReportProcessingLocation location = (ILocalReportProcessingLocation)report.ReportProcessingLocation;

            DataTable table;

            using (IDataConnection connection = SimpleQuery.ConfigurationManagerConnection(location.DataSourceName))
            {
                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                }

                IReportDataCommandTemplate reportDataCommandTemplate = report.DataSource(dataSetName);

                using (IDataCommand command = connection.CreateCommand(reportDataCommandTemplate, new DictionaryDataParameterValue(parameterValues).DataParameterValue))
                {
                    command.CommandTimeout = 90;

                    using (IDataReader reader = command.ExecuteReader())
                    {
                        table = DataTableMapper.ToDataTable(reader, reportDataCommandTemplate.DataMap, callback);
                    }
                }
            }
            return(table);
        }
Ejemplo n.º 2
0
        public void ToDataTableNoRows()
        {
            var customerRecords = new List <CustomerRecord>();

            var propertyMapper   = new PropertyMapper <CustomerRecord>();
            var dataColumnMapper = new DataColumnMapper <CustomerRecord>(propertyMapper);
            var dataRowMapper    = new DataRowMapper <CustomerRecord>(propertyMapper);
            var dataTableMapper  = new DataTableMapper <CustomerRecord>(dataColumnMapper, dataRowMapper);

            var dataTable = dataTableMapper.ToDataTable(customerRecords);

            Assert.Equal(customerRecords.Count, dataTable.Rows.Count);

            Assert.Equal(6, dataTable.Columns.Count);

            Assert.Equal(0, dataTable.Rows.Count);
        }
Ejemplo n.º 3
0
        public void ToDataTableWithMultipleRows()
        {
            var customerRecords = new List <CustomerRecord>
            {
                new CustomerRecord
                {
                    Id             = 1,
                    FirstName      = "John",
                    LastName       = "Smith",
                    AccountBalance = 25.60m,
                    DateJoined     = new DateTime(2018, 9, 15),
                    IsActive       = true,
                },

                new CustomerRecord
                {
                    Id             = 2,
                    FirstName      = "Mary",
                    LastName       = "McDonanld",
                    AccountBalance = 30.950m,
                    DateJoined     = new DateTime(2017, 4, 10),
                    IsActive       = false,
                }
            };

            var propertyMapper   = new PropertyMapper <CustomerRecord>();
            var dataColumnMapper = new DataColumnMapper <CustomerRecord>(propertyMapper);
            var dataRowMapper    = new DataRowMapper <CustomerRecord>(propertyMapper);
            var dataTableMapper  = new DataTableMapper <CustomerRecord>(dataColumnMapper, dataRowMapper);

            var dataTable = dataTableMapper.ToDataTable(customerRecords);

            Assert.Equal(customerRecords.Count, dataTable.Rows.Count);

            Assert.Equal(6, dataTable.Columns.Count);

            // TODO: VC: Assert columns equality

            CustomerRecordAssert.Equal(customerRecords, dataTable.Rows);
        }
Ejemplo n.º 4
0
        protected void BindLocalReport(MsLocalReport localReport, IReport report)
        {
            ILocalReportProcessingLocation location = (ILocalReportProcessingLocation)report.ReportProcessingLocation;

            localReport.LoadReportDefinition(ReportDefinitionCache.GetReportDefinition(location.File).GetReportStream());

            localReport.EnableHyperlinks = true;

            localReport.EnableExternalImages = true;

            localReport.SetBasePermissionsForSandboxAppDomain(new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted));
            //localReport.ExecuteReportInCurrentAppDomain(AppDomain.CurrentDomain.Evidence);
            //localReport.AddFullTrustModuleInSandboxAppDomain(new System.Security.Policy.StrongName(new System.Security.Permissions.StrongNamePublicKeyBlob(Nullable),"VB.Reports.App.ReportStyleLibrary.StyleSheet","1.0.0"));
            //localReport.AddTrustedCodeModuleInCurrentAppDomain(System.Reflection.Assembly.GetAssembly(typeof(VB.Reports.App.ReportStyleLibrary.StyleSheet)).ToString());

            if (localReport.IsDrillthroughReport)
            {
                localReport.SetParameters(localReport.OriginalParametersToDrillthrough);
            }
            else
            {
                IList <MsReportParameter> parameters = new List <MsReportParameter>();

                foreach (IReportParameter parameter in report.ReportParameters)
                {
                    parameters.Add(new MsReportParameter(parameter.Name, GetParameterValue(parameter)));
                }

                localReport.SetParameters(parameters);
            }

            localReport.DataSources.Clear();

            foreach (IReportDataCommandTemplate reportDataCommandTemplate in report.ReportDataCommandTemplates)
            {
                DictionaryDataParameterValue parameterValues = new DictionaryDataParameterValue();

                foreach (IReportParameter parameter in reportDataCommandTemplate.Parameters)
                {
                    if (localReport.IsDrillthroughReport)
                    {
                        parameterValues[parameter.Name] =
                            GetParameterValue(parameter, localReport.OriginalParametersToDrillthrough);
                    }
                    else
                    {
                        parameterValues[parameter.Name] = GetParameterValue(parameter);
                    }
                }

                using (IDataConnection connection = SimpleQuery.ConfigurationManagerConnection(location.DataSourceName))
                {
                    if (connection.State == ConnectionState.Closed)
                    {
                        connection.Open();
                    }

                    using (IDataCommand command = connection.CreateCommand(reportDataCommandTemplate, parameterValues.DataParameterValue))
                    {
                        command.CommandTimeout = 200;
                        using (IDataReader reader = command.ExecuteReader())
                        {
                            DataTable table = DataTableMapper.ToDataTable(reader);
                            localReport.DataSources.Add(new MsReportDataSource(reportDataCommandTemplate.Name, table));
                        }
                    }
                }
            }

            localReport.Refresh();
        }
Ejemplo n.º 5
0
        protected void BindLocalReport(MsLocalReport localReport, IReport report)
        {
            ILocalReportProcessingLocation location = (ILocalReportProcessingLocation)report.ReportProcessingLocation;

            localReport.LoadReportDefinition(ReportDefinitionCache.GetReportDefinition(location.File).GetReportStream());

            localReport.EnableHyperlinks = true;

            localReport.EnableExternalImages = true;

            localReport.SetBasePermissionsForSandboxAppDomain(new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted));

            if (localReport.IsDrillthroughReport)
            {
                localReport.SetParameters(localReport.OriginalParametersToDrillthrough);
            }
            else
            {
                IList <MsReportParameter> parameters = new List <MsReportParameter>();

                foreach (IReportParameter parameter in report.ReportParameters)
                {
                    parameters.Add(new MsReportParameter(parameter.Name, GetParameterValue(parameter)));
                }

                localReport.SetParameters(parameters);
            }

            localReport.DataSources.Clear();


            foreach (IReportDataCommandTemplate reportDataCommandTemplate in report.ReportDataCommandTemplates)
            {
                DictionaryDataParameterValue parameterValues = new DictionaryDataParameterValue();

                foreach (var dataParameterTemplate in reportDataCommandTemplate.Parameters)
                {
                    var parameter = (IReportParameter)dataParameterTemplate;
                    if (localReport.IsDrillthroughReport)
                    {
                        parameterValues[parameter.Name] =
                            GetParameterValue(parameter, localReport.OriginalParametersToDrillthrough);
                    }
                    else
                    {
                        parameterValues[parameter.Name] = GetParameterValue(parameter);
                    }
                }

                var dataCommandTemplate = reportDataCommandTemplate as ReportDataCommandTemplate;
                if (dataCommandTemplate != null)
                {
                    using (IDataConnection connection = SimpleQuery.ConfigurationManagerConnection(dataCommandTemplate.DataSourceName))
                    {
                        if (connection.State == ConnectionState.Closed)
                        {
                            connection.Open();
                        }
                        DataTable table  = null;
                        Boolean   isOlap = ChangeOlapParameter(dataCommandTemplate.DataSourceName,
                                                               parameterValues);

                        if (reportDataCommandTemplate.Name.Equals("DealerGroupID"))
                        {
                            continue;
                        }

                        if (isOlap)
                        {
                            table = ReportAnalyticsClient.GetReportData <DataTable>(GetParameterList(parameterValues));
                        }
                        if (table == null)
                        {
                            using (IDataCommand command = connection.CreateCommand(reportDataCommandTemplate, parameterValues.DataParameterValue))
                            {
                                command.CommandTimeout = 200;
                                using (IDataReader reader = command.ExecuteReader())
                                {
                                    table = (isOlap.Equals(true) ? DataTableMapper.ToOlapDataTable(reader, reportDataCommandTemplate.DataMap, new DataTableCallback()) :
                                             DataTableMapper.ToDataTable(reader, reportDataCommandTemplate.DataMap, new DataTableCallback()));
                                }
                            }
                        }

                        localReport.DataSources.Add(new MsReportDataSource(reportDataCommandTemplate.Name, table));
                    }
                }
            }

            localReport.Refresh();
        }