/// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void Page_Load(object sender, EventArgs e)
        {
            lblQuiz.Text = moduleSettings["QuizName"].ToString();

            PieUrl       = new PortalUrlDataType();
            PieUrl.Value = "/Quiz/Pie.gif";

            PortalUrlDataType pt;

            pt       = new PortalUrlDataType();
            pt.Value = moduleSettings["XMLsrc"].ToString();
            string xmlsrc = pt.FullPath;

            bool xmlsrcOk = false;

            if ((xmlsrc != null) && (xmlsrc.Length != 0))
            {
                XmlFile = Server.MapPath(xmlsrc);
                if (File.Exists(XmlFile))
                {
                    //Load xml data
                    xDoc.Load(XmlFile);
                    xmlsrcOk = true;
                }
                else
                {
                    QuizScreen.Visible   = false;
                    ResultScreen.Visible = false;
                    Controls.Add(
                        new LiteralControl("<br>" + "<span class='Error'>" +
                                           General.GetString("FILE_NOT_FOUND").Replace("%1%", xmlsrc) + "<br>"));
                }
            }

            //Start a new quiz?
            if (!Page.IsPostBack)
            {
                if (xmlsrcOk)
                {
                    //Yes! Count total question
                    intTotalQuestion = xDoc.SelectNodes("/quiz/mchoice").Count;

                    //Record start time
                    ViewState["StartTime"] = DateTime.Now;

                    ShowQuestion(intQuestionNo);
                }
            }
        }
示例#2
0
        /// <summary>
        /// The Page_Load event handler on this User Control uses
        /// the Portal configuration system to obtain an xml document
        /// and xsl/t transform file location.  It then sets these
        /// properties on an &lt;asp:Xml&gt; server control.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Page_Load(object sender, System.EventArgs e)
        {
            PortalUrlDataType pt;

            pt       = new PortalUrlDataType();
            pt.Value = Settings["XMLsrc"].ToString();
            string xmlsrc = pt.FullPath;

            if ((xmlsrc != null) && (xmlsrc != string.Empty))
            {
                if (System.IO.File.Exists(Server.MapPath(xmlsrc)))
                {
                    xml1.DocumentSource = xmlsrc;
                    // Change - 28/Feb/2003 - Jeremy Esland
                    // Builds cache dependency files list
                    this.ModuleConfiguration.CacheDependency.Add(Server.MapPath(xmlsrc));
                }
                else
                {
                    Controls.Add(new LiteralControl("<br>" + "<span class='Error'>" + Esperantus.Localize.GetString("FILE_NOT_FOUND").Replace("%1%", xmlsrc) + "<br>"));
                }
            }

            pt       = new PortalUrlDataType();
            pt.Value = Settings["XSLsrc"].ToString();
            string xslsrc = pt.FullPath;

            if ((xslsrc != null) && (xslsrc != string.Empty))
            {
                if (System.IO.File.Exists(Server.MapPath(xslsrc)))
                {
                    xml1.TransformSource = xslsrc;
                    // Change - 28/Feb/2003 - Jeremy Esland
                    // Builds cache dependency files list
                    this.ModuleConfiguration.CacheDependency.Add(Server.MapPath(xslsrc));
                }
                else
                {
                    Controls.Add(new LiteralControl("<br>" + "<span class='Error'>" + Esperantus.Localize.GetString("FILE_NOT_FOUND").Replace("%1%", xslsrc) + "<br>"));
                }
            }
        }
