private static void RunReport(string templateFilename, string outputFilename, Dictionary <string, object> adHocVariables)
        {
            // get the report ready to run.
            using (Stream template = new FileStream(templateFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (Stream output = new FileStream(outputFilename, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    using (Report report = new ReportDocx(template, output))
                    {
                        report.ProcessSetup();

                        // Create the datasource - Northwind.
                        using (AdoDataSourceImpl datasource = new AdoDataSourceImpl("System.Data.SqlClient",
                                                                                    "Data Source=mssql.windward.net;Initial Catalog=Northwind;User ID=demo;Password=demo"))
                        {
                            // set the variables to provide list results for each var
                            report.Parameters = adHocVariables;

                            // run the datasource
                            report.ProcessData(datasource, "");
                        }

                        // and we're done!
                        report.ProcessComplete();
                        output.Close();
                    }
                }
            }
            Console.Out.WriteLine(string.Format("Completed: {0}", outputFilename));
            System.Diagnostics.Process.Start(outputFilename);
        }
Пример #2
0
        public void RunReport()
        {
            Console.Out.WriteLine(string.Format("Requesting report {0}", Path.GetFileName(reportFilename)));

            // this will not return until there is an available semaphore. When it returns, the used semaphore count is incremented by one.
            sem.WaitOne();

            try
            {
                Console.Out.WriteLine(string.Format("     processing report {0}", Path.GetFileName(reportFilename)));

                // Open template file and create output file
                using (FileStream template = File.OpenRead(templateFilename))
                {
                    using (FileStream output = File.Create(reportFilename))
                    {
                        // Create report process
                        // !!!!! you MUST have using on this to insure it is closed and the thread count for the engine is decreased !!!!!
                        using (Report myReport = new ReportDocx(template, output))
                        {
                            myReport.ProcessSetup();

                            // remove this - this is here insure that all threads try to run at once.
                            Thread.Sleep(10 * 1000);

                            // Open an inputfilestream for our data file
                            FileStream Xml = File.OpenRead(xmlDataFilename);

                            // Open a data object to connect to our xml file
                            IReportDataSource data = new XmlDataSourceImpl(Xml, false);

                            // Close out of our template file and output
                            Xml.Close();

                            // Run the report process
                            myReport.ProcessData(data, "");
                            myReport.ProcessComplete();
                        }
                    }
                }
            }
            finally
            {
                Console.Out.WriteLine(string.Format("          report completed (releasing semaphore) {0}", Path.GetFileName(reportFilename)));

                // you must call this in a finally block so it is always called.
                // this decrements the used semaphore count by one.
                sem.Release(1);
            }
        }
Пример #3
0
        private static void RunReport(string templateFilename, string outputFilename, Dictionary <string, object> adHocVariables)
        {
            // get the report ready to run.
            using (Stream template = new FileStream(templateFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (Stream output = new FileStream(outputFilename, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    using (Report report = new ReportDocx(template, output))
                    {
                        report.ProcessSetup();

                        // Create the datasource - SouthWind.xml.
                        // We need the XSD too so it knows the type of nodes.
                        using (Stream xmlStream = new FileStream(Path.GetFullPath("../../SouthWind.xml"), FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            using (Stream xsdStream = new FileStream(Path.GetFullPath("../../SouthWind.xsd"), FileMode.Open, FileAccess.Read, FileShare.Read))
                            {
                                using (XmlDataSourceImpl datasource = new XmlDataSourceImpl(xmlStream, xsdStream, true))
                                {
                                    // set the variables to provide list results for each var
                                    report.Parameters = adHocVariables;

                                    // run the datasource
                                    report.ProcessData(datasource, "");
                                }
                            }
                        }

                        // and we're done!
                        report.ProcessComplete();
                        output.Close();
                    }
                }
            }
            Console.Out.WriteLine(string.Format("Completed: {0}", outputFilename));
        }