private void RenderHtmlUsingXslt(BTBWeatherFeedInfo info, string xsltFile)
        {
            XPathDocument doc       = new XPathDocument(new XmlTextReader(info.Feed, XmlNodeType.Document, null));
            MemoryStream  ms        = new MemoryStream();
            var           transform = new XslCompiledTransform();

            //if we don't have a custom XSLT defined then we should just use the
            //default one which we install with the module
            string xslFolder = HttpContext.Current.Server.MapPath("~/DesktopModules/BTBYahooWeather/Templates/Xslt");

            xsltFile = Path.Combine(xslFolder, xsltFile);

            if (!File.Exists(xsltFile))
            {
                //if we don't have the file call back to the default
                //xslt file which should exist in all instances
                xsltFile = Path.Combine(xslFolder, "weatherReport.xsl");
            }

            transform.Load(xsltFile);
            transform.Transform(doc, null, ms);

            ms.Position          = 0;
            info.TransformedFeed = new StreamReader(ms, System.Text.Encoding.UTF8).ReadToEnd();

            //clean up
            ms.Close();
        }
Ejemplo n.º 2
0
 public static void UpdateBTBWeatherFeed(BTBWeatherFeedInfo feed)
 {
     using (var dataContext = DataContext.Instance())
     {
         var rep = dataContext.GetRepository <BTBWeatherFeedInfo>();
         rep.Update(feed);
     }
 }
Ejemplo n.º 3
0
 public static int AddBTBWeatherFeed(BTBWeatherFeedInfo newFeed)
 {
     using (var dataContext = DataContext.Instance())
     {
         var rep = dataContext.GetRepository <BTBWeatherFeedInfo>();
         rep.Insert(newFeed);
         return(newFeed.WeatherId);
     }
 }
        public void ImportModule(int ModuleID, string Content, string Version, int UserId)
        {
            XmlNode weatherNode = Globals.GetContent(Content, "BTBYahooWeather");

            XmlNodeList nodeList = weatherNode.SelectNodes("url");

            if (nodeList != null)
            {
                for (int i = 0; i < nodeList.Count; i++)
                {
                    BTBWeatherFeedInfo info = new BTBWeatherFeedInfo();
                    info.ModuleId = ModuleID;
                    info.Url      = nodeList[i].InnerText;

                    DataProvider.AddBTBWeatherFeed(info);
                }
            }
        }
        /// <summary>
        /// renders the xml data into the HTML
        /// </summary>
        /// <param name="info"></param>
        /// <param name="moduleConfiguration"></param>
        public void RenderRssData(BTBWeatherFeedInfo info, ModuleInfo moduleConfiguration)
        {
            //work out if we are going to use the XSLT files or the razor engine
            //to render the weather into HTML
            var moduleSettings = new BTBYahooWeatherSettings(moduleConfiguration.TabModuleID);

            switch (moduleSettings.RenderEngine)
            {
            case BTBYahooWeatherSettings.TemplateEngine.Razor:
                RenderHtmlUsingRazor(info, moduleSettings.TemplateName);
                break;

            case BTBYahooWeatherSettings.TemplateEngine.Xlst:
            default:
                RenderHtmlUsingXslt(info, moduleSettings.TemplateName);
                break;
            }
        }
        public void UpdateWeatherFeed(BTBWeatherFeedInfo info, PortalSettings portalSettings, ModuleInfo moduleConfiguration)
        {
            string proxyHost     = Host.GetHostSettingsDictionary()["ProxyServer"];
            string proxyPort     = Host.GetHostSettingsDictionary()["ProxyPort"];
            string proxyUsername = Host.GetHostSettingsDictionary()["ProxyUsername"];
            string proxyPassword = Host.GetHostSettingsDictionary()["ProxyPassword"];

            //version 1.6
            //26/8/2008
            //fix to check if we have a proxy port, in which case we should append to the proxyhost
            //Thanks to Corrie Meyer for finding this bug.
            string proxyUrl = proxyPort.Trim() == string.Empty ? proxyHost : proxyHost + ":" + proxyPort;

            RssReader reader = new RssReader(info.Url, proxyUrl, proxyUsername, proxyPassword);

            //get the raw feed
            info.Feed = reader.Response();

            //render the xml into the HTML
            RenderRssData(info, moduleConfiguration);

            //get the ttl
            int ttl = reader.Ttl();

            if (ttl > -1)
            {
                info.Ttl = reader.Ttl();
            }
            else
            {
                //no value of ttl in feed
                //default to 20 minutes
                info.Ttl = 20;
            }

            //set the date stamps
            info.UpdatedDate  = DateTime.Now;
            info.CachedDate   = DateTime.Now.AddMinutes(info.Ttl);
            info.LocationName = reader.LocationName();

            //cache the feed in the database
            DataProvider.UpdateBTBWeatherFeed(info);
        }
        private void RenderHtmlUsingRazor(BTBWeatherFeedInfo info, string razorTemplate)
        {
            //if we don't have a custom XSLT defined then we should just use the
            //default one which we install with the module
            string razorFolder = HttpContext.Current.Server.MapPath("~/DesktopModules/BTBYahooWeather/Templates/Razor");
            string pathCheck   = Path.Combine(razorFolder, razorTemplate);

            if (!File.Exists(pathCheck))
            {
                //if we don't have the file call back to the default
                //xslt file which should exist in all instances
                razorTemplate = "weatherReport.cshtml";
            }

            using (var stringWriter = new StringWriter())
            {
                var razorEngine = new RazorEngine("~/DesktopModules/BTBYahooWeather/Templates/Razor/" + razorTemplate, null, null);
                razorEngine.Render <MainModel>(stringWriter, new MainModel(info.ModuleId, info.Feed));

                info.TransformedFeed = stringWriter.ToString();
            }
        }