示例#3
0
        /// <summary>
        /// The Page_Load event handler on this User Control uses
        /// the Portal configuration system to obtain an xml document
        /// and xsl/t transform file location.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Page_Load(object sender, System.EventArgs e)
        {
            XslTransform      xs;
            XPathDocument     xd;
            XsltArgumentList  xa = new XsltArgumentList();
            XslHelper         xh = new XslHelper();
            StringBuilder     sb = new StringBuilder();
            TextWriter        tw = new StringWriter(sb);
            PortalUrlDataType pt;

            pt       = new PortalUrlDataType();
            pt.Value = Settings["XMLsrc"].ToString();
            string xmlsrc = Server.MapPath(pt.FullPath);

            pt       = new PortalUrlDataType();
            pt.Value = Settings["XSLsrc"].ToString();
            string xslsrc = Server.MapPath(pt.FullPath);

            if ((xmlsrc != null) && (xmlsrc != string.Empty) &&
                (xslsrc != null) && (xslsrc != string.Empty) &&
                File.Exists(xmlsrc) &&
                File.Exists(xslsrc))
            {
                xd = new XPathDocument(xmlsrc);
                xs = new XslTransform();
                xs.Load(xslsrc);
                xa.AddParam("Lang", string.Empty, this.portalSettings.PortalContentLanguage.Name.ToLower());
                xa.AddExtensionObject("urn:rainbow", xh);
#if FW11
                xs.Transform(xd, xa, tw, new XmlUrlResolver());
#else
                xs.Transform(xd, xa, tw);
#endif
                this.Content = sb.ToString();
                this.ContentHolder.Controls.Add(new LiteralControl(this.Content.ToString()));

                this.ModuleConfiguration.CacheDependency.Add(xslsrc);
                this.ModuleConfiguration.CacheDependency.Add(xmlsrc);
            }
        }
        /// <summary>
        /// Fills the settingsXml parameter with the xml from a file
        /// </summary>
        /// <param name="settingsXml">The settings XML.</param>
        /// <param name="file">The file.</param>
        /// <returns></returns>
        protected bool GetSettingsXml(ref XmlDocument settingsXml, string file)
        {
            bool retValue = true;

            PortalUrlDataType pt = new PortalUrlDataType();

            pt.Value = file;
            string xmlFile = pt.FullPath;

            if ((xmlFile != null) && (xmlFile.Length != 0))
            {
                if (File.Exists(Server.MapPath(xmlFile)))
                {
                    settingsXml.Load(Server.MapPath(xmlFile));
                }
                else
                {
                    retValue = false;
                }
            }
            return(retValue);
        }
        public void BindXSL()
        {
            PortalUrlDataType pt = new PortalUrlDataType();

            pt.Value = Settings["XSLsrc"].ToString();
            string xslsrc = pt.FullPath;

            if ((xslsrc != null) && (xslsrc != string.Empty))
            {
                if (System.IO.File.Exists(Server.MapPath(xslsrc)))
                {
                    xmlControl.TransformSource = xslsrc;
                    // Change - 28/Feb/2003 - Jeremy Esland
                    // Builds cache dependency files list
                    this.ModuleConfiguration.CacheDependency.Add(Server.MapPath(xslsrc));
                }
                else
                {
                    xmlControl.TransformSource = Rainbow.Settings.Path.WebPathCombine(Rainbow.Settings.Path.ApplicationRoot, "DesktopModules/UserDefinedTable/default.xslt");
                    Controls.Add(new LiteralControl("<br>" + "<span class='Error'>" + Esperantus.Localize.GetString("FILE_NOT_FOUND").Replace("%1%", xslsrc) + "<br>"));
                }
            }
        }
示例#6
0
        /// <summary>
        /// Fills the settingsXml parameter with the xml from a file
        /// </summary>
        /// <param name="settingsXml">
        /// The settings XML.
        /// </param>
        /// <param name="file">
        /// The file path.
        /// </param>
        /// <returns>
        /// The get settings xml.
        /// </returns>
        protected bool GetSettingsXml(ref XmlDocument settingsXml, string file)
        {
            var retValue = true;

            var pt = new PortalUrlDataType {
                Value = file
            };
            var xmlFile = pt.FullPath;

            if (!string.IsNullOrEmpty(xmlFile))
            {
                if (File.Exists(this.Server.MapPath(xmlFile)))
                {
                    settingsXml.Load(this.Server.MapPath(xmlFile));
                }
                else
                {
                    retValue = false;
                }
            }

            return(retValue);
        }
