Example #1
0
        /// <summary>
        /// —оздаЄт отчЄт с указанными параметрами и направл¤ет его в текущий <see cref="System.Web.HttpResponse"/>.
        /// </summary>
        /// <param name="parameters">ѕараметры отчЄта.</param>
        /// <param name="overrideParametersContentType">MIME-тип дл¤ использовани¤ вместо встроенного в ReportParameters</param>
        /// <param name="encoding"> одировка</param>
        public static void GenerateReportToHttpResponse(ReportParameters parameters, string overrideParametersContentType, Encoding encoding)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            HttpContext context = HttpContext.Current;

            if (context == null)
            {
                throw new InvalidOperationException("HttpContext is not present.");
            }

            HttpResponse resp = context.Response;

            resp.ContentEncoding = encoding;
            resp.Clear();
            try
            {
                GenerateReport(parameters, resp.Output);
                resp.ContentType = (overrideParametersContentType != null) ? overrideParametersContentType : parameters.ContentType;
                if (string.IsNullOrEmpty(parameters.TargetFileName) == false)
                {
                    AddContentDispositionHeader(parameters.TargetFileName);
                }
            }
            catch (Exception)
            {
                resp.Clear();
                throw;
            }
            resp.End();
        }
Example #2
0
        public static string GenerateReportToRawString(ReportParameters parameters)
        {
            using (var txtstream = new StringWriter())
            {
                try
                {
                    GenerateReport(parameters, txtstream);
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException(string.Format("ќшибка при генерации файла отчета. " + Environment.NewLine + "ќшибка: {0}", ex.Message), ex);
                }

                return(txtstream.ToString());
            }
        }
Example #3
0
        /// <summary>
        /// —оздаЄт отчЄт.
        /// </summary>
        /// <param name="parameters">ѕараметры отчЄта.</param>
        /// <param name="tw">ќбъект <see cref="System.IO.TextWriter"/>, куда будет записаны результаты.</param>
        public static void GenerateReport(ReportParameters parameters, TextWriter tw)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (tw == null)
            {
                throw new ArgumentNullException("tw");
            }

            if (s_Providers == null)
            {
                lock (typeof(ReportGenerator))
                {
                    if (s_Providers == null)
                    {
                        s_Providers = new List <IReportProvider>();
                        InitializeProviders();
                    }
                }
            }

            XslCompiledTransform transform = GetCachedTransform(parameters.ReportName, parameters.ContentType, parameters.LanguageCode);

            if (transform == null)
            {
                XmlDocument transformXmlDoc = null;
                XmlResolver resolver        = null;
                lock (s_Providers)
                {
                    foreach (IReportProvider provider in s_Providers)
                    {
                        transformXmlDoc = provider.GetReportTemplate(parameters.ReportName, parameters.ContentType, parameters.LanguageCode);
                        if (transformXmlDoc != null)
                        {
                            resolver = provider.GetResolver(parameters.ReportName, parameters.ContentType, parameters.LanguageCode);
                            break;
                        }
                    }
                }

                if (transformXmlDoc == null)
                {
                    throw new ReportNotFoundException(string.Format("Report \"{0}\" with content type \"{1}\" was not found.", parameters.ReportName, parameters.ContentType));
                }

                transform = new XslCompiledTransform(true);
                XsltSettings xsltSettings = new XsltSettings();
                xsltSettings.EnableDocumentFunction = true;
                transform.Load(new XmlNodeReader(transformXmlDoc), xsltSettings, resolver);
                StoreInCache(new ReportFullName(parameters.ReportName, parameters.ContentType, parameters.LanguageCode), transform);
            }

            CultureInfo sysCulture    = null;
            CultureInfo reportCulture = null;

            if (parameters.LanguageCode != null)
            {
                reportCulture = CultureInfo.GetCultureInfo(parameters.LanguageCode);
            }

            try
            {
                if (reportCulture != null)
                {
                    sysCulture = Thread.CurrentThread.CurrentCulture;
                    Thread.CurrentThread.CurrentCulture = reportCulture;
                }

                XmlDocument      inputDoc = parameters.GenerateInputDocument();
                XsltArgumentList xslArgs  = new XsltArgumentList();
                xslArgs.AddExtensionObject("http://www.regionfund.ru/fol/ReportXsltHelper/", new XsltHelper());
                XPathDocument xpathDoc = new XPathDocument(new XmlNodeReader(inputDoc));
                transform.Transform(xpathDoc, xslArgs, tw);
            }
            finally
            {
                if (sysCulture != null)
                {
                    Thread.CurrentThread.CurrentCulture = sysCulture;
                }
            }
        }
Example #4
0
 /// <summary>
 /// —оздаЄт отчЄт с указанными параметрами и направл¤ет  его в текущий <see cref="System.Web.HttpResponse"/>.
 /// </summary>
 /// <param name="parameters">ѕараметры отчЄта.</param>
 public static void GenerateReportToHttpResponse(ReportParameters parameters)
 {
     GenerateReportToHttpResponse(parameters, null, Encoding.UTF8);
 }
