Exemplo n.º 1
0
        /// <summary>
        /// Prepares the Media.
        /// </summary>
        /// <param name="card">The card.</param>
        /// <param name="printstatusreport">The printstatusreport.</param>
        /// <remarks>Documented by Dev03, 2007-08-17</remarks>
        private void PrepareMedia(XmlNode card, PrintStatusReport printstatusreport)
        {
            if (printstatusreport != null)
                printstatusreport.PrepareCount = card.SelectNodes(XPathResourceFilter).Count;

            foreach (XmlNode resource in card.SelectNodes(XPathResourceFilter))
            {
                string path = resource.Value;
                try
                {
                    if (DAL.Helper.GetMediaType(path) == EMedia.Image)
                    {
                        //try to read the image size from the file if it is not given ([ML-128])
                        XmlElement xeMedia = (XmlElement)resource.ParentNode;
                        if (xeMedia.GetAttribute("width") == String.Empty)
                        {
                            using (System.Drawing.Bitmap image = new System.Drawing.Bitmap(path))
                            {
                                System.Drawing.Size size = image.Size;
                                xeMedia.SetAttribute("width", size.Width.ToString());
                                xeMedia.SetAttribute("height", size.Height.ToString());
                            }
                        }
                    }
                }
                catch { }
                if (printstatusreport != null)
                    printstatusreport.SetPrepareStatus();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Transforms the specified card document.
        /// </summary>
        /// <param name="document">The card document.</param>
        /// <param name="stylesheet">The stylesheet.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>The transformed document as HTML.</returns>
        /// <remarks>Documented by Dev05, 2007-09-03</remarks>
        private string Transform(XmlDocument document, string stylesheet, XsltArgumentList xsltArguments, PrintStatusReport printstatusreport)
        {
            if (dictionary.Parent.CurrentUser.ConnectionString.Typ == DatabaseType.Xml)
                PrepareMedia(document, printstatusreport);

            XslCompiledTransform xslTransformer = new XslCompiledTransform();
            //XsltArgumentList xsltArguments = new XsltArgumentList();
            //if (arguments != null)
            //{
            //    foreach (object argument in arguments)
            //    {
            //        xsltArguments.AddParam("chapters", String.Empty, argument);
            //    }
            //}
            xsltArguments.AddParam("baseURL", string.Empty,
                Uri.UnescapeDataString(new Uri(DirectoryName.Replace(@"\", @"/")).AbsoluteUri) + "/");
            xsltArguments.AddParam("titleText", string.Empty, Path.GetFileNameWithoutExtension(DictionaryPath));
            XsltSettings settings = new XsltSettings(false, false);     //disable scripts and document()
            xslTransformer.Load(stylesheet, settings, new XmlUrlResolver());

            StringWriter htmlContent = new StringWriter();
            xslTransformer.Transform(document, xsltArguments, htmlContent);
            //StringBuilder htmlContent = new StringBuilder();
            //StringWriter htmlWriter = new StringWriter(htmlContent);
            //XmlTextWriter htmlTextWriter = new XmlTextWriter(htmlWriter);
            //xslTransformer.Transform(document, xsltArguments, htmlTextWriter);

            return htmlContent.ToString();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates the Html file for printing, using given transformation stylesheet.
        /// </summary>
        /// <param name="chapters">Integer Array containing the IDs of the chapters to print</param>
        /// <param name="stylesheet">Card ID</param>
        /// <returns>Path to the print file</returns>
        /// <remarks>Documented by Dev03, 2007-07-20</remarks>
        /// <remarks>Documented by Dev02, 2007-11-22</remarks>
        public string GeneratePrintOut(List<ICard> cards, string stylesheet, BackgroundWorker backgroundworker, BackgroundWorker mediaprepareworker)
        {
            try
            {
                //generate new xml dictionary document for printing
                XmlDocument printDocument = new System.Xml.XmlDocument();
                XmlNode printDocumentDictionary = printDocument.AppendChild(printDocument.CreateElement("dictionary"));

                //attach each card as xml to the xml document
                foreach (ICard card in cards)
                {
                    printDocumentDictionary.AppendChild(printDocument.ImportNode(card.Card, true));
                }

                XsltArgumentList arguments = new XsltArgumentList();
                PrintStatusReport printstatusreport;
                arguments.AddParam("questioncaption", String.Empty, Settings.QuestionCaption);
                arguments.AddParam("answercaption", String.Empty, Settings.AnswerCaption);
                arguments.AddParam("Description", String.Empty, dictionary.Description);

                arguments.AddExtensionObject("urn:status", printstatusreport = new PrintStatusReport(backgroundworker, cards.Count, mediaprepareworker));
                arguments.AddExtensionObject("urn:cardobject", new Card(cards[0], this));

                return Transform(printDocument, stylesheet, arguments, printstatusreport);
            }
            catch (Exception)
            {
                return string.Format(Properties.Resources.ERROR_PAGE, Properties.Resources.XSL_ERROR_CAPTION,
                    String.Format(Properties.Resources.XSL_ERROR_TEXT, stylesheet));
            }
        }