示例#7
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event.
        /// </summary>
        /// <param name="e">
        /// The <see cref="T:System.EventArgs"/> object that contains the event data.
        /// </param>
        /// <remarks>
        /// The Page_Load event handler on this User Control obtains
        ///   an xml document and xsl/t transform file location.
        ///   It then sets these properties on an &lt;asp:Xml&gt; server control.
        ///   Patch 11/11/2003 by Manu: Errors are logged.
        /// </remarks>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            var xmlsrcType = this.Settings["XML Type"].ToString();
            var xmlsrc = xmlsrcType == "File"
                             ? this.Settings["XML File"].ToString()
                             : this.Settings["XML URL"].ToString();

            var xslsrcType = this.Settings["XSL Type"].ToString();
            var xslsrc = xslsrcType == "File"
                             ? this.Settings["XSL File"].ToString()
                             : this.Settings["XSL Predefined"].ToString();

            // Timeout
            var timeout = int.Parse(this.Settings["Timeout"].ToString());

            if (xmlsrc.Length != 0)
            {
                if (xmlsrcType == "File")
                {
                    var pathXml = new PortalUrlDataType { Value = xmlsrc };
                    xmlsrc = pathXml.FullPath;

                    if (File.Exists(this.Server.MapPath(xmlsrc)))
                    {
                        this.xml1.DocumentSource = xmlsrc;
                    }
                    else
                    {
                        this.Controls.Add(
                            new LiteralControl(
                                string.Format("<br /><div class='error'>File {0} not found.<br /></div>", xmlsrc)));
                    }
                }
                else
                {
                    try
                    {
                        ErrorHandler.Publish(
                            LogLevel.Warn,
                            string.Format("XMLFeed - This should not done more than once in 30 minutes: '{0}'", xmlsrc));

                        // handle on the remote resource
                        var wr = (HttpWebRequest)WebRequest.Create(xmlsrc);

                        // jes1111 - not needed: global proxy is set in Global class Application Start
                        // if (ConfigurationSettings.AppSettings.Get("UseProxyServerForServerWebRequests") == "true")
                        // wr.Proxy = PortalSettings.GetProxy();

                        // set the HTTP properties
                        wr.Timeout = timeout * 1000; // milliseconds to seconds

                        // Read the response
                        var resp = wr.GetResponse();

                        // Stream read the response
                        var stream = resp.GetResponseStream();
                        if (stream != null)
                        {
                            // Read XML data from the stream
                            // ignore the DTD (resolver null)
                            var reader = new XmlTextReader(stream) { XmlResolver = null };

                            // Create a new document object
                            var doc = new XmlDocument();

                            // Create the content of the XML Document from the XML data stream
                            doc.Load(reader);

                            // the XML control to hold the generated XML document
                            this.xml1.Document = doc;
                        }
                    }
                    catch (Exception ex)
                    {
                        // connectivity issues
                        this.Controls.Add(
                            new LiteralControl(
                                string.Format(
                                    "<br /><div class='error'>Error loading: {0}.<br />{1}</div>", xmlsrc, ex.Message)));
                        ErrorHandler.Publish(LogLevel.Error, string.Format("Error loading: {0}.", xmlsrc), ex);
                    }
                }
            }

            if (xslsrcType == "File")
            {
                var pathXsl = new PortalUrlDataType { Value = xslsrc };
                xslsrc = pathXsl.FullPath;
            }
            else
            {
                // if (ConfigurationSettings.AppSettings.Get("XMLFeedXSLFolder") != null)
                // {
                // if (ConfigurationSettings.AppSettings.Get("XMLFeedXSLFolder").ToString().Length > 0)
                //     xslsrc = ConfigurationSettings.AppSettings.Get("XMLFeedXSLFolder").ToString() + xslsrc;
                // else
                //     xslsrc = "~/DesktopModules/CommunityModules/XmlFeed/" + xslsrc;
                // }
                // else
                // {
                //     xslsrc = "~/DesktopModules/CommunityModules/XmlFeed/" + xslsrc;
                // }
                xslsrc =
                    Path.WebPathCombine(
                        Config.XMLFeedXSLFolder.Length == 0 ? this.TemplateSourceDirectory : Config.XMLFeedXSLFolder,
                        xslsrc);

                if (!xslsrc.EndsWith(".xslt"))
                {
                    xslsrc += ".xslt";
                }
            }

            if (!string.IsNullOrEmpty(xslsrc))
            {
                if (File.Exists(this.Server.MapPath(xslsrc)))
                {
                    this.xml1.TransformSource = xslsrc;
                }
                else
                {
                    this.Controls.Add(
                        new LiteralControl(
                            string.Format("<br /><div class='error'>File {0} not found.<br /></div>", xslsrc)));
                }
            }
        }
        /// <summary>
        /// The Page_Load event handler on this User Control obtains
        /// an xml document and xsl/t transform file location.
        /// It then sets these properties on an &lt;asp:Xml&gt; server control.
        /// Patch 11/11/2003 by Manu: Errors are logged.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void Page_Load(object sender, EventArgs e)
        {
            string xmlsrc     = string.Empty;
            string xmlsrcType = Settings["XML Type"].ToString();

            if (xmlsrcType == "File")
            {
                xmlsrc = Settings["XML File"].ToString();
            }
            else
            {
                xmlsrc = Settings["XML URL"].ToString();
            }


            string xslsrc     = string.Empty;
            string xslsrcType = Settings["XSL Type"].ToString();

            if (xslsrcType == "File")
            {
                xslsrc = Settings["XSL File"].ToString();
            }
            else
            {
                xslsrc = Settings["XSL Predefined"].ToString();
            }


            //Timeout
            int timeout = int.Parse(Settings["Timeout"].ToString());

            if ((xmlsrc != null) && (xmlsrc.Length != 0))
            {
                if (xmlsrcType == "File")
                {
                    PortalUrlDataType pathXml = new PortalUrlDataType();
                    pathXml.Value = xmlsrc;
                    xmlsrc        = pathXml.FullPath;

                    if (File.Exists(Server.MapPath(xmlsrc)))
                    {
                        xml1.DocumentSource = xmlsrc;
                    }
                    else
                    {
                        Controls.Add(
                            new LiteralControl("<br><div class='error'>File " + xmlsrc + " not found.<br></div>"));
                    }
                }
                else
                {
                    try
                    {
                        LogHelper.Log.Warn("XMLFeed - This should not done more than once in 30 minutes: '" + xmlsrc +
                                           "'");

                        // handle on the remote ressource
                        HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(xmlsrc);
                        //jes1111 - not needed: global proxy is set in Global class Application Start
                        //						if (ConfigurationSettings.AppSettings.Get("UseProxyServerForServerWebRequests") == "true")
                        //							wr.Proxy = PortalSettings.GetProxy();

                        // set the HTTP properties
                        wr.Timeout = timeout * 1000; // milliseconds to seconds
                        // Read the response
                        WebResponse resp = wr.GetResponse();
                        // Stream read the response
                        Stream stream = resp.GetResponseStream();
                        // Read XML data from the stream
                        XmlTextReader reader = new XmlTextReader(stream);
                        // ignore the DTD
                        reader.XmlResolver = null;
                        // Create a new document object
                        XmlDocument doc = new XmlDocument();
                        // Create the content of the XML Document from the XML data stream
                        doc.Load(reader);
                        // the XML control to hold the generated XML document
                        xml1.Document = doc;
                    }
                    catch (Exception ex)
                    {
                        // connectivity issues
                        Controls.Add(
                            new LiteralControl("<br><div class='error'>Error loading: " + xmlsrc + ".<br>" + ex.Message +
                                               "</div>"));
                        ErrorHandler.Publish(LogLevel.Error, "Error loading: " + xmlsrc + ".", ex);
                    }
                }
            }

            if (xslsrcType == "File")
            {
                PortalUrlDataType pathXsl = new PortalUrlDataType();
                pathXsl.Value = xslsrc;
                xslsrc        = pathXsl.FullPath;
            }
            else
            {
                //				if (ConfigurationSettings.AppSettings.Get("XMLFeedXSLFolder") != null)
                //				{
                //					if (ConfigurationSettings.AppSettings.Get("XMLFeedXSLFolder").ToString().Length > 0)
                //						xslsrc = ConfigurationSettings.AppSettings.Get("XMLFeedXSLFolder").ToString() + xslsrc;
                //					else
                //						xslsrc = "~/DesktopModules/CommunityModules/XmlFeed/" + xslsrc;
                //				}
                //				else
                //				{
                //					xslsrc = "~/DesktopModules/CommunityModules/XmlFeed/" + xslsrc;
                //				}
                if (Config.XMLFeedXSLFolder.Length == 0)
                {
                    xslsrc = Path.WebPathCombine(TemplateSourceDirectory, xslsrc);
                }
                else
                {
                    xslsrc = Path.WebPathCombine(Config.XMLFeedXSLFolder, xslsrc);
                }

                if (!xslsrc.EndsWith(".xslt"))
                {
                    xslsrc += ".xslt";
                }
            }

            if ((xslsrc != null) && (xslsrc.Length != 0))
            {
                if (File.Exists(Server.MapPath(xslsrc)))
                {
                    xml1.TransformSource = xslsrc;
                }
                else
                {
                    Controls.Add(new LiteralControl("<br><div class='error'>File " + xslsrc + " not found.<br></div>"));
                }
            }
        }