Example #5
0
		/// <summary>
		/// —оздаЄт отчЄт.
		/// </summary>
		/// <param name="parameters">ѕараметры отчЄта.</param>
		/// <param name="tw">ќбъект <see cref="System.IO.TextWriter"/>, куда будет записаны результаты.</param>
		public static void GenerateReport(ReportParameters parameters, TextWriter tw)
		{
			if (parameters == null)
				throw new ArgumentNullException("parameters");

			if (tw == null)
				throw new ArgumentNullException("tw");

			if (s_Providers == null)
			{
				lock (typeof(ReportGenerator))
				{
					if (s_Providers == null)
					{
						s_Providers = new List<IReportProvider>();
						InitializeProviders();
					}
				}
			}

			XslCompiledTransform transform = GetCachedTransform(parameters.ReportName, parameters.ContentType, parameters.LanguageCode);
			if (transform == null)
			{
				XmlDocument transformXmlDoc = null;
				XmlResolver resolver = null;
				lock (s_Providers)
				{
					foreach (IReportProvider provider in s_Providers)
					{
						transformXmlDoc = provider.GetReportTemplate(parameters.ReportName, parameters.ContentType, parameters.LanguageCode);
						if (transformXmlDoc != null)
						{
							resolver = provider.GetResolver(parameters.ReportName, parameters.ContentType, parameters.LanguageCode);
							break;
						}
					}
				}

				if (transformXmlDoc == null)
					throw new ReportNotFoundException(string.Format("Report \"{0}\" with content type \"{1}\" was not found.", parameters.ReportName, parameters.ContentType));

				transform = new XslCompiledTransform(true);
				XsltSettings xsltSettings = new XsltSettings();
				xsltSettings.EnableDocumentFunction = true;
				transform.Load(new XmlNodeReader(transformXmlDoc), xsltSettings, resolver);
				StoreInCache(new ReportFullName(parameters.ReportName, parameters.ContentType, parameters.LanguageCode), transform);
			}

			CultureInfo sysCulture = null;
			CultureInfo reportCulture = null;
			if (parameters.LanguageCode != null)
				reportCulture = CultureInfo.GetCultureInfo(parameters.LanguageCode);

			try
			{
				if (reportCulture != null)
				{
					sysCulture = Thread.CurrentThread.CurrentCulture;
					Thread.CurrentThread.CurrentCulture = reportCulture;
				}

				XmlDocument inputDoc = parameters.GenerateInputDocument();
				XsltArgumentList xslArgs = new XsltArgumentList();
				xslArgs.AddExtensionObject("http://www.regionfund.ru/fol/ReportXsltHelper/", new XsltHelper());
				XPathDocument xpathDoc = new XPathDocument(new XmlNodeReader(inputDoc));
				transform.Transform(xpathDoc, xslArgs, tw);
			}
			finally
			{
				if (sysCulture != null)
					Thread.CurrentThread.CurrentCulture = sysCulture;
			}
		}
Example #6
0
		/// <summary>
		/// —оздаЄт отчЄт с указанными параметрами и направл¤ет его в текущий <see cref="System.Web.HttpResponse"/>.
		/// </summary>
		/// <param name="parameters">ѕараметры отчЄта.</param>
		/// <param name="overrideParametersContentType">MIME-тип дл¤ использовани¤ вместо встроенного в ReportParameters</param>
		/// <param name="encoding"> одировка</param>
		public static void GenerateReportToHttpResponse(ReportParameters parameters, string overrideParametersContentType, Encoding encoding)
		{
			if (parameters == null)
				throw new ArgumentNullException("parameters");

			HttpContext context = HttpContext.Current;
			if (context == null)
				throw new InvalidOperationException("HttpContext is not present.");

			HttpResponse resp = context.Response;
			resp.ContentEncoding = encoding;
			resp.Clear();
			try
			{
				GenerateReport(parameters, resp.Output);
				resp.ContentType = (overrideParametersContentType != null) ? overrideParametersContentType : parameters.ContentType;
				if (string.IsNullOrEmpty(parameters.TargetFileName) == false)
					AddContentDispositionHeader(parameters.TargetFileName);
			}
			catch (Exception)
			{
				resp.Clear();
				throw;
			}
			resp.End();
		}
Example #7
0
		/// <summary>
		/// —оздаЄт отчЄт с указанными параметрами и направл¤ет  его в текущий <see cref="System.Web.HttpResponse"/>.
		/// </summary>
		/// <param name="parameters">ѕараметры отчЄта.</param>
		public static void GenerateReportToHttpResponse(ReportParameters parameters)
		{
			GenerateReportToHttpResponse(parameters, null, Encoding.UTF8);
		}
Example #8
0
        public static string GenerateReportToRawString(ReportParameters parameters)
        {
            using (var txtstream = new StringWriter())
            {
                try
                {
                    GenerateReport(parameters, txtstream);
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException(string.Format("ќшибка при генерации файла отчета. " + Environment.NewLine + "ќшибка: {0}", ex.Message), ex);
                }

                return txtstream.ToString();
            }
        }