示例#9
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event.
        /// </summary>
        /// <param name="e">
        /// The <see cref="T:System.EventArgs"/> object that contains the event data.
        /// </param>
        /// <remarks>
        /// The Page_Load event handler on this User Control obtains
        ///   an xml document and xsl/t transform file location.
        ///   It then sets these properties on an &lt;asp:Xml&gt; server control.
        ///   Patch 11/11/2003 by Manu: Errors are logged.
        /// </remarks>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            var xmlsrcType = this.Settings["XML Type"].ToString();
            var xmlsrc     = xmlsrcType == "File"
                             ? this.Settings["XML File"].ToString()
                             : this.Settings["XML URL"].ToString();

            var xslsrcType = this.Settings["XSL Type"].ToString();
            var xslsrc     = xslsrcType == "File"
                             ? this.Settings["XSL File"].ToString()
                             : this.Settings["XSL Predefined"].ToString();

            // Timeout
            var timeout = int.Parse(this.Settings["Timeout"].ToString());

            if (xmlsrc.Length != 0)
            {
                if (xmlsrcType == "File")
                {
                    var pathXml = new PortalUrlDataType {
                        Value = xmlsrc
                    };
                    xmlsrc = pathXml.FullPath;

                    if (File.Exists(this.Server.MapPath(xmlsrc)))
                    {
                        this.xml1.DocumentSource = xmlsrc;
                    }
                    else
                    {
                        this.Controls.Add(
                            new LiteralControl(
                                string.Format("<br /><div class='error'>File {0} not found.<br /></div>", xmlsrc)));
                    }
                }
                else
                {
                    try
                    {
                        ErrorHandler.Publish(
                            LogLevel.Warn,
                            string.Format("XMLFeed - This should not done more than once in 30 minutes: '{0}'", xmlsrc));

                        // handle on the remote resource
                        var wr = (HttpWebRequest)WebRequest.Create(xmlsrc);

                        // jes1111 - not needed: global proxy is set in Global class Application Start
                        // if (ConfigurationSettings.AppSettings.Get("UseProxyServerForServerWebRequests") == "true")
                        // wr.Proxy = PortalSettings.GetProxy();

                        // set the HTTP properties
                        wr.Timeout = timeout * 1000; // milliseconds to seconds

                        // Read the response
                        var resp = wr.GetResponse();

                        // Stream read the response
                        var stream = resp.GetResponseStream();
                        if (stream != null)
                        {
                            // Read XML data from the stream
                            // ignore the DTD (resolver null)
                            var reader = new XmlTextReader(stream)
                            {
                                XmlResolver = null
                            };

                            // Create a new document object
                            var doc = new XmlDocument();

                            // Create the content of the XML Document from the XML data stream
                            doc.Load(reader);

                            // the XML control to hold the generated XML document
                            this.xml1.Document = doc;
                        }
                    }
                    catch (Exception ex)
                    {
                        // connectivity issues
                        this.Controls.Add(
                            new LiteralControl(
                                string.Format(
                                    "<br /><div class='error'>Error loading: {0}.<br />{1}</div>", xmlsrc, ex.Message)));
                        ErrorHandler.Publish(LogLevel.Error, string.Format("Error loading: {0}.", xmlsrc), ex);
                    }
                }
            }

            if (xslsrcType == "File")
            {
                var pathXsl = new PortalUrlDataType {
                    Value = xslsrc
                };
                xslsrc = pathXsl.FullPath;
            }
            else
            {
                // if (ConfigurationSettings.AppSettings.Get("XMLFeedXSLFolder") != null)
                // {
                // if (ConfigurationSettings.AppSettings.Get("XMLFeedXSLFolder").ToString().Length > 0)
                //     xslsrc = ConfigurationSettings.AppSettings.Get("XMLFeedXSLFolder").ToString() + xslsrc;
                // else
                //     xslsrc = "~/DesktopModules/CommunityModules/XmlFeed/" + xslsrc;
                // }
                // else
                // {
                //     xslsrc = "~/DesktopModules/CommunityModules/XmlFeed/" + xslsrc;
                // }
                xslsrc =
                    Path.WebPathCombine(
                        Config.XMLFeedXSLFolder.Length == 0 ? this.TemplateSourceDirectory : Config.XMLFeedXSLFolder,
                        xslsrc);

                if (!xslsrc.EndsWith(".xslt"))
                {
                    xslsrc += ".xslt";
                }
            }

            if (!string.IsNullOrEmpty(xslsrc))
            {
                if (File.Exists(this.Server.MapPath(xslsrc)))
                {
                    this.xml1.TransformSource = xslsrc;
                }
                else
                {
                    this.Controls.Add(
                        new LiteralControl(
                            string.Format("<br /><div class='error'>File {0} not found.<br /></div>", xslsrc)));
                }
            }
        }
示例#10
0
        /// <summary>
        /// The Page_Load event handler on this User Control uses
        ///   the Portal configuration system to obtain an xml document
        ///   and xsl/t transform file location.  It then sets these
        ///   properties on an &lt;asp:Xml&gt; server control.
        /// </summary>
        /// <param name="e">
        /// The <see cref="System.EventArgs"/> instance containing the event data.
        /// </param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var xmlSetting = this.Settings["XMLsrc"].ToString();

            if (xmlSetting.StartsWith("http://") || xmlSetting.StartsWith("https://"))
            {
                try {
                    var wr = (HttpWebRequest)WebRequest.Create(xmlSetting);

                    // set the HTTP properties
                    wr.Timeout = 300 * 1000; // milliseconds to seconds

                    // Read the response
                    var resp = wr.GetResponse();

                    // Stream read the response
                    var stream = resp.GetResponseStream();
                    if (stream != null)
                    {
                        // Read XML data from the stream
                        // ignore the DTD (resolver null)
                        var reader = new XmlTextReader(stream)
                        {
                            XmlResolver = null
                        };

                        // Create a new document object
                        var doc = new XmlDocument();

                        // Create the content of the XML Document from the XML data stream
                        doc.Load(reader);

                        // the XML control to hold the generated XML document
                        this.xml1.Document = doc;
                    }
                }
                catch (Exception ex) {
                    this.Controls.Add(
                        new LiteralControl(
                            string.Format(
                                "<br /><span class='Error'>{0}<br />",
                                General.GetString("FILE_NOT_FOUND").Replace("%1%", xmlSetting))));
                    ErrorHandler.Publish(LogLevel.Error, ex);
                }
            }
            else
            {
                var pt = new PortalUrlDataType {
                    Value = this.Settings["XMLsrc"].ToString()
                };
                var xmlsrc = pt.FullPath;

                if (!string.IsNullOrEmpty(xmlsrc))
                {
                    if (File.Exists(this.Server.MapPath(xmlsrc)))
                    {
                        this.xml1.DocumentSource = xmlsrc;

                        // Change - 28/Feb/2003 - Jeremy Esland
                        // Builds cache dependency files list
                        this.ModuleConfiguration.CacheDependency.Add(this.Server.MapPath(xmlsrc));
                    }
                    else
                    {
                        this.Controls.Add(
                            new LiteralControl(
                                string.Format(
                                    "<br /><span class='Error'>{0}<br />",
                                    General.GetString("FILE_NOT_FOUND").Replace("%1%", xmlsrc))));
                    }
                }
            }

            var xslSetting = this.Settings["XSLsrc"].ToString();

            if (xslSetting.StartsWith("http://") || xslSetting.StartsWith("https://"))
            {
                try {
                    var t = new XslTransform();
                    t.Load(xslSetting);
                    xml1.Transform = t;
                }
                catch (Exception ex) {
                    this.Controls.Add(
                        new LiteralControl(
                            string.Format(
                                "<br /><span class='Error'>{0}<br />",
                                General.GetString("FILE_NOT_FOUND").Replace("%1%", xslSetting))));
                    ErrorHandler.Publish(LogLevel.Error, ex);
                }
            }
            else
            {
                var pt = new PortalUrlDataType {
                    Value = this.Settings["XSLsrc"].ToString()
                };
                var xslsrc = pt.FullPath;

                if (string.IsNullOrEmpty(xslsrc))
                {
                    return;
                }

                if (File.Exists(this.Server.MapPath(xslsrc)))
                {
                    this.xml1.TransformSource = xslsrc;

                    // Change - 28/Feb/2003 - Jeremy Esland
                    // Builds cache dependency files list
                    this.ModuleConfiguration.CacheDependency.Add(this.Server.MapPath(xslsrc));
                }
                else
                {
                    this.Controls.Add(
                        new LiteralControl(
                            string.Format(
                                "<br /><span class='Error'>{0}<br />",
                                General.GetString("FILE_NOT_FOUND").Replace("%1%", xslsrc))));
                }
            }
        }
示例#11
0
        /// <summary>
        /// Fills the settingsXml parameter with the xml from a file
        /// </summary>
        /// <param name="settingsXml">
        /// The settings XML.
        /// </param>
        /// <param name="file">
        /// The file path.
        /// </param>
        /// <returns>
        /// The get settings xml.
        /// </returns>
        protected bool GetSettingsXml(ref XmlDocument settingsXml, string file)
        {
            var retValue = true;

            var pt = new PortalUrlDataType { Value = file };
            var xmlFile = pt.FullPath;

            if (!string.IsNullOrEmpty(xmlFile))
            {
                if (File.Exists(this.Server.MapPath(xmlFile)))
                {
                    settingsXml.Load(this.Server.MapPath(xmlFile));
                }
                else
                {
                    retValue = false;
                }
            }

            return retValue;
        }
示例#12
0
        /// <summary>
        /// The Page_Load event handler on this User Control uses
        ///   the Portal configuration system to obtain an xml document
        ///   and xsl/t transform file location.  It then sets these
        ///   properties on an &lt;asp:Xml&gt; server control.
        /// </summary>
        /// <param name="e">
        /// The <see cref="System.EventArgs"/> instance containing the event data.
        /// </param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var xmlSetting = this.Settings["XMLsrc"].ToString();

            if (xmlSetting.StartsWith("http://") || xmlSetting.StartsWith("https://")) {
                try {
                    var wr = (HttpWebRequest)WebRequest.Create(xmlSetting);

                    // set the HTTP properties
                    wr.Timeout = 300 * 1000; // milliseconds to seconds

                    // Read the response
                    var resp = wr.GetResponse();

                    // Stream read the response
                    var stream = resp.GetResponseStream();
                    if (stream != null) {
                        // Read XML data from the stream
                        // ignore the DTD (resolver null)
                        var reader = new XmlTextReader(stream) { XmlResolver = null };

                        // Create a new document object
                        var doc = new XmlDocument();

                        // Create the content of the XML Document from the XML data stream
                        doc.Load(reader);

                        // the XML control to hold the generated XML document
                        this.xml1.Document = doc;
                    }
                }
                catch (Exception ex) {
                    this.Controls.Add(
                            new LiteralControl(
                                string.Format(
                                    "<br /><span class='Error'>{0}<br />",
                                    General.GetString("FILE_NOT_FOUND").Replace("%1%", xmlSetting))));
                    ErrorHandler.Publish(LogLevel.Error, ex);
                }
            }
            else {
                var pt = new PortalUrlDataType { Value = this.Settings["XMLsrc"].ToString() };
                var xmlsrc = pt.FullPath;

                if (!string.IsNullOrEmpty(xmlsrc)) {
                    if (File.Exists(this.Server.MapPath(xmlsrc))) {
                        this.xml1.DocumentSource = xmlsrc;

                        // Change - 28/Feb/2003 - Jeremy Esland
                        // Builds cache dependency files list
                        this.ModuleConfiguration.CacheDependency.Add(this.Server.MapPath(xmlsrc));
                    }
                    else {
                        this.Controls.Add(
                            new LiteralControl(
                                string.Format(
                                    "<br /><span class='Error'>{0}<br />",
                                    General.GetString("FILE_NOT_FOUND").Replace("%1%", xmlsrc))));
                    }
                }
            }

            var xslSetting = this.Settings["XSLsrc"].ToString();
            if (xslSetting.StartsWith("http://") || xslSetting.StartsWith("https://")) {
                try {

                    var t = new XslTransform();
                    t.Load(xslSetting);
                    xml1.Transform = t;

                }
                catch (Exception ex) {

                    this.Controls.Add(
                        new LiteralControl(
                            string.Format(
                                "<br /><span class='Error'>{0}<br />",
                                General.GetString("FILE_NOT_FOUND").Replace("%1%", xslSetting))));
                    ErrorHandler.Publish(LogLevel.Error, ex);
                }

            }
            else {
                var pt = new PortalUrlDataType { Value = this.Settings["XSLsrc"].ToString() };
                var xslsrc = pt.FullPath;

                if (string.IsNullOrEmpty(xslsrc)) {
                    return;
                }

                if (File.Exists(this.Server.MapPath(xslsrc))) {
                    this.xml1.TransformSource = xslsrc;

                    // Change - 28/Feb/2003 - Jeremy Esland
                    // Builds cache dependency files list
                    this.ModuleConfiguration.CacheDependency.Add(this.Server.MapPath(xslsrc));
                }
                else {
                    this.Controls.Add(
                        new LiteralControl(
                            string.Format(
                                "<br /><span class='Error'>{0}<br />",
                                General.GetString("FILE_NOT_FOUND").Replace("%1%", xslsrc))));
                }
            }
        }
示例#13
0
        /// <summary>
        /// The Page_Load event handler on this User Control uses
        ///   the Portal configuration system to obtain an xml document
        ///   and xsl/t transform file location.  It then sets these
        ///   properties on an &lt;asp:Xml&gt; server control.
        /// </summary>
        /// <param name="e">
        /// The <see cref="System.EventArgs"/> instance containing the event data.
        /// </param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var xmlSetting = this.Settings["XMLsrc"].ToString();

            if (xmlSetting.StartsWith("http://") || xmlSetting.StartsWith("https://"))
            {
                try
                {
                    var wr = (HttpWebRequest)WebRequest.Create(xmlSetting);

                    // set the HTTP properties
                    wr.Timeout = 300 * 1000; // milliseconds to seconds

                    // Read the response
                    var resp = wr.GetResponse();

                    // Stream read the response
                    var stream = resp.GetResponseStream();
                    if (stream != null)
                    {
                        // Read XML data from the stream
                        // ignore the DTD (resolver null)
                        var reader = new XmlTextReader(stream)
                        {
                            XmlResolver = null
                        };

                        // Create a new document object
                        // var doc = new XmlDocument();

                        // Create the content of the XML Document from the XML data stream
                        //doc.Load(reader);

                        // the XML control to hold the generated XML document
                        //this.xml1.Document = doc;
                        this.xml1.DocumentContent = (new XPathDocument(reader)).CreateNavigator().OuterXml;
                    }
                }
                catch (Exception ex)
                {
                    this.Controls.Add(
                        new LiteralControl(
                            string.Format(
                                "<br /><span class='Error'>{0}<br />",
                                General.GetString("FILE_NOT_FOUND").Replace("%1%", xmlSetting))));
                    ErrorHandler.Publish(LogLevel.Error, ex);
                }
            }
            else
            {
                var pt = new PortalUrlDataType {
                    Value = this.Settings["XMLsrc"].ToString()
                };
                var xmlsrc = pt.FullPath;

                if (!string.IsNullOrEmpty(xmlsrc))
                {
                    if (File.Exists(this.Server.MapPath(xmlsrc)))
                    {
                        this.xml1.DocumentSource = xmlsrc;

                        // Change - 28/Feb/2003 - Jeremy Esland
                        // Builds cache dependency files list
                        this.ModuleConfiguration.CacheDependency.Add(this.Server.MapPath(xmlsrc));
                    }
                    else
                    {
                        this.Controls.Add(
                            new LiteralControl(
                                string.Format(
                                    "<br /><span class='Error'>{0}<br />",
                                    General.GetString("FILE_NOT_FOUND").Replace("%1%", xmlsrc))));
                    }
                }
            }

            //Xslt file
            var xslSetting = this.Settings["XSLsrc"].ToString();

            if (xslSetting.StartsWith("http://") || xslSetting.StartsWith("https://"))
            {
                try
                {
                    var wr = (HttpWebRequest)WebRequest.Create(xslSetting);
                    wr.Timeout = 300 * 1000; // milliseconds to seconds

                    // Read the response
                    var resp = wr.GetResponse();

                    // Stream read the response
                    var stream = resp.GetResponseStream();
                    if (stream != null)
                    {
                        // Read XML data from the stream
                        // ignore the DTD (resolver null)
                        var reader = new XmlTextReader(stream)
                        {
                            XmlResolver = null
                        };
                        string filedata;
                        using (WebClient client = new WebClient())
                        {
                            filedata = client.DownloadString(this.Settings["XSLsrc"].ToString());
                        }

                        //string fileName = Server.MapPath("/Portals/_Appleseed/XsltSource.Xslt");
                        string filepath = System.Configuration.ConfigurationManager.AppSettings["XsltFilePath"];

                        if (filepath != "" || !string.IsNullOrEmpty(filepath))
                        {
                            string serverpath = Server.MapPath(filepath);
                            if (File.Exists(serverpath))
                            {
                                System.IO.File.SetAttributes(serverpath, FileAttributes.Normal);
                                System.IO.File.Delete(serverpath);

                                using (FileStream fs = File.Create(serverpath))
                                {
                                    // Add html to file
                                    Byte[] title = new UTF8Encoding(true).GetBytes(filedata);
                                    fs.Write(title, 0, title.Length);
                                }

                                this.xml1.TransformSource = serverpath;
                            }
                        }
                        else
                        {
                            string directory = Server.MapPath("/XsltFiles");
                            string path      = Server.MapPath("/XsltFiles/XslFiles.xslt");
                            if (System.IO.Directory.Exists(directory))
                            {
                                if (File.Exists(path))
                                {
                                    System.IO.File.SetAttributes(path, FileAttributes.Normal);
                                    System.IO.File.Delete(path);
                                }
                                System.IO.Directory.Delete(Server.MapPath("/XsltFiles"));
                            }

                            System.IO.Directory.CreateDirectory(directory);
                            using (FileStream fs = File.Create(directory + "/" + "XslFiles.xslt"))
                            {
                                // Add html to file
                                Byte[] title = new UTF8Encoding(true).GetBytes(filedata);
                                fs.Write(title, 0, title.Length);
                            }

                            this.xml1.TransformSource = path;
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.Controls.Add(
                        new LiteralControl(
                            string.Format(
                                "<br /><span class='Error'>{0}<br />",
                                General.GetString("FILE_NOT_FOUND").Replace("%1%", xslSetting))));
                    ErrorHandler.Publish(LogLevel.Error, ex);
                }
            }
            else
            {
                var pt = new PortalUrlDataType {
                    Value = this.Settings["XSLsrc"].ToString()
                };
                var xslsrc = pt.FullPath;

                if (string.IsNullOrEmpty(xslsrc))
                {
                    return;
                }

                if (File.Exists(this.Server.MapPath(xslsrc)))
                {
                    this.xml1.TransformSource = xslsrc;

                    // Change - 28/Feb/2003 - Jeremy Esland
                    // Builds cache dependency files list
                    this.ModuleConfiguration.CacheDependency.Add(this.Server.MapPath(xslsrc));
                }
                else
                {
                    this.Controls.Add(
                        new LiteralControl(
                            string.Format(
                                "<br /><span class='Error'>{0}<br />",
                                General.GetString("FILE_NOT_FOUND").Replace("%1%", xslsrc))));
                }
            }